/****************************************************************************** * * * Function: queue_stats_export * * * * Purpose: export queue stats to JSON format * * * * Parameters: queue_stats - [IN] a hashset containing item stats * * id_name - [IN] the name of stats id field * * json - [OUT] the output JSON * * * ******************************************************************************/ static void queue_stats_export(zbx_hashset_t *queue_stats, const char *id_name, struct zbx_json *json) { zbx_hashset_iter_t iter; zbx_queue_stats_t *stats; zbx_json_addarray(json, ZBX_PROTO_TAG_DATA); zbx_hashset_iter_reset(queue_stats, &iter); while (NULL != (stats = zbx_hashset_iter_next(&iter))) { zbx_json_addobject(json, NULL); zbx_json_adduint64(json, id_name, stats->id); zbx_json_adduint64(json, "delay5", stats->delay5); zbx_json_adduint64(json, "delay10", stats->delay10); zbx_json_adduint64(json, "delay30", stats->delay30); zbx_json_adduint64(json, "delay60", stats->delay60); zbx_json_adduint64(json, "delay300", stats->delay300); zbx_json_adduint64(json, "delay600", stats->delay600); zbx_json_close(json); } zbx_json_close(json); }
/****************************************************************************** * * * Function: db_get_query_functions * * * * Purpose: get event query functionids from database * * * ******************************************************************************/ static void db_get_query_functions(zbx_vector_ptr_t *event_queries) { DB_ROW row; DB_RESULT result; int i; zbx_vector_uint64_t triggerids; zbx_hashset_t triggers; zbx_hashset_iter_t iter; char *sql = NULL; size_t sql_alloc = 0, sql_offset = 0; zbx_trigger_functions_t *trigger = NULL, trigger_local; zbx_uint64_t triggerid, functionid; zbx_event_suppress_query_t *query; /* cache functionids by triggerids */ zbx_hashset_create(&triggers, 100, ZBX_DEFAULT_UINT64_HASH_FUNC, ZBX_DEFAULT_UINT64_COMPARE_FUNC); zbx_vector_uint64_create(&triggerids); for (i = 0; i < event_queries->values_num; i++) { query = (zbx_event_suppress_query_t *)event_queries->values[i]; zbx_vector_uint64_append(&triggerids, query->triggerid); } zbx_vector_uint64_sort(&triggerids, ZBX_DEFAULT_UINT64_COMPARE_FUNC); zbx_vector_uint64_uniq(&triggerids, ZBX_DEFAULT_UINT64_COMPARE_FUNC); zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, "select functionid,triggerid from functions where"); DBadd_condition_alloc(&sql, &sql_alloc, &sql_offset, "triggerid", triggerids.values, triggerids.values_num); zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, " order by triggerid"); result = DBselect("%s", sql); zbx_free(sql); while (NULL != (row = DBfetch(result))) { ZBX_STR2UINT64(functionid, row[0]); ZBX_STR2UINT64(triggerid, row[1]); if (NULL == trigger || trigger->triggerid != triggerid) { trigger_local.triggerid = triggerid; trigger = (zbx_trigger_functions_t *)zbx_hashset_insert(&triggers, &trigger_local, sizeof(trigger_local)); zbx_vector_uint64_create(&trigger->functionids); } zbx_vector_uint64_append(&trigger->functionids, functionid); } DBfree_result(result); /* copy functionids to event queries */ for (i = 0; i < event_queries->values_num; i++) { query = (zbx_event_suppress_query_t *)event_queries->values[i]; if (NULL == (trigger = (zbx_trigger_functions_t *)zbx_hashset_search(&triggers, &query->triggerid))) continue; zbx_vector_uint64_append_array(&query->functionids, trigger->functionids.values, trigger->functionids.values_num); } zbx_hashset_iter_reset(&triggers, &iter); while (NULL != (trigger = (zbx_trigger_functions_t *)zbx_hashset_iter_next(&iter))) zbx_vector_uint64_destroy(&trigger->functionids); zbx_hashset_destroy(&triggers); zbx_vector_uint64_destroy(&triggerids); }