[ZBX-8258] calculation of nextcheck is incorrect when "Interval" of "flexible intervals" is set to a large value. Created: 2014 May 26  Updated: 2017 May 30  Resolved: 2014 May 29

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Server (S)
Affects Version/s: 2.2.3
Fix Version/s: None

Type: Incident report Priority: Major
Reporter: Kazuo Ito Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: flexibleintervals
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File calculate_item_nextcheck.log    
Issue Links:
Duplicate
duplicates ZBX-8167 Flexible Intervals on Zabbix 2.2.3 Closed

 Description   

calculation of nextcheck is incorrect when "Interval" of "flexible intervals" is set to a large value.

1)Type : Zabbix agent
2)Update interval (in sec) : 300
3)Flexible intervals
Interval : 22200
Period : 1-7,00:54-07:00

Added the log output to calculate_item_nextcheck.
look at the log of [2014/5/24 00:50:06]

43876:20140524:005006.793 calculate_item_nextcheck **********************************************
43876:20140524:005006.793 calculate_item_nextcheck interfaceid : 1
43876:20140524:005006.793 calculate_item_nextcheck shift : 23706
43876:20140524:005006.793 calculate_item_nextcheck tmax - 1432396206 - 0:50:6 (tmax : t + one year)
43876:20140524:005006.793 calculate_item_nextcheck ********* loop *********
43876:20140524:005006.793 calculate_item_nextcheck next_interval - 341966240 - 6:31:12
43876:20140524:005006.793 calculate_item_nextcheck t - 1400860206 - 0:50:6
43876:20140524:005006.793 calculate_item_nextcheck current_delay : 300
43876:20140524:005006.793 calculate_item_nextcheck 1:nextcheck - 1400860206 - 0:50:6
43876:20140524:005006.793 calculate_item_nextcheck 2:nextcheck - 1400860506 - 0:55:6 <-- orver "Period"of "flexible intervals"
43876:20140524:005006.793 calculate_item_nextcheck ********* not break *********
43876:20140524:005006.793 calculate_item_nextcheck ********* loop *********
43876:20140524:005006.793 calculate_item_nextcheck next_interval - 1400860440 - 0:54:0
43876:20140524:005006.793 calculate_item_nextcheck t - 1400860440 - 0:54:0
43876:20140524:005006.793 calculate_item_nextcheck current_delay : 22200
43876:20140524:005006.793 calculate_item_nextcheck 1:nextcheck - 1400843706 - 20:15:6 <-- here!
43876:20140524:005006.793 calculate_item_nextcheck 2:nextcheck - 1400865906 - 2:25:6 <-- here!
43876:20140524:005006.793 calculate_item_nextcheck return - 1400865906 - 2:25:6

