-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimpleget.py
62 lines (45 loc) · 1.63 KB
/
simpleget.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from pysnmp.hlapi import*
# snmpget module
# params: ipadr: remote IP, pw: password and key
# oid: user requested OID
# returns: mibVars, MIB variable
# data is contained in varBinds[3]
def request(user, ipadr, pw, port, oid):
remoteIP = ipadr
password = pw
bulkGet = ""
mibVars = ""
mibName = ""
oidName = ""
oidNameIndex = ""
oidIndex = ""
oidNumeric = ""
print(oid)
if oid.find("::") > -1:
oid = oid.split("::")
mibName = oid[0]
oidNameIndex = oid[1]
oidNameIndex = oidNameIndex.split(".")
oidName = oidNameIndex[0]
oidIndex = ""
if len(oidNameIndex) > 1:
oidIndex = oidNameIndex[1]
print("user entered oidInst: ", oidIndex)
print("user entered mibName: ", mibName)
print("user entered oidName: ", oidName)
else:
oidNumeric = oid
print(remoteIP, password, oid)
if len(mibName) > 0 and len(oidName) > 0 and len(oidIndex) > 0:
userCred = UsmUserData(user, password , password)
remoteHost = UdpTransportTarget((remoteIP, port), timeout=1, retries=1)
get = getCmd(SnmpEngine(), userCred, remoteHost, ContextData(),
ObjectType(ObjectIdentity(mibName, oidName, oidIndex)))
mibVars = next(get)
elif len(oidNumeric) > 0:
userCred = UsmUserData(user, password , password)
remoteHost = UdpTransportTarget((remoteIP, port), timeout=1, retries=1)
get = getCmd(SnmpEngine(), userCred, remoteHost, ContextData(),
ObjectType(ObjectIdentity(oidNumeric)))
mibVars = next(get)
return mibVars