From d836bf729849a3549d226e78d1efabb5e05d9f2a Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 30 Oct 2018 13:56:09 -0400 Subject: [PATCH] Map health to nagios compatible codes nodehealth adds granularity and health to the return code. Rather than only reflecting failure running command, also have nodehealth assign exit code according to the expectations of nagios. --- confluent_client/bin/nodehealth | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/confluent_client/bin/nodehealth b/confluent_client/bin/nodehealth index 5cafd960..f758431c 100755 --- a/confluent_client/bin/nodehealth +++ b/confluent_client/bin/nodehealth @@ -44,6 +44,13 @@ except IndexError: client.check_globbing(noderange) +codemappings = { + 'ok': 0, + 'warning': 1, + 'critical': 2, + 'failed': 2, +} + def main(): global session, exitcode, healthbynode, healthexplanations, health, node, sensor, explanation session = client.Command() @@ -66,9 +73,11 @@ def main(): if 'error' in health[node]: sys.stderr.write('{0}: Error: {1}\n'.format( node, health[node]['error'])) - exitcode |= 1 + exitcode = 3 if 'health' in health[node]: healthbynode[node] = health[node]['health']['value'] + if codemappings[healthbynode[node]] > exitcode: + exitcode = codemappings[healthbynode[node]] if 'sensors' in health[node]: healthexplanations[node] = [] for sensor in health[node]['sensors']: @@ -94,5 +103,5 @@ try: main() except KeyboardInterrupt: print('') - sys.exit(0) +sys.exit(exitcode)