Skip to content

Instantly share code, notes, and snippets.

@lloydsheng
Created April 11, 2014 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lloydsheng/10440385 to your computer and use it in GitHub Desktop.
Save lloydsheng/10440385 to your computer and use it in GitHub Desktop.
monit snmp with snmpwalk
import os
import time
import datetime
command = 'snmpwalk -v3 -l NoAuthNoPriv -u cisco 192.168.1.1 "ifInOctets.10"'
r = os.popen(command).read()
last_octes = r.replace("\n", "").split(" ")[-1]
last_octes = int(last_octes)
per = 3
while (True):
r = os.popen(command).read()
octes = r.replace("\n", "").split(" ")[-1]
octes = int(octes)
width = (octes - last_octes)/1024.0/1024.0/per*8
print "%s: %.1fm" % (datetime.datetime.now().strftime("%H:%M:%S"), width)
last_octes = octes;
time.sleep(per)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment