https://github.com/hakkaofdev/py-snmp-utils
An opensource library to use SNMP get/bulk/set/walk/table in Python
https://github.com/hakkaofdev/py-snmp-utils
librairy opensource pysnmp python snmp
Last synced: about 1 year ago
JSON representation
An opensource library to use SNMP get/bulk/set/walk/table in Python
- Host: GitHub
- URL: https://github.com/hakkaofdev/py-snmp-utils
- Owner: HakkaOfDev
- Created: 2021-11-11T18:34:52.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-04T08:53:45.000Z (over 4 years ago)
- Last Synced: 2025-02-08T03:26:02.930Z (over 1 year ago)
- Topics: librairy, opensource, pysnmp, python, snmp
- Language: Python
- Homepage:
- Size: 4.88 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SNMP-UTILS
[]()
[]()
[]()
An opensource library to use SNMP get/set/bulk/walk/table more easily in Python
## Features
* [GET](#GET) command
* [SET](#SET) command
* [WALK](#WALK) command
* [BULK](#BULK) command
* [TABLE](#TABLE) command
* [CHECK IF DEVICE IS ONLINE](#CHECK)
## Link with oids.json
```python
import json
oids = None
with open('OIDS.json', 'r') as file:
oids = json.load(file)
```
## GET
GET SNMP Command return the value of a specific OID. \
`get(oid)`
```python
switch = SnmpUtils("10.0.0.1")
switch_name = switch.get(oids['system']['name']) # return name of device
```
You can also use `get_by_id(oid, id)` which returns the value of the inferior OID.
```python
switch = SnmpUtils("10.0.0.1")
switch_interface_3_description = switch.get_by_id(oids['interfaces']['description'], 3) # return the description of the third interface
```
## SET
SET SNMP is use for set value of a specific OID. \
`set(oid, value_type, value)` \
*value_type can be one of i/u/t/a/o/s/x/d/b*
```python
switch = SnmpUtils("10.0.0.1")
switch_name = switch.set(oids['system']['name'], 's', "Test")
```
## WALK
WALK SNMP Command return a dict of all values of inferiors OIDs. \
`walk(oid)`
```
switch = SnmpUtils("10.0.0.1")
switch_interfaces_description = switch.walk(oids['interfaces']['description']) # return a dict with key/value
for k,v in switch_interfaces_description.items():
print(k,v)
```
## BULK
BULK SNMP returns all following items up to a limit for an/several item(s). \
`bulk(*oids_list)`
```
switch = SnmpUtils("10.0.0.1")
switch_interfaces_description = switch.bulk(oids['interfaces']['description']) #return a dict with description for all interfaces
```
## TABLE
TABLE SNMP returns list of dicts \
`get_table(oid, sort_key)`
```
switch = SnmpUtils("10.0.0.1")
switch_interfaces = switch.get_table('1.3.6.1.2.1.2.2') # return list of dicts
```
## CHECK
You can easily check if a device is online \
`is_online()`
```
switch = ("10.0.0.1")
if switch.is_online():
print("Switch online")
```
## Dependencies
* [PySNMP](https://pysnmp.readthedocs.io/en/latest/)
* [SNMP-CMDS](https://snmp-cmds.readthedocs.io/en/latest/)
## Contributors
* [Alexandre GOSSARD](https://www.github.com/HakkaOfDev)
* [Alexis LEBEL](https://www.github.com/Alestrio)