|
@@ -51,32 +51,25 @@ def main():
|
|
|
with open(options.alert_file, 'r') as f:
|
|
|
data = json.load(f)
|
|
|
|
|
|
- found = False
|
|
|
- buf = ''
|
|
|
+ buf_list = []
|
|
|
+ exit_code = 0
|
|
|
|
|
|
for_hosts = data[options.alert_name]
|
|
|
if for_hosts.has_key(options.host):
|
|
|
for host_entry in for_hosts[options.host]:
|
|
|
+ buf_list.append(host_entry['text'])
|
|
|
alert_state = host_entry['state']
|
|
|
- alert_text = host_entry['text']
|
|
|
- if alert_state == 'CRITICAL':
|
|
|
- print str(alert_text)
|
|
|
- exit(2)
|
|
|
- elif alert_state == 'WARNING':
|
|
|
- print str(alert_text)
|
|
|
- exit(1)
|
|
|
- else:
|
|
|
- if found:
|
|
|
- buf = buf + ', '
|
|
|
- buf = buf + alert_text
|
|
|
- found = True
|
|
|
+ if alert_state == 'CRITICAL' and exit_code < 2:
|
|
|
+ exit_code = 2
|
|
|
+ elif alert_state == 'WARNING' and exit_code < 1:
|
|
|
+ exit_code = 1
|
|
|
|
|
|
- if not found:
|
|
|
+ if 0 == len(buf_list):
|
|
|
print "Status is not reported"
|
|
|
exit(3)
|
|
|
else:
|
|
|
- print buf
|
|
|
- exit(0)
|
|
|
+ print ", ".join(buf_list)
|
|
|
+ exit(exit_code)
|
|
|
|
|
|
except Exception:
|
|
|
traceback.print_exc()
|