Need help on JSON file monitoring

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
bsivavani
Posts: 339
Joined: Tue Oct 06, 2015 9:17 am

Need help on JSON file monitoring

Post by bsivavani »

Hi,

We are planning to monitor attributes present in JSON file which is the output of URL http://remotehostname:8080/actuator/health.

JSON file content:
{"status":"UP","details":{"diskSpace":{"status":"UP","details":{"total":42947571712,"free":40454283264,"threshold":10485760}}}}

We would like to monitor diskSpace attribute. Kindly advice ?
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Need help on JSON file monitoring

Post by npolovenko »

Hello, @bsivavani. Here are some of the plugins I've found on the exchange to check JSON:
https://exchange.nagios.org/directory/P ... s)/details
https://exchange.nagios.org/directory/P ... on/details
https://exchange.nagios.org/directory/P ... s)/details
Please take a look and let me know if one of them could work for you.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
SteveBeauchemin
Posts: 524
Joined: Mon Oct 14, 2013 7:19 pm

Re: Need help on JSON file monitoring

Post by SteveBeauchemin »

I am using a check_json.pl plugin on EMC XtremIO Cluster to get free space.
This is how I worked through it. Actually, this is how I do all my plugin related work.

1. Use command line to get data and see how it looks. Find the piece you are wanting to monitor.
2. Get the plugin to work from the command line using the syntax figured out from step 1.
3. Transplant to the GUI.

Start by using curl as a basic test to see if we get any response. Once we have username, password, and URL figured out we can move to the actual plugin. It is good to see it work using a basic tool before you get fancy.

This a shortened version of the response.
Pay attention to "content" and "free-ud-ssd-space-in-percent": 35
as those define the data I want to use.

Code: Select all

curl -sk https://<username>:<password>@<Host-IP-address>/api/json/types/clusters/1
{
    "content": {
        "wr-iops-gt1mb": "0",
        "rd-bw-512b": "0",
        "free-ud-ssd-space-in-percent": 35,
        "wr-latency-256kb": "1954",
        "rd-iops": "1504",
        "small-bw": "29064"
    },
    "links": [
        {
            "index": 1,
            "href": "https://131.198.26.23/api/json/types/clusters/1",
            "rel": "self"
        }
    ]
}
Once I know I have working syntax I move to the plugin.
The Plugin named check_json.pl will use this syntax from the command line. Trial and error until it looks the way you need it.
(Notice content and free-ud-ssd-space-in-percent)

Code: Select all

./check_json.pl --url "https://<username>:<password>@<Host-IP-address>/api/json/types/clusters/1" --ignoressl --attributes '{content}->{"free-ud-ssd-space-in-percent"}' --perfvars '{content}->{"free-ud-ssd-space-in-percent"}' --warning 4: --critical 2:

Check JSON status API OK - free-ud-ssd-space-in-percent: 35 | free-ud-ssd-space-in-percent=35;4:;2:
Then I transplant to the GUI.

Check_command = check_json

Code: Select all

/usr/local/nagios/libexec/check_json.pl $ARG1$ $ARG2$ $ARG3$ $ARG4$ $ARG5$ $ARG6$ $ARG7$ $ARG8$
Service Definition
Service args

Code: Select all

$ARG1$ = --url "https://[username]:[password]@$HOSTADDRESS$:443/api/json/types/clusters/1"
$ARG2$ = --ignoressl
$ARG3$ = --attributes '{content}->{"free-ud-ssd-space-in-percent"}'
$ARG4$ = --perfvars '{content}->{"free-ud-ssd-space-in-percent"}'
$ARG5$ = --warning 4:
$ARG6$ = --critical 2:
I am pretty certain that I got the plugin from here https://github.com/c-kr/check_json

I hope this helps get you successful.

Steve B
XI 5.7.3 / Core 4.4.6 / NagVis 1.9.8 / LiveStatus 1.5.0p11 / RRDCached 1.7.0 / Redis 3.2.8 /
SNMPTT / Gearman 0.33-7 / Mod_Gearman 3.0.7 / NLS 2.0.8 / NNA 2.3.1 /
NSClient 0.5.0 / NRPE Solaris 3.2.1 Linux 3.2.1 HPUX 3.2.1
bsivavani
Posts: 339
Joined: Tue Oct 06, 2015 9:17 am

Re: Need help on JSON file monitoring

Post by bsivavani »

Thanks for your help.

I am able to get the output using check_json.pl plugin from command line (Nagios server), below is output
[root@XXXXX tmp]# /usr/local/nagios/libexec/check_json.pl --url 'http://XXXXX:8080/storm-report-test/actuatortest/health' --attributes '{status}'
Use of uninitialized value in split at /usr/local/nagios/libexec/check_json.pl line 145.
Use of uninitialized value in split at /usr/local/nagios/libexec/check_json.pl line 146.
Check JSON status API OK
[root@XXXXX tmp]#

But from Nagios console I am receiving below error

COMMAND: /usr/local/nagios/libexec/check_json.pl --url "http://XXXXX:8080/storm-report-test/actuatortest/health" --attributes '{status}'
OUTPUT: (No output on stdout) stderr: Can't locate JSON/backportPP.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at (eval 15) line 3.

But the module is installed on Nagios server and located at /usr/local/share/perl5.
[root@XXXXX tmp]# locate backportPP.pm
/usr/local/share/perl5/JSON/backportPP.pm
[root@XXXXX tmp]#

Kindly advice on this error ?
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Need help on JSON file monitoring

Post by npolovenko »

@SteveBeauchemin, Thanks for the detailed walkthrough! I'm sure many forum users will find this very useful.

@bsivavani , Try adding the following entry to the /etc/sudoers file:
NAGIOSXI ALL = NOPASSWD:/usr/local/nagios/libexec/check_json.pl *
Did you install the following packages?
yum install perl-JSON
yum install perl-Nagios-Plugin
Please show me the permissions on JSON folder and modules inside it:
ls -l /usr/share/perl5/vendor_perl/JSON/
ls -ld /usr/share/perl5/vendor_perl/JSON/
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
bsivavani
Posts: 339
Joined: Tue Oct 06, 2015 9:17 am

Re: Need help on JSON file monitoring

Post by bsivavani »

@bsivavani , Try adding the following entry to the /etc/sudoers file:
NAGIOSXI ALL = NOPASSWD:/usr/local/nagios/libexec/check_json.pl *
I tried with adding check_json.pl to /etc/sudoers file, but still getting the same error.

Did you install the following packages?
yum install perl-JSON
yum install perl-Nagios-Plugin
Yes. I have both modules installed on Nagios server.

Please show me the permissions on JSON folder and modules inside it:
ls -l /usr/share/perl5/vendor_perl/JSON/
ls -ld /usr/share/perl5/vendor_perl/JSON/
Please find below output
[root@XXXXX ~]# ls -l /usr/local/share/perl5/JSON
total 192
drwx------ 2 root root 4096 Feb 14 13:36 backportPP
-rwxr-xr-x 1 root root 100704 Dec 6 18:29 backportPP.pm
drwx------ 2 root root 4096 May 19 2016 PP
-r--r--r-- 1 root root 81997 May 19 2016 PP.pm
[root@XXXXX ~]#

[root@XXXXX ~]# ls -ld /usr/local/share/perl5/JSON
drwx------ 4 root root 4096 Feb 14 13:36 /usr/local/share/perl5/JSON
[root@XXXXX ~]#
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Need help on JSON file monitoring

Post by npolovenko »

@bsivavani, Let's try giving permissions to the JSON folder and all modules inside it. Let us know if that fixes your issue.
chmod -R 777 /usr/local/share/perl5
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked