Model nagios notifications

My usual method of testing the notification chain and escalation is to simulate a failure by causing it, for example, by blocking the port.

But this is completely unsatisfactory. I do not want the time recorded in nagios to be absent. I also do not want to wait.

Does anyone know a way to test the notification chain without causing a shutdown? For example, something like this:

$ ./check_notifications_chain <service|host> <time down>
at <x> minutes notification email sent to group <people>
at <2x> minutes notification email sent to group <people>
at <3x> minutes escalated to group <management>
at <200x> rm -rf; shutdown -h now executed.

Extension of this paradigm. I can make the notification chain the nagios check itself, but I will stop here before my brain explodes.

Is anyone

+5
source share
2 answers

, , .

test_alert.sh:

#!/bin/bash

date=`date -u +%H%M`

echo $date
echo "Nagios test script. Intentionally generates a warning daily."

if [[ "$date" -ge "1900" && "$date" -le "1920" ]] ; then
  exit 1
else
  exit 0
fi

commands.cfg:

define command{
  command_name  test_alert
  command_line  /bin/bash /usr/local/scripts/test_alert.sh
}

services.cfg:

define service {
  host                  localhost
  service_description   Test Alert
  check_command         test_alert
  use                   generic-service
}
+4

, , , - .

"check_dummy", Nagios. , .

, :

Usage:
 check_dummy <integer state> [optional text]
$ ./check_dummy 0
OK
$ ./check_dummy 2
CRITICAL
$ ./check_dummy 3 salut
UNKNOWN: salut
$ ./check_dummy 1 azerty
WARNING: azerty
$ echo $?
1

, : echo 0 OKAY | sudo tee/usr/local/nagios/libexec/dummy.txt sudo chown nagios: nagios/usr/local/nagios/libexec/dummy.txt

:

# Dummy check (notifications tests)
define command {
    command_name    my_check_dummy
    command_line    $USER1$/check_dummy $(cat /usr/local/nagios/libexec/dummy.txt)
}

:

define service {
    use                             generic-service
    host_name                       localhost
    service_description             Dummy check
    check_period                    24x7
    check_interval                  1
    max_check_attempts              1
    retry_interval                  1
    notifications_enabled           1
    notification_options            w,u,c,r
    notification_interval           0
    notification_period             24x7
    check_command                   my_check_dummy
}

"dummy.txt", :

echo "2 Oups" | sudo tee /usr/local/nagios/libexec/dummy.txt
echo "1 AHHHH" | sudo tee /usr/local/nagios/libexec/dummy.txt
echo "0 Parfait !" | sudo tee /usr/local/nagios/libexec/dummy.txt

.

, !

0

Source: https://habr.com/ru/post/1529743/


All Articles