zabbix-agent2/src/libs/zbxserver/expression.c
/******************************************************************************
 *                                                                            *
 * Function: DBget_history_log_value                                          *
 *                                                                            *
 * Purpose: retrieve a particular attribute of a log value                    *
 *                                                                            *
 * Return value: upon successful completion return SUCCEED                    *
 *               otherwise FAIL                                               *
 *                                                                            *
 ******************************************************************************/
DBget_history_log_value

Purpose: retrieve a particular attribute of a log value

Return value: upon successful completion return SUCCEED
otherwise FAIL
DBget_history_log_value Purpose : retrieve a particular attribute of a log value Return value : upon successful completion return SUCCEED otherwise FAIL
static int	DBget_history_log_value(zbx_uint64_t itemid, char **replace_to, int request, int clock, int ns,
		const char *tz)
{
	DC_ITEM			item;
	int			ret = FAIL, errcode = FAIL;
	zbx_timespec_t		ts = {clock, ns};
	zbx_history_record_t	value;
	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
	DCconfig_get_items_by_itemids(&item, &itemid, &errcode, 1);
	if (SUCCEED != errcode || ITEM_VALUE_TYPE_LOG != item.value_type)
		goto out;
	if (SUCCEED != zbx_vc_get_value(itemid, item.value_type, &ts, &value))
		goto out;
	zbx_vc_flush_stats();
	switch (request)
	{
		case ZBX_REQUEST_ITEM_LOG_DATE:
			*replace_to = zbx_strdup(*replace_to, zbx_date2str((time_t)value.value.log->timestamp, tz));
			goto success;
		case ZBX_REQUEST_ITEM_LOG_TIME:
			*replace_to = zbx_strdup(*replace_to, zbx_time2str((time_t)value.value.log->timestamp, tz));
			goto success;
		case ZBX_REQUEST_ITEM_LOG_AGE:
			*replace_to = zbx_strdup(*replace_to, zbx_age2str(time(NULL) - value.value.log->timestamp));
			goto success;
	}
	if (0 != strncmp(item.key_orig, "eventlog[", 9))
		goto clean;
	switch (request)
	{
		case ZBX_REQUEST_ITEM_LOG_SOURCE:
			*replace_to = zbx_strdup(*replace_to, (NULL == value.value.log->source ? "" :
					value.value.log->source));
			break;
		case ZBX_REQUEST_ITEM_LOG_SEVERITY:
			*replace_to = zbx_strdup(*replace_to,
					zbx_item_logtype_string((unsigned char)value.value.log->severity));
			break;
		case ZBX_REQUEST_ITEM_LOG_NSEVERITY:
			*replace_to = zbx_dsprintf(*replace_to, "%d", value.value.log->severity);
			break;
		case ZBX_REQUEST_ITEM_LOG_EVENTID:
			*replace_to = zbx_dsprintf(*replace_to, "%d", value.value.log->logeventid);
			break;
	}
success:
	ret = SUCCEED;
clean:
	zbx_history_record_clear(&value, ITEM_VALUE_TYPE_LOG);
out:
	DCconfig_clean_items(&item, &errcode, 1);
	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
	return ret;
}
static int DBget_history_log_value ( zbx_uint64_t itemid , char * * replace_to , int request , int clock , int ns , const char * tz ) { DC_ITEM item ; int ret = FAIL , errcode = FAIL ; zbx_timespec_t ts = { clock , ns } ; zbx_history_record_t value ; zabbix_log ( LOG_LEVEL_DEBUG , " " , __func__ ) ; DCconfig_get_items_by_itemids ( & item , & itemid , & errcode , 1 ) ; if ( SUCCEED != errcode || ITEM_VALUE_TYPE_LOG != item . value_type ) goto out ; if ( SUCCEED != zbx_vc_get_value ( itemid , item . value_type , & ts , & value ) ) goto out ; zbx_vc_flush_stats ( ) ; switch ( request ) { case ZBX_REQUEST_ITEM_LOG_DATE : * replace_to = zbx_strdup ( * replace_to , zbx_date2str ( ( time_t ) value . value . log -> timestamp , tz ) ) ; goto success ; case ZBX_REQUEST_ITEM_LOG_TIME : * replace_to = zbx_strdup ( * replace_to , zbx_time2str ( ( time_t ) value . value . log -> timestamp , tz ) ) ; goto success ; case ZBX_REQUEST_ITEM_LOG_AGE : * replace_to = zbx_strdup ( * replace_to , zbx_age2str ( time ( NULL ) - value . value . log -> timestamp ) ) ; goto success ; } if ( 0 != strncmp ( item . key_orig , " " , 9 ) ) goto clean ; switch ( request ) { case ZBX_REQUEST_ITEM_LOG_SOURCE : * replace_to = zbx_strdup ( * replace_to , ( NULL == value . value . log -> source ? " " : value . value . log -> source ) ) ; break ; case ZBX_REQUEST_ITEM_LOG_SEVERITY : * replace_to = zbx_strdup ( * replace_to , zbx_item_logtype_string ( ( unsigned char ) value . value . log -> severity ) ) ; break ; case ZBX_REQUEST_ITEM_LOG_NSEVERITY : * replace_to = zbx_dsprintf ( * replace_to , " " , value . value . log -> severity ) ; break ; case ZBX_REQUEST_ITEM_LOG_EVENTID : * replace_to = zbx_dsprintf ( * replace_to , " " , value . value . log -> logeventid ) ; break ; } success : ret = SUCCEED ; clean : zbx_history_record_clear ( & value , ITEM_VALUE_TYPE_LOG ) ; out : DCconfig_clean_items ( & item , & errcode , 1 ) ; zabbix_log ( LOG_LEVEL_DEBUG , " " , __func__ , zbx_result_string ( ret ) ) ; return ret ; }
Function: DBget_history_log_value                                          
                                                                            
 Purpose: retrieve a particular attribute of a log value                    
                                                                            
 Return value: upon successful completion return SUCCEED                    
               otherwise FAIL
Function : DBget_history_log_value Purpose : retrieve a particular attribute of a log value Return value : upon successful completion return SUCCEED otherwise FAIL
/* the following attributes are set only for windows eventlog items */