#include "zbxalerter.h"
#include "alerter_defs.h"
#include "alerter_protocol.h"
#include "zbxlog.h"
#include "zbxalgo.h"
#include "zbxdb.h"
#include "zbxdbhigh.h"
#include "zbxipcservice.h"
#include "zbxjson.h"
#include "zbxnix.h"
#include "zbxnum.h"
#include "zbxself.h"
#include "zbxservice.h"
#include "zbxstr.h"
#include "zbxthreads.h"
#include "zbxtime.h"
#include "zbxtypes.h"
#include "zbxmedia.h"
#include "zbxcacheconfig.h"
typedef struct
{
zbx_hashset_t mediatypes;
zbx_ipc_async_socket_t am;
}
zbx_am_db_t;
static zbx_am_db_alert_t *am_db_create_alert(zbx_uint64_t alertid, zbx_uint64_t mediatypeid, int source,
int object, zbx_uint64_t objectid, zbx_uint64_t eventid, zbx_uint64_t p_eventid, const char *sendto,
const char *subject, const char *message, const char *params, int status, int retries)
{
zbx_am_db_alert_t *alert;
alert = (zbx_am_db_alert_t *)zbx_malloc(NULL, sizeof(zbx_am_db_alert_t));
alert->alertid = alertid;
alert->mediatypeid = mediatypeid;
alert->source = source;
alert->object = object;
alert->objectid = objectid;
alert->eventid = eventid;
alert->p_eventid = p_eventid;
alert->sendto = zbx_strdup(NULL, sendto);
alert->subject = zbx_strdup(NULL, subject);
alert->message = zbx_strdup(NULL, message);
alert->params = zbx_strdup(NULL, params);
alert->status = status;
alert->retries = retries;
alert->expression = NULL;
alert->recovery_expression = NULL;
return alert;
}
static int am_db_init(zbx_am_db_t *amdb, char **error)
{
zbx_hashset_create(&amdb->mediatypes, 5, ZBX_DEFAULT_UINT64_HASH_FUNC, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
if (SUCCEED != zbx_ipc_async_socket_open(&amdb->am, ZBX_IPC_SERVICE_ALERTER, SEC_PER_MIN, error))
return FAIL;
return SUCCEED;
}
static void am_db_clear(zbx_am_db_t *amdb)