Interact with Nagios Interface programatically

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
lb2cons
Posts: 72
Joined: Mon Dec 08, 2014 4:11 pm

Interact with Nagios Interface programatically

Post by lb2cons »

Hello Experts.

We need to develop a script capable of interact with Nagios "Scheduled Downtime" via OS. Is it possible?

There are some servers from a customer that do database offline backup and because of that many alarms of "Database Down" are generated. The backup window it's not fixed, so it's not possible to scheduled a "Recurring Downtime".

My best options is develop this script that could be executed before the script that do the backup.

Is it possible?
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Interact with Nagios Interface programatically

Post by jdalrymple »

What you need to do is run an external command prior to your downtime window.

Here is our (dated) information on available external commands:

https://old.nagios.org/developerinfo/ex ... ndlist.php

Here is a little more info on how they work:

https://assets.nagios.com/downloads/nag ... mands.html
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Interact with Nagios Interface programatically

Post by WillemDH »

lb2cons,

I have something that could make you happy. I did not put it on the Nagios Exchange yet, but you can find it on my GitHub page here:

https://github.com/willemdh/naf_schedule_downtime

Put it in Reactor and you can put hosts, services and hostgroups in downtime from anywhere os and scripting language independent. I'm using it a lot in Powershell and Bash scripts.

Let me know if you like it.

Grtz

Willem
Nagios XI 5.8.1
https://outsideit.net
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: Interact with Nagios Interface programatically

Post by hsmith »

Hi lb2cons,

Were Willem and jdalrymple able to answer your question?
Former Nagios Employee.
me.
lb2cons
Posts: 72
Joined: Mon Dec 08, 2014 4:11 pm

Re: Interact with Nagios Interface programatically

Post by lb2cons »

Hi WillemDH, I'm very happy knowing that you are working on a solution for this problem.

https://github.com/willemdh/naf_schedul ... e/issues/1

I've tried to use your script but the service wasn't down timed. I've created an issue for your investigation. I'm interested in assist you with this script, please let me know if I can help.
mp4783
Posts: 116
Joined: Wed May 14, 2014 11:11 am

Re: Interact with Nagios Interface programatically

Post by mp4783 »

One thing to remember about these programmatic interfaces is that the changes occur only to the running Nagios collector and do not survive a restart of the Nagios. Permanent changes require modification to configuration files and updating (reconfiguring) of Nagios XI.

This is a non-trivial task for many things.
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Interact with Nagios Interface programatically

Post by WillemDH »

@lb2cons I'll try helping you find the issue:
It's working for me, so it should be possible to get it working for you too. For debugging you can set the verbose in 1 the beginning of the script.
Use writelog Verbose priority message
Can you please try to schedule the downtime of one host and set --Service to 'All' without the single quotes?
Can you try to use the curl command with the variables from shell:

Code: Select all

curl --fail --silent --show-error "http://$NagiosServer/nrdp/?cmd=submitcmd&token=$NrdpToken&command=SCHEDULE_HOST_DOWNTIME;$Target;$Now;$End;1;0;300;$NagiosUser;$Comment"
echo this command and then copy the echo and try executing it in your shell. Are you 100 % sure your nrdp token is correct?
The fact that

Code: Select all

        writelog Verbose Info "Attempting to schedule downtime for service $Service on host $Target."
        Now=`date +%s`
        End=$((Now + $Duration))
        curl --fail --silent --show-error "http://$NagiosServer/nrdp/?cmd=submitcmd&token=$NrdpToken&command=SCHEDULE_SVC_DOWNTIME;$Target;$Service;$Now;$End;1;0;300;$NagiosUser;$Comment" > /dev/null
        CommandResult=$?
        if [ $CommandResult -eq 0 ]; then
            writelog $Logfile Info "Schedule downtime succeeded for service $Service on host $Target."
and you get a succes could also imply there is something wrong with the date and you might be trying to set downtime on a wrong date? Please debug and verify. The curl command needs Linux time ticks..

@mp4783 This addon makes use of nrdp to activate an external command with curl. No program restart is needed for that?
Nagios XI 5.8.1
https://outsideit.net
lb2cons
Posts: 72
Joined: Mon Dec 08, 2014 4:11 pm

Re: Interact with Nagios Interface programatically

Post by lb2cons »

WillemDH. the epoch date seems to be the problem, but the date it's correct. Check my last comment on Github.

What more can we test?
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Interact with Nagios Interface programatically

Post by WillemDH »

Please post your test Bash script here. i'm curious what the Nagios support has to say about this? It should work, check also this out: https://old.nagios.org/developerinfo/ex ... and_id=119

They also use

Code: Select all

now=`date +%s`
Nagios XI 5.8.1
https://outsideit.net
lb2cons
Posts: 72
Joined: Mon Dec 08, 2014 4:11 pm

Re: Interact with Nagios Interface programatically

Post by lb2cons »

The script:

#!/bin/bash
NagiosServer=10.200.0.113
NrdpToken=Flessak
Target=Flessak-PRD
Now=`date +%s`
Duration=7200
End=$(($Now + $Duration))
echo $End
NagiosUser=bernardo.vale
echo "http://$NagiosServer/nrdp/?cmd=submitcmd&token=$NrdpToken&command=SCHEDULE_HOST_DOWNTIME;$Target;$Now;$End;1;0;300;$NagiosUser;$Comment"
curl --fail --silent --show-error "http://$NagiosServer/nrdp/?cmd=submitcmd&token=$NrdpToken&command=SCHEDULE_HOST_DOWNTIME;$Target;$Now;$End;1;0;300;$NagiosUser;$Comment"
date -d $@Now +"%Y-%m-%d %H:%M:%S"

Mon Sep 14 11:41:39 BRT 2015
Output:

[root@LB2-NagiosXI ~]# ./curl_test.sh
1442248897
http://10.200.0.113/nrdp/?cmd=submitcmd ... nardo.vale;
<?xml version="1.0" encoding="utf-8"?>
<result>
<status>0</status>
<message>OK</message>
</result>
2015-09-14 11:41:37
[root@LB2-NagiosXI ~]# date
Locked