Groovy SNMP Access
Last updated on 08 October, 2024For some types of SNMP monitoring, you’ll need to resort to Groovy to get at your SNMP data. For example, a typical use case is a DataSource that requires aggregation of SNMP values across various nodes.
A complete reference of LogicMonitor’s Groovy SNMP methods can be found at the bottom of this page, but here are a few examples to demonstrate how this feature works.
Example 1 – Obtain a device’s sysDescr using SNMP v1/v2c
This script will output something like the following:
Example 2 – List all Network interfaces of a Linux Device using SNMP v1
The output from the above looks something like:
Example 3 – List all Network Interfaces of a Linux Device using SNMP v3
The above script behaves just like the preceding example, but uses SNMP v3 authentication & encryption.
SNMP Method Reference
SNMP v1/v2
Snmp.get(host, [community], [version], oid, [timeout]) – get a single SNMP OID value from a v1 or v2 agent
- @param string host – device hostname or ip address
- @param string community – optional snmp community name. If omitted, LogicMonitor will attempt to determine the appropriate value from the snmp.community property on the corresponding device record and otherwise default to “public”
- @param string version – optional snmp version; required only if community is provided. If omitted, LogicMonitor will attempt to determine the appropriate value from the snmp.version property on the corresponding device record
- @param string oid – the snmp oid to query
- @param int timeout – connection timeout in milliseconds
- @return string oid_value – the value of this SNMP OID as returned by the agent
Snmp.walk(host, [community], [version], tree_oid, [timeout], port) – walk an SNMP OID tree from a v1 or v2 agent
- @param string host – device hostname or ip address
- @param string community – (optional) snmp community name. If omitted, LogicMonitor will attempt to determine the appropriate value from the snmp.community property on the corresponding device record and otherwise default to “public”
- @param string version – (optional) snmp version; required only if community is provided. If omitted, LogicMonitor will attempt to determine the appropriate value from the snmp.version property on the corresponding device record
- @param string tree_oid – the snmp tree oid to walk
- @param int timeout – (optional) connection timeout in milliseconds
- @return string walk_output – the OIDs and values returned by the SNMP walk separated by “=” with one entry per line
- @param string port– (optional) the port to which you want access.
SNMP v3
Snmp.get(host, oid, [options], [timeout]) – get a single SNMP OID value from a v3 agent
- @param string host – device hostname or ip address
- @param string oid – the snmp oid to query
- @param map options – optional snmp v3 options map name. If omitted, LogicMonitor will attempt to determine the appropriate values from properties on the device record matching the hostname supplied in the first parameter.
- @param int timeout – connection timeout in milliseconds
- @return string oid_value – the value of this SNMP OID as returned by the agent
Snmp.walk(host, tree_oid, [options], [timeout]) – walk an SNMP OID tree from a v3 agent
- @param string host – device hostname or ip address
- @param string tree_oid – the snmp tree oid to walk
- @param map options – optional snmp v3 options map name. If omitted, LogicMonitor will attempt to determine the appropriate values from properties on the device record matching the hostname supplied in the first parameter.
- @param int timeout – connection timeout in milliseconds
- @return string walk_output – the OIDs and values returned by the SNMP walk separated by “=” with one entry per line
- @param string port– (optional) the port to which you want access.
The SNMP v3 options map requires the following parameters:
- snmp.version – the version used (v3)
- snmp.security – the snmp v3 security name
- snmp.auth – the snmp v3 authentcation type (MD5|SHA)
- snmp.authToken – the snmp v3 authentcation passphrase
- snmp.priv – the snmp v3 privacy type (AES|DES)
- snmp.privToken – the snmp v3 privacy encryption key