1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/*
** Zabbix
** Copyright (C) 2000-2011 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
#include "common.h"
#include "db.h"
#include "log.h"
#include "zbxserver.h"
#include "actions.h"
#include "events.h"
/******************************************************************************
* *
* Function: add_trigger_info *
* *
* Purpose: add trigger info to event if required *
* *
* Parameters: event - [IN] event data *
* *
******************************************************************************/
static int add_trigger_info(DB_EVENT *event)
{
const char *__function_name = "add_trigger_info";
int ret = SUCCEED;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
if (SUCCEED == DBis_node_local_id(event->objectid))
{
ret = DCconfig_get_trigger_for_event(&event->trigger, event->objectid);
}
else
{
DB_RESULT result;
DB_ROW row;
result = DBselect(
"select description,expression,priority,type"
" from triggers"
" where triggerid=" ZBX_FS_UI64,
event->objectid);
if (NULL != (row = DBfetch(result)))
{
event->trigger.triggerid = event->objectid;
event->trigger.description = zbx_strdup(event->trigger.description, row[0]);
event->trigger.expression = zbx_strdup(event->trigger.expression, row[1]);
event->trigger.priority = (unsigned char)atoi(row[2]);
event->trigger.type = (unsigned char)atoi(row[3]);
}
else
ret = FAIL;
DBfree_result(result);
}
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));
return ret;
}
static void free_trigger_info(DB_EVENT *event)
{
zbx_free(event->trigger.description);
zbx_free(event->trigger.expression);
}
/******************************************************************************
* *
* Function: process_event *
* *
* Purpose: process new event *
* *
* Parameters: event - event data (event.eventid - new event) *
* *
* Return value: SUCCEED - event added *
* FAIL - event not added *
* *
* Author: Alexei Vladishev *
* *
******************************************************************************/
int process_event(zbx_uint64_t eventid, int source, int object, zbx_uint64_t objectid,
const zbx_timespec_t *timespec, int value, int acknowledged)
{
const char *__function_name = "process_event";
DB_EVENT event;
int ret = FAIL;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() eventid:" ZBX_FS_UI64 " object:%d objectid:" ZBX_FS_UI64 " value:%d",
__function_name, eventid, object, objectid, value);
/* preparing event for processing */
memset(&event, 0, sizeof(DB_EVENT));
event.eventid = eventid;
event.source = source;
event.object = object;
event.objectid = objectid;
event.clock = timespec->sec;
event.ns = timespec->ns;
event.value = value;
event.acknowledged = acknowledged;
if (EVENT_SOURCE_TRIGGERS == event.source && SUCCEED != add_trigger_info(&event))
goto fail;
if (0 == event.eventid)
event.eventid = DBget_maxid("events");
DBexecute("insert into events (eventid,source,object,objectid,clock,ns,value)"
" values (" ZBX_FS_UI64 ",%d,%d," ZBX_FS_UI64 ",%d,%d,%d)",
event.eventid, event.source, event.object, event.objectid, event.clock, event.ns, event.value);
process_actions(&event);
if (EVENT_SOURCE_TRIGGERS == event.source)
{
DBupdate_services(event.objectid, TRIGGER_VALUE_PROBLEM == event.value ? event.trigger.priority : 0,
event.clock);
free_trigger_info(&event);
}
ret = SUCCEED;
fail:
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));
return ret;
}
|