Automatically Monitor Dynamic Linux Inventory

Wouldn’t it be great if any new Linux host automatically configured itself for monitoring with Nagios XI?

What if we told you it was already possible?

It’s true. The only reason your new Linux inventory isn’t configuring itself in Nagios XI is that you’re
not doing it! It’s easier than you might think.

It Starts with the XI API

The cool thing about the Nagios XI API is that we can use API calls to create new hosts and services. Since the API uses cURL from the command line to send and request information, it’s relatively simple to use an API call in a Bash script. Using a couple other commands, we can quickly produce a simple script that allows a Linux machine to register itself as a host in Nagios XI and set up a ping check.

Check out this sample script, which takes all the headache out of understanding the intricacies of the API. The API call itself is at the bottom. As you read through the script, you can see that before the script runs the call, you have the opportunity to provide some information.

Put in your XI server IP address and your Nagios XI API key. The next command you see will find and store your new machine’s IP address. That’s the best line in the script. If you assign unique host names to your hosts, you can follow the instructions for including that in the API call as well.

If you add the script as an executable and set it to run at boot on your base deployment image, your host will automatically register itself!

Taking It to the Next Level

Ok, sure, you can register the host through the API. You can ping it. That’s cool, but automating agent-based monitoring for CPU and disk space and all the metrics is really what we’re after, isn’t it? No worries.

Now that you know a little about the API, you can really dig into how powerful it can be for you. In fact, once you know your way around API calls, it is just as easy to automatically set up monitoring via NCPA and add service checks as well. The API documentation is all on-board in the Nagios XI interface. Simply navigate to the Help page, and then on the left sidebar, in the REST API Docs section, click on Config Reference. Dynamic inventory has never been so simple!

Need help or additional tips? Let us know at sales@nagios.com

Recent Posts

Common Nagios Misconceptions

Although Nagios made its start as an open-source monitoring solution, it’s a common misconception that that is all Nagios is when, in fact, Nagios includes