Ejemplo n.º 1
0
Archivo: timer.c Proyecto: Shmuma/z
/******************************************************************************
 *                                                                            *
 * Function: main_timer_loop                                                  *
 *                                                                            *
 * Purpose: periodically updates time-related triggers                        *
 *                                                                            *
 * Parameters:                                                                *
 *                                                                            *
 * Return value:                                                              *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments: does update once per 30 seconds (hardcoded)                      *
 *                                                                            *
 ******************************************************************************/
void main_timer_loop()
{
	int	now, cur;

/*	int	itemid,functionid;
	char	*function;
	char	*parameter;*/

	DB_ITEM	item;

	DB_RESULT	result;
	DB_ROW	row;

	for(;;)
	{
		zbx_setproctitle("Timer: updating nodata() functions");

		DBconnect(ZBX_DB_CONNECT_NORMAL);

		now=time(NULL);
/*
#ifdef HAVE_POSTGRESQL
		zbx_snprintf(sql,sizeof(sql),"select distinct f.itemid,f.functionid,f.parameter from functions f, items i,hosts h where h.hostid=i.hostid and h.status=%d and i.itemid=f.itemid and f.function in ('nodata','date','dayofweek','time','now') and i.lastclock+f.parameter::text::integer<=%d and i.status=%d", HOST_STATUS_MONITORED, now, ITEM_STATUS_ACTIVE);
#else
		zbx_snprintf(sql,sizeof(sql),"select distinct f.itemid,f.functionid,f.parameter,f.function from functions f, items i,hosts h where h.hostid=i.hostid and h.status=%d and i.itemid=f.itemid and f.function in ('nodata','date','dayofweek','time','now') and i.lastclock+f.parameter<=%d and i.status=%d", HOST_STATUS_MONITORED, now, ITEM_STATUS_ACTIVE);
#endif
	*/

		result = DBselect("select %s, functions f where h.hostid=i.hostid and h.status=%d and i.status=%d and f.function in ('nodata','date','dayofweek','time','now','count') and i.itemid=f.itemid and " ZBX_COND_SITE,
			ZBX_SQL_ITEM_SELECT,
			HOST_STATUS_MONITORED,
			ITEM_STATUS_ACTIVE,
			getSiteCondition ());
		cur = 1;

		while((row=DBfetch(result)))
		{
#ifdef HAVE_MYSQL			
			zbx_setproctitle("Timer: processing %d item of %d", cur++, result->row_count);
#endif
			DBget_item_from_db(&item,row);

			DBbegin();
			update_functions(&item);
			update_triggers(item.itemid);
			DBcommit();

			DBfree_item(&item);
		}

		DBfree_result(result);
		DBclose();

		zbx_setproctitle("Timer: sleeping for 10 sec");

		sleep(10);
	}
}
Ejemplo n.º 2
0
/******************************************************************************
 *                                                                            *
 * Function: process_new_value                                                *
 *                                                                            *
 * Purpose: process new item value                                            *
 *                                                                            *
 * Parameters: item - item data                                               *
 *             value - new value of the item                                  *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments: for trapper poller process                                       *
 *                                                                            *
 ******************************************************************************/
void	process_new_value(DB_ITEM *item, AGENT_RESULT *value, time_t now)
{
	zabbix_log( LOG_LEVEL_DEBUG, "In process_new_value(%s)",
		item->key);

	if (0 == CONFIG_DBSYNCER_FORKS)
	{
		if (SUCCEED == add_history(item, value, now))
		{
			update_item(item, value, now);
			update_functions(item, now);
			update_triggers(item->itemid);
		}
		else
			update_item(item, value, now);
	}
	else
		dc_add_history(item, value, now);
}