Graphing the number of active HOSTS and SERVICES

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
da1701d
Posts: 23
Joined: Tue Jun 25, 2013 3:57 pm

Graphing the number of active HOSTS and SERVICES

Post by da1701d »

I have a nagiosxi environment where multiple admins make changes and we also have an automated deployment system setup where machines get added/deleted automatically using the API in Nagiosxi. I'm trying to find a easy way to make a graph showing the number of current/active HOSTS (and also SERVICE CHECKS) being monitored so I can have a way graph the historical trend. I have not found any quick out of the box type of way but maybe some sort of mysql query with the plugin "check_mysql_query" that is talked about in this article https://support.nagios.com/kb/article.php?id=513 showing how to check and monitor both max_connections and threads_connected. Maybe someone has figured out the mysql query to output the of hosts the database know about. Any help is appreciated.

Thanks
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Graphing the number of active HOSTS and SERVICES

Post by npolovenko »

Hello, @da1701d.

**Disclaimer. The example that I'm giving below may be not 100% accurate and serves just as a concept on how to create a plugin that is going to do what you want. You will need to adjust the code to get your plugin to work. Also, you could contact Nagios support for a custom plugin development.


1. You can make custom JSON query to Nagios which will return the info on a number of hosts/services.
Take a look at this manual:
https://labs.nagios.com/2014/06/19/expl ... -7-part-1/

Paste this link in your web browser:
http://<nagios server>/nagios/jsonquery.html

2. Create a PHP script in libexec folder

//example of a json url from step 1
$url = "http://192.168.4.172/nagios/cgi-bin/sta ... le+pending";
$json=file_get_contents($url);
$data=json_decode($json,true);
$hosts = $data['count'];

2. Now you can output this data into a graph.
Take a look at this documentation:
https://nagios-plugins.org/doc/guidelines.html

Add this line:
echo "OK|'Number of hosts'=$hosts"

Basically everything after | sign in a format String = Value will be automatically rendered to the graph in XI.

3. Create a new check command in XI:

Code: Select all

$USER1$/your_plugin_name.php
4. Create a new service check for localhost that is going to use the command from step 3.

Regards.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
da1701d
Posts: 23
Joined: Tue Jun 25, 2013 3:57 pm

Re: Graphing the number of active HOSTS and SERVICES

Post by da1701d »

Thanks! I was not familiar with this feature of nagios. I think it can be the solution. I notice the initial http query requires a username and password. What did you do from a script perspective for getting around the username and password?

Thanks
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Graphing the number of active HOSTS and SERVICES

Post by npolovenko »

@da1701d, Not a problem. Basic authentication is used in this case, so you can add username and password to your query in this format:

Code: Select all

http://nagiosadmin:[email protected]/nagios/cgi-bin/statusjson.cgi?query=servicecount&hoststatus=up+down+unreachable+pending
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked