<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[SNMP отдает значение OCTET, как разбирать?]]></title><description><![CDATA[<p dir="auto">Как вообще работать с этим значением?</p>
<p dir="auto">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]: ?   <br />
                       <br />
Мониторим принтеры, элемент hrPrinterDetectedErrorStateинтересует oid: 1.3.6.1.2.1.25.3.5.1.2.1 выдаёт octet string (hex string).</p>
<p dir="auto">Из описания</p>
<p dir="auto">            Condition        Bit #</p>
<p dir="auto">            lowPaper              0</p>
<p dir="auto">            noPaper              1<br />
            lowToner              2<br />
            noToner              3<br />
            doorOpen              4<br />
            jammed                5<br />
            offline              6<br />
            serviceRequested      7<br />
            inputTrayMissing      8<br />
            outputTrayMissing    9<br />
            markerSupplyMissing  10<br />
            outputNearFull      11<br />
            outputFull          12<br />
            inputTrayEmpty      13<br />
            overduePreventMaint  14</p>
]]></description><link>https://forum.netxms.org/topic/7580/snmp-отдает-значение-octet-как-разбирать</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Nov 2026 21:28:41 GMT</lastBuildDate><atom:link href="https://forum.netxms.org/topic/7580.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 14 Dec 2022 08:25:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to SNMP отдает значение OCTET, как разбирать? on Thu, 15 Dec 2022 16:13:02 GMT]]></title><description><![CDATA[<p dir="auto">Если запустить скрипт на ноде, то:</p>
<pre><code>transport = $node-&gt;createSNMPTransport();
if (transport == null) exit;
value = transport-&gt;get(".1.3.6.1.2.1.25.3.5.1.2.1");
if (value == null) exit;
bytestream = value-&gt;getValueAsByteStream();
bytestream-&gt;seek(0);
println(bytestream-&gt;readByte());
</code></pre>
<p dir="auto">bytestream-&gt;seek(xxx) позволяет указать, с какого байта мы хотим читать. При создании byte stream будет стоять на 0, так что bytestream-&gt;seek(0); делать и не нужно.</p>
<p dir="auto">Тут мы прочитали один байт. Можно прочитать и сразу два:<br />
println(bytestream-&gt;readUInt32B());<br />
или<br />
println(bytestream-&gt;readUInt32L());<br />
смотря как они там идут - как Little Endian или Big Endian.</p>
<p dir="auto">Ну и стоит проверить, что bytestream-&gt;size достаточной длины, чтоб в нем два байта поместилось.</p>
<p dir="auto">Судя по описанию там каждый бит сообщает о каком-то состоянии. Нужен ли пример разбора по битам?</p>
<p dir="auto">------</p>
<p dir="auto">В документации bytestream не описан, будем потихоньку добавлять. Но информацию об NXSL классах можно добыть прямо в скрипте, это может помочь разобраться:</p>
<pre><code>transport = $node-&gt;createSNMPTransport();
if (transport == null) exit;

value = transport-&gt;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-&gt;__class-&gt;attributes)
  println(a . " = " . value-&gt;__get(a));
println("=== Methods ===");
for(a : value-&gt;__class-&gt;methods)
  println(a);

bytestream = value-&gt;getValueAsByteStream();

println("=========================================================");
println("Class: " . classof(bytestream));
println("=== Attributes ===");
for(a : bytestream-&gt;__class-&gt;attributes)
  println(a . " = " . bytestream-&gt;__get(a));
println("=== Methods ===");
for(a : bytestream-&gt;__class-&gt;methods)
  println(a);
</code></pre>
]]></description><link>https://forum.netxms.org/post/32087</link><guid isPermaLink="true">https://forum.netxms.org/post/32087</guid><dc:creator><![CDATA[Filipp Sudanov]]></dc:creator><pubDate>Thu, 15 Dec 2022 16:13:02 GMT</pubDate></item></channel></rss>