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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-06-04 09:22:37 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080604092237-zgwq7kmraj1oohoz
Tags: 1:1.4.5-1ubuntu1
* Merge from debian unstable, remaining changes: 
  + fixing missing pid directory in /var/run
* Added the same patch to debian/zabbix-server-{mysql,pgsql}.zabbix-server.init
  (LP: #172775)

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
/******************************************************************************
32
32
 *                                                                            *
 
33
 * Function: process_node_history_log                                         *
 
34
 *                                                                            *
 
35
 * Purpose: process new history_log data                                      *
 
36
 *                                                                            *
 
37
 * Parameters:                                                                *
 
38
 *                                                                            *
 
39
 * Return value: SUCCESS - processed succesfully                              * 
 
40
 *               FAIL - an error occured                                      *
 
41
 *                                                                            *
 
42
 * Author: Alexei Vladishev                                                   *
 
43
 *                                                                            *
 
44
 * Comments:                                                                  *
 
45
 *                                                                            *
 
46
 ******************************************************************************/
 
47
static int process_node_history_log(int nodeid, int master_nodeid)
 
48
{
 
49
        const char      *ids_table_name = {"history_log"};
 
50
        const char      *ids_field_name = {"sync_lastid"};
 
51
        DB_RESULT       result;
 
52
        DB_ROW          row;
 
53
        char            sql[MAX_STRING_LEN];
 
54
        int             ids_found = 0, found = 0;
 
55
        int             offset = 0;
 
56
        char            *data = NULL, *hex = NULL;
 
57
        int             allocated = 1024*1024, hex_allocated = 1024;
 
58
        zbx_uint64_t    sync_lastid = 0, id, len;
 
59
 
 
60
        zabbix_log( LOG_LEVEL_DEBUG, "In process_node_history_log(nodeid:%d, master_nodeid:%d)",
 
61
                nodeid,
 
62
                master_nodeid);
 
63
 
 
64
        /* Do not send history for current node if CONFIG_NODE_NOHISTORY is set */
 
65
        if((CONFIG_NODE_NOHISTORY != 0) && (CONFIG_NODEID == nodeid))
 
66
                return SUCCEED;
 
67
 
 
68
 
 
69
        data = zbx_malloc(data, allocated);
 
70
        hex = zbx_malloc(hex, hex_allocated);
 
71
 
 
72
        result = DBselect("select nextid from ids where nodeid=%d and table_name='%s' and field_name='%s'",
 
73
                                nodeid,
 
74
                                ids_table_name,
 
75
                                ids_field_name);
 
76
 
 
77
        if((row=DBfetch(result)))
 
78
        {
 
79
                ZBX_STR2UINT64(sync_lastid,row[0])
 
80
                ids_found = 1;
 
81
        }
 
82
        DBfree_result(result);
 
83
 
 
84
        zbx_snprintf_alloc(&data, &allocated, &offset, 64, "History%c%d%c%d",
 
85
                ZBX_DM_DELIMITER,
 
86
                CONFIG_NODEID,
 
87
                ZBX_DM_DELIMITER,
 
88
                nodeid);
 
89
 
 
90
        zbx_snprintf(sql,sizeof(sql),"select id,itemid,clock,timestamp,source,severity,value,length(value) from history_log where id>"ZBX_FS_UI64" and "ZBX_COND_NODEID" order by id",
 
91
                sync_lastid,
 
92
                ZBX_NODE("id", nodeid));
 
93
 
 
94
        result = DBselectN(sql, 10000);
 
95
        while((row=DBfetch(result)))
 
96
        {
 
97
                ZBX_STR2UINT64(id,row[0])
 
98
                found = 1;
 
99
 
 
100
                len = atoi(row[7]);
 
101
                zbx_binary2hex((u_char *)row[6], len, &hex, &hex_allocated);
 
102
 
 
103
                zbx_snprintf_alloc(&data, &allocated, &offset, len * 2 + 256, "\n%d%c%s%c%s%c%s%c%s%c%s%c%s%c%s",
 
104
                                ZBX_TABLE_HISTORY_LOG, ZBX_DM_DELIMITER,
 
105
                                row[1], ZBX_DM_DELIMITER,       /* itemid */
 
106
                                row[2], ZBX_DM_DELIMITER,       /* clock */
 
107
                                row[0], ZBX_DM_DELIMITER,       /* id */
 
108
                                row[3], ZBX_DM_DELIMITER,       /* timestamp */
 
109
                                row[4], ZBX_DM_DELIMITER,       /* source */
 
110
                                row[5], ZBX_DM_DELIMITER,       /* severity */
 
111
                                hex);                           /* value */
 
112
        }
 
113
        if(found == 1)
 
114
        {
 
115
                if(send_to_node("new history_log", master_nodeid, nodeid, data) == SUCCEED)
 
116
                {
 
117
                        if(ids_found == 1)
 
118
                        {
 
119
                                DBexecute("update ids set nextid="ZBX_FS_UI64" where nodeid=%d and table_name='%s' and field_name='%s'",
 
120
                                        id,
 
121
                                        nodeid,
 
122
                                        ids_table_name,
 
123
                                        ids_field_name);
 
124
                        }
 
125
                        else
 
126
                        {
 
127
                                DBexecute("insert into ids (nodeid,table_name,field_name,nextid) values (%d,'%s','%s',"ZBX_FS_UI64")",
 
128
                                        nodeid,
 
129
                                        ids_table_name,
 
130
                                        ids_field_name,
 
131
                                        id);
 
132
                        }
 
133
                }
 
134
                else
 
135
                {
 
136
                        zabbix_log( LOG_LEVEL_DEBUG, "process_node_history_log() FAIL");
 
137
                }
 
138
        }
 
139
        DBfree_result(result);
 
140
 
 
141
        zbx_free(data);
 
142
        zbx_free(hex);
 
143
 
 
144
        return SUCCEED;
 
145
}
 
146
 
 
147
/******************************************************************************
 
148
 *                                                                            *
33
149
 * Function: process_node_history_str                                         *
34
150
 *                                                                            *
35
151
 * Purpose: process new history_str data                                      *
93
209
                if( ((CONFIG_NODE_NOHISTORY !=0) && (CONFIG_NODEID == nodeid)) ||
94
210
                        send_to_node("new history_str", master_nodeid, nodeid, data) == SUCCEED)
95
211
                {
96
 
/*                      zabbix_log( LOG_LEVEL_WARNING, "Updating nodes.history_lastid");*/
97
 
                        DBexecute("update nodes set history_str_lastid=" ZBX_FS_UI64 " where nodeid=%d",
98
 
                                id,
99
 
                                nodeid);
100
212
                        DBexecute("delete from history_str_sync where nodeid=%d and id<=" ZBX_FS_UI64,
101
213
                                nodeid,
102
214
                                id);
103
215
                }
