Modify dhcp_failed_machines for nagios nrpe

Add two more optional arguments (warning and critical threshold), so nagios
nrpe can directly call the script to check dhcp status.

BUG=chromium:333107
TEST=manual test in chromeos-mcp1 and chromeos-sam1

Change-Id: I35c85fa9d5209846c018d112d28139200e3e2ffb
Reviewed-on: https://chromium-review.googlesource.com/182853
Tested-by: Dan Shi <[email protected]>
Reviewed-by: Alex Miller <[email protected]>
Commit-Queue: Dan Shi <[email protected]>
diff --git a/contrib/dhcp_failed_machines.py b/contrib/dhcp_failed_machines.py
index 865b59a..f38c7295 100755
--- a/contrib/dhcp_failed_machines.py
+++ b/contrib/dhcp_failed_machines.py
@@ -61,4 +61,21 @@
 def lookup(h):
   return lookups.get(h, h)
 
-pprint.pprint(sorted([lookup(h) for h in offenders]))
+hosts = sorted([lookup(h) for h in offenders])
+if len(sys.argv) == 2:
+  pprint.pprint(hosts)
+else:
+  warning = int(sys.argv[2])
+  critical = int(sys.argv[3])
+  if len(offenders) > critical:
+    print ('DHCP Critical, number of duts with DHCP failure is %d: %s' %
+           (len(hosts), ', '.join(hosts)))
+    sys.exit(2)
+  elif len(offenders) > warning:
+    print ('DHCP Warning, number of duts with DHCP failure is %d: %s' %
+           (len(hosts), ', '.join(hosts)))
+    sys.exit(1)
+  else:
+    print ('DHCP OK, number of duts with DHCP failure is %d: %s' %
+           (len(hosts), ', '.join(hosts)))
+    sys.exit(0)
\ No newline at end of file