3
** Copyright (C) 2000-2006 SIA Zabbix
5
** This program is free software; you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License as published by
7
** the Free Software Foundation; either version 2 of the License, or
8
** (at your option) any later version.
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
** GNU General Public License for more details.
15
** You should have received a copy of the GNU General Public License
16
** along with this program; if not, write to the Free Software
17
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
#include "nodecomms.h"
28
#include "nodesender.h"
31
#define ZBX_NODE_MASTER 0
32
#define ZBX_NODE_SLAVE 1
34
/******************************************************************************
36
* Function: process_node *
38
* Purpose: select all related nodes and send config changes *
42
* Return value: SUCCESS - processed succesfully *
43
* FAIL - an error occured *
45
* Author: Alexei Vladishev *
49
******************************************************************************/
50
static int process_node(int nodeid, int master_nodeid, zbx_uint64_t event_lastid)
62
zabbix_log( LOG_LEVEL_DEBUG, "In process_node(local:%d, event_lastid:" ZBX_FS_UI64 ")",
67
data = malloc(allocated);
68
memset(data,0,allocated);
70
zbx_snprintf_alloc(&data, &allocated, &offset, 128, "Events%c%d%c%d",
76
result = DBselect("select eventid,source,object,objectid,clock,value,acknowledged from events where eventid>" ZBX_FS_UI64 " and " ZBX_COND_NODEID " order by eventid",
78
ZBX_NODE("eventid", nodeid));
79
while((row=DBfetch(result)))
81
ZBX_STR2UINT64(eventid,row[0])
83
zbx_snprintf_alloc(&data, &allocated, &offset, 1024, "\n%s%c%s%c%s%c%s%c%s%c%s%c%s",
100
zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]",
102
if(send_to_node("new events", master_nodeid, nodeid, data) == SUCCEED)
104
zabbix_log( LOG_LEVEL_DEBUG, "Updating nodes.event_lastid");
105
DBexecute("update nodes set event_lastid=" ZBX_FS_UI64 " where nodeid=%d",
111
zabbix_log( LOG_LEVEL_DEBUG, "Not updating nodes.event_lastid");
114
DBfree_result(result);
120
/******************************************************************************
122
* Function: main_eventsender *
124
* Purpose: periodically sends new events to master node *
130
* Author: Alexei Vladishev *
132
* Comments: never returns *
134
******************************************************************************/
135
void main_eventsender()
143
zabbix_log( LOG_LEVEL_DEBUG, "In main_eventsender()");
147
master_nodeid = get_master_node(CONFIG_NODEID);
149
if(master_nodeid == 0) return;
151
result = DBselect("select nodeid,event_lastid from nodes");
153
while((row = DBfetch(result)))
156
ZBX_STR2UINT64(lastid,row[1])
158
process_node(nodeid, master_nodeid, lastid);
161
DBfree_result(result);