The nextcheck of [2014/5/24 00:50] must be after [2014/5/24 07:00].

                • calculate_item_nextcheck ***************************
                  int calculate_item_nextcheck(zbx_uint64_t interfaceid, zbx_uint64_t itemid, int item_type,
                  int delay, const char *flex_intervals, time_t now, int *effective_delay)
                  {
                  const char *__function_name = "calculate_item_nextcheck";
                  struct tm *d_tm;
                  time_t d_time;
                  int nextcheck = 0;

zabbix_log(LOG_LEVEL_ERR, "%s **********************************************", __function_name);
zabbix_log(LOG_LEVEL_ERR, "%s interfaceid : %d", __function_name, interfaceid);

if (0 == delay)
delay = SEC_PER_YEAR;

/* special processing of active items to see better view in queue */
if (ITEM_TYPE_ZABBIX_ACTIVE == item_type)

{ nextcheck = (int)now + delay; }

else
{
int current_delay = SEC_PER_YEAR, try = 0;
time_t next_interval, t, tmax;
zbx_uint64_t shift;

/* Try to find the nearest 'nextcheck' value with condition */
/* 'now' < 'nextcheck' < 'now' + SEC_PER_YEAR */

t = now;
tmax = now + SEC_PER_YEAR;

shift = (ITEM_TYPE_JMX == item_type ? interfaceid : itemid);
zabbix_log(LOG_LEVEL_ERR, "%s shift : %d", __function_name, shift);

d_time = (time_t)tmax;
d_tm = localtime(&d_time);
zabbix_log(LOG_LEVEL_ERR, "%s tmax - %d - %d:%d:%d (tmax : t + one year)", __function_name, tmax, d_tm->tm_hour, d_tm->tm_min, d_tm->tm_sec);
while (t < tmax)
{
zabbix_log(LOG_LEVEL_ERR, "%s ********* loop *********", __function_name);
d_time = (time_t)next_interval;
d_tm = localtime(&d_time);
zabbix_log(LOG_LEVEL_ERR, "%s next_interval - %d - %d:%d:%d", __function_name, next_interval, d_tm->tm_hour, d_tm->tm_min, d_tm->tm_sec);
d_time = (time_t)t;
d_tm = localtime(&d_time);
zabbix_log(LOG_LEVEL_ERR, "%s t - %d - %d:%d:%d", __function_name, t, d_tm->tm_hour, d_tm->tm_min, d_tm->tm_sec);
/* calculate 'nextcheck' value for the current interval */
current_delay = get_current_delay(delay, flex_intervals, t);

zabbix_log(LOG_LEVEL_ERR, "%s current_delay : %d", __function_name, current_delay);
nextcheck = current_delay * (int)(t / (time_t)current_delay) +
(int)(shift % (zbx_uint64_t)current_delay);

d_time = (time_t)nextcheck;
d_tm = localtime(&d_time);
zabbix_log(LOG_LEVEL_ERR, "%s 1:nextcheck - %d - %d:%d:%d", __function_name, nextcheck, d_tm->tm_hour, d_tm->tm_min, d_tm->tm_sec);
if (0 == try)

{ while (nextcheck <= t) nextcheck += current_delay; }

else

{ while (nextcheck < t) nextcheck += current_delay; }

d_time = (time_t)nextcheck;
d_tm = localtime(&d_time);
zabbix_log(LOG_LEVEL_ERR, "%s 2:nextcheck - %d - %d:%d:%d", __function_name, nextcheck, d_tm->tm_hour, d_tm->tm_min, d_tm->tm_sec);
/* 'nextcheck' < end of the current interval ? */
/* the end of the current interval is the beginning of the next interval - 1 */
if (FAIL != get_next_delay_interval(flex_intervals, t, &next_interval) &&
nextcheck >= next_interval)

{ /* 'nextcheck' is beyond the current interval */ t = next_interval; try++; zabbix_log(LOG_LEVEL_ERR, "%s ********* not break *********", __function_name); }

else
break; /* nextcheck is within the current interval */
}
delay = current_delay;
}

if (NULL != effective_delay)
*effective_delay = delay;

d_time = (time_t)nextcheck;
d_tm = localtime(&d_time);
zabbix_log(LOG_LEVEL_ERR, "%s return - %d - %d:%d:%d", __function_name, nextcheck, d_tm->tm_hour, d_tm->tm_min, d_tm->tm_sec);
return nextcheck;
}



 Comments   
Comment by Aleksandrs Saveljevs [ 2014 May 26 ]

Similarly to ZBX-8167, I would say that Zabbix works as designed. It provides an update interval of 22200 seconds from 00:54 to 07:00. Since the update interval is the same length as the period from 00:54 to 07:00, you are guaranteed that the item will be checked exactly once from 00:54 to 07:00. If you wish to disable checking of the item during that period, you should use a delay of 0 inside the flexible interval.

Comment by Aleksandrs Saveljevs [ 2014 May 29 ]

martins-v has updated documentation at the following locations and provided a more elaborate explanation for flexible intervals with examples:

It should probably be enough to consider this issue resolved. So closing as a duplicate.

Generated at Fri Mar 14 11:12:36 EET 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.