SNMP
The SNMP API allows getting device info using the Simple Network Management Protocol.
Warning
RadKIT SNMP support is EXPERIMENTAL and may contain backwards-incompatible changes from version to version.
Service configuration
To activate the SNMP API, either when creating a new device or modifying an existing one, simply select the SNMP checkbox. This action will enable the SNMP API functionality for the device.
The SNMP configuration section contains four fields:
- Version (1 or 2)
Selects SNMP v1 or SNMP v2 as the version. SNMP v3 is not yet supported
- Port Number
The UDP port number the SNMP service is running at. Defaults to 161
- Community String
The community string used in SNMP v1 or v2 requests. Not applicable for SNMP v3
Client operation
Devices SNMP status
As part of the service inventory, the Client receives an internal attribute named snmp_version
for each device. This attribute is set to either 1
, 2
, 3
, or None
, depending on whether the
SNMP management protocol is enabled and configured for the device on the Service side.
>>> device = service.inventory['snmpdevice']
>>> device.attributes.internal
<radkit_client.sync.device.DeviceAttributesDict object at 0x10ed4bfa0>
key value
------------------- ---------
description
device_type LINUX
forwarded_tcp_ports
host localhost
http_config True
netconf_config False
snmp_version 2
swagger_config False
terminal_config False
Querying One Device
The SNMP API implements get and walk.
These are implemented as a method on top of the Device
object’s snmp
attribute, which is an instance of
SNMP_API
.
Both of these methods accept the following parameters:
oids
(str or tuple)The Object IDs to request (for get), or to walk (for walk). One or more OID can be passed, as variadic arguments. Each OID can be passed as either:
A dot-separated string:
"1.3.6.1.2.1.1.1.0"
A tuple of integers:
(1, 3, 6, 1, 2, 1, 1, 1, 0)
request_timeout
(float, optional)The individual timeout (in seconds) for each SNMP request.
session_timeout
(float, optional)The total timeout (in seconds) for all SNMP requests made to satisfy the query.
session_limit
(int, optional)The maximum number of SNMP entries to return.
Example
You can use the SNMP API to query the device info through RADKit Service:
>>> device = service.inventory['snmpdevice']
>>> result = device.snmp.walk("1.3.6.1.2.1.1").wait().result
>>> result
[SUCCESS] <radkit_client.sync.snmp.SNMPTable object at 0x17eb1bd31f0>
i oid value
--- ----------------- --------------------------------------------------------------------------------------------------
0 1.3.6.1.2.1.1.1.0 Cisco IOS XR Software (NCS-5500), Version 7.3.4 36 Copyright (c) 2013-2022 by Cisco Systems, Inc.
1 1.3.6.1.2.1.1.2.0 1.3.6.1.4.1.9.1.2349
2 1.3.6.1.2.1.1.3.0 26695784
3 1.3.6.1.2.1.1.4.0
4 1.3.6.1.2.1.1.5.0 SNMPDEVICE
5 1.3.6.1.2.1.1.6.0 SN:FGE20220AJL,ASSET:8832111
6 1.3.6.1.2.1.1.7.0 78
>>> result[0]
SNMPRow(oid_str='1.3.6.1.2.1.1.1.0', value='Cisco IOS XR Software (NCS-5500), Version 7.3.4 36 Copyright (c) 2013-2022 by Cisco Systems, Inc.')
----- --------------------------------------------------------------------------------------------------
oid 1.3.6.1.2.1.1.1.0
type DisplayString
value Cisco IOS XR Software (NCS-5500), Version 7.3.4 36 Copyright (c) 2013-2022 by Cisco Systems, Inc.
----- --------------------------------------------------------------------------------------------------
>>> result[(1, 3, 6, 1, 2, 1, 1, 3, 0)]
SNMPRow(oid_str='1.3.6.1.2.1.1.3.0', value=26721423)
----- -----------------
oid 1.3.6.1.2.1.1.3.0
type TimeTicks
value 26721423
----- -----------------
>>> result["1.3.6.1.2.1.1.3.0"]
SNMPRow(oid_str='1.3.6.1.2.1.1.3.0', value=26721423)
----- -----------------
oid 1.3.6.1.2.1.1.3.0
type TimeTicks
value 26721423
----- -----------------
>>> device.snmp.get("1.3.6.1.2.1.1.2.0", (1,3,6,1,2,1,1,3,0)).wait().result
[SUCCESS] <radkit_client.sync.snmp.SNMPTable object at 0x17eb2c615e0>
i oid value
--- ----------------- --------------------
0 1.3.6.1.2.1.1.2.0 1.3.6.1.4.1.9.1.2349
1 1.3.6.1.2.1.1.3.0 26722297
The response.result
object is an instance of SNMPTable
.
It is a dictionary of SNMPRow
, indexed by row number or OID.
Querying Multiple Devices
Similar to querying one device, you can query multiple devices at once by using
the Device
object’s snmp
attribute, which is an instance of
SNMP_API
.
These take the same parameters as the single-device versions, but instead return an
SNMP_API
containing a set of
SNMPTable
. To see all the results at once, use
walk
Example
>>> devices = service.inventory.subset(['snmpdevice1', 'snmpdevice2'])
>>> r = devices.snmp.get("1.3.6.1.2.1.1.2.0", "1.3.6.1.2.1.2.1.0").wait().result
>>> r
[SUCCESS] <radkit_client.sync.snmp.SNMPQuerySet object at 0x7f344ec3a130>
device status results
----------- -------- ---------
snmpdevice2 SUCCESS 2
snmpdevice1 SUCCESS 2
>>> r['snmpdevice1']
[SUCCESS] <radkit_client.sync.snmp.SNMPTable object at 0x7f344c0a12b0>
i oid value
--- ----------------- ----------------------
0 1.3.6.1.2.1.1.2.0 '1.3.6.1.4.1.9.1.1017'
1 1.3.6.1.2.1.2.1.0 1287
>>> r['snmpdevice2']
[SUCCESS] <radkit_client.sync.snmp.SNMPTable object at 0x7f344cf7ad30>
i oid value
--- ----------------- ----------------------
0 1.3.6.1.2.1.1.2.0 '1.3.6.1.4.1.9.1.2349'
1 1.3.6.1.2.1.2.1.0 296
>>> r.join()
[SUCCESS] <radkit_client.async_.snmp.MultiDeviceSNMPTable object at 0x7f344fedce50>
i oid device value
--- ----------------- ----------- ----------------------
0 1.3.6.1.2.1.1.2.0 snmpdevice1 '1.3.6.1.4.1.9.1.2349'
1 1.3.6.1.2.1.1.2.0 snmpdevice2 '1.3.6.1.4.1.9.1.1017'
2 1.3.6.1.2.1.2.1.0 snmpdevice1 296
3 1.3.6.1.2.1.2.1.0 snmpdevice2 1287