snmp_diagnostics.plugins

if_mib (OIDs 1.3.6.1.2.1.2 and 1.3.6.1.2.1.31)

A plugins that can process SNMP IF-MIB data into ROS diagnostics.

class snmp_diagnostics.plugins.if_mib.IfMibDiagnostics(engine, config)

Bases: snmp_diagnostics.snmp_diag_plugin.SnmpDiagPlugin

A plugin that can process SNMP IF-MIB data into ROS diagnostics.

ROS parameters of the plugin are:

  • if_mib (dict)
    • num_ports (int, optional): If specified, the diagnostics will check that exactly this number of ports is reported.
    • ports (dict port_name => port_params): Specification of the expected ports. port_name is a string identifying the port (e.g. eth0), mangled either from ifAlias, ifName or ifDescr (see below). port_params is a dict with following keys:
      • connected (bool, optional): Check that the connection state of this port is as specified.
      • speed (int or tuple (int, int), optional): The expected speed of the port in Mbps. If a tuple is specified, it denotes a (min, max) range.
      • mtu (int or tuple (int, int), optional): The expected MTU of the port in B. If a tuple is specified, it denotes a (min, max) range.
      • dummy (whatever): If you only need to specify a port to be present, but do not require any particular properties or state, just specify a dummy parameter so that the port’s key is present in the ports dictionary.

The port_name is mangled so that it is a valid ROS graph resource name - i.e. matching regex ^[a-zA-Z][a-zA-Z0-9_]*$. To perform this mangling, iconv //TRANSLIT feature is used to find the “closest” ASCII character to all non-ASCII ones, and then all non-alphanumeric characters are replaced by underscores (e.g. spaces), and multiple underscores are coalesced into a single one. If the resulting name is not a valid graph resource name (e.g. it starts with a number), the next name “source” is tried - in the order ifAlias, ifName, ifDescr.

Parameters:
get_diag_name()

The name that will be shown in the top-level diagnostics item.

Returns:The name.
Return type:str
get_oids()

Get the list of OIDs that should be queried for this plugin.

Returns:The list of OIDs.
Return type:list of pysnmp.smi.rfc1902.ObjectType
parse_response(response_iterator)

Parse the SNMP response iterator into something this plugin understands.

Parameters:response_iterator (iterator) – The SNMP response iterator.
Returns:The processed response data.
Return type:any
process_response(response)

Process the response of SNMP agent and save the result in the plugin for later use by produce_diagnostics().

Parameters:response (any) – The SNMP response processed by parse_response().
produce_diagnostics(diagnostics)

Produce diagnostics from the data stored by process_response().

Parameters:diagnostics (diagnostic_updater.DiagnosticStatusWrapper) – The diagnostics wrapper to update.