Closed
Description
Is there any way to have date related macros (i.e. S_HOUR, S_MIN, S_SEC, S_DAY
etc.) based on UTC times?
In my syslog-ng I have systems which provide local times and others provide UTC times. Thus I have different date-parsers:
options {
time-zone("Europe/Zurich");
};
parser p_date_time_local {
date-parser(
format("%Y-%m-%d %H:%M:%S"),
template("${.FN.date} ${.FN.time}"),
time-zone("Europe/Zurich")
);
};
parser p_date_time_utc {
date-parser(
format("%Y-%m-%d %H:%M:%S"),
template("${.HW.date} ${.HW.time}"),
time-zone("UTC")
);
};
In order to avoid clashes of filenames while transition of daylight-saving times I like to get hour as UTC time. I managed to develop these rewrites, but certainly these are just workarounds:
rewrite r_set_hour_local {
set("${S_HOUR}", value("HOUR_UTC"));
subst("^0", "", value("HOUR_UTC"));
set("$(- ${HOUR_UTC} 1)", value("HOUR_UTC"), condition("${S_TZOFFSET}" eq "+01:00"));
set("$(- ${HOUR_UTC} 2)", value("HOUR_UTC"), condition("${S_TZOFFSET}" eq "+02:00"));
set("23", value("HOUR_UTC"), condition("${HOUR_UTC}" eq "-1"));
set("22", value("HOUR_UTC"), condition("${HOUR_UTC}" eq "-2"));
};
rewrite r_set_hour_utc {
fix-time-zone("Europe/Zurich");
set-time-zone("UTC");
set("${S_HOUR}", value("HOUR_UTC"));
subst("^0", "", value("HOUR_UTC"));
};
Note, in general I like to get local time when I use S_HOUR
macro. But for some parts, UTC based hour is required.
Would you have any other proposal?
Kind Regards
Wernfried