Page 1 of 1

Monitoring freeze after time change

Posted: Wed Jun 21, 2023 5:59 am
by ELger
Hi,

I have a temporary installation of Nagios in a virtual machine, on a computer that I turn off for the night. After turning it on, a message appears in the logs

[1687278386] Warning: A system time change of 7880 seconds (0d 2h 11m 20s forwards in time) has been detected. Compensating...

So it would seem that Nagios has understood that the time has changed and should work. Unfortunately, the service monitoring freezes. Only a restart of Nagios helps. Is this standard behaviour or a bug? On the production server I have never had a similar problem with monitoring freezing.

In summary, the web interface works, but the 'last check' of the services is from the previous day. I waited an hour and nothing.

Re: Monitoring freeze after time change

Posted: Wed Jun 21, 2023 11:22 am
by ELger
I temporarily solved the problem through a small program in C

Code: Select all

vim /root/timechange.c

Code: Select all

#include <sys/timerfd.h>
#include <limits.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <dirent.h>
#include <stdlib.h>
#include <string.h>

int main(void) {

  while(1) {
        int fd = timerfd_create(CLOCK_REALTIME, 0);
        timerfd_settime(fd, TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET,
                        &(struct itimerspec){ .it_value = { .tv_sec = INT_MAX } },
                        NULL);
        printf("Waiting\n");
        char buffer[10];
        if (-1 == read(fd, &buffer, 10)) {
                if (errno == ECANCELED) {
                        printf("Timer cancelled - system clock changed\n");
                        system("systemctl reload nagios");
                }
                else
                        perror("error");
        }
        close(fd);
  }
return(0);
}

then

Code: Select all

# gcc timechange.c -o timechange; chmod +x timechange
and add to /etc/crontab

Code: Select all

@reboot root /root/timechange &

Re: Monitoring freeze after time change

Posted: Wed Jun 21, 2023 11:23 am
by bv406
Maybe refer to this post to see if it helps.

viewtopic.php?p=232597