Nagios API and nmap
What’s in your subnet?
In my /24 development lab subnet we’re constantly bringing up new vms and decommisioning old ones. And sometimes I forget to update nagios with the new hosts to monitor. Here’s how I remind myself to keep the nagios host list in sync with reality:
It’s a long command, and won’t win any awards for readability, but essentially we’re querying Nagios for a complete list of hosts that we currently monitor, then we’re running an nmap
scan of the subnet, and then we’re diffing the result. If there’s a difference between the two, alert!
Note
In the above snipet, you’d of course need to provide your own file containing your nagios user basic auth header, the ip range to limit the diff to, and your subnet’s range in CIDR notitation.
When sorting a list of IP addresses, use the -V
option.
Here’s a great resource on learning more about the Nagios API.