Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: modules/nagios/files/check_bandwidth

Issue 9349198: Properly return WARNING and CRITICAL in check_bandwidth (Closed)
Patch Set: Fixed usage Created Feb. 19, 2013, 2:14 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld