Reputation:
Does PySNMP support Unicode for sending snmptrap. I sent trap with unicode character in it but I get the result in hex. Is there any work around to get the value in Unicode. e.g. Here is my snmp trap command
sudo snmptrap -v2c -c public 192.168.2.162 '' .1.2.3.4.5.6.7.8.9 ifIndex i 2 ifAdminStatus i 1 1.3.6.1.4.1.9.9.599.1.3.1.1.1.0 s "विवेक सुवेदी"
But in the place of "विवेक सुवेदी", I got 0xe0a4b5e0a4bfe0a4b5e0a587e0a49520e0a4b8e0a581e0a4b5e0a587e0a4a6e0a580 . Is there any way to get unicode?
Upvotes: 0
Views: 814
Reputation: 5555
AFAIK, to properly render UTF-8 strings, MIB object (1.3.6.1.4.1.9.9.599.1.3.1.1.1.0) should be typed as some TEXTUAL-CONVENTION having DISPLAY-STRING="255t" that indicates UTF-8 string.
If that is not the case, SNMP will treat it as a binary string and will not attempt to render it properly. The same happens if you do not use MIB resolution (what converts pure ASN.1/SNMP types into MIB-defined subtypes) and deal with pure ASN.1 objects.
In the latter case a hackerish solution is to skip .prettyPrint()-ing values through SNMP and use them as-is via .asOctets:
>>> print(OctetString(u'кириллица'.encode('utf-8')).asOctets())
кириллица
The problem here is that you might have to programmatically apply this logic to specific OIDs -- this is what MIB is designed for. ;)
Upvotes: 1