zabbix-agent2/src/zabbix_server/actions.c
/******************************************************************************
 *                                                                            *
 * Function: check_intern_host_template_condition                             *
 *                                                                            *
 * Purpose: check host template condition for internal events                 *
 *                                                                            *
 * Parameters: esc_events - [IN] events to check                              *
 *             condition  - [IN/OUT] condition for matching, outputs          *
 *                                   event ids that match condition           *
 *                                                                            *
 * Return value: SUCCEED - supported operator                                 *
 *               NOTSUPPORTED - not supported operator                        *
 *                                                                            *
 ******************************************************************************/
check_intern_host_template_condition

Purpose: check host template condition for internal events

Parameters: esc_events - [IN] events to check
condition  - [IN/OUT] condition for matching, outputs
event ids that match condition

Return value: SUCCEED - supported operator
NOTSUPPORTED - not supported operator
check_intern_host_template_condition Purpose : check host template condition for internal events Parameters : esc_events - [ IN ] events to check condition - [ IN / OUT ] condition for matching outputs event ids that match condition Return value : SUCCEED - supported operator NOTSUPPORTED - not supported operator
static int	check_intern_host_template_condition(const zbx_vector_ptr_t *esc_events, zbx_condition_t *condition)
{
	char				*sql = NULL;
	size_t				sql_alloc = 0;
	DB_RESULT			result;
	DB_ROW				row;
	zbx_uint64_t			condition_value;
	int				i, j;
	int				objects[3] = {EVENT_OBJECT_TRIGGER, EVENT_OBJECT_ITEM, EVENT_OBJECT_LLDRULE};
	zbx_vector_uint64_t		objectids[3];
	zbx_vector_uint64_pair_t	objectids_pair[3];
	if (CONDITION_OPERATOR_EQUAL != condition->op && CONDITION_OPERATOR_NOT_EQUAL != condition->op)
		return NOTSUPPORTED;
	for (i = 0; i < (int)ARRSIZE(objects); i++)
	{
		zbx_vector_uint64_create(&objectids[i]);
		zbx_vector_uint64_pair_create(&objectids_pair[i]);
	}
	get_object_ids_internal(esc_events, objectids, objects, (int)ARRSIZE(objects));
	ZBX_STR2UINT64(condition_value, condition->value);
	for (i = 0; i < (int)ARRSIZE(objects); i++)
	{
		zbx_vector_uint64_t		*objectids_ptr = &objectids[i];
		zbx_vector_uint64_pair_t	*objectids_pair_ptr = &objectids_pair[i];
		if (0 == objectids_ptr->values_num)
			continue;
		objectids_to_pair(objectids_ptr, objectids_pair_ptr);
		if (EVENT_OBJECT_TRIGGER == objects[i])
			trigger_parents_sql_alloc(&sql, &sql_alloc, objectids_ptr);
		else	
			item_parents_sql_alloc(&sql, &sql_alloc, objectids_ptr);
		result = DBselect("%s", sql);
		while (NULL != (row = DBfetch(result)))
		{
			zbx_uint64_pair_t	pair;
			ZBX_STR2UINT64(pair.first, row[0]);
			if (FAIL != (j = zbx_vector_uint64_pair_search(objectids_pair_ptr, pair,
					ZBX_DEFAULT_UINT64_COMPARE_FUNC)))
			{
				ZBX_STR2UINT64(objectids_pair_ptr->values[j].second, row[1]);
			}
		}
		DBfree_result(result);
		check_object_hierarchy(objects[i], esc_events, objectids_ptr, objectids_pair_ptr, condition, condition_value,
				0 == i ?
					"select distinct t.triggerid,t.templateid,i.hostid"
						" from items i,functions f,triggers t"
						" where i.itemid=f.itemid"
							" and f.triggerid=t.templateid"
							" and" :
					"select distinct h.itemid,t.itemid,t.hostid"
						" from items t,items h"
						" where t.itemid=h.templateid"
							" and",
				0 == i ? "t.triggerid" : "h.itemid");
	}
	for (i = 0; i < (int)ARRSIZE(objects); i++)
	{
		zbx_vector_uint64_destroy(&objectids[i]);
		zbx_vector_uint64_pair_destroy(&objectids_pair[i]);
	}
	zbx_free(sql);
	return SUCCEED;
}
static int check_intern_host_template_condition ( const zbx_vector_ptr_t * esc_events , zbx_condition_t * condition ) { char * sql = NULL ; size_t sql_alloc = 0 ; DB_RESULT result ; DB_ROW row ; zbx_uint64_t condition_value ; int i , j ; int objects [ 3 ] = { EVENT_OBJECT_TRIGGER , EVENT_OBJECT_ITEM , EVENT_OBJECT_LLDRULE } ; zbx_vector_uint64_t objectids [ 3 ] ; zbx_vector_uint64_pair_t objectids_pair [ 3 ] ; if ( CONDITION_OPERATOR_EQUAL != condition -> op && CONDITION_OPERATOR_NOT_EQUAL != condition -> op ) return NOTSUPPORTED ; for ( i = 0 ; i < ( int ) ARRSIZE ( objects ) ; i ++ ) { zbx_vector_uint64_create ( & objectids [ i ] ) ; zbx_vector_uint64_pair_create ( & objectids_pair [ i ] ) ; } get_object_ids_internal ( esc_events , objectids , objects , ( int ) ARRSIZE ( objects ) ) ; ZBX_STR2UINT64 ( condition_value , condition -> value ) ; for ( i = 0 ; i < ( int ) ARRSIZE ( objects ) ; i ++ ) { zbx_vector_uint64_t * objectids_ptr = & objectids [ i ] ; zbx_vector_uint64_pair_t * objectids_pair_ptr = & objectids_pair [ i ] ; if ( 0 == objectids_ptr -> values_num ) continue ; objectids_to_pair ( objectids_ptr , objectids_pair_ptr ) ; if ( EVENT_OBJECT_TRIGGER == objects [ i ] ) trigger_parents_sql_alloc ( & sql , & sql_alloc , objectids_ptr ) ; else item_parents_sql_alloc ( & sql , & sql_alloc , objectids_ptr ) ; result = DBselect ( " " , sql ) ; while ( NULL != ( row = DBfetch ( result ) ) ) { zbx_uint64_pair_t pair ; ZBX_STR2UINT64 ( pair . first , row [ 0 ] ) ; if ( FAIL != ( j = zbx_vector_uint64_pair_search ( objectids_pair_ptr , pair , ZBX_DEFAULT_UINT64_COMPARE_FUNC ) ) ) { ZBX_STR2UINT64 ( objectids_pair_ptr -> values [ j ] . second , row [ 1 ] ) ; } } DBfree_result ( result ) ; check_object_hierarchy ( objects [ i ] , esc_events , objectids_ptr , objectids_pair_ptr , condition , condition_value , 0 == i ? " " " " " " " " " " : " " " " " " " " , 0 == i ? " " : " " ) ; } for ( i = 0 ; i < ( int ) ARRSIZE ( objects ) ; i ++ ) { zbx_vector_uint64_destroy ( & objectids [ i ] ) ; zbx_vector_uint64_pair_destroy ( & objectids_pair [ i ] ) ; } zbx_free ( sql ) ; return SUCCEED ; }
Function: check_intern_host_template_condition                             
                                                                            
 Purpose: check host template condition for internal events                 
                                                                            
 Parameters: esc_events - [IN] events to check                              
             condition  - [IN/OUT] condition for matching, outputs          
                                   event ids that match condition           
                                                                            
 Return value: SUCCEED - supported operator                                 
               NOTSUPPORTED - not supported operator
Function : check_intern_host_template_condition Purpose : check host template condition for internal events Parameters : esc_events - [ IN ] events to check condition - [ IN / OUT ] condition for matching outputs event ids that match condition Return value : SUCCEED - supported operator NOTSUPPORTED - not supported operator
/* EVENT_OBJECT_ITEM, EVENT_OBJECT_LLDRULE */