When automating server provisioning you might be considering implementing Nagios for monitoring servers and services as part of the build process. Apart from the help section of Nagios console giving some hints on how to interact with the API, there isn’t much else to go on so I’m sharing my learnings on how to do this.

I’m not going to go through the whole implementation of automating Nagios into server builds but more specifically connecting to the API.

The Nagios reference is http://host.example.com/nagiosxi/help/ and then click on “Config Reference”

The first step is to add the host – now this is in the Nagios help section so hopefully, this is nothing new

curl -XPOST "http://nagios.example.com/nagiosxi/api/v1/config/host?apikey=aw33E58m17bH6d3m4z6Y5V9FNVwJTvDU5tjEAGw7C35iLarr&pretty=1" -d "host_name=testapihost&address=127.0.0.1&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"

You will need to change the FQDN, API Key, Hostname and address to your requirements to make this work for you.

Scroll to the right of the code to see it all.

One thing to note is every setting is separated by a “&” and variables specified by the check start with “!”. This is the key to understanding how this works.

Add Processor

curl -XPOST "http://nagios.example.com/nagiosxi/api/v1/config/service?apikey=aw33E58m17bH6d3m4z6Y5V9FNVwJTvDU5tjEAGw7C35iLarr&pretty=1" -d "host_name=testapihost&service_description=CPU&check_command=check_xi_service_nsclient\!password\!CPULOAD\!80,90&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"

Add Disk

curl -XPOST "http://nagios.example.com/nagiosxi/api/v1/config/service?apikey=aw33E58m17bH6d3m4z6Y5V9FNVwJTvDU5tjEAGw7C35iLarr&pretty=1" -d "host_name=testapikey&service_description=CDisk&check_command=check_xi_service_nsclient\!password\!USEDDISKSPACE\!-l C -w 80 -c 95&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"

Add Memory

curl -XPOST "http://nagios.example.com/nagiosxi/api/v1/config/service?apikey=aw33E58m17bH6d3m4z6Y5V9FNVwJTvDU5tjEAGw7C35iLarr&pretty=1" -d "host_name=testapihost&service_description=Mem&check_command=check_xi_service_nsclient\!password\!MEMUSE\!-w 80 -c 90&check_interval=5&retry_interval=4&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"

Add Uptime

curl -XPOST "http://nagios.example.com/nagiosxi/api/v1/config/service?apikey=aw33E58m17bH6d3m4z6Y5V9FNVwJTvDU5tjEAGw7C35iLarr&pretty=1" -d "host_name=testapihost&service_description=Uptime&check_command=check_xi_service_nsclient\!password\!UPTIME&check_interval=5&retry_interval=7&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"

Make sure you change the FQDN, API Key, Hostname and password variables for this to work.

I found the configuration wizard very helpful, what I did was add the service I wanted to check, see what the “check command” was and the variables set and then crafted my own curl command to add to Nagios.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.