zabbix-agent2/src/libs/zbxdbcache/dbconfig.c
/******************************************************************************
 *                                                                            *
 * Function: dc_schedule_new_trigger_timers                                   *
 *                                                                            *
 * Purpose: set timer schedule and evaluation times based on functions and    *
 *          old trend function queue                                          *
 *                                                                            *
 ******************************************************************************/
dc_schedule_new_trigger_timers

Purpose: set timer schedule and evaluation times based on functions and
old trend function queue
dc_schedule_new_trigger_timers Purpose : set timer schedule and evaluation times based on functions and old trend function queue
static void	dc_schedule_trigger_timers(zbx_hashset_t *trend_queue, int now)
{
	ZBX_DC_FUNCTION		*function;
	ZBX_DC_TRIGGER		*trigger;
	zbx_trigger_timer_t	*timer, *old;
	zbx_timespec_t		ts;
	zbx_hashset_iter_t	iter;
	ts.ns = 0;
	zbx_hashset_iter_reset(&config->functions, &iter);
	while (NULL != (function = (ZBX_DC_FUNCTION *)zbx_hashset_iter_next(&iter)))
	{
		if (ZBX_FUNCTION_TYPE_TIMER != function->type && ZBX_FUNCTION_TYPE_TRENDS != function->type)
			continue;
		if (function->timer_revision == function->revision)
			continue;
		if (NULL == (trigger = (ZBX_DC_TRIGGER *)zbx_hashset_search(&config->triggers, &function->triggerid)))
			continue;
		if (TRIGGER_STATUS_ENABLED != trigger->status || TRIGGER_FUNCTIONAL_TRUE != trigger->functional)
			continue;
		if (NULL == (timer = dc_trigger_function_timer_create(function)))
			continue;
		if (NULL != trend_queue && NULL != (old = (zbx_trigger_timer_t *)zbx_hashset_search(trend_queue,
				&timer->objectid)) && old->eval_ts.sec < now + 10 * SEC_PER_MIN)
		{
			if (old->eval_ts.sec < now + 10 * SEC_PER_MIN)
				ts.sec = now + 10 * SEC_PER_MIN + timer->triggerid % (10 * SEC_PER_MIN);
			else
				ts.sec = old->eval_ts.sec;
			dc_schedule_trigger_timer(timer, &old->eval_ts, &ts);
		}
		else
		{
			if (0 == (ts.sec = dc_function_calculate_nextcheck(timer, now, timer->triggerid)))
			{
				dc_trigger_timer_free(timer);
				function->timer_revision = 0;
			}
			else
				dc_schedule_trigger_timer(timer, NULL, &ts);
		}
	}
	zbx_hashset_iter_reset(&config->triggers, &iter);
	while (NULL != (trigger = (ZBX_DC_TRIGGER *)zbx_hashset_iter_next(&iter)))
	{
		if (ZBX_TRIGGER_TIMER_DEFAULT == trigger->timer)
			continue;
		if (trigger->timer_revision == trigger->revision)
			continue;
		if (NULL == (timer = dc_trigger_timer_create(trigger)))
			continue;
		if (0 == (ts.sec = dc_function_calculate_nextcheck(timer, now, timer->triggerid)))
		{
			dc_trigger_timer_free(timer);
			trigger->timer_revision = 0;
		}
		else
			dc_schedule_trigger_timer(timer, NULL, &ts);
	}
}
static void dc_schedule_trigger_timers ( zbx_hashset_t * trend_queue , int now ) { ZBX_DC_FUNCTION * function ; ZBX_DC_TRIGGER * trigger ; zbx_trigger_timer_t * timer , * old ; zbx_timespec_t ts ; zbx_hashset_iter_t iter ; ts . ns = 0 ; zbx_hashset_iter_reset ( & config -> functions , & iter ) ; while ( NULL != ( function = ( ZBX_DC_FUNCTION * ) zbx_hashset_iter_next ( & iter ) ) ) { if ( ZBX_FUNCTION_TYPE_TIMER != function -> type && ZBX_FUNCTION_TYPE_TRENDS != function -> type ) continue ; if ( function -> timer_revision == function -> revision ) continue ; if ( NULL == ( trigger = ( ZBX_DC_TRIGGER * ) zbx_hashset_search ( & config -> triggers , & function -> triggerid ) ) ) continue ; if ( TRIGGER_STATUS_ENABLED != trigger -> status || TRIGGER_FUNCTIONAL_TRUE != trigger -> functional ) continue ; if ( NULL == ( timer = dc_trigger_function_timer_create ( function ) ) ) continue ; if ( NULL != trend_queue && NULL != ( old = ( zbx_trigger_timer_t * ) zbx_hashset_search ( trend_queue , & timer -> objectid ) ) && old -> eval_ts . sec < now + 10 * SEC_PER_MIN ) { if ( old -> eval_ts . sec < now + 10 * SEC_PER_MIN ) ts . sec = now + 10 * SEC_PER_MIN + timer -> triggerid % ( 10 * SEC_PER_MIN ) ; else ts . sec = old -> eval_ts . sec ; dc_schedule_trigger_timer ( timer , & old -> eval_ts , & ts ) ; } else { if ( 0 == ( ts . sec = dc_function_calculate_nextcheck ( timer , now , timer -> triggerid ) ) ) { dc_trigger_timer_free ( timer ) ; function -> timer_revision = 0 ; } else dc_schedule_trigger_timer ( timer , NULL , & ts ) ; } } zbx_hashset_iter_reset ( & config -> triggers , & iter ) ; while ( NULL != ( trigger = ( ZBX_DC_TRIGGER * ) zbx_hashset_iter_next ( & iter ) ) ) { if ( ZBX_TRIGGER_TIMER_DEFAULT == trigger -> timer ) continue ; if ( trigger -> timer_revision == trigger -> revision ) continue ; if ( NULL == ( timer = dc_trigger_timer_create ( trigger ) ) ) continue ; if ( 0 == ( ts . sec = dc_function_calculate_nextcheck ( timer , now , timer -> triggerid ) ) ) { dc_trigger_timer_free ( timer ) ; trigger -> timer_revision = 0 ; } else dc_schedule_trigger_timer ( timer , NULL , & ts ) ; } }
Function: dc_schedule_new_trigger_timers                                   
                                                                            
 Purpose: set timer schedule and evaluation times based on functions and    
          old trend function queue
Function : dc_schedule_new_trigger_timers Purpose : set timer schedule and evaluation times based on functions and old trend function queue
/* if the trigger was scheduled during next 10 minutes         */ /* schedule its evaluation later to reduce server startup load */