3

I have a requirement where check interval is 180 mins while notification interval is 10 mins. Means service owner wants if he miss any alert that usually comes after 180 mins if service is critical then Icinga keeps on checking and informing them every 10 mins until service goes back to normal.

i tried interval = 0 parameter in notification.conf but that is not fulfilling the requirement.

It sends alert every 10 mins if service is not okay but it doesn't check the service.

For eg. if service comes to normal before 180 mins(i.e. next check) , it'll keep on alerting till next check.

Found similar question here but it is for Nagios & i'm not able to merge it with Icinga2.

I'm sure it will be done using CHANGE_NORMAL_SVC_CHECK_INTERVAL parameter but don't know how to implement it.

I also found below Icinga page:

Icinga external commands link

Kindly help.

Manii
  • 101
  • 8
  • You can change configuration via the API on demand, but why do you not want to check the server every 5 or 10 minutes in the first place? – lazyfrosch May 31 '16 at 06:58
  • Actually it is a custom plugin through which we are monitoring if a log file is getting updated or not & that file gets updated after 180 mins approx.. – Manii May 31 '16 at 07:09
  • So I'd recommend to tune the script to check if the log has been modified in the last 180 min, and not rely on Icinga 2 to run the check at the right time. (It should always be able to evaluate what the status is) – lazyfrosch May 31 '16 at 07:11
  • Actually that script is in perl & i don't know much about perl. I'm taking this as last option as I have read it is possible within Icinga only through Event Handlers. So just curios to learn about that. – Manii May 31 '16 at 07:16
  • 1
    .I resolved it by myself with help of external commands [given in link here](http://serverfault.com/questions/308802/dynamically-setting-a-new-test-interval-for-nagios-checks/308808#308808) – Manii Jun 02 '16 at 10:29
  • @Manii Could you post an answer outline the way you took? This would help other people reading this question. – gxx Mar 06 '17 at 10:26

1 Answers1

0

This is what I did to resolve my issue.

1. Created script /icinga/plugins/change_check_interval.sh

#!/bin/bash

now=`date +%s`
commandfile='/var/run/icinga2/cmd/icinga2.cmd'
case "$1" in
    OK)
        /usr/bin/printf "[%lu] CHANGE_NORMAL_SVC_CHECK_INTERVAL;servername;servicename;180\n" $now >> $commandfile
    ;;
    WARNING)
        ;;
    UNKNOWN)
        ;;
    CRITICAL)
        /usr/bin/printf "[%lu] CHANGE_NORMAL_SVC_CHECK_INTERVAL;servername;servicename;10\n" $now >> $commandfile
        ;;
esac

exit 0

2. Then used this script to define event_command in commands.conf

object EventCommand  "change_check_interval"{
  import "plugin-event-command"
    command = [ "/icinga/plugins/change_check_interval.sh", "$service.state$" ]
}

3. And used event_command in services.conf

apply Service "Service-Name" {
 import "template"
  check_command = "nrpe-arg"
  vars.remote_nrpe_command = "nrpe command"
  vars.remote_nrpe_arguments = "arg1"
  event_command = "change_check_interval"
  assign where host.name == "servername"
}

This eventhandler runs every 180 mins when service is okay while run every 10 mins when service is critical.

Manii
  • 101
  • 8