5

I need to configure Nagios to send a notification that says everything goes well, if there's no problems.

Does this sort of setting exist or is there a plugin for that?

Roman Prykhodchenko
  • 297
  • 2
  • 4
  • 13
  • 1
    Out of curiosity, why is it that you want it this way (rather than ok messages when state changes from not ok) ? - sounds like extra messages for no gain. – Sirex Aug 12 '11 at 15:21

5 Answers5

4

I use the following setup to send an email once per day. This let's me know that all is well with my Nagios server, the email system and the Nagios config.

  # nagios/objects/localhost.cfg
  ....
  # Send a message once per day to make sure nagios is working ok
  define service{
        use                     local-service
        host_name               localhost
        service_description     Nagios is OK
        check_command           check_all_is_well
        check_period            morning     ; this is a custom period
        normal_check_interval   60          
            ; setting this to an hour and making the check_period 
            ; interval 59 minutes long each day ensures it only 
            ; happens once per day in a specific window
        }

and in you timeperiods config file:

# nagios/objects/timeperiods.cfg
....
define timeperiod{
        timeperiod_name morning
        alias           First thing in the am
        monday          06:00-6:59
        tuesday         06:00-6:59
        wednesday       06:00-6:59
        thursday        06:00-6:59
        friday          06:00-6:59
        saturday        06:00-6:59
        sunday          06:00-6:59
        }

And the check_all_is_ok command is a simple wrapper around sendmail:

# check_all_is_ok
#!/bin/bash

echo "All is well from Nagio on `hostname`" \
       | /etc/nagios/sendmail -s "Nagios on PIP is OK" <your email address>

echo "OK: nagios is ok on `hostname`";
exit 0

It doesn't check that there haven't been problems in the prior 24 hours, but you could add some grep-ping of the logs as guanta suggested if you need that. You could also accomplish the once a day requirement by setting normal_check_interval to 1440 (24 hours), but I want the check to be run in a specific window each day.

Mark Grimes
  • 654
  • 1
  • 6
  • 8
1

For the benefit of others: I just went through this question myself and the most simple solution came up to the mind is this, checking nagios process every 8 hrs to make sure nagios is running

#crontab -e

Add the following

* */8 * * * /usr/local/nagios/libexec/check_nagios -t 20 -e 5 -F /usr/local/nagios/var/status.dat -C /usr/local/nagios/bin/nagios > /var/local/nagios_stats && sendemail -f "NAGIOS STATUS SenderAddress@gmail.com" -u Nagios Process Status -s smtp.gmail.com:587 -xu SenderAddress@gmail.com -xp SenderPassword -o tls=yes -t RecipientAddress@gmail.com -m < /var/local/nagios_stats

Don't forget to

Creating file in /var/local/nagios_stats (or somewhere else but change it in the crontab)

SenderAddress,RecipientAddress,MailPassword

Stuggi
  • 3,506
  • 4
  • 19
  • 36
1

If you configured daily log rotation (log_rotation_method=d), you can write a script to count the number of alerts in nagios.log, something like this:

[ `grep -c ALERT var/nagios.log` -eq 0 ] && echo "Everything is OK!" | mail -s "Nagios daily report" your@email

Put it into a cron job to run at the end of day, before you go to bed.

If you don't, refer to this topic to filter according to the date.

quanta
  • 51,413
  • 19
  • 159
  • 217
0

The solution heavily depends on when you actually want to send out notifications:

  • On each successful run of an active check: Then it might make sense to actually run the notification step as part of your active check. A simple way would be to wrap your check inside a script that first does the check, introspects the result and sends the notification. You could do that using embedded Perl.
  • When things used to be not okay but are now: This is standard behavior.
  • On passive checks: This is actually an interesting problem for which I don't have a solution on top of my head...

Depending on the scenario you should decide for one solution. And always remember: do the simplest thing that could possibly work.

Holger Just
  • 3,325
  • 1
  • 17
  • 23
0

It's a bit late, but for anyone else looking for a solution, there's an easy way using the livestatus broker module.

Set up livestatus to use a unix socket (Shinken, by default, has it only set up with tcp port, you can add the socket like in the config on this page), and you can poll that directly using eg a python script.

Demelziraptor
  • 479
  • 1
  • 4
  • 11