Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-9387

Incorrect maintenance calculations on when DST changed to summer time

XMLWordPrintable

    • Sprint 39, Sprint 59 (Dec 2019), Sprint 60 (Jan 2020), Sprint 61 (Feb 2020), Sprint 62 (Mar 2020), Sprint 64 (May 2020)
    • 1

      Problem:
      After the change to summer time occurred, maintenance happens when it should not.

      How to replicate:

      1. Grab a virtual machine, set OS and PHP timezones to America/Chicago.
      2. Create a maintenance that happens weekly as per attached screenshot.
      3. date --set="6 mar 2015 23:58"
      4. We are now at the end of Friday. Winter time is active. Maintenance will start in a couple of minutes.
      5. date --set="8 mar 2015 00:58"
      6. We are in the beginning of Sunday. Winter time is still active. Maintenance will end in a couple of minutes.
      7. date --set="8 mar 2015 01:58"
      8. In two minutes summer time will start. When this will happen, Zabbix erroneously will again decide that maintenance should start.

      I've added the following debug code in timer.c:

                                      active_since = db_active_since - (wday * SEC_PER_DAY + tm->tm_hour * SEC_PER_HOUR +
                                                      tm->tm_min * SEC_PER_MIN + tm->tm_sec);
      
                                      zabbix_log(LOG_LEVEL_DEBUG, "  active since: %d", active_since);
      
                                      for (; db_start_date >= db_active_since; db_start_date -= SEC_PER_DAY)
                                      {
                                              zabbix_log(LOG_LEVEL_DEBUG, "    db_start_date %d", db_start_date);
      
                                              /* check for every x week(s) */
                                              week = (db_start_date - active_since) / SEC_PER_WEEK;
                                              if (0 != week % db_every) {
                                                      zabbix_log(LOG_LEVEL_DEBUG, "    continue from: if (0 != week % db_every)");
                                                      continue;
                                              }
      
                                              /* check for day of the week */
                                              tm = localtime(&db_start_date);
                                              wday = (0 == tm->tm_wday ? 7 : tm->tm_wday) - 1;
                                              zabbix_log(LOG_LEVEL_DEBUG, "    wday: %d", wday);
                                              zabbix_log(LOG_LEVEL_DEBUG, "    db_dayofweek %d", db_dayofweek);
                                              if (0 == (db_dayofweek & (1 << wday))) {
                                                      zabbix_log(LOG_LEVEL_DEBUG, "    continue from:  if (0 == (db_dayofweek & (1 << wday)))");
                                                      continue;
                                              }
      
                                              zabbix_log(LOG_LEVEL_DEBUG, "    break");
                                              break;
                                      }
                                      break;
                              case TIMEPERIOD_TYPE_MONTHLY:
      

      And here's the debug output:

      Maintenance begins:
       28112:20150307:000014.298   active since: 952322386
       28112:20150307:000014.298     db_start_date 1425708000
       28112:20150307:000014.298     wday: 5
       28112:20150307:000014.298     db_dayofweek 32
       28112:20150307:000014.299     break
       28112:20150307:000014.299 In process_maintenance_hosts()
       28112:20150307:000014.299 query [txnlev:0] [select h.hostid,h.host,h.maintenanceid,h.maintenance_status,h.maintenance_type,h.maintenance_from from maintenances_hosts mh,hosts h where mh.hostid=h.hostid and h.status=0 and mh.maintenanceid=1]
       28112:20150307:000014.300 query [txnlev:0] [select h.hostid,h.host,h.maintenanceid,h.maintenance_status,h.maintenance_type,h.maintenance_from from maintenances_groups mg,hosts_groups hg,hosts h where mg.groupid=hg.groupid and hg.hostid=h.hostid and h.status=0 and mg.maintenanceid=1]
       28112:20150307:000014.302 End of process_maintenance_hosts()
       28112:20150307:000014.302 In update_maintenance_hosts()
       28112:20150307:000014.302 query [txnlev:1] [begin;]
       28112:20150307:000014.302 putting host 'Zabbix server' into maintenance (with data collection)
      
      Maintenance ends:
       28112:20150308:010006.679   active since: 952318794
       28112:20150308:010006.679     db_start_date 1425794400
       28112:20150308:010006.679     wday: 6
       28112:20150308:010006.679     db_dayofweek 32
       28112:20150308:010006.679     continue from:  if (0 == (db_dayofweek & (1 << wday)))
       28112:20150308:010006.679     db_start_date 1425708000
       28112:20150308:010006.680     wday: 5
       28112:20150308:010006.680     db_dayofweek 32
       28112:20150308:010006.680     break
       28112:20150308:010006.680 In update_maintenance_hosts()
       28112:20150308:010006.680 query [txnlev:1] [begin;]
       28112:20150308:010006.681 query [txnlev:1] [select hostid,host,maintenance_type,maintenance_from from hosts where status=0 and flags<>2 and maintenance_status=1]
       28112:20150308:010006.681 taking host 'Zabbix server' out of maintenance
      
      Maintenance erroneously begins again:
       28112:20150308:030019.733   active since: 952311581
       28112:20150308:030019.733     db_start_date 1425790800
       28112:20150308:030019.733     wday: 5
       28112:20150308:030019.733     db_dayofweek 32
       28112:20150308:030019.733     break
       28112:20150308:030019.733 In process_maintenance_hosts()
       28112:20150308:030019.734 query [txnlev:0] [select h.hostid,h.host,h.maintenanceid,h.maintenance_status,h.maintenance_type,h.maintenance_from from maintenances_hosts mh,hosts h where mh.hostid=h.hostid and h.status=0 and mh.maintenanceid=1]
       28112:20150308:030019.734 query [txnlev:0] [select h.hostid,h.host,h.maintenanceid,h.maintenance_status,h.maintenance_type,h.maintenance_from from maintenances_groups mg,hosts_groups hg,hosts h where mg.groupid=hg.groupid and hg.hostid=h.hostid and h.status=0 and mg.maintenanceid=1]
       28112:20150308:030019.736 End of process_maintenance_hosts()
       28112:20150308:030019.736 In update_maintenance_hosts()
       28112:20150308:030019.736 query [txnlev:1] [begin;]
       28112:20150308:030019.737 putting host 'Zabbix server' into maintenance (with data collection)
      

      Looks like wday is calculated incorrectly after DST change, it should be 6, but it's 5 again.

            atocko Andrey Tocko (Inactive)
            filipp.sudanov Filipp Sudanov (Inactive)
            Team C
            Votes:
            0 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated:
              Resolved: