I recently acquired a nice 7×11 LED display, and I want (among other stuff) display my nagios status on it. For that I need to query the status of my Nagios installation.
What is the appropriate way to get a status summary (e.g. number of non-OK services) from a remote Nagios server from, say, a perl script?
I maintain an extremely large nagios installation, and can say the absolute best method to do this is via the "livestatus" event broker:
http://mathias-kettner.de/checkmk_livestatus.html
Livestatus provides instant access to nagios status via a local or tcp socket and introduces almost zero additional CPU load on your monitoring server (but does have a memory footprint, of course). Simple integration with xinetd/unixcat allows it to be queried via the network. Output is in one of three formats: CSV, JSON and Python. Numerous configuration options are available, and it is stable enough for Production usage. The documentation is very good.
Additionally, livestatus enables other nagios add-ons, such as "MK Multisite", which aggregates the results from multiple nagios installations into a single GUI without the use of NSCA or passive service checks results, which require nagios configurations to be maintained on both worker and master servers.
As far as I know there is no nagios.com supported API for querying nagios status. There are quite a few different add-ons that will allow you do to this. Some are discussed in this question.
https://stackoverflow.com/questions/7768215/is-there-a-way-to-extract-data-from-nagios-as-if-it-was-a-web-service
You can query the cgi directly and "screen scrape" the returned html, but that is not a very robust solution. I have messed around a bit with this version of an api server, but have not put in it production.
https://github.com/xb95/nagios-api