提交 74149f93 编写于 作者: 曾伟伟

u

上级 a18989a2
......@@ -25,81 +25,78 @@ SERVER = '10.128.120.38:2281'
if __name__ == '__main__':
while True:
try:
for unit in monitor:
if not unit.get('name'):
try:
cmd = 'snmpwalk -c '+unit['public']+' -v '+unit['version']+' '+unit['ip']+' '+CISCO_NAME_OID
p = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)
p.wait()
unit['name'] = p.stdout.read().split(': ')[1].strip()
except Exception, e:
print str(e)
unit['name'] = 'unknown'
cmd = 'snmpget -c '+unit['public']+' -v '+unit['version']+' '+unit['ip']+' '
if unit['type'] == 'cisco':
in_traffic_oid = CISCO_IN_TRAFFIC_OID
out_traffic_oid = CISCO_OUT_TRAFFIC_OID
in_count_oid = CISCO_IN_COUNT_OID
out_count_oid = CISCO_OUT_COUNT_OID
else:
print 'The unit ' + unit['name'] + '\'s type can not resolved!! [' + unit['type'] + ']'
for unit in monitor:
if not unit.get('name'):
try:
cmd = 'snmpwalk -c '+unit['public']+' -v '+unit['version']+' '+unit['ip']+' '+CISCO_NAME_OID
p = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)
p.wait()
unit['name'] = p.stdout.read().split(': ')[1].strip()
except Exception, e:
print str(e)
unit['name'] = 'unknown'
cmd = 'snmpget -c '+unit['public']+' -v '+unit['version']+' '+unit['ip']+' '
if unit['type'] == 'cisco':
in_traffic_oid = CISCO_IN_TRAFFIC_OID
out_traffic_oid = CISCO_OUT_TRAFFIC_OID
in_count_oid = CISCO_IN_COUNT_OID
out_count_oid = CISCO_OUT_COUNT_OID
else:
print 'The unit ' + unit['name'] + '\'s type can not resolved!! [' + unit['type'] + ']'
continue
if not unit.get('portname'):
try:
cmd = 'snmpget -c '+unit['public']+' -v '+unit['version']+' '+unit['ip']+' '
if unit['type'] == 'cisco':
for p in unit['port']:
cmd += CISCO_PORT_NAME_OID + str(p) + ' '
else:
raise Exception('unknown device type!')
p = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)
p.wait()
unit['portname'] = p.stdout.read().split(': ')[1].strip()
except Exception, e:
print str(e)
unit['portname'] = unit['port']
for port in unit['port']:
if not port:
continue
if not unit.get('portname'):
cmd += in_traffic_oid + str(port) + ' '
cmd += out_traffic_oid + str(port) + ' '
cmd += in_count_oid + str(port) + ' '
cmd += out_count_oid + str(port) + ' '
p = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)
p.wait()
result = [r.split(': ')[1] for r in p.stdout.read().split('\n') if r]
if not unit.get('last'):
unit['last'] = [int(r) for r in result]
else:
now = [int(r) for r in result]
diff = []
i = 0
while i < len(now):
d = now[i]-unit['last'][i]
if d < 0:
d += 4294967296
diff.append(d)
i += 1
unit['last'] = now
print unit['last']
i = 0
while i < len(unit['port']):
try:
cmd = 'snmpget -c '+unit['public']+' -v '+unit['version']+' '+unit['ip']+' '
if unit['type'] == 'cisco':
for p in unit['port']:
cmd += CISCO_PORT_NAME_OID + str(p) + ' '
else:
raise Exception('unknown device type!')
p = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)
p.wait()
unit['portname'] = p.stdout.read().split(': ')[1].strip()
#in
print 'http://'+SERVER+'/cat/r/systemMonitor?group='+unit['group']+'&domain='+ \
unit['name']+'&key='+str(unit['portname'][i])+'-in&op=sum&sum='+str(diff[::4][i])
#urllib2.urlopen('http://'+SERVER+'/cat/r/systemMonitor?group='+unit['group']+'&domain='+
# unit['name']+'&key='+unit['name']+'-'+group['key']+'/in-traffic'+'&op=sum&sum='+str(data),timeout=0)
#out
print 'http://'+SERVER+'/cat/r/systemMonitor?group='+unit['group']+'&domain='+ \
unit['name']+'&key='+str(unit['portname'][i])+'-in&op=sum&sum='+str(diff[1::4][i])
#urllib2.urlopen('http://'+SERVER+'/cat/r/systemMonitor?group='+unit['group']+'&domain='+
# unit['name']+'&key='+unit['name']+'-'+group['key']+'/in-traffic'+'&op=sum&sum='+str(data),timeout=0)
except Exception, e:
print str(e)
unit['portname'] = unit['port']
for port in unit['port']:
if not port:
continue
cmd += in_traffic_oid + str(port) + ' '
cmd += out_traffic_oid + str(port) + ' '
cmd += in_count_oid + str(port) + ' '
cmd += out_count_oid + str(port) + ' '
p = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)
p.wait()
result = [r.split(': ')[1] for r in p.stdout.read().split('\n') if r]
if not unit.get('last'):
unit['last'] = [int(r) for r in result]
else:
now = [int(r) for r in result]
diff = []
i = 0
while i < len(now):
d = now[i]-unit['last'][i]
if d < 0:
d += 4294967296
diff.append(d)
i += 1
unit['last'] = now
print unit['last']
i = 0
while i < len(unit['port']):
try:
#in
print 'http://'+SERVER+'/cat/r/systemMonitor?group='+unit['group']+'&domain='+ \
unit['name']+'&key='+str(unit['portname'][i])+'-in&op=sum&sum='+str(diff[::4][i])
#urllib2.urlopen('http://'+SERVER+'/cat/r/systemMonitor?group='+unit['group']+'&domain='+
# unit['name']+'&key='+unit['name']+'-'+group['key']+'/in-traffic'+'&op=sum&sum='+str(data),timeout=0)
#out
print 'http://'+SERVER+'/cat/r/systemMonitor?group='+unit['group']+'&domain='+ \
unit['name']+'&key='+str(unit['portname'][i])+'-in&op=sum&sum='+str(diff[1::4][i])
#urllib2.urlopen('http://'+SERVER+'/cat/r/systemMonitor?group='+unit['group']+'&domain='+
# unit['name']+'&key='+unit['name']+'-'+group['key']+'/in-traffic'+'&op=sum&sum='+str(data),timeout=0)
except Exception, e:
print str(e)
i += 1
except Exception, e:
print 'exception!!! ' + str(e)
i += 1
time.sleep(SLEEP_TIME)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册