~ubuntu-dev/ubuntu/lucid/zabbix/lucid-201002110857

« back to all changes in this revision

Viewing changes to src/zabbix_server/nodewatcher/events.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Ablassmeier
  • Date: 2007-07-02 09:06:51 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070702090651-8l6fl3fjw9rh6l2u
Tags: 1:1.4.1-2
Add patch from SVN in order to fix Incorrect processing of character '%'
in user parameters and remote commands.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
** ZABBIX
 
3
** Copyright (C) 2000-2006 SIA Zabbix
 
4
**
 
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.
 
9
**
 
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.
 
14
**
 
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.
 
18
**/
 
19
 
 
20
#include "common.h"
 
21
 
 
22
#include "cfg.h"
 
23
#include "db.h"
 
24
#include "log.h"
 
25
#include "zlog.h"
 
26
 
 
27
#include "nodecomms.h"
 
28
#include "nodesender.h"
 
29
#include "events.h"
 
30
 
 
31
#define ZBX_NODE_MASTER 0
 
32
#define ZBX_NODE_SLAVE  1
 
33
 
 
34
/******************************************************************************
 
35
 *                                                                            *
 
36
 * Function: process_node                                                     *
 
37
 *                                                                            *
 
38
 * Purpose: select all related nodes and send config changes                  *
 
39
 *                                                                            *
 
40
 * Parameters:                                                                *
 
41
 *                                                                            *
 
42
 * Return value: SUCCESS - processed succesfully                              * 
 
43
 *               FAIL - an error occured                                      *
 
44
 *                                                                            *
 
45
 * Author: Alexei Vladishev                                                   *
 
46
 *                                                                            *
 
47
 * Comments:                                                                  *
 
48
 *                                                                            *
 
49
 ******************************************************************************/
 
50
static int process_node(int nodeid, int master_nodeid, zbx_uint64_t event_lastid)
 
51
{
 
52
        DB_RESULT       result;
 
53
        DB_ROW          row;
 
54
        char            *data;
 
55
        int             found = 0;
 
56
 
 
57
        int             offset = 0;
 
58
        int             allocated = 1024;
 
59
 
 
60
        zbx_uint64_t    eventid;
 
61
 
 
62
        zabbix_log( LOG_LEVEL_DEBUG, "In process_node(local:%d, event_lastid:" ZBX_FS_UI64 ")",
 
63
                nodeid,
 
64
                event_lastid);
 
65
        /* Begin work */
 
66
 
 
67
        data = malloc(allocated);
 
68
        memset(data,0,allocated);
 
69
 
 
70
        zbx_snprintf_alloc(&data, &allocated, &offset, 128, "Events%c%d%c%d",
 
71
                ZBX_DM_DELIMITER,
 
72
                CONFIG_NODEID,
 
73
                ZBX_DM_DELIMITER,
 
74
                nodeid);
 
75
 
 
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",
 
77
                event_lastid,
 
78
                ZBX_NODE("eventid", nodeid));
 
79
        while((row=DBfetch(result)))
 
80
        {
 
81
                ZBX_STR2UINT64(eventid,row[0])
 
82
                found = 1;
 
83
                zbx_snprintf_alloc(&data, &allocated, &offset, 1024, "\n%s%c%s%c%s%c%s%c%s%c%s%c%s",
 
84
                                row[0],
 
85
                                ZBX_DM_DELIMITER,
 
86
                                row[1],
 
87
                                ZBX_DM_DELIMITER,
 
88
                                row[2],
 
89
                                ZBX_DM_DELIMITER,
 
90
                                row[3],
 
91
                                ZBX_DM_DELIMITER,
 
92
                                row[4],
 
93
                                ZBX_DM_DELIMITER,
 
94
                                row[5],
 
95
                                ZBX_DM_DELIMITER,
 
96
                                row[6]);
 
97
        }
 
98
        if(found == 1)
 
99
        {
 
100
                zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]",
 
101
                        data);
 
102
                if(send_to_node("new events", master_nodeid, nodeid, data) == SUCCEED)
 
103
                {
 
104
                        zabbix_log( LOG_LEVEL_DEBUG, "Updating nodes.event_lastid");
 
105
                        DBexecute("update nodes set event_lastid=" ZBX_FS_UI64 " where nodeid=%d",
 
106
                                eventid,
 
107
                                nodeid);
 
108
                }
 
109
                else
 
110
                {
 
111
                        zabbix_log( LOG_LEVEL_DEBUG, "Not updating nodes.event_lastid");
 
112
                }
 
113
        }
 
114
        DBfree_result(result);
 
115
        free(data);
 
116
 
 
117
        return SUCCEED;
 
118
}
 
119
 
 
120
/******************************************************************************
 
121
 *                                                                            *
 
122
 * Function: main_eventsender                                                 *
 
123
 *                                                                            *
 
124
 * Purpose: periodically sends new events to master node                      *
 
125
 *                                                                            *
 
126
 * Parameters:                                                                *
 
127
 *                                                                            *
 
128
 * Return value:                                                              * 
 
129
 *                                                                            *
 
130
 * Author: Alexei Vladishev                                                   *
 
131
 *                                                                            *
 
132
 * Comments: never returns                                                    *
 
133
 *                                                                            *
 
134
 ******************************************************************************/
 
135
void main_eventsender()
 
136
{
 
137
        DB_RESULT       result;
 
138
        DB_ROW          row;
 
139
        zbx_uint64_t    lastid;
 
140
        int             nodeid;
 
141
        int             master_nodeid;
 
142
 
 
143
        zabbix_log( LOG_LEVEL_DEBUG, "In main_eventsender()");
 
144
 
 
145
        DBbegin();
 
146
 
 
147
        master_nodeid = get_master_node(CONFIG_NODEID);
 
148
 
 
149
        if(master_nodeid == 0)          return;
 
150
 
 
151
        result = DBselect("select nodeid,event_lastid from nodes");
 
152
 
 
153
        while((row = DBfetch(result)))
 
154
        {
 
155
                nodeid=atoi(row[0]);
 
156
                ZBX_STR2UINT64(lastid,row[1])
 
157
 
 
158
                process_node(nodeid, master_nodeid, lastid);
 
159
        }
 
160
 
 
161
        DBfree_result(result);
 
162
 
 
163
        DBcommit();
 
164
}