I am trying to create a plugin (in python) for nagios that would fetch a json file from a remote server and then according to the contents of that file will generate alerts.
The specific file is actually alerts generated from a separate monitoring system hence my goal is to generate nagios notifications by polling the alerts form the other system.
Assuming the json file could contains, lets say three alerts, i would like my script to generate three different alert entries.
So far i have a loop in my script that checks if the script has at least one alert and if so, it will print the alertname and exit with status code of two ( 2 ) so it can indicate a CRITICAL to nagios.
data = urllib2.urlopen("http://127.0.0.1:880").read() alerts = json.loads(data) if len(alerts["data"]) == 0: exit(0) else: print "Alerts: " for alert in alerts["data"]: print " " + alert["labels"]["alertname"] exit(2)
Is it possible to generate multiple alerts on nagios using a single script?
I mean, if you can only have a single exit code how could you generate multiple different alerts?