jchonig / docker-mmonit

A container to run M/Monit
Creative Commons Zero v1.0 Universal
10 stars 4 forks source link

Timezone TZ not used by M/Monit #28

Closed sebastianhelbig closed 3 months ago

sebastianhelbig commented 3 months ago

We recently switched from "traditional hosting" of M/Monit to the docker container. But there is one issue which previously worked, so it is not a bug in M/Monit itself.

The dates in alert mails M/Monit is sending are in UTC instead of our set timezone. The TZ param seems to have no influence on M/Monit. We have set the following in a docker-compose.yml:

environment:
  - TZ=Europe/Berlin
image: jchonig/mmonit:3.7.15
…
jchonig commented 3 months ago

That's an old version of M/Monit.

Can you provide some debugging info?

docker compose logs | grep TZ

Then docker compose exec mmonit /bin/bash and run the commands echo $TZ and date?

Thanks.

Jeff

sebastianhelbig commented 3 months ago

Unfortunately we currently only have a license for 3.x.

> docker compose logs | grep TZ
mmonit.…  |     TZ=Europe/Berlin
mmonit.…  |     TZ=Europe/Berlin

> echo $TZ
Europe/Berlin

> date
Thu May 16 22:19:22 CEST 2024

The date on the system seems correct. But M/Monit is not using it when sending the alert mails. I am not sure if this may fix it, but /etc/localtime is not present; see https://wiki.alpinelinux.org/wiki/Setting_the_timezone

sebastianhelbig commented 3 months ago

I just tried it. When setting the timezone as explained here https://wiki.alpinelinux.org/wiki/Setting_the_timezone the dates in the alert mails show the correct timezone.

jchonig commented 3 months ago

One more thing to check. Does it look like M/Monit log entries are in UTC or CEST?

jchonig commented 3 months ago

I just saw your second response...

jchonig commented 3 months ago

I've build the image backup-4.2.2 with the fix. It works for setting /etc/localtime:

root@mmonit:/opt# ls -Flas /etc/localtime
1 lrwxrwxrwx 1 root root 36 May 16 17:26 /etc/localtime -> /usr/share/zoneinfo/America/New_York

The only other changes in this image are for adding support for mysql backups.

Please test to see if this works for you.

jchonig commented 3 months ago

As it is simple and works for me, I applied it to master where it will rebuild 4.2.2.

sebastianhelbig commented 3 months ago

Thanks a lot. It is working :-)