Skip to content
Permalink
Browse files

Made mib translation configurable

  • Loading branch information
LarsMichelsen committed Apr 29, 2015
1 parent 06d2dc8 commit 9dd71752d223cc56c4d34f533610ce4096846da4
Showing with 52 additions and 19 deletions.
  1. +40 −17 mkeventd/bin/mkeventd
  2. +12 −2 mkeventd/web/plugins/wato/mkeventd.py
@@ -1150,6 +1150,22 @@ class EventServer:

return os.open(g_pipe_path, os.O_RDWR | os.O_NONBLOCK)

def load_mibs(self):
builder = MibBuilder() # manages python MIB modules

# load MIBs from our compiled MIB and default MIB paths
builder.setMibSources(*[DirMibSource(g_compiled_mibs_dir)]
+ list(builder.getMibSources()))

# Indicate we wish to load DESCRIPTION and other texts from MIBs
builder.loadTexts = True

# This loads all or specified pysnmp MIBs into memory
builder.loadModules()

# This object maintains various indices built from MIBs data
self._mib_resolver = MibViewController(builder)

# Format time difference seconds into approximated
# human readable value
def fmt_timeticks(self, ticks):
@@ -1168,26 +1184,28 @@ class EventServer:
days, hours = divmod(hours, 24)
return "%d days, %d hours, %d min" % (days, hours, mins)

# Convert pysnmp datatypes to simply handable ones
def snmptrap_convert_var_binds(self, var_bind_list):
var_binds = []
for oid, value in var_bind_list:
key = str(oid)

def load_mibs(self):
builder = MibBuilder() # manages python MIB modules

# load MIBs from our compiled MIB and default MIB paths
builder.setMibSources(*[DirMibSource(g_compiled_mibs_dir)]
+ list(builder.getMibSources()))

# Indicate we wish to load DESCRIPTION and other texts from MIBs
builder.loadTexts = True

# This loads all or specified pysnmp MIBs into memory
builder.loadModules()
if value.__class__.__name__ == 'ObjectIdentifier':
val = str(value)
elif value.__class__.__name__ == 'TimeTicks':
val = self.fmt_timeticks(value._value)
else:
val = value._value

# This object maintains various indices built from MIBs data
self._mib_resolver = MibViewController(builder)
# Translate some standard SNMPv2 oids
if key == '1.3.6.1.2.1.1.3.0':
key = 'Uptime'

var_binds.append((key, val))
return var_binds

# Convert pysnmp datatypes to simply handable ones
def snmptrap_convert_var_binds(self, var_bind_list):
def snmptrap_translate_varbinds(self, var_bind_list):
var_binds = []
for oid, value in var_bind_list:
mib_var = MibVariable(oid).resolveWithMib(self._mib_resolver)
@@ -1240,7 +1258,11 @@ class EventServer:
else:
break # Skip unhandled version

trap = self.snmptrap_convert_var_binds(proto.apiPDU.getVarBinds(pdu))
if g_config['translate_snmptraps']:
trap = self.snmptrap_translate_varbinds(proto.apiPDU.getVarBinds(pdu))
else:
trap = self.snmptrap_convert_var_binds(proto.apiPDU.getVarBinds(pdu))

# Use the trap sender IP address as host name
host = ipaddress

@@ -3514,6 +3536,7 @@ def load_configuration():
"hostname_translation" : {},
"archive_orphans" : False,
"archive_mode" : "file",
"translate_snmptraps" : False,
}
main_file = g_config_dir + "/mkeventd.mk"
if not os.path.exists(main_file):
@@ -3778,7 +3801,7 @@ try:
g_event_status.load_status()
g_status_server = StatusServer()
g_event_server = EventServer()
if opt_snmptrap:
if opt_snmptrap and g_config['translate_snmptraps']:
g_event_server.load_mibs()
g_event_server.compile_rules(g_config["rules"])

@@ -1894,8 +1894,6 @@ def upload_mib(filename, mimetype, content):
domain = "mkeventd",
)



register_configvar(group,
"retention_interval",
Age(title = _("State Retention Interval"),
@@ -2079,6 +2077,18 @@ def upload_mib(filename, mimetype, content):
domain = "mkeventd",
)

register_configvar(group,
"translate_snmptraps",
Checkbox(title = _("Translate SNMP traps"),
label = _("Use the available SNMP MIBs to translate contents of the SNMP traps"),
help = _("When this option is enabled all available SNMP MIB files will be used "
"to translate the incoming SNMP traps. Information which can not be "
"translated, e.g. because a MIB is missing, are written untouched to "
"the event message."),
default_value = False),
domain = "mkeventd",
)

# A few settings for Multisite and WATO
register_configvar(_("Status GUI (Multisite)"),
"mkeventd_connect_timeout",

0 comments on commit 9dd7175

Please sign in to comment.
You can’t perform that action at this time.