SNMP отдает значение OCTET, как разбирать?
-
Как вообще работать с этим значением?
nxsnmpwalk.exe 10.102.12.2 .1.3.6.1.2.1.25.3.5.1.2 .1.3.6.1.2.1.25.3.5.1.2.1 [STRING]: ?
Мониторим принтеры, элемент hrPrinterDetectedErrorStateинтересует oid: 1.3.6.1.2.1.25.3.5.1.2.1 выдаёт octet string (hex string).Из описания
Condition Bit #
lowPaper 0
noPaper 1
lowToner 2
noToner 3
doorOpen 4
jammed 5
offline 6
serviceRequested 7
inputTrayMissing 8
outputTrayMissing 9
markerSupplyMissing 10
outputNearFull 11
outputFull 12
inputTrayEmpty 13
overduePreventMaint 14 -
Если запустить скрипт на ноде, то:
transport = $node->createSNMPTransport(); if (transport == null) exit; value = transport->get(".1.3.6.1.2.1.25.3.5.1.2.1"); if (value == null) exit; bytestream = value->getValueAsByteStream(); bytestream->seek(0); println(bytestream->readByte());bytestream->seek(xxx) позволяет указать, с какого байта мы хотим читать. При создании byte stream будет стоять на 0, так что bytestream->seek(0); делать и не нужно.
Тут мы прочитали один байт. Можно прочитать и сразу два:
println(bytestream->readUInt32B());
или
println(bytestream->readUInt32L());
смотря как они там идут - как Little Endian или Big Endian.Ну и стоит проверить, что bytestream->size достаточной длины, чтоб в нем два байта поместилось.
Судя по описанию там каждый бит сообщает о каком-то состоянии. Нужен ли пример разбора по битам?
------
В документации bytestream не описан, будем потихоньку добавлять. Но информацию об NXSL классах можно добыть прямо в скрипте, это может помочь разобраться:
transport = $node->createSNMPTransport(); if (transport == null) exit; value = transport->get(".1.3.6.1.2.1.25.3.5.1.2.1"); if (value == null) exit; println("========================================================="); println("Class: " . classof(value)); println("=== Attributes ==="); for(a : value->__class->attributes) println(a . " = " . value->__get(a)); println("=== Methods ==="); for(a : value->__class->methods) println(a); bytestream = value->getValueAsByteStream(); println("========================================================="); println("Class: " . classof(bytestream)); println("=== Attributes ==="); for(a : bytestream->__class->attributes) println(a . " = " . bytestream->__get(a)); println("=== Methods ==="); for(a : bytestream->__class->methods) println(a);
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login