104
216
                else
105
217
                {
106
 
                        zabbix_log( LOG_LEVEL_DEBUG, "Not updating nodes.history_str_lastid");
 
218
                        zabbix_log( LOG_LEVEL_DEBUG, "process_node_history_str() FAIL");
107
219
                }
108
220
        }
109
221
        DBfree_result(result);
181
293
                if( ((CONFIG_NODE_NOHISTORY !=0) && (CONFIG_NODEID == nodeid)) ||
182
294
                        send_to_node("new history_uint", master_nodeid, nodeid, data) == SUCCEED)
183
295
                {
184
 
/*                      zabbix_log( LOG_LEVEL_WARNING, "Updating nodes.history_lastid"); */
185
 
                        DBexecute("update nodes set history_uint_lastid=" ZBX_FS_UI64 " where nodeid=%d",
186
 
                                id,
187
 
                                nodeid);
188
296
                        DBexecute("delete from history_uint_sync where nodeid=%d and id<=" ZBX_FS_UI64,
189
297
                                nodeid,
190
298
                                id);
191
299
                }
192
300
                else
193
301
                {
194
 
                        zabbix_log( LOG_LEVEL_DEBUG, "Not updating nodes.history_uint_lastid");
 
302
                        zabbix_log( LOG_LEVEL_DEBUG, "process_node_history_uint() FAIL");
195
303
                }
196
304
        }
197
305
        DBfree_result(result);
275
383
                if( ((CONFIG_NODE_NOHISTORY !=0) && (CONFIG_NODEID == nodeid)) ||
276
384
                        send_to_node("new history", master_nodeid, nodeid, data) == SUCCEED)
277
385
                {
278
 
/*                      zabbix_log( LOG_LEVEL_WARNING, "Updating nodes.history_lastid=" ZBX_FS_UI64, id); */
279
 
                        DBexecute("update nodes set history_lastid=" ZBX_FS_UI64 " where nodeid=%d",
280
 
                                id,
281
 
                                nodeid);
282
386
                        DBexecute("delete from history_sync where nodeid=%d and id<=" ZBX_FS_UI64,
283
387
                                nodeid,
284
388
                                id);
285
389
                }
286
390
                else
287
391
                {
288
 
                        zabbix_log( LOG_LEVEL_DEBUG, "Not updating nodes.history_lastid");
 
392
                        zabbix_log( LOG_LEVEL_DEBUG, "process_node_history() FAIL");
289
393
                }
290
394
        }
291
395
        DBfree_result(result);
324
428
        process_node_history(nodeid, master_nodeid);
325
429
        process_node_history_uint(nodeid, master_nodeid);
326
430
        process_node_history_str(nodeid, master_nodeid);
 
431
        process_node_history_log(nodeid, master_nodeid);
327
432
}
328
433
 
329
434
/******************************************************************************
345
450
{
346
451
        DB_RESULT       result;
347
452
        DB_ROW          row;
348
 
        zbx_uint64_t    lastid;
349
453
        int             nodeid;
350
454
        int             master_nodeid;
351
455
 
355
459
 
356
460
        master_nodeid = get_master_node(CONFIG_NODEID);
357
461
 
358
 
        if(master_nodeid != 0)
 
462
        if(master_nodeid)
359
463
        {
360
 
                result = DBselect("select nodeid from nodes");
 
464
                result = DBselect("select nodeid from nodes where nodeid<>%d", master_nodeid);
361
465
 
362
466
                while((row = DBfetch(result)))
363
467
                {
364
468
                        nodeid=atoi(row[0]);
365
 
                        ZBX_STR2UINT64(lastid,row[1])
366
 
 
367
469
                        process_node(nodeid, master_nodeid);
368
470
                }
369
471
                DBfree_result(result);