Interact with Nagios Interface programatically
Interact with Nagios Interface programatically
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?
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
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
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
Re: Interact with Nagios Interface programatically
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
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
https://outsideit.net
Re: Interact with Nagios Interface programatically
Hi lb2cons,
Were Willem and jdalrymple able to answer your question?
Were Willem and jdalrymple able to answer your question?
Former Nagios Employee.
me.
me.
Re: Interact with Nagios Interface programatically
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.
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.
Re: Interact with Nagios Interface programatically
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.
This is a non-trivial task for many things.
Re: Interact with Nagios Interface programatically
@lb2cons I'll try helping you find the issue:
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?
The fact thatIt'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:echo this command and then copy the echo and try executing it in your shell. Are you 100 % sure your nrdp token is correct?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"
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."@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
https://outsideit.net
Re: Interact with Nagios Interface programatically
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?
What more can we test?
Re: Interact with Nagios Interface programatically
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
They also use
Code: Select all
now=`date +%s`Nagios XI 5.8.1
https://outsideit.net
https://outsideit.net
Re: Interact with Nagios Interface programatically
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
#!/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