5

Our routine maintenance requires services have to be brought down.

The problem is these services have Nagios checks and we either have to go to the web interface and disable the check or get the emails.

Is there a way from command line on a Windows and/or Linux guest to disable the Nagios check (or notifications) and enable it? Ideally this would happen on the machine we are performing the maintenance on, not the Nagios server itself.

I would like to disable notifications/checks pre-maintenance and re-enable them post maintenance.

andyhky
  • 2,732
  • 2
  • 25
  • 26

3 Answers3

7

Assuming that the guest can reach the web interface, the following command lines should work:

To disable notifications

curl -d "cmd_typ=23&cmd_mod=2&host=[THE HOST]&service=[THE SERVICE]&btnSubmit=Commit" "http://[[NAGIOS SERVER]/nagios/cgi-bin/cmd.cgi"

To enable notifications

curl -d "cmd_typ=22&cmd_mod=2&host=[THE HOST]&service=[THE SERVICE]&btnSubmit=Commit" "http://[[NAGIOS SERVER]/nagios/cgi-bin/cmd.cgi"

Depending on your setup, you may also need to use the --insecure or --user options of curl.

And IIRC, the cmd_type number is different for service and host groups -- look at what links are being used in your web browser.

Matt
  • 933
  • 5
  • 12
  • Looks great. I'll give it a try before marking this question as answered. Thanks! – andyhky Aug 26 '09 at 14:52
  • Those command work well for service/host notification enable/disable purpose. But could you please suggest how could I achieve scheduled host downtime by this kind of script? Because the downtime option takes more argument.Please suggest. – unixbhaskar Jul 27 '11 at 09:58
  • 1
    To schedule downtime, again, follow Matt's advice: "Look at what links are being used in your browser" — Look at the HTML form and just emulate that. For "downtime for host and all services" additional parameters are `cmd_typ=86`, `cmd_mod=2`, `com_data=your comment`, `trigger=0`, `start_time=2012-01-02 22:33:00`, `end_time=2012......`, `fixed=1`, `hours=0`, `minutes=0` – mogsie Aug 08 '12 at 06:58
  • The `cmd_typ` codes can be found here: http://docs.icinga.org/latest/en/cgiparams.html. Do not use the docs located at old.icinga.org (even though most of the posts will list those ones!) – Ben Dec 11 '14 at 18:37
2

Yo can Enable/Disable host notification with nagios.cmd command

e.g:

Disable all notification for my-host

now=`date +%s`
#Check first path nagios.cmd & printf 
commandfile='/var/lib/nagios3/rw/nagios.cmd'  

/usr/bin/printf "[%lu] DISABLE_HOST_NOTIFICATIONS;my-host\n" $now > $commandfile

Enable all notification for my-host

now=`date +%s`
#Check first path nagios.cmd & printf 
commandfile='/var/lib/nagios3/rw/nagios.cmd'  
/usr/bin/printf "[%lu] ENABLE_HOST_NOTIFICATIONS;my-host\n" $now > $commandfile

You can also check this url Nagios Notification command

nikitux
  • 21
  • 2
  • 1
    The link is for the old docs, make sure to use http://docs.icinga.org/latest/en/cgiparams.html instead. – Ben Dec 11 '14 at 18:38
0

For such use, you may edit your nagios services file, and disable checks of all services on this host, like what you did in the web interface, and that require the modification of some options.
Let's take an example If you need to disable checks for DNS service in machine nibiru, disable the active/passive checks like the following.


define service{
    host_name               nibiru
    service_description     DNS
    ...
    active_checks_enabled   0  ; set value to 0
    passive_checks_enabled  0  ; set value to 0
    ...
}
Ali Mezgani
  • 3,850
  • 2
  • 24
  • 36