Page 1 of 1

[Nagios-devel] Patch to add timezone support for timeperiods

Posted: Mon Feb 04, 2008 3:30 pm
by Guest
Hello,

Below is a simple patch to add support for timezones to timeperiods. I =
see nagios 3 is now at RC2, but will post this patch in the hope it may =
make it in for the final 3 build, but if not, then the next version.

With this patch you can now define a TimeZone for a timeperiod as show =
below, this will also handle any daylight time changes etc if the =
systems tzdata files are current.

No changes are made to how time is displayed within nagios or the cgi =
problems, the timezone check is only done within the timeperiod checks. =
This way all times displayed are still using the currently defined =
Timezone setting for the CGI's or as defined in/for the Nagios =
configuration.

# 'workhours' in NZ, timeperiod definition
define timeperiod{
timeperiod_name NZ_workhours
alias NZ Normal Work Hours
monday 09:00-17:00
tuesday 09:00-17:00
wednesday 09:00-17:00
thursday 09:00-17:00
friday 09:00-17:00
timezone Pacific/Auckland
}

# 'ASX trading hours' in Australia, timeperiod definition
define timeperiod{
timeperiod_name ASX_tradinghours
alias ASX Trading Hours
monday 07:00-19:00
tuesday 07:00-19:00
wednesday 07:00-19:00
thursday 07:00-19:00
friday 07:00-19:00
timezone Australia/NSW
}

-------------------------------------------------------------------------=
---

diff -ru nagios-cvs-orig/base/utils.c nagios-cvs/base/utils.c
--- nagios-cvs-orig/base/utils.c=A0=A0=A0=A0=A0=A0=A0 2008-01-25 =
00:21:52.000000000 +1000
+++ nagios-cvs/base/utils.c=A0=A0=A0=A0 2008-02-04 12:21:16.000000000 =
+1000
@@ -790,6 +790,7 @@
=A0=A0=A0=A0=A0=A0=A0 int test_time_mday=3D0;
=A0=A0=A0=A0=A0=A0=A0 int test_time_wday=3D0;
=A0=A0=A0=A0=A0=A0=A0 int year=3D0;
+=A0=A0=A0=A0=A0=A0 char *current_timezone=3DNULL;

=A0=A0=A0=A0=A0=A0=A0 =
log_debug_info(DEBUGL_FUNCTIONS,0,"check_time_against_period()\n");

@@ -809,6 +810,15 @@
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 }
=A0=A0=A0 =A0=A0=A0=A0tperiod->exclusions=3Dfirst_timeperiodexclusion;

+=A0=A0=A0=A0=A0=A0 /* Run timeperiod checks in the requied timezone */
+=A0=A0=A0=A0=A0=A0 log_debug_info(DEBUGL_FUNCTIONS,0,"New TZ is:%s Old =
TZ was:%s\n", tperiod->timezone?tperiod->timezone:"None", =
current_timezone?current_timezone:"None");
+=A0=A0=A0=A0=A0=A0 if (tperiod->timezone!=3DNULL) {
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if(getenv("TZ")!=3DNULL)
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =
=A0=A0=A0=A0=A0=A0=A0current_timezone=3Dstrdup(getenv("TZ"));
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =
set_environment_var("TZ",tperiod->timezone,1);
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 tzset();
+=A0=A0=A0=A0=A0=A0 }
+
=A0=A0=A0=A0=A0=A0=A0 /* save values for later */
=A0=A0=A0=A0=A0=A0=A0 t=3Dlocaltime((time_t *)&test_time);
=A0=A0=A0=A0=A0=A0=A0 test_time_year=3Dt->tm_year;
@@ -992,6 +1002,13 @@

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 /* =
found a day match, so see if time ranges are good */
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =
if(found_match=3D=3DTRUE){
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0 /* restore default timezone */
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0 if (tperiod->timezone!=3DNULL) {
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =
set_environment_var("TZ",current_timezone,current_timezone?1:0);
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 tzset();
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 my_free(current_timezone);
+=A0=A0=A0=A0=A0=A0=A0=A0=A0 =
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0}
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0 log_debug_info(DEBUGL_FUNCTIONS,0,"TZ reset to:%s\n", =


...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]