如何读取 SNMP OID 输出(位) [英] How to read SNMP OID Output (bits)

查看:132
本文介绍了如何读取 SNMP OID 输出(位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题.很可能是用户错误,所以在开始之前我先道歉.

I have a quick question. Its most likely user error so I apologize before I begin.

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

I’m trying to setup threshold for a device so that it will alert us when one of our printers is in a certain state. (Jammed, out of toner, no paper etc) I’ve found the specific oid that handles this. (1.3.6.1.2.1.25.3.5.1.2.1) The specific oid is called hrPrinterDetectedErrorState under the HOST-RESOURCE-MIB. I’ve verified that I can see the oid via SNMPWALK. My problem is interpreting the data its spitting out. What i'm reading in the MIB and what i'm seeing via SNMPWALK are different.

这是来自 MIB 的 oid 描述:

Here is the description of oid from the MIB:

     "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 所说的相符?

The odd part is that SNMPWALK says the oid is a Hex-String while the MIB specifies that it should be a Octet-String. Are the two different? Do I need to convert the data that is output by SNMPWALK somehow to get it to match up with what the MIB is saying?

为了测试一切,我将打印机置于几个不同的状态".然后我在设备上运行 SNMPWALK 以查看 oid 输出.这是结果.如您所见,这些结果与 MIB 指定的不符.

To test everything, I put the printer into several different "States." I then ran an SNMPWALK on the device to see what the oid output. Here are the results. As you will see, these results don’t match up to what the MIB specifies.

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 时它会执行特定操作.

I’m confused at the output. I just need to know how to read the oid so I can setup thresholds so that when it sees, for example, a 08 it performs a certain action.

感谢您的帮助!

推荐答案

你读错了.您收到的数据实际上应该被解释为一个位数组,并且每一位都是您案例中特定警报的自己的值

You are reading this wrong. The data you receive back should actually be interpreted as a bit array and every bit is its own value for the specific alarm in your case

Expected Output based on MIB: 4
SNMP Output: 08

你实际上得到了输出:

00001000 00000000

这里的第一个字节包含这些值

The first byte here covers those values

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

所以 lowPaper 是第 0 位,noPaper 是第 1 位,lowToner 是第 2 位,等等.还有 doorOpen> 是第 4 位,如您所见,该位已设置,表示门已打开.

So lowPaper is bit 0, noPaper is bit 1, lowToner is bit 2, etc. And doorOpen is bit 4 and as you can see that bit is set, indicating that the door is open.

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

This is very dependent on the device and implementation. To know how to parse it right involves a lot of trial and error (at least from my experience). As an example if you get back the message 9104, this could be either be

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

这意味着纸张不足、无墨粉、服务请求和 inputTrayEmpty.这看起来是最有可能的工作方式.

Which would mean low paper, noToner, service requested and inputTrayEmpty. This looks like the most likely way this works.

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

If you only get one byte back this then means you should only look for alarms in the first 8 bits. As a example of things you need to look out for: If the only alarm present is doorOpen you could be getting back only 08 but it would actually be 0008 where the first 2 hex chars are actually the second part of the alarms but aren't shown because they are none present. So in your case you actually first have to switch the bytes (if there are 4) parse the first two and the second two on their own and then you get the actual result.

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

As I said there is no real standard here from what i have seen and you have to just work with it until you are sure you know how the data is sent and how to parse it.

这篇关于如何读取 SNMP OID 输出(位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