Hi,
We have a client system using BST as timezone. However we want to change the date output of NOTIFY_SHORTDATETIME to be in UTC in our Python custom notification script.
Has anyone had success with this?
Hi,
We have a client system using BST as timezone. However we want to change the date output of NOTIFY_SHORTDATETIME to be in UTC in our Python custom notification script.
Has anyone had success with this?
On my system the relevant variables are
NOTIFY_SHORTDATETIME=2020-08-17 17:19:41
NOTIFY_LONGDATETIME=Mon Aug 17 17:19:41 CEST 2020
NOTIFY_MICROTIME=1597677581260409
NOTIFY_SHORTDATETIME
doesn’t contain timezone information which makes the conversion to UTC at least difficult.
NOTIFY_LONGDATETIME
could be used instead becaue it contains timezone information. There are various Python modules and functions that can parse such strings, for example dateutil.parser.parse
or datetime.datetime.strptime
.
NOTIFY_MICROTIME
already is in UTC and fits best:
import os, datetime
ts = int(int(os.environ.get('NOTIFY_MICROTIME')) / 1000000)
dt_object = datetime.datetime.fromtimestamp(ts)
BTW: you can have a single monitoring site running in a different time zone than the monitoring server by setting the TZ environment variable in $OMD_ROOT/etc/environment
.
Thanks, this worked for me.
import os, datetime
ts = int(int(os.environ.get('NOTIFY_MICROTIME')) / 1000000)
dt_object = datetime.datetime.utcfromtimestamp(ts)
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.