31
31
/******************************************************************************
33
* Function: process_node_history_log *
35
* Purpose: process new history_log data *
39
* Return value: SUCCESS - processed succesfully *
40
* FAIL - an error occured *
42
* Author: Alexei Vladishev *
46
******************************************************************************/
47
static int process_node_history_log(int nodeid, int master_nodeid)
49
const char *ids_table_name = {"history_log"};
50
const char *ids_field_name = {"sync_lastid"};
53
char sql[MAX_STRING_LEN];
54
int ids_found = 0, found = 0;
56
char *data = NULL, *hex = NULL;
57
int allocated = 1024*1024, hex_allocated = 1024;
58
zbx_uint64_t sync_lastid = 0, id, len;
60
zabbix_log( LOG_LEVEL_DEBUG, "In process_node_history_log(nodeid:%d, master_nodeid:%d)",
64
/* Do not send history for current node if CONFIG_NODE_NOHISTORY is set */
65
if((CONFIG_NODE_NOHISTORY != 0) && (CONFIG_NODEID == nodeid))
69
data = zbx_malloc(data, allocated);
70
hex = zbx_malloc(hex, hex_allocated);
72
result = DBselect("select nextid from ids where nodeid=%d and table_name='%s' and field_name='%s'",
77
if((row=DBfetch(result)))
79
ZBX_STR2UINT64(sync_lastid,row[0])
82
DBfree_result(result);
84
zbx_snprintf_alloc(&data, &allocated, &offset, 64, "History%c%d%c%d",
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",
92
ZBX_NODE("id", nodeid));
94
result = DBselectN(sql, 10000);
95
while((row=DBfetch(result)))
97
ZBX_STR2UINT64(id,row[0])
101
zbx_binary2hex((u_char *)row[6], len, &hex, &hex_allocated);
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 */
115
if(send_to_node("new history_log", master_nodeid, nodeid, data) == SUCCEED)
119
DBexecute("update ids set nextid="ZBX_FS_UI64" where nodeid=%d and table_name='%s' and field_name='%s'",
127
DBexecute("insert into ids (nodeid,table_name,field_name,nextid) values (%d,'%s','%s',"ZBX_FS_UI64")",
136
zabbix_log( LOG_LEVEL_DEBUG, "process_node_history_log() FAIL");
139
DBfree_result(result);
147
/******************************************************************************
33
149
* Function: process_node_history_str *
35
151
* Purpose: process new history_str data *
275
383
if( ((CONFIG_NODE_NOHISTORY !=0) && (CONFIG_NODEID == nodeid)) ||
276
384
send_to_node("new history", master_nodeid, nodeid, data) == SUCCEED)
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",
282
386
DBexecute("delete from history_sync where nodeid=%d and id<=" ZBX_FS_UI64,
288
zabbix_log( LOG_LEVEL_DEBUG, "Not updating nodes.history_lastid");
392
zabbix_log( LOG_LEVEL_DEBUG, "process_node_history() FAIL");
291
395
DBfree_result(result);