#include "housekeeper_server.h"
#include "zbxthreads.h"
#include "zbxlog.h"
#include "zbxself.h"
#include "zbxnix.h"
#include "zbxservice.h"
#include "zbxrtc.h"
#include "zbxnum.h"
#include "zbxtime.h"
#include "zbx_rtc_constants.h"
#include "zbxalgo.h"
#include "zbxdb.h"
#include "zbxdbhigh.h"
#include "zbxipcservice.h"
#include "zbxcacheconfig.h"
static void housekeep_service_problems(const zbx_vector_uint64_t *eventids)
{
unsigned char *data = NULL;
size_t data_alloc = 0, data_offset = 0;
for (int i = 0; i < eventids->values_num; i++)
zbx_service_serialize_id(&data, &data_alloc, &data_offset, eventids->values[i]);
if (NULL == data)
return;
if (0 != zbx_dc_get_itservices_num())
zbx_service_flush(ZBX_IPC_SERVICE_SERVICE_PROBLEMS_DELETE, data, (zbx_uint32_t)data_offset);
zbx_free(data);
}
static int housekeep_problems_without_triggers(void)
{
zbx_db_result_t result;
zbx_db_row_t row;
zbx_vector_uint64_t ids;
int deleted = 0;
zbx_vector_uint64_create(&ids);
result = zbx_db_select("select eventid"
" from problem"
" where source=%d"
" and object=%d"
" and not exists (select NULL from triggers where triggerid=objectid)",
EVENT_SOURCE_TRIGGERS, EVENT_OBJECT_TRIGGER);
while (NULL != (row = zbx_db_fetch(result)))
{
zbx_uint64_t id;
ZBX_STR2UINT64(id, row[0]);
zbx_vector_uint64_append(&ids, id);
}
zbx_db_free_result(result);
zbx_vector_uint64_sort(&ids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
if (0 != ids.values_num)
{
if (SUCCEED != zbx_db_execute_multiple_query(
"update problem"
" set cause_eventid=null"
" where", "cause_eventid", &ids))
{
zabbix_log(LOG_LEVEL_WARNING, "Failed to unlink problem symptoms while housekeeping a cause"
" problem without a trigger");
goto fail;
}
if (SUCCEED != zbx_db_execute_multiple_query(
"delete"
" from event_symptom"
" where", "cause_eventid", &ids))
{