質問

I am trying to store the generated PYSNMP data into mysql database.

The data generated is a tuple or a list—I am not sure.

The output that I get is 9016, but when I wish to save it to the database it is something like (OID(1.3.6.1.1.18443.1.1.), Integer(9016). I got to know about this after I go a print value about it.

I tried with output = re.split(r'', val). Here val has the above mentioned string/tuple.

Need help in getting just the integer data.

役に立ちましたか?

解決

pysnmp returns a sequence of two-component tuples. These components are OID and value. That is called variable-binding in SNMP.

So what you see might be:

varBinds = [ (ObjectIdentifier('1.3.6.1.1.18443.1.1'), Integer(9016)) ]

which is a list of variable-bindings.

To save just the value part of the first variable binding in a sequence you could need to:

varBind = varBinds[0]
oid, value = varBind
str(value)

or

int(value)

depending on the database data type.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top