Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support (Russian)
  3. SNMP отдает значение OCTET, как разбирать?

SNMP отдает значение OCTET, как разбирать?

Scheduled Pinned Locked Moved Support (Russian)
2 Posts 2 Posters 4.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A
    A
    Akira
    wrote on last edited by
    #1

    Как вообще работать с этим значением?

    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

    1 Reply Last reply
    0
    • F
      F
      Filipp Sudanov
      wrote on last edited by
      #2

      Если запустить скрипт на ноде, то:

      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);
      
      1 Reply Last reply
      0

      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
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      Powered by NodeBB Contributors
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups