本文整理汇总了Python中netsnmp.snmpget函数的典型用法代码示例。如果您正苦于以下问题:Python snmpget函数的具体用法?Python snmpget怎么用?Python snmpget使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snmpget函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate
def generate(out, ip, switch):
# Get Cisco model name (two tries)
for i in xrange(2):
var = netsnmp.Varbind('.1.3.6.1.2.1.47.1.1.1.1.13.1')
model = netsnmp.snmpget(var, Version=2, DestHost=ip, Community='private')[0]
if model == None:
var = netsnmp.Varbind('.1.3.6.1.2.1.47.1.1.1.1.13.1001')
model = netsnmp.snmpget(var, Version=2, DestHost=ip, Community='private')[0]
if model == None:
sw_reload(ip)
error("Could not get model for switch" , ip)
return
if not model in config.models:
sw_reload(ip)
error("Template for model " + model_id + " not found")
return
# Throws exception if something bad happens
try:
txt = config.generate(switch, model)
out.write("! Config for " + switch + "\n")
out.write(txt)
except:
sw_reload(ip)
error("Exception in generation for %s :" % switch, traceback.format_exc())
out.close()
return None
return out
示例2: getdetails
def getdetails(host, community):
# HP ETHERNET MULTI-ENVIRONMENT,SN:XXXXXXXXXX,FN:XXXXXXX,SVCID:XXXXX,PID:HP LaserJet CM1415fn
details = dict()
# sysName.0
details['name'] = netsnmp.snmpget(netsnmp.Varbind('.1.3.6.1.2.1.1.5.0'), Version = 1, DestHost=host, Community=community)[0]
# sysContact.0
details['contact'] = netsnmp.snmpget(netsnmp.Varbind('.1.3.6.1.2.1.1.4.0'), Version = 1, DestHost=host, Community=community)[0]
# sysUpTimeInstance
details['uptime'] = int(netsnmp.snmpget(netsnmp.Varbind('.1.3.6.1.2.1.1.3.0'), Version = 1, DestHost=host, Community=community)[0]) / 100
# sysDescr.0
res = netsnmp.snmpget(netsnmp.Varbind('.1.3.6.1.2.1.1.1.0'), Version = 1, DestHost=host, Community=community)
match = re.search(r'HP ETHERNET MULTI-ENVIRONMENT,SN:(.*),FN:(.*),SVCID:(.*),PID:(.*)', res[0])
if match:
details['sn'] = match.group(1)
details['fn'] = match.group(2)
details['svcid'] = match.group(3)
details['pid'] = match.group(4)
return details
示例3: update_rrd
def update_rrd(Host, eth_in_oid, eth_out_oid, rrd_path, auth):
eth_in_trffic = netsnmp.snmpget(eth_in_oid, Version=2, DestHost=Host, Community=auth)[0]
eth_out_trffic = netsnmp.snmpget(eth_out_oid, Version=2, DestHost=Host, Community=auth)[0]
ret = rrd_update(rrd_path, 'N:%s:%s' %(eth_in_trffic, eth_out_trffic))
if not ret:
print rrdtool.error()
print "update %s N:%s:%s" %(rrd_path, eth_in_trffic, eth_out_trffic)
示例4: check_neighbor_status_v4
def check_neighbor_status_v4(host,community):
peers_v4 = {}
asns_v4 = {}
reasons_v4 = {}
# Walk all peers from BGP-MIB
oids_v4 = netsnmp.VarList( netsnmp.Varbind('.1.3.6.1.4.1.9.9.187.1.2.5.1.3.1.4'))
res_v4 = netsnmp.snmpwalk( oids_v4, Version = 2, DestHost = host, Community = community)
# Due to SNMP deamon lagg in the router, when switching communities from one to the other,
# sometimes we fail to get snmp.
# If we wait 5 sec and try again it should work just fine
if not res_v4:
time.sleep(5)
oids_v4 = netsnmp.VarList( netsnmp.Varbind('.1.3.6.1.4.1.9.9.187.1.2.5.1.3.1.4'))
res_v4 = netsnmp.snmpwalk( oids_v4, Version = 2, DestHost = host, Community = community)
for oid_v4 in oids_v4:
ipv4 = oid_v4.tag.replace("enterprises.9.9.187.1.2.5.1.3.1.4.", "")
peers_v4[ipv4] = get_state(oid_v4.val)
# Get RemoteAs from BGP-MIB
asoid = netsnmp.Varbind('.1.3.6.1.4.1.9.9.187.1.2.5.1.11.1.4.'+ipv4)
asn = netsnmp.snmpget( asoid, Version = 2, DestHost = host, Community = community )
asns_v4[ipv4] = asn[0]
# Get lastErrorTxt from BGP-MIB
reasonoid = netsnmp.Varbind('.1.3.6.1.4.1.9.9.187.1.2.5.1.28.1.4.'+ipv4)
reason = netsnmp.snmpget( reasonoid, Version = 2, DestHost = host, Community = community )
reasons_v4[ipv4] = reason[0]
return (peers_v4,asns_v4,reasons_v4)
示例5: get_ring_status
def get_ring_status(remote_ip, community):
ring_status_oid = netsnmp.Varbind('.1.3.6.1.4.1.9.9.500.1.1.3.0')
logging.debug('Getting stack ring redundancy status -- ')
netsnmp.snmpget(ring_status_oid, DestHost=remote_ip, Version=1, Community=community)
if not ring_status_oid:
plugin_exit(CRITICAL, 'Unable to retrieve SNMP ring status')
logging.debug('Ring status: {0}'.format(ring_status_oid.print_str()))
stack_ring_status = ring_status_oid.val
return stack_ring_status
示例6: getlevel
def getlevel(cnt,ipn):
cur_capacity = netsnmp.Varbind('.1.3.6.1.2.1.43.11.1.1.9.1.%d' % cnt)
cur_level = netsnmp.snmpget(cur_capacity, Version=1, DestHost=ipn, Community='public', Timeout=100000, Retries=1)
color_bind = netsnmp.Varbind('.1.3.6.1.2.1.43.11.1.1.6.1.%d' % cnt)
color_name = netsnmp.snmpget(color_bind, Version=1, DestHost=ipn, Community='public', Timeout=100000, Retries=1)
max_capacity = netsnmp.Varbind('.1.3.6.1.2.1.43.11.1.1.8.1.%d' % cnt)
max_level = netsnmp.snmpget(max_capacity, Version=1, DestHost=ipn, Community='public', Timeout=100000, Retries=1)
if max_level < 0:
max_level == 0
levels = color_name + cur_level + max_level
return levels
示例7: get_cisco_inet_traffic
def get_cisco_inet_traffic():
"""Returns (rcvd, sent). Note that rcvd == inbound."""
rcvd = netsnmp.snmpget('.1.3.6.1.2.1.2.2.1.10.49',
Version = 1,
Community = 'public',
DestHost = cisco_hostname)[0]
sent = netsnmp.snmpget('.1.3.6.1.2.1.2.2.1.16.49',
Version = 1,
Community = 'public',
DestHost = cisco_hostname)[0]
return int(rcvd), int(sent)
示例8: check_neighbor_status_v6
def check_neighbor_status_v6(host,community):
peers_v6 = {}
asns_v6 = {}
reasons_v6= {}
# Walk all peers from BGP-MIB
oids_v6 = netsnmp.VarList( netsnmp.Varbind('.1.3.6.1.4.1.9.9.187.1.2.5.1.3.2.16'))
res_v6 = netsnmp.snmpwalk( oids_v6, Version = 2, DestHost = host, Community = community )
for oid_v6 in oids_v6:
ipv6 = oid_v6.tag.split('.')
oid = oid_v6.tag
# Convert into hexadecimal, each variable 16 bytes long
a = ipv6_converter(ipv6[11]) +ipv6_converter(ipv6[12])
b = ipv6_converter(ipv6[13]) +ipv6_converter(ipv6[14])
c = ipv6_converter(ipv6[15]) +ipv6_converter(ipv6[16])
d = ipv6_converter(ipv6[17]) +ipv6_converter(ipv6[18])
e = ipv6_converter(ipv6[19]) +ipv6_converter(ipv6[20])
f = ipv6_converter(ipv6[21]) +ipv6_converter(ipv6[22])
g = ipv6_converter(ipv6[23]) +ipv6_converter(ipv6[24])
h = ipv6_converter(ipv6[25]) +ipv6_converter(ipv6[26])
# Remove leading zeroes
a = a.lstrip("0")
b = b.lstrip("0")
c = c.lstrip("0")
d = d.lstrip("0")
e = e.lstrip("0")
f = f.lstrip("0")
g = g.lstrip("0")
h = h.lstrip("0")
# Contstruct properly formatted IPv6 address
ipv6 = a +':' +b +':' +c +':' +d +':' +e +':' +f +':' +g
ipv6 = ipv6.rstrip(":")
ipv6 = ipv6 +'::' +h
peers_v6[ipv6] = get_state(oid_v6.val)
# Get RemoteAs from BGP-MIB
oid = oid.replace("enterprises.9.9.187.1.2.5.1.3.2.16.", "enterprises.9.9.187.1.2.5.1.11.2.16.")
asoid = netsnmp.Varbind(oid)
asn = netsnmp.snmpget( asoid, Version = 2, DestHost = host, Community = community )
asns_v6[ipv6] = asn[0]
# Get lastErrorTxt from BGP-MIB
oid = oid.replace("enterprises.9.9.187.1.2.5.1.11.2.16.", "enterprises.9.9.187.1.2.5.1.28.2.16.")
reasonoid = netsnmp.Varbind(oid)
reason = netsnmp.snmpget( reasonoid, Version = 2, DestHost = host, Community = community )
reasons_v6[ipv6] = reason[0]
return (peers_v6,asns_v6,reasons_v6)
示例9: getdetails
def getdetails(host, community):
# HP ETHERNET MULTI-ENVIRONMENT,SN:XXXXXXXXXX,FN:XXXXXXX,SVCID:XXXXX,PID:HP LaserJet CM1415fn
# Xerox WorkCentre 6505N; Net 95.45,ESS 201104251224,IOT 02.00.02,Boot 201009241127
# Xerox WorkCentre 7845 v1; SS 072.040.004.09100, NC 072.044.09100, UI 072.044.09100, ME 090.079.000, CC 072.044.09100, DF 007.019.000, FI 032.054.000, FA 003.011.009, CCOS 072.004.09100, NCOS 072.004.09100, SC 008.088.000, SU 010.116.00294
# Lexmark CX510de version NH63.GM.N638 kernel 3.0.0 All-N-1
details = dict()
# sysName.0
details['name'] = netsnmp.snmpget(netsnmp.Varbind('.1.3.6.1.2.1.1.5.0'), Version = 1, DestHost=host, Community=community)[0]
# sysContact.0
details['contact'] = netsnmp.snmpget(netsnmp.Varbind('.1.3.6.1.2.1.1.4.0'), Version = 1, DestHost=host, Community=community)[0]
# sysUpTimeInstance
details['uptime'] = int(netsnmp.snmpget(netsnmp.Varbind('.1.3.6.1.2.1.1.3.0'), Version = 1, DestHost=host, Community=community)[0]) / 100
# sysDescr.0
res = netsnmp.snmpget(netsnmp.Varbind('.1.3.6.1.2.1.1.1.0'), Version = 1, DestHost=host, Community=community)
# Default details values (unknown)
details['sn'] = 'unknown'
details['fn'] = details['sn']
details['svcid'] = details['sn']
details['pid'] = details['sn']
# Case 1: HP printer
match = re.search(r'HP ETHERNET MULTI-ENVIRONMENT,SN:(.*),FN:(.*),SVCID:(.*),PID:(.*)', res[0])
if match:
details['sn'] = match.group(1)
details['fn'] = match.group(2)
details['svcid'] = match.group(3)
details['pid'] = match.group(4)
# Case 2: Xerox printer
match = re.search(r'Xerox (.*);', res[0])
if match:
details['pid'] = 'Xerox ' + match.group(1)
# Case 3: Xerox printer
match = re.search(r'Lexmark (.*) version (.*) kernel (.*)', res[0])
if match:
details['pid'] = 'Lexmark ' + match.group(1)
return details
示例10: getconsumableslevels
def getconsumableslevels(host, community):
consumables_number = len(netsnmp.snmpwalk(netsnmp.Varbind(".1.3.6.1.2.1.43.11.1.1.6.1"), Version = 1, DestHost=host, Community=community))
res = dict()
for i in range(1, consumables_number + 1):
res[i] = dict()
res[i]['name'] = netsnmp.snmpget(netsnmp.Varbind(".1.3.6.1.2.1.43.11.1.1.6.1." + str(i)), Version = 1, DestHost=host, Community=community)[0]
res[i]['level'] = netsnmp.snmpget(netsnmp.Varbind(".1.3.6.1.2.1.43.11.1.1.9.1." + str(i)), Version = 1, DestHost=host, Community=community)[0]
return res
示例11: getcartridgelevels
def getcartridgelevels(host, community):
cartridge_number = 5
res = dict()
for i in range(1, cartridge_number):
res[i] = dict()
res[i]['name'] = netsnmp.snmpget(netsnmp.Varbind(".1.3.6.1.2.1.43.11.1.1.6.1." + str(i)), Version = 1, DestHost=host, Community=community)[0]
res[i]['level'] = netsnmp.snmpget(netsnmp.Varbind(".1.3.6.1.2.1.43.11.1.1.9.1." + str(i)), Version = 1, DestHost=host, Community=community)[0]
return res
示例12: target_function
def target_function(self, running, data):
module_verbosity = boolify(self.verbosity)
name = threading.current_thread().name
address = "{}:{}".format(self.target, self.port)
print_status(name, 'thread is starting...', verbose=module_verbosity)
while running.is_set():
try:
string = data.next().strip()
bindvariable = netsnmp.Varbind(".1.3.6.1.2.1.1.1.0")
res = netsnmp.snmpget(bindvariable, Version=1, DestHost=address, Community=string)
if res[0] is not None:
running.clear()
print_success("Target: {}:{} {}: Valid community string found - String: '{}'".format(self.target, self.port, name, string), verbose=module_verbosity)
self.strings.append((self.target, self.port, string))
else:
print_error("Target: {}:{} {}: Invalid community string - String: '{}'".format(self.target, self.port, name, string), verbose=module_verbosity)
except StopIteration:
break
print_status(name, 'thread is terminated.', verbose=module_verbosity)
示例13: snmp_get
def snmp_get(host, credential, object_type):
""" Impelmentation of snmp get functionality
param str object_type : mib object
param str host : switch ip
param dict credential : credential to access switch
"""
try:
import netsnmp
except ImportError:
logging.error("Module 'netsnmp' do not exist! Please install it first")
return None
if 'Version' not in credential or 'Community' not in credential:
logging.error('[uitls][snmp_get] missing keywords in %s for %s',
credential, host)
return None
if credential['Version'] in AUTH_VERSIONS:
version = AUTH_VERSIONS[credential['Version']]
credential['Version'] = version
varbind = netsnmp.Varbind(object_type)
res = netsnmp.snmpget(varbind, DestHost=host, **credential)
if not res:
logging.error('no result found for %s %s', host, credential)
return None
return res[0]
示例14: get_originators_nexthop
def get_originators_nexthop(self):
host = self.smp_ip
mibr = netsnmp.Varbind('iso.3.6.1.4.1.32.1.2')
orig = netsnmp.snmpget(mibr, Version=2, DestHost=host,
Community='public', Timeout=50000, Retries=3)
on = str(orig[0]).split()
return on[::2], on[1::2]
示例15: _snmp_discover_personality
def _snmp_discover_personality(self):
'''Loads netsnmp mod and attempts to discover the host's personality
via snmp by querying sysDescr'''
varbind = netsnmp.snmpget(
netsnmp.Varbind('.1.3.6.1.2.1.1.1.0'),
DestHost=self.hostname,
Version=self.snmp_version,
Community=self.snmp_community,
)
if varbind[0] is None:
raise Error('%s: SNMP query failed' % self.hostname)
sys_descr = varbind[0]
for personality in PERSONALITIES:
# skip generic personality
if personality == 'generic':
continue
if re.search(
PERSONALITIES[personality]['sys_descr'], sys_descr,
flags=re.I
):
self.personality = personality
break
else:
raise Error(
'%s: Unable to determine personality of "%s"' % (
self.hostname, sys_descr))