Commit 09ad163a by JR Dalrymple

Works in beta - going to monitor some GSE LLC interfaces with it

parent 65fa1686
...@@ -32,11 +32,12 @@ import subprocess ...@@ -32,11 +32,12 @@ import subprocess
import datetime import datetime
host = '' host = ''
debug = 0
communityString = 'public' communityString = 'public'
OIDDateTime = '.1.3.6.1.2.1.25.1.2.0' OIDDateTime = '.1.3.6.1.2.1.25.1.2.0'
OIDIfDescr = '.1.3.6.1.2.1.2.2.1.2' OIDIfDescr = '.1.3.6.1.2.1.2.2.1.2'
OIDIfInBytes = '.1.3.6.1.2.1.2.2.1.10.1.' OIDIfInBytes = '.1.3.6.1.2.1.2.2.1.10.'
OIDIfOutBytes = '.1.3.6.1.2.1.2.2.1.16.1.' OIDIfOutBytes = '.1.3.6.1.2.1.2.2.1.16.'
unitMultipliers = { 'b' : 1, unitMultipliers = { 'b' : 1,
'B' : 1, 'B' : 1,
...@@ -56,7 +57,7 @@ limitMatch = re.compile(r"([0-9]+)([bBkKmMgGtT]{0,1})") ...@@ -56,7 +57,7 @@ limitMatch = re.compile(r"([0-9]+)([bBkKmMgGtT]{0,1})")
def usage(): def usage():
print('Usage: check_snmp_usage.py -H hostname -i interface -b bandwidth limit (bytes) -c community string \n') print('Usage: check_snmp_usage.py -H hostname -i interface -b bandwidth limit (bytes) -c community string \n')
try: try:
opts, args = getopt.getopt(sys.argv[1:], 'H:i:b:c') opts, args = getopt.getopt(sys.argv[1:], 'H:i:b:cd')
except getopt.GetoptError as err: except getopt.GetoptError as err:
print(err) print(err)
usage() usage()
...@@ -71,6 +72,8 @@ for opt, arg in opts: ...@@ -71,6 +72,8 @@ for opt, arg in opts:
bytesLimit = arg bytesLimit = arg
elif opt in ('-c'): elif opt in ('-c'):
communityString = arg communityString = arg
elif opt in ('-d'):
debug = 1
else: else:
usage() usage()
sys.exit(3) sys.exit(3)
...@@ -246,4 +249,28 @@ monthComplete = ( float(secondsIntoMonth.total_seconds()) / float(secondsInMonth ...@@ -246,4 +249,28 @@ monthComplete = ( float(secondsIntoMonth.total_seconds()) / float(secondsInMonth
totalDataUsed = int(inBytesTotal) + int(outBytesTotal) totalDataUsed = int(inBytesTotal) + int(outBytesTotal)
percentageDataUsed = ( float(totalDataUsed) / float(bytesLimit) ) * 100 percentageDataUsed = ( float(totalDataUsed) / float(bytesLimit) ) * 100
print percentageDataUsed # Generate perfdata:
perfdata = '|\'BytesInRate\'=' + str(inBytesPerSec) +'bytes/sec;;;;\'BytesOutRate\'=' + str(outBytesPerSec) + 'bytes/sec;;;;'
# Calculate warning/critical
if totalDataUsed > bytesLimit:
print('CRITICAL - You have exceeded your alloted data usage for this period' + perfdata)
print('You are alloted ' + str(bytesLimit) + ' bytes for the month but have already used ' + str(totalDataUsed) + ' bytes.')
sys.exit(2)
elif percentageDataUsed > monthComplete:
print('WARNING - You are using data at a rate that will cause you to exceed usage allotment for this period' + perfdata)
print('The month is ' + str(round(monthComplete,2)) + '% complete.')
print('The data allotment on interface ' + interface + ' is ' + str(round(percentageDataUsed,2)) +'% used.')
sys.exit(1)
else:
print('OK - You will not use all of your alloted data for this period at the current rate' + perfdata)
sys.exit(0)
if debug == 1:
print('The month is ' + str(round(monthComplete,2)) + '% complete.')
print('The data allotment on interface ' + interface + ' is ' + str(round(percentageDataUsed,2)) +'% used.')
print('The current incoming rate is ' + str(inBytesPerSec) + ' bytes/second.')
print('The current outgoing rate is ' + str(outBytesPerSec) + ' bytes/second.')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment