SNMP
Read, walk and write values on network devices, printers, UPS and sensors with SNMP versions 1, 2c and 3. Typical uses: monitor the state of network equipment, collect counters.
snmp get <host> <oids>
Description
Read one value or a list of values in version 2c with the community public on port 161. Result: JSON array of {oid, type, value, encoding when not text}
Read one value or a list of values in version 2c with the community public on port 161. Result: JSON array of {oid, type, value, encoding when not text}
Parameters
host: The host name or IP address of the device - String - required
oids: A numeric OID such as 1.3.6.1.2.1.1.1.0, or a JSON array of up to 100 OIDs. Names like sysDescr.0 are not read: no MIB is loaded - String - required
host: The host name or IP address of the device - String - required
oids: A numeric OID such as 1.3.6.1.2.1.1.1.0, or a JSON array of up to 100 OIDs. Names like sysDescr.0 are not read: no MIB is loaded - String - required
admin
snmp get "127.0.0.1" "1.3.6.1.2.1.1.2.0"
mentdb
[{"oid": "1.3.6.1.2.1.1.2.0", "type": "OID", "value": "1.3.6.1.4.1.20408"}]
snmp get <host> <oids> <json_params>
Description
Read values with parameters: version (1, 2c or 3; 2c by default), port (161), timeout_ms (2000, for each try), retries (1 for reading, 0 for snmp set, 0 to 5), community (the name of a secret: secret set). Version 3: user, auth_protocol (SHA, SHA224, SHA256, SHA384, SHA512, MD5; SHA by default), auth_password, priv_protocol (AES, AES192, AES256, DES; AES by default), priv_password, context. The security level follows the passwords given: none, auth, or auth and priv; passwords have from 8 to 256 characters
Read values with parameters: version (1, 2c or 3; 2c by default), port (161), timeout_ms (2000, for each try), retries (1 for reading, 0 for snmp set, 0 to 5), community (the name of a secret: secret set). Version 3: user, auth_protocol (SHA, SHA224, SHA256, SHA384, SHA512, MD5; SHA by default), auth_password, priv_protocol (AES, AES192, AES256, DES; AES by default), priv_password, context. The security level follows the passwords given: none, auth, or auth and priv; passwords have from 8 to 256 characters
Parameters
host: The host name or IP address of the device - String - required
oids: A numeric OID such as 1.3.6.1.2.1.1.1.0, or a JSON array of up to 100 OIDs. Names like sysDescr.0 are not read: no MIB is loaded - String - required
json_params: The parameters - String - required
host: The host name or IP address of the device - String - required
oids: A numeric OID such as 1.3.6.1.2.1.1.1.0, or a JSON array of up to 100 OIDs. Names like sysDescr.0 are not read: no MIB is loaded - String - required
json_params: The parameters - String - required
admin
snmp get "127.0.0.1" "1.3.6.1.2.1.1.2.0" "{\"port\": 24162}"
mentdb
[{"oid": "1.3.6.1.2.1.1.2.0", "type": "OID", "value": "1.3.6.1.4.1.20408"}]
Fixed result from a real call on a local test server (127.0.0.1): several values, one of them missing
admin
snmp get "127.0.0.1" "[\"1.3.6.1.2.1.1.2.0\", \"1.3.6.1.2.1.1.7.0\", \"1.3.6.1.2.1.99.0\"]" "{\"port\": 24162}"
mentdb
[{"oid": "1.3.6.1.2.1.1.2.0", "type": "OID", "value": "1.3.6.1.4.1.20408"}, {"oid": "1.3.6.1.2.1.1.7.0", "type": "Integer32", "value": 0}, {"oid": "1.3.6.1.2.1.99.0", "type": "noSuchObject", "value": null}]
Fixed result from a real call on a local test server (127.0.0.1): version 1
admin
snmp get "127.0.0.1" "1.3.6.1.2.1.1.2.0" "{\"port\": 24162, \"version\": \"1\"}"
mentdb
[{"oid": "1.3.6.1.2.1.1.2.0", "type": "OID", "value": "1.3.6.1.4.1.20408"}]
Fixed result from a real call on a local test server (127.0.0.1): version 3 with SHA-256 and AES-256, the passwords in secrets
admin
snmp get "127.0.0.1" "1.3.6.1.2.1.1.2.0" "{\"port\": 24162, \"version\": \"3\", \"user\": \"sha256user\", \"auth_protocol\": \"SHA256\", \"auth_password\": \"snmp_auth\", \"priv_protocol\": \"AES256\", \"priv_password\": \"snmp_priv\"}"
mentdb
[{"oid": "1.3.6.1.2.1.1.2.0", "type": "OID", "value": "1.3.6.1.4.1.20408"}]
Fixed result from a real call on a local test server (127.0.0.1): a wrong community is not answered
admin
snmp get "127.0.0.1" "1.3.6.1.2.1.1.2.0" "{\"port\": 24162, \"community\": \"wrong\", \"timeout_ms\": 500, \"retries\": 0}"
mentdb
Sorry, an error appears (no answer from 127.0.0.1:24162 after 1 tries of 500 ms: the agent is down, or it silently ignores wrong credentials).
snmp walk <host> <oid>
Description
Read all the values of a subtree in version 2c, 1000 rows at most. Result: {count, complete, stopped_by, rows}
Read all the values of a subtree in version 2c, 1000 rows at most. Result: {count, complete, stopped_by, rows}
Parameters
host: The host name or IP address of the device - String - required
oid: The numeric OID of the root of the subtree - String - required
host: The host name or IP address of the device - String - required
oid: The numeric OID of the root of the subtree - String - required
admin
snmp walk "127.0.0.1" "1.3.6.1.2.1.1.2"
mentdb
{"count": 1, "complete": true, "stopped_by": "end", "rows": [{"oid": "1.3.6.1.2.1.1.2.0", "type": "OID", "value": "1.3.6.1.4.1.20408"}]}
snmp walk <host> <oid> <json_params>
Description
Walk with parameters: version (1, 2c or 3; 2c by default), port (161), timeout_ms (2000, for each try), retries (1 for reading, 0 for snmp set, 0 to 5), community (the name of a secret: secret set). Version 3: user, auth_protocol (SHA, SHA224, SHA256, SHA384, SHA512, MD5; SHA by default), auth_password, priv_protocol (AES, AES192, AES256, DES; AES by default), priv_password, context. The security level follows the passwords given: none, auth, or auth and priv; passwords have from 8 to 256 characters, max_rows (1000, up to 100000), deadline_ms (60000, up to 600000: the whole walk, the time-out of a request is reduced to what is left), max_repetitions (20, 1 to 100; GETBULK in 2c and 3, version 1 uses GETNEXT)
Walk with parameters: version (1, 2c or 3; 2c by default), port (161), timeout_ms (2000, for each try), retries (1 for reading, 0 for snmp set, 0 to 5), community (the name of a secret: secret set). Version 3: user, auth_protocol (SHA, SHA224, SHA256, SHA384, SHA512, MD5; SHA by default), auth_password, priv_protocol (AES, AES192, AES256, DES; AES by default), priv_password, context. The security level follows the passwords given: none, auth, or auth and priv; passwords have from 8 to 256 characters, max_rows (1000, up to 100000), deadline_ms (60000, up to 600000: the whole walk, the time-out of a request is reduced to what is left), max_repetitions (20, 1 to 100; GETBULK in 2c and 3, version 1 uses GETNEXT)
Parameters
host: The host name or IP address of the device - String - required
oid: The numeric OID of the root of the subtree - String - required
json_params: The parameters - String - required
host: The host name or IP address of the device - String - required
oid: The numeric OID of the root of the subtree - String - required
json_params: The parameters - String - required
admin
snmp walk "127.0.0.1" "1.3.6.1.2.1.1" "{\"port\": 24162, \"max_rows\": 3}"
mentdb
{"count": 3, "complete": false, "stopped_by": "max_rows", "rows": [{"oid": "1.3.6.1.2.1.1.1.0", "type": "OctetString", "value": "PySNMP engine version 7.1.21, Python 3.9.6 (default, Feb 3 2024, 15:58:27) [Clang 15.0.0 (clang-1500.3.9.4)]"}, {"oid": "1.3.6.1.2.1.1.2.0", "type": "OID", "value": "1.3.6.1.4.1.20408"}, {"oid": "1.3.6.1.2.1.1.3.0", "type": "TimeTicks", "value": 61}]}
Fixed result from a real call on a local test server (127.0.0.1): version 1
admin
snmp walk "127.0.0.1" "1.3.6.1.2.1.1.2" "{\"port\": 24162, \"version\": \"1\"}"
mentdb
{"count": 1, "complete": true, "stopped_by": "end", "rows": [{"oid": "1.3.6.1.2.1.1.2.0", "type": "OID", "value": "1.3.6.1.4.1.20408"}]}
snmp set <host> <json_varbinds> <json_params>
Description
Write values, all or none according to the agent. Needs json_params with a community or a version 3 user. Returns the values as the agent answers them. Acts at once on the device. Parameters: version (1, 2c or 3; 2c by default), port (161), timeout_ms (2000, for each try), retries (1 for reading, 0 for snmp set, 0 to 5), community (the name of a secret: secret set). Version 3: user, auth_protocol (SHA, SHA224, SHA256, SHA384, SHA512, MD5; SHA by default), auth_password, priv_protocol (AES, AES192, AES256, DES; AES by default), priv_password, context. The security level follows the passwords given: none, auth, or auth and priv; passwords have from 8 to 256 characters
Write values, all or none according to the agent. Needs json_params with a community or a version 3 user. Returns the values as the agent answers them. Acts at once on the device. Parameters: version (1, 2c or 3; 2c by default), port (161), timeout_ms (2000, for each try), retries (1 for reading, 0 for snmp set, 0 to 5), community (the name of a secret: secret set). Version 3: user, auth_protocol (SHA, SHA224, SHA256, SHA384, SHA512, MD5; SHA by default), auth_password, priv_protocol (AES, AES192, AES256, DES; AES by default), priv_password, context. The security level follows the passwords given: none, auth, or auth and priv; passwords have from 8 to 256 characters
Parameters
host: The host name or IP address of the device - String - required
json_varbinds: A JSON array of up to 100 {oid, type, value, encoding}. type: Integer32, OctetString (encoding utf-8 by default, or hex), OID, IpAddress, Counter32, Gauge32, Unsigned32, TimeTicks, Counter64 (not in version 1), Opaque (hexadecimal) - String - required
json_params: The parameters - String - required
host: The host name or IP address of the device - String - required
json_varbinds: A JSON array of up to 100 {oid, type, value, encoding}. type: Integer32, OctetString (encoding utf-8 by default, or hex), OID, IpAddress, Counter32, Gauge32, Unsigned32, TimeTicks, Counter64 (not in version 1), Opaque (hexadecimal) - String - required
json_params: The parameters - String - required
admin
snmp set "127.0.0.1" "[{\"oid\": \"1.3.6.1.2.1.1.4.0\", \"type\": \"OctetString\", \"value\": \"ops@example.org\"}]" "{\"port\": 24162, \"community\": \"snmp_rw\"}"
mentdb
[{"oid": "1.3.6.1.2.1.1.4.0", "type": "OctetString", "value": "ops@example.org"}]
Fixed result from a real call on a local test server (127.0.0.1): in version 3
admin
snmp set "127.0.0.1" "[{\"oid\": \"1.3.6.1.2.1.1.6.0\", \"type\": \"OctetString\", \"value\": \"Room 12\"}]" "{\"port\": 24162, \"version\": \"3\", \"user\": \"sha256user\", \"auth_protocol\": \"SHA256\", \"auth_password\": \"snmp_auth\", \"priv_protocol\": \"AES256\", \"priv_password\": \"snmp_priv\"}"
mentdb
[{"oid": "1.3.6.1.2.1.1.6.0", "type": "OctetString", "value": "Room 12"}]
