ROS diagnostics created from SNMP agent data
ROS node that reads various data over SNMP and turns them into ROS diagnostics messages.
~agent_address
(str, default '127.0.0.1'): Address of the SNMP agent.~agent_port
(int, default 161): UDP port of the SNMP agent.~community
(str, default 'public'): SNMP community.~snmp_v2
(bool, default True): Whether to use SNMPv2c or SNMPv1.~udpv6
(bool, default False): Whether to use UDPv6 transport or UDPv4.~rate
(float, default 1.0): The rate at which the SNMP agent is polled.~plugins
(dict): Plugin-specific configuration. Keys areconfig_key
attributes of the plugins (e.g.if_mib
). Values are dictionaries described further for each plugin.
So far, there is only a single plugin, but more are planned to be added (e.g. host resources).
This plugin reads IF-MIB
(1.3.6.1.2.1.2 and 1.3.6.1.2.1.31) and extracts information about network
ports and their status.
num_ports
(int, optional): If specified, the diagnostics will check that exactly this number of ports is reported.ports
(dictport_name
=>port_params
): Specification of the expected ports.port_name
is a string identifying the port (e.g.eth0
), mangled either fromifAlias
,ifName
orifDescr
(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 theports
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
number), the next name "source" is tried - in the order ifAlias
, ifName
, ifDescr
.
To create a new plugin processing different MIBs, just write a normal Python ROS package that
exports a Python package
containing your plugin. The plugin has to inherit from class snmp_diagnostics.SnmpDiagPlugin
and
implement its abstract methods.
Add the following lines to your package's package.xml
:
<exec_depend>snmp_diagnostics</exec_depend>
<export>
<snmp_diagnostics class="my_package.module.Class" config_key="my_plugin" />
</export>
Make sure my_package.module.Class
is the fully qualified name of your plugin class.
config_key
if the name under which you will configure the plugin on ROS parameter server, i.e.
it will get its configuration from ~/plugins/<config_key>
.
This is a simplified version of the process described at https://askubuntu.com/a/223734/153828 .
- Install system packages
snmp
,snmpd
,snmp-mibs-downloader
. - Run
echo "view systemonly included .1.3.6.1.2.1.2" | sudo tee -a /etc/snmp/snmpd.conf
for each MIB you want to enable. Just substitute the exact MIB number. sudo sed -i 's/^mibs :$/# mibs :/' /etc/snmp/snmp.conf
sudo systemctl enable snmpd && sudo systemctl start snmpd
- Then you should be able to walk your local machine:
snmpwalk -v 2c -c public 127.0.0.1
. If not, try restarting thesnmpd
daemon.