Skip to content
This repository was archived by the owner on Dec 17, 2021. It is now read-only.

Commit 4c5a841

Browse files
authored
fix: call str() or prettyPrint() before sending data to MIB-server (#72)
1 parent 16c9e4d commit 4c5a841

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

splunk_connect_for_snmp_traps/manager/mib_server_client.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import logging
21
import json
3-
import requests
2+
import logging
43
import os
4+
5+
import requests
56
from requests.adapters import HTTPAdapter
67
from requests.packages.urllib3.util.retry import Retry
78

9+
from splunk_connect_for_snmp_traps.utilities import format_value_for_mib_server
10+
811
logger = logging.getLogger(__name__)
912

1013

@@ -22,7 +25,7 @@ def get_translation(var_binds, mib_server_url):
2225
var_bind = {
2326
"oid": str(name),
2427
"oid_type": name.__class__.__name__,
25-
"val": str(val),
28+
"val": format_value_for_mib_server(val),
2629
"val_type": val.__class__.__name__,
2730
}
2831
var_binds_list.append(var_bind)

splunk_connect_for_snmp_traps/utilities.py

+21
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,24 @@ def initialize_signals_handler():
2929
)
3030
for one_signal in signals_to_catch:
3131
signal.signal(one_signal, default_signal_handler)
32+
33+
34+
# 1.3.6.1.2.1.2.2.1.4.1|Integer|16436|16436|True
35+
# 1.3.6.1.2.1.1.6.0|DisplayString|San Francisco, California, United States|San Francisco, California, United States|True
36+
# 1.3.6.1.2.1.2.2.1.6.2|OctetString|<null>ybù@|0x00127962f940|False
37+
# 1.3.6.1.2.1.1.9.1.2.7|ObjectIdentity|1.3.6.1.2.1.50|SNMPv2-SMI::mib-2.50|False
38+
# 1.3.6.1.2.1.6.13.1.4.195.218.254.105.51684.194.67.10.226.22|IpAddress|ÂCâ|194.67.10.226|False
39+
# 1.3.6.1.2.1.25.3.2.1.6.1025|Counter32|0|0|True
40+
# 1.3.6.1.2.1.31.1.1.1.15.2|Gauge32|100|100|True
41+
# 1.3.6.1.2.1.1.3.0|TimeTicks|148271768|148271768|True
42+
# 1.3.6.1.4.1.2021.10.1.6.1|Opaque|Ÿx>ë…|0x9f78043eeb851f|False
43+
# 1.3.6.1.2.1.31.1.1.1.10.1|Counter64|453477588|453477588|True
44+
#
45+
# As you can see, for most types str(value) == value.prettyPrint(), however:
46+
# - for Opaque, IpAddress, and OctetString we need to use prettyPrint(), otherwise the data is rubbish
47+
# - any other type should use str() before sending data to MIB-server
48+
def format_value_for_mib_server(value, value_type):
49+
if value_type in ("OctetString", "IpAddress", "Opaque"):
50+
return value.prettyPrint()
51+
else:
52+
return str(value)

0 commit comments

Comments
 (0)