2

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 and 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

ryuujin
  • 192
  • 3
  • 16

2 Answers2

1

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.

opsguy
  • 1,781
  • 1
  • 12
  • 11
0

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.