#############################################################################################
# ICINGA TEST CONFIG BY ISSUES
# (c) 2009-2013 Icinga Development Team and Community Contributors
#
# #1782
# Icinga forgets to schedule non-testconfig-24x7 checks (left as is)
#############################################################################################

define command {
        command_name                    1782check_multi
        command_line                    $USER1$/check_multi -l /opt/nagios/libexec -s HOSTADDRESS=$HOSTADDRESS$ -s HOSTADDRESS6=$HOSTADDRESS6$ -f /etc/icinga/$ARG1$ $ARG2$ $ARG3$ $ARG4$
}

define host{
        name                            1782linux-server
        use                             test-generic-host
        check_period                    testconfig-24x7
        check_interval                  5
        retry_interval                  1
        max_check_attempts              10
        check_command                   testconfig-check-host-alive
        notification_period             testconfig-workhours
        notification_interval           120
        notification_options            d,u,r
        contact_groups                 	testconfig-group-admin
        register                        0
}

define host{
        use                             1782linux-server            ; Name of host template to use
        host_name                       1782localhost
        alias                           1782localhost
        address                         127.0.0.1
        address6                        ::1
        check_command                   1782check_multi!check_multi_host_dualstack.cmd -r 1+2+4+8
}

define command {
	command_name			1782check_ping
	command_line			$USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$
}


define service{
	use                             test-generic-service
	check_interval                  5
	retry_interval                  1
	max_check_attempts              3
	host_name                       1782localhost
	service_description             Testping
	check_command                   1782check_ping!100.0,20%!500.0,60%
	check_period                    test_timeperiod
}

 # now it's 10:43
##
#Last Check Time:	2011-08-08 10:42:51
#Next Scheduled Check:  	2011-08-08 10:47:51

# now it's 10:48
# Last Check Time:       2011-08-08 10:42:51 (Last Update:	2011-08-08 10:48:30  ( 0d 0h 0m 20s ago)) <- ok, check did not happen due to timeperiod
# Next Scheduled Check:  	2011-08-08 10:52:51

# now it's 10:53
# Last Check Time:	2011-08-08 10:52:51
# Next Scheduled Check:  	2011-08-08 10:57:51

# date -s 10:47

# Aug  8 10:47:00 xxx icinga: Warning: A system time change of 0d 0h 7m 18s (backwards in time) has been detected.  Compensating...
# Aug  8 10:47:00 xxx icinga: TIMEPERIOD TRANSITION: test_timeperiod;1;0
# Aug  8 10:47:00 xxx nagios: Warning: A system time change of 0d 0h 7m 18s (backwards in time) has been detected.  Compensating...

# now it's 10:55 - faked 10_48
# Last Check Time:	2011-08-08 10:45:33
# Next Scheduled Check:  	2011-08-08 10:50:33

# resync it
# Aug  8 10:50:00 xxx icinga: TIMEPERIOD TRANSITION: test_timeperiod;0;1
# Aug  8 10:57:49 xxx icinga: Warning: The results of service 'cert[exp]: thomas-1.office.crt' on host 'localhost' are stale by 0d 0h 6m 52s (threshold=0d 0h 7m 15s).  I'm forcing an immediate check of the service.
# Aug  8 10:57:49 xxx icinga: Warning: The results of service 'sys[proc]: httpd' on host 'localhost' are stale by 0d 0h 6m 52s (threshold=0d 0h 7m 15s).  I'm forcing an immediate check of the service.

## 2nd try
## now it's 11:01, disallow checks at 11:05

# Last Check Time:	2011-08-08 10:57:49
# Next Scheduled Check:  	2011-08-08 11:02:49

# Last Check Time:	2011-08-08 11:02:49
# Next Scheduled Check:  	2011-08-08 11:15:00 <- this is exactly the timeperiod definition ...

## 3rd try
# remove the timeperiod force a check
# Last Check Time:	2011-08-08 11:06:28
# Next Scheduled Check:  	2011-08-08 11:11:28

# now enable the timeperiod
# reforce a check
# Last Check Time:	2011-08-08 11:08:42
# Next Scheduled Check:  	2011-08-08 11:13:42 <- ok

# adjust the timeperiod again to 11:20
# reload core, force check, wait
# Last Check Time:	2011-08-08 11:11:45
# Next Scheduled Check:  	2011-08-08 11:20:00 <- this is also correct ...


define timeperiod {
  timeperiod_name test_timeperiod
  alias           Test Timeperiod
  sunday          00:00-06:00,18:00-24:00
  monday          00:00-11:05,11:20-24:00
  tuesday         00:00-06:00,19:40-24:00
  wednesday       00:00-06:00,21:00-24:00
  thursday        00:00-06:00,22:00-24:00
  friday          00:00-06:00,18:00-24:00
  saturday        00:00-06:00,18:00-24:00
}

