Running a ssh check twice a week

Hi, running ssh checks from icinga to numerous hosts. i want to run a check (nagios plugin) twice a week, once on a thursday and once on a monday… how would i do this ? I can run it once a week by setting the check_interval in the templates file to 168hours. and if i halved that it would run it twice a week, but how do i know what days it will run it. say if i restart icinga.
thanks in advance.

you need to use timeperoids

object TimePeriod "MyTimePeriod" {
    import "legacy-timeperiod"
    ranges = {
        "monday"	= "08:00-08:45"
        "thursday"	= "08:00-08:45"
    }
}
template Service "MyServiceTemplate" {
    import "generic-service"
    check_interval = 30m 
    ...
    check_period = "MyTimePeriod"
}

after that you use a service apply rule to add the service to the host

I don’t know if the check gets executed right when the time period starts, maybe you have to adjust the timeperiods or the check_interval.

1 Like

many thanks… will give it a try

Hi im a bit confused… i have in templates.
object TimePeriod “MyTimePeriod” {
import “legacy-timeperiod”
ranges = {
“monday” = “08:00-08:45”
“thursday” = “08:00-08:45”
}
}

template Service “WeeklyCheck-Service” {
import “generic-service”
check_interval = 30m
max_check_attempts = 5
retry_interval = 24h
check_timeout = 600s

check_period = "MyTimePeriod"

}

And then my ssh check
apply Service "Satellite Subscription " {
import “WeeklyCheck-Service”
check_command = “by_ssh”
vars.by_ssh_logname = “root”
vars.by_ssh_options = “StrictHostKeyChecking=no”
// the [ ] syntax below joins the strings
vars.by_ssh_command = “/ns/tec/unix/u/patching/check_subscribed_status.sh”
vars.by_ssh_skip_stderr = 0
vars.by_ssh_timeout = 60
vars.by_ssh_arguments = {
}
assign where host.vars.os == “Linux7”
}

but when i look at the check in icinga2

ast check on Nov 23
Next check in 1d 19h Reschedule
Check attempts 1/5 (hard state)
Check execution time 1.691s
Check latency 0.085298s
Check Timeperiod MyTimePeriod

I think its working… strange behaviour regarding “next check” but its run when i set it to… thanks.

1 Like

so please mark my post as the solution to your problem :slight_smile:

2 Likes