Populate NAGIOS host fetching status data from a database
we have a Nagios server and we use it to monitor our hosts.
Now we have an old system that reports in a mysql database the status of some specific hosts. I'm wondering if there is a method (also if there is the possibility) to write a plugin that can fetch data from the database a开发者_Go百科nd populate Nagios monitor.
Let's image the database has a table like this: IP, HOSTNAME, STATUS, CPU_TEMP, HDD_TEMP
and I'd like to fetch these data into Nagios monitor. Is it possible?
There's no way to connect client through nagios daemon, I can only fetch data from this database.
Thanks!!! regards
If you can hit the DB directly from nagios, I'd do some bash script like this:
mysql -uuser -ppass -H monitoringDb.mydomain.com -e "select HOSTNAME,STATUS,CPU_TEMP,HDD_TEMP from monitoring where STATUS != "OK" OR CPU_TEMP > '40' OR HDD_TEMP > '20'" > /tmp/check_monitoring
if [[ `wc -l /tmp/check_monitoring` > 0 ]]; # If that query returned anything, you have an issue
then echo "CRITICAL: `cat /tmp/check_monitoring`" && exit 2
fi
echo "OK: Monitoring DB Checks passed" && exit 0
The SQL probably has a bug or two, but you should get the idea. If you wanna get fancy you could do more if statements for warning levels and return 1.
you would need to craft a plugin that would connect to the DB, query for a given HOSTNAME or IP, and check the STATUS to be within parameters.
精彩评论