Index: modules/nagios/files/check_bandwidth |
=================================================================== |
--- a/modules/nagios/files/check_bandwidth |
+++ b/modules/nagios/files/check_bandwidth |
@@ -1,6 +1,6 @@ |
#!/usr/bin/env python |
-import re, subprocess, sys |
+import os, re, subprocess, sys |
def extract_data(type, vnstat_output): |
match = re.search(r"%s\s*([\d\.]*) (.bit/s)" % type, vnstat_output) |
@@ -21,10 +21,13 @@ |
if __name__ == "__main__": |
if len(sys.argv) != 3: |
- print "Usage: `basename $0` WARN CRIT" |
+ script_name = os.path.basename(sys.argv[0]) |
+ print "Usage: %s WARN CRIT" % script_name |
sys.exit(0) |
(warn, crit) = sys.argv[1:3] |
+ warn = int(sys.argv[1]) |
+ crit = int(sys.argv[2]) |
vnstat_output = subprocess.check_output(["vnstat", "-tr"]) |
(rx, rx_unit) = extract_data("rx", vnstat_output) |
@@ -37,12 +40,12 @@ |
output = "%s|%s" % (status, perfdata) |
- if warn <= rx or warn <= tx: |
+ if rx >= crit or tx >= crit: |
+ print "CRITICAL - " + output |
+ sys.exit(2) |
+ |
+ if rx >= warn or tx >= warn: |
print "WARNING - " + output |
sys.exit(1) |
- if crit <= rx or crit <= tx: |
- print "CRITICAL - " + output |
- sys.exit(2) |
- |
print "OK - " + output |