4
4
[ ![ foryou] ( https://img.shields.io/static/v1?label=For&message=You&color=aqua&labelColor=blue&style=for-the-badge )] ( )
5
5
[ ![ license] ( https://img.shields.io/static/v1?label=License&message=OPENSOURCE&color=green&labelColor=darkgreen&style=for-the-badge )] ( )
6
6
<br ><br >
7
- An opensource library to use SNMP get/bulk/ set/walk in Python
7
+ An opensource library to use SNMP get/set/bulk/ walk/table more easily in Python
8
8
9
9
## Features
10
-
11
- * Work with OIDS json list [ Find Here] (#OIDS List)
12
10
* [ GET] ( #GET ) command
13
11
* [ SET] ( #SET ) command
14
12
* [ WALK] ( #WALK ) command
15
13
* [ BULK] ( #BULK ) command
16
- * [ CHECK IF DEVICE CONNECTED] ( #CHECK )
17
-
18
- ## OIDS List
19
-
20
- Change ` PATH_TO_LIST ` to your OIDS list if you want to use it.
14
+ * [ TABLE] ( #TABLE ) command
15
+ * [ CHECK IF DEVICE IS ONLINE] ( #CHECK )
21
16
22
- Example for ` OIDS .json`
17
+ ## Link with oids .json
23
18
24
- ```
25
- {
26
- "system": {
27
- "name": "1.3.6.1.2.1.1.5",
28
- "uptime": "1.3.6.1.2.1.1.3",
29
- "mac_address": "1.3.6.1.2.1.2.2.1.6",
30
- "temperature": "1.3.6.1.4.1.6296.9.1.1.2.5.1.3"
31
- }
32
- }
33
- ```
34
-
35
- When constructor ` SnmpUtils() ` is called, the method ` defineOIDsList() ` is automaticaly called. So you can use the list
36
- like this:
37
-
38
- ```
39
- switch = SnmpUtils("10.0.0.1")
40
- print(switch.oids.system.name) #return 1.3.6.1.2.1.1.5
19
+ ``` python
20
+ import json
21
+ oids = None
22
+ with open (' OIDS.json' , ' r' ) as file :
23
+ oids = json.load(file )
41
24
```
42
25
43
26
## GET
44
27
45
28
GET SNMP Command return the value of a specific OID. \
46
29
` get(oid) `
47
30
48
- ```
31
+ ``` python
49
32
switch = SnmpUtils(" 10.0.0.1" )
50
- switch_name = switch.get(switch. oids. system. name)
33
+ switch_name = switch.get(oids[ ' system' ][ ' name' ]) # return name of device
51
34
```
52
35
53
- You can also use ` getByID (oid, id)` which returns the value of the inferior OID.
36
+ You can also use ` get_by_id (oid, id)` which returns the value of the inferior OID.
54
37
55
- ```
38
+ ``` python
56
39
switch = SnmpUtils(" 10.0.0.1" )
57
- switch_interface_3_description = switch.getByID(switch. oids. interfaces. description, 3) # return the description of the third interface
40
+ switch_interface_3_description = switch.get_by_id( oids[ ' interfaces' ][ ' description' ] , 3 ) # return the description of the third interface
58
41
```
59
42
60
43
## SET
61
44
62
45
SET SNMP is use for set value of a specific OID. \
63
- ` set(oid, value) `
64
-
65
- ```
46
+ ` set(oid, value_type, value) ` \
47
+ * value_type can be one of i/u/t/a/o/s/x/d/b *
48
+ ``` python
66
49
switch = SnmpUtils(" 10.0.0.1" )
67
- switch_name = switch.set(switch. oids. system. name, "Test")
50
+ switch_name = switch.set(oids[ ' system' ][ ' name' ], ' s ' , " Test" )
68
51
```
69
52
70
53
## WALK
71
54
72
55
WALK SNMP Command return a dict of all values of inferiors OIDs. \
73
- ` walk(oid, numberOfIterations, dotPrefix) `
74
-
75
- You can specify the number of value do you want in second parameter.
76
- ` dotPrefix ` is used for add . in front of OID.
56
+ ` walk(oid) `
77
57
78
58
```
79
59
switch = SnmpUtils("10.0.0.1")
80
- switch_10_interfaces_description = switch.walk(switch. oids. interfaces. description, 10 ) # return a dict with key/value
81
- for k,v in switch_10_interfaces_description .items():
60
+ switch_interfaces_description = switch.walk(oids[' interfaces'][' description'] ) # return a dict with key/value
61
+ for k,v in switch_interfaces_description .items():
82
62
print(k,v)
83
63
```
84
64
@@ -89,23 +69,35 @@ BULK SNMP returns all following items up to a limit for an/several item(s). \
89
69
90
70
```
91
71
switch = SnmpUtils("10.0.0.1")
92
- switch_interfaces_description = switch.bulk(switch.oids.interfaces.description) #return a dict with description for all interfaces
72
+ switch_interfaces_description = switch.bulk(oids['interfaces']['description']) #return a dict with description for all interfaces
73
+ ```
74
+
75
+ ## TABLE
76
+
77
+ TABLE SNMP returns list of dicts \
78
+ ` get_table(oid, sort_key) `
79
+
80
+ ```
81
+ switch = SnmpUtils("10.0.0.1")
82
+ switch_interfaces = switch.get_table('1.3.6.1.2.1.2.2') # return list of dicts
93
83
```
94
84
85
+
95
86
## CHECK
96
87
97
88
You can easily check if a device is online \
98
- ` isConnected ()`
89
+ ` is_online ()`
99
90
100
91
```
101
92
switch = ("10.0.0.1")
102
- if switch.isConnected ():
93
+ if switch.is_online ():
103
94
print("Switch online")
104
95
```
105
96
106
97
## Dependencies
107
98
108
99
* [ PySNMP] ( https://pysnmp.readthedocs.io/en/latest/ )
100
+ * [ SNMP-CMDS] ( https://snmp-cmds.readthedocs.io/en/latest/ )
109
101
110
102
## Contributors
111
103
0 commit comments