check-linux-by-ssh
check-linux-by-ssh copied to clipboard
Proposal: add an option required to check_processes_by_ssh
This option raise an error if no command was found in the processes list.
Here is a patch to test:
diff --git a/check_processes_by_ssh.py b/check_processes_by_ssh.py
index 3e84c78..7216925 100755
--- a/check_processes_by_ssh.py
+++ b/check_processes_by_ssh.py
@@ -117,8 +117,8 @@ parser.add_option('-C', '--command',
dest="command", help='Command name to match for the check')
parser.add_option('-S', '--sum', action='store_true',
dest="sum_all", help='Sum all consomtion of matched processes for the check')
-
-
+parser.add_option('-r', '--required', action='store_true',
+ dest="required", help='if command not found raise a critical alert')
if __name__ == '__main__':
# Ok first job : parse args
@@ -128,7 +128,7 @@ if __name__ == '__main__':
port = opts.port
hostname = opts.hostname or ''
-
+ required = opts.required or False
command = opts.command
# Look if we need to sum all value from the process match or not
sum_all = opts.sum_all
@@ -159,13 +159,17 @@ if __name__ == '__main__':
status = 0 # all is green until it is no more ok :)
bad_processes = []
global_sum = 0
+ found = False
+ count = 0
for ps in pss:
(user, vsz, rss, pcpu, cmd) = ps
# Look if the cmd match out command filter
if command and command not in cmd:
continue
-
+ else:
+ count += 1
+ found = True
#perfdata += '"%s_used_pct"=%s%%;%s%%;%s%%;0%%;100%% "%s_used"=%s;%s;%s;0;%s ' % (mount, used_pct, warning, critical, mount, used, _size_warn, _size_crit, size)
# If we sum all, we will look at the comparision later
if sum_all:
@@ -194,7 +198,7 @@ if __name__ == '__main__':
sys.exit(2)
# Ok here we are in sum_all
- perfdata = '"%s_consumtion"=%dMB' % (command, float(global_sum)/1024)
+ perfdata = '"%s_consumtion"=%dMB;%s;%s;;' % (command, float(global_sum)/1024, warning, critical)
if global_sum >= critical*1024:
print 'Critical: the processes %s are too high %dMB | %s' % (command, float(global_sum)/1024, perfdata)
sys.exit(2)
@@ -203,6 +207,9 @@ if __name__ == '__main__':
print "Warning: the processes %s are too high %dMB | %s" % (command, float(global_sum)/1024, perfdata)
sys.exit(1)
-
- print "OK: the processes %s are good %dMB | %s" % (command, float(global_sum)/1024, perfdata)
- sys.exit(0)
+ if required and not found:
+ print "CRITICAL: no processes found for command line %s" % (command)
+ sys.exit(0)
+ else:
+ print "OK: the processes %s are good %dMB | %s" % (command, float(global_sum)/1024, perfdata)
+ sys.exit(0)