如何读取 SNMP OID 输出(位)(hrPrinterDetectedErrorState)

2023-12-04

我有一个快速的问题。这很可能是用户错误,所以在开始之前我深表歉意。

我正在尝试为设备设置阈值,以便当我们的一台打印机处于某种状态时它会提醒我们。 (卡纸、碳粉用完、无纸等)我找到了处理此问题的特定 oid。 (1.3.6.1.2.1.25.3.5.1.2.1) 具体的 oid 在 HOST-RESOURCE-MIB 下称为 hrPrinterDetectedErrorState。我已经验证我可以通过 SNMPWALK 查看 oid。我的问题是解释它吐出的数据。我在 MIB 中读到的内容和通过 SNMPWALK 看到的内容是不同的。

以下是 MIB 中对 oid 的描述:

     "This object represents any error conditions detected
      by the printer.  The error conditions are encoded as
      bits in an octet string, with the following
      definitions:

            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

      Bits are numbered starting with the most significant
      bit of the first byte being bit 0, the least
      significant bit of the first byte being bit 7, the
      most significant bit of the second byte being bit 8,
      and so on.  A one bit encodes that the condition was
      detected, while a zero bit encodes that the condition
      was not detected.

      This object is useful for alerting an operator to
      specific warning or error conditions that may occur,
      especially those requiring human intervention."

奇怪的是,SNMPWALK 说 oid 是一个十六进制字符串,而 MIB 指定它应该是一个八位字节字符串。两者有不同吗?我是否需要以某种方式转换 SNMPWALK 输出的数据以使其与 MIB 所说的内容匹配?

为了测试一切,我将打印机置于几种不同的“状态”。然后我在设备上运行 SNMPWALK 以查看 oid 输出的内容。这是结果。正如您将看到的,这些结果与 MIB 指定的不匹配。

Case 1: Opened the toner door

Expected Output based on MIB: 4
SNMP Output: 08

Case 2: Removed Toner & Closed the door

Expected Output based on MIB:  1
SNMP Output:  10

Case 3: Placed 1 sheet of paper and printed a 2 page document. The printer ran out of paper.

Expected Output based on MIB: 0 or 1
SNMP Output: @

我对输出感到困惑。我只需要知道如何读取 oid,以便我可以设置阈值,以便当它看到(例如)08 时,它会执行特定操作。

感谢您的帮助!


你读错了。您收到的数据实际上应该被解释为一个位数组,每个位都是您的情况下特定警报的自己的值

Expected Output based on MIB: 4
SNMP Output: 08

你实际上得到了输出:

00001000 00000000

这里的第一个字节涵盖了这些值

lowPaper             0
noPaper              1
lowToner             2
noToner              3
doorOpen             4
jammed               5
offline              6
serviceRequested     7

So lowPaper是位 0,noPaper是位 1,lowToner是位 2,等等。并且doorOpen是位 4,正如您所看到的,该位已设置,表明门已打开。

EDIT:

这非常依赖于设备和实现。要知道如何正确解析它需要大量的尝试和错误(至少从我的经验来看)。例如,如果您收到消息 9104,则可能是

91 and 04 are separate so you first translate 91 to binary from hex and then the 
same thing with 04
91: 10010001
04: 00000100

这意味着纸张不足、无碳粉、请求服务且 inputTray 为空。这看起来是最有可能的工作方式。

如果您只返回一个字节,则意味着您应该只在前 8 位中查找警报。作为您需要注意的事情的一个例子:如果唯一存在的警报是doorOpen,您可能只返回08,但实际上是0008,其中前2个十六进制字符实际上是警报的第二部分,但不是显示是因为它们不存在。所以在你的情况下,你实际上首先必须切换字节(如果有4个)自己解析前两个和后两个,然后你得到实际的结果。

正如我所说,从我所看到的来看,这里没有真正的标准,您必须使用它,直到您确定您知道数据是如何发送以及如何解析它为止。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何读取 SNMP OID 输出(位)(hrPrinterDetectedErrorState) 的相关文章

随机推荐