I've written quite a lot of code, but I'm loathe to share any of it because I find it embarrassing. It's like letting you see my underpants, sure they're very nice underpants, but at the same time they give you insight that I'd rather you didn't have (if it's all the same to you). So the code that appears herein is the stuff that I've found SO useful I couldn't help but share it.
Nagfs is a Nagios event broker module that creates a filesystem containing the current runtime state of the Nagios system. This means in a nutshell that you can query the status of a given service or set of services using everyday shell tools like find and grep. For example, once Nagfs is running, you can list all the services currently in a critical state by typing:
grep -rl '2' /usr/share/nagios/status/local
The numbers are what you'd expect ( 0:OK, 1:Warning, 2:Critical, 3,Unknown). If the service is in a soft state a 'servicename.soft' file is created with the soft state status number. Each host also has a HOST file which contains the current status of the host itself.
nagfs registers for SERVICE_STATUS_DATA and HOST_STATUS_DATA updates from the Nagios server, which means that the nagfs filesystem is immediately up to date upon Nagios startup, and is always perfectly in sync with Nagios' memory state.
download it here