API for interfacing with nagios?

I manage a network that consists of many distributed nodes containing servers that I need to query on a on demand basis. Some of these sites are connected through redundant circuits, and some sites share a circuit, so it’s been somewhat difficult to design my software and database to account for the complexity and be “smart” enough to handle a dropped or slow link. It suddenly hit me that I already had all of the functionality that I needed (and then some) already configured into my nagios installation…

So what I’m looking for is a way to be able to talk to nagios through a cgi to retrieve info about specific hosts…for instance query a specific host group for a particular host type, and return it’s status, IP and any other info I may desire. I though about accessing the existing cgi’s through something similar to php CURL, and filtering through the retrieved HTML, but I’d rather have a proper, elegant interface. This kind of integration would also make it easier for my techs to acknowledge and and handle problems, so having the ability to send commands back to nagios would be nice as well.

Does anyone have any thoughts on how to approach this?