zabbix-agent2/src/zabbix_server/actions.c
/******************************************************************************
 *                                                                            *
 * Function: check_intern_host_group_condition                                *
 *                                                                            *
 * Purpose: check host group 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_group_condition

Purpose: check host group 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_group_condition Purpose : check host group 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_group_condition(const zbx_vector_ptr_t *esc_events, zbx_condition_t *condition)
{
	char			*sql = NULL;
	size_t			sql_alloc = 0, i;
	DB_RESULT		result;
	DB_ROW			row;
	int			objects[3] = {EVENT_OBJECT_TRIGGER, EVENT_OBJECT_ITEM, EVENT_OBJECT_LLDRULE};
	zbx_vector_uint64_t	objectids[3], groupids;
	zbx_uint64_t		condition_value;
	if (CONDITION_OPERATOR_EQUAL != condition->op && CONDITION_OPERATOR_NOT_EQUAL != condition->op)
		return NOTSUPPORTED;
	ZBX_STR2UINT64(condition_value, condition->value);
	for (i = 0; i < (int)ARRSIZE(objects); i++)
		zbx_vector_uint64_create(&objectids[i]);
	zbx_vector_uint64_create(&groupids);
	get_object_ids_internal(esc_events, objectids, objects, (int)ARRSIZE(objects));
	zbx_dc_get_nested_hostgroupids(&condition_value, 1, &groupids);
	for (i = 0; i < (int)ARRSIZE(objects); i++)
	{
		size_t	sql_offset = 0;
		if (0 == objectids[i].values_num)
			continue;
		if (EVENT_OBJECT_TRIGGER == objects[i])
		{
			zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset,
					"select distinct f.triggerid"
					" from hosts_groups hg,hosts h,items i,functions f"
					" where hg.hostid=h.hostid"
						" and h.hostid=i.hostid"
						" and i.itemid=f.itemid"
						" and");
			DBadd_condition_alloc(&sql, &sql_alloc, &sql_offset, "f.triggerid", objectids[i].values,
					objectids[i].values_num);
		}
		else	
		{
			zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset,
					"select distinct i.itemid"
					" from hosts_groups hg,hosts h,items i"
					" where hg.hostid=h.hostid"
						" and h.hostid=i.hostid"
						" and");
			DBadd_condition_alloc(&sql, &sql_alloc, &sql_offset, "i.itemid",
					objectids[i].values, objectids[i].values_num);
		}
		zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, " and");
		DBadd_condition_alloc(&sql, &sql_alloc, &sql_offset, "hg.groupid", groupids.values,
				groupids.values_num);
		result = DBselect("%s", sql);
		while (NULL != (row = DBfetch(result)))
		{
			zbx_uint64_t	objectid;
			ZBX_STR2UINT64(objectid, row[0]);
			if (CONDITION_OPERATOR_NOT_EQUAL == condition->op)
			{
				int	index;
				if (FAIL != (index = zbx_vector_uint64_search(&objectids[i], objectid,
						ZBX_DEFAULT_UINT64_COMPARE_FUNC)))
				{
					zbx_vector_uint64_remove_noorder(&objectids[i], index);
				}
			}
			else
				add_condition_match(esc_events, condition, objectid, objects[i]);
		}
		DBfree_result(result);
	}
	for (i = 0; i < (int)ARRSIZE(objects); i++)
	{
		if (CONDITION_OPERATOR_NOT_EQUAL == condition->op)
		{
			int	j;
			for (j = 0; j < objectids[i].values_num; j++)
				add_condition_match(esc_events, condition, objectids[i].values[j], objects[i]);
		}
		zbx_vector_uint64_destroy(&objectids[i]);
	}
	zbx_vector_uint64_destroy(&groupids);
	zbx_free(sql);
	return SUCCEED;
}
static int check_intern_host_group_condition ( const zbx_vector_ptr_t * esc_events , zbx_condition_t * condition ) { char * sql = NULL ; size_t sql_alloc = 0 , i ; DB_RESULT result ; DB_ROW row ; int objects [ 3 ] = { EVENT_OBJECT_TRIGGER , EVENT_OBJECT_ITEM , EVENT_OBJECT_LLDRULE } ; zbx_vector_uint64_t objectids [ 3 ] , groupids ; zbx_uint64_t condition_value ; if ( CONDITION_OPERATOR_EQUAL != condition -> op && CONDITION_OPERATOR_NOT_EQUAL != condition -> op ) return NOTSUPPORTED ; ZBX_STR2UINT64 ( condition_value , condition -> value ) ; for ( i = 0 ; i < ( int ) ARRSIZE ( objects ) ; i ++ ) zbx_vector_uint64_create ( & objectids [ i ] ) ; zbx_vector_uint64_create ( & groupids ) ; get_object_ids_internal ( esc_events , objectids , objects , ( int ) ARRSIZE ( objects ) ) ; zbx_dc_get_nested_hostgroupids ( & condition_value , 1 , & groupids ) ; for ( i = 0 ; i < ( int ) ARRSIZE ( objects ) ; i ++ ) { size_t sql_offset = 0 ; if ( 0 == objectids [ i ] . values_num ) continue ; if ( EVENT_OBJECT_TRIGGER == objects [ i ] ) { zbx_snprintf_alloc ( & sql , & sql_alloc , & sql_offset , " " " " " " " " " " " " ) ; DBadd_condition_alloc ( & sql , & sql_alloc , & sql_offset , " " , objectids [ i ] . values , objectids [ i ] . values_num ) ; } else { zbx_snprintf_alloc ( & sql , & sql_alloc , & sql_offset , " " " " " " " " " " ) ; DBadd_condition_alloc ( & sql , & sql_alloc , & sql_offset , " " , objectids [ i ] . values , objectids [ i ] . values_num ) ; } zbx_strcpy_alloc ( & sql , & sql_alloc , & sql_offset , " " ) ; DBadd_condition_alloc ( & sql , & sql_alloc , & sql_offset , " " , groupids . values , groupids . values_num ) ; result = DBselect ( " " , sql ) ; while ( NULL != ( row = DBfetch ( result ) ) ) { zbx_uint64_t objectid ; ZBX_STR2UINT64 ( objectid , row [ 0 ] ) ; if ( CONDITION_OPERATOR_NOT_EQUAL == condition -> op ) { int index ; if ( FAIL != ( index = zbx_vector_uint64_search ( & objectids [ i ] , objectid , ZBX_DEFAULT_UINT64_COMPARE_FUNC ) ) ) { zbx_vector_uint64_remove_noorder ( & objectids [ i ] , index ) ; } } else add_condition_match ( esc_events , condition , objectid , objects [ i ] ) ; } DBfree_result ( result ) ; } for ( i = 0 ; i < ( int ) ARRSIZE ( objects ) ; i ++ ) { if ( CONDITION_OPERATOR_NOT_EQUAL == condition -> op ) { int j ; for ( j = 0 ; j < objectids [ i ] . values_num ; j ++ ) add_condition_match ( esc_events , condition , objectids [ i ] . values [ j ] , objects [ i ] ) ; } zbx_vector_uint64_destroy ( & objectids [ i ] ) ; } zbx_vector_uint64_destroy ( & groupids ) ; zbx_free ( sql ) ; return SUCCEED ; }
Function: check_intern_host_group_condition                                
                                                                            
 Purpose: check host group 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_group_condition Purpose : check host group 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 */