Wouldn’t it be great if any new Linux host automatically configured itself for monitoring with Nagios XI?
What if we told you it is 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 down at the bottom. As you read through the script you can see that before the script runs the call, you have the opportunity to supply 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.
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 in to 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 side bar, 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 firstname.lastname@example.org