diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/zbxdbhigh/db.c | 70 | ||||
-rw-r--r-- | src/zabbix_server/actions.c | 14 | ||||
-rw-r--r-- | src/zabbix_server/housekeeper/housekeeper.c | 24 | ||||
-rw-r--r-- | src/zabbix_server/nodewatcher/.deps/nodewatcher.Po | 30 | ||||
-rw-r--r-- | src/zabbix_server/nodewatcher/nodesender.c | 31 | ||||
-rw-r--r-- | src/zabbix_server/nodewatcher/nodewatcher.c | 24 | ||||
-rw-r--r-- | src/zabbix_server/trapper/nodesync.c | 12 |
7 files changed, 105 insertions, 100 deletions
diff --git a/src/libs/zbxdbhigh/db.c b/src/libs/zbxdbhigh/db.c index a4e3ba7a..c270689f 100644 --- a/src/libs/zbxdbhigh/db.c +++ b/src/libs/zbxdbhigh/db.c @@ -45,7 +45,7 @@ sqlo_db_handle_t oracle; #endif -extern void apply_actions(DB_TRIGGER *trigger,int alarmid,int trigger_value); +extern void apply_actions(DB_TRIGGER *trigger,int eventid,int trigger_value); extern void update_services(int triggerid, int status); extern int CONFIG_NODEID; @@ -694,7 +694,7 @@ int DBget_prev_trigger_value(int triggerid) zabbix_log(LOG_LEVEL_DEBUG,"In DBget_prev_trigger_value[%d]", triggerid); - result = DBselect("select max(clock) from alarms where triggerid=%d",triggerid); + result = DBselect("select max(clock) from events where triggerid=%d",triggerid); row=DBfetch(result); @@ -707,7 +707,7 @@ int DBget_prev_trigger_value(int triggerid) clock=atoi(row[0]); DBfree_result(result); - result=DBselect("select max(clock) from alarms where triggerid=%d and clock<%d",triggerid,clock); + result=DBselect("select max(clock) from events where triggerid=%d and clock<%d",triggerid,clock); row=DBfetch(result); if(!row || DBis_null(row[0])==SUCCEED) @@ -722,7 +722,7 @@ status changes to TRUE for te first time */ clock=atoi(row[0]); DBfree_result(result); - result = DBselect("select value from alarms where triggerid=%d and clock=%d",triggerid,clock); + result = DBselect("select value from events where triggerid=%d and clock=%d",triggerid,clock); row=DBfetch(result); if(!row || DBis_null(row[0])==SUCCEED) @@ -737,9 +737,9 @@ status changes to TRUE for te first time */ return value; } -/* SUCCEED if latest alarm with triggerid has this status */ +/* SUCCEED if latest event with triggerid has this status */ /* Rewrite required to simplify logic ?*/ -static int latest_alarm(int triggerid, int status) +static int latest_event(int triggerid, int status) { char sql[MAX_STRING_LEN]; DB_RESULT result; @@ -747,9 +747,9 @@ static int latest_alarm(int triggerid, int status) int ret = FAIL; - zabbix_log(LOG_LEVEL_DEBUG,"In latest_alarm()"); + zabbix_log(LOG_LEVEL_DEBUG,"In latest_event()"); - zbx_snprintf(sql,sizeof(sql),"select value from alarms where triggerid=%d order by clock desc",triggerid); + zbx_snprintf(sql,sizeof(sql),"select value from events where triggerid=%d order by clock desc",triggerid); zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql); result = DBselectN(sql,1); row = DBfetch(result); @@ -812,32 +812,32 @@ int latest_service_alarm(int serviceid, int status) return ret; } -/* Returns alarmid or 0 */ -int add_alarm(int triggerid,int status,int clock,int *alarmid) +/* Returns eventid or 0 */ +int add_event(int triggerid,int status,int clock,int *eventid) { - *alarmid=0; + *eventid=0; - zabbix_log(LOG_LEVEL_DEBUG,"In add_alarm(%d,%d,%d)",triggerid, status, *alarmid); + zabbix_log(LOG_LEVEL_DEBUG,"In add_event(%d,%d,%d)",triggerid, status, *eventid); - /* Latest alarm has the same status? */ - if(latest_alarm(triggerid,status) == SUCCEED) + /* Latest event has the same status? */ + if(latest_event(triggerid,status) == SUCCEED) { zabbix_log(LOG_LEVEL_DEBUG,"Alarm for triggerid [%d] status [%d] already exists",triggerid,status); return FAIL; } - *alarmid = DBinsert_id( - DBexecute("insert into alarms(triggerid,clock,value) values(%d,%d,%d)", triggerid, clock, status), - "alarms", "alarmid"); + *eventid = DBinsert_id( + DBexecute("insert into events(triggerid,clock,value) values(%d,%d,%d)", triggerid, clock, status), + "events", "eventid"); /* Cancel currently active alerts */ if(status == TRIGGER_VALUE_FALSE || status == TRIGGER_VALUE_TRUE) { - DBexecute("update alerts set retries=3,error='Trigger changed its status. WIll not send repeats.' where triggerid=%d and repeats>0 and status=%d", triggerid, ALERT_STATUS_NOT_SENT); + DBexecute("update events set retries=3,error='Trigger changed its status. WIll not send repeats.' where triggerid=%d and repeats>0 and status=%d", triggerid, ALERT_STATUS_NOT_SENT); } - zabbix_log(LOG_LEVEL_DEBUG,"End of add_alarm()"); + zabbix_log(LOG_LEVEL_DEBUG,"End of add_event()"); return SUCCEED; } @@ -860,7 +860,7 @@ int DBadd_service_alarm(int serviceid,int status,int clock) int DBupdate_trigger_value(DB_TRIGGER *trigger, int new_value, int now, char *reason) { - int alarmid; + int eventid; int ret = SUCCEED; if(reason==NULL) @@ -875,7 +875,7 @@ int DBupdate_trigger_value(DB_TRIGGER *trigger, int new_value, int now, char *re if(trigger->value != new_value) { trigger->prevvalue=DBget_prev_trigger_value(trigger->triggerid); - if(add_alarm(trigger->triggerid,new_value,now,&alarmid) == SUCCEED) + if(add_event(trigger->triggerid,new_value,now,&eventid) == SUCCEED) { if(reason==NULL) { @@ -897,7 +897,7 @@ int DBupdate_trigger_value(DB_TRIGGER *trigger, int new_value, int now, char *re ((trigger->prevvalue == TRIGGER_VALUE_TRUE) && (trigger->value == TRIGGER_VALUE_UNKNOWN) && (new_value == TRIGGER_VALUE_FALSE))) { zabbix_log(LOG_LEVEL_DEBUG,"In update_trigger_value. Before apply_actions. Triggerid [%d] prev [%d] curr [%d] new [%d]", trigger->triggerid, trigger->prevvalue, trigger->value, new_value); - apply_actions(trigger,alarmid,new_value); + apply_actions(trigger,eventid,new_value); if(new_value == TRIGGER_VALUE_TRUE) { update_services(trigger->triggerid, trigger->priority); @@ -993,7 +993,7 @@ void DBdelete_trigger(int triggerid) { DBexecute("delete from trigger_depends where triggerid_down=%d or triggerid_up=%d", triggerid, triggerid); DBexecute("delete from functions where triggerid=%d", triggerid); - DBexecute("delete from alarms where triggerid=%d", triggerid); + DBexecute("delete from events where triggerid=%d", triggerid); /* zbx_snprintf(sql,sizeof(sql),"delete from actions where triggerid=%d and scope=%d", triggerid, ACTION_SCOPE_TRIGGER); DBexecute(sql);*/ @@ -1638,7 +1638,7 @@ void DBvacuum(void) #ifdef HAVE_PGSQL char *table_for_housekeeping[]={"services", "services_links", "graphs_items", "graphs", "sysmaps_links", "sysmaps_elements", "sysmaps", "config", "groups", "hosts_groups", "alerts", - "actions", "alarms", "functions", "history", "history_str", "hosts", "trends", + "actions", "events", "functions", "history", "history_str", "hosts", "trends", "items", "media", "media_type", "triggers", "trigger_depends", "users", "sessions", "rights", "service_alarms", "profiles", "screens", "screens_items", NULL}; @@ -1723,7 +1723,8 @@ void DBget_item_from_db(DB_ITEM *item,DB_ROW row) { char *s; - item->itemid=atoi(row[0]); + ZBX_STR2UINT64(item->itemid, row[0]); +// item->itemid=atoi(row[0]); strscpy(item->key,row[1]); item->host=row[2]; item->port=atoi(row[3]); @@ -1758,7 +1759,8 @@ void DBget_item_from_db(DB_ITEM *item,DB_ROW row) item->prevvalue_str=s; item->prevvalue=atof(s); } - item->hostid=atoi(row[15]); +// item->hostid=atoi(row[15]); + ZBX_STR2UINT64(item->hostid, row[15]); item->host_status=atoi(row[16]); item->value_type=atoi(row[17]); @@ -1811,26 +1813,32 @@ zbx_uint64_t DBget_nextid(char *table, char *field) DB_RESULT result; DB_ROW row; zbx_uint64_t res; + zbx_uint64_t min; + zbx_uint64_t max; zabbix_log(LOG_LEVEL_DEBUG,"In DBget_nextid(%s,%s)", table, field); - result = DBselect("select max(%s) from %s where mod(%s,100)=%d", field, table, field, CONFIG_NODEID); + min = (zbx_uint64_t)100000000000000*(zbx_uint64_t)CONFIG_NODEID; + max = (zbx_uint64_t)100000000000000*(zbx_uint64_t)(CONFIG_NODEID+1)-1; + + result = DBselect("select max(%s) from %s where %s>=" ZBX_FS_UI64 " and %s<=" ZBX_FS_UI64, field, table, field, min, field, max); +// zabbix_log(LOG_LEVEL_WARNING, "select max(%s) from %s where %s>=" ZBX_FS_UI64 " and %s<=" ZBX_FS_UI64, field, table, field, min, field, max); row=DBfetch(result); if(row && (DBis_null(row[0])!=SUCCEED)) { - zabbix_log(LOG_LEVEL_DEBUG,"3 [%s]", row[0]); sscanf(row[0],ZBX_FS_UI64,&res); - res=res+100; + res++; } else { - zabbix_log(LOG_LEVEL_DEBUG,"4"); - res=(zbx_uint64_t)(100+CONFIG_NODEID); +// zabbix_log(LOG_LEVEL_WARNING,"4"); + res=(zbx_uint64_t)100000000000000*(zbx_uint64_t)CONFIG_NODEID+1; } DBfree_result(result); +// zabbix_log(LOG_LEVEL_WARNING, ZBX_FS_UI64, res); return res; } diff --git a/src/zabbix_server/actions.c b/src/zabbix_server/actions.c index b40e06f8..18d26b58 100644 --- a/src/zabbix_server/actions.c +++ b/src/zabbix_server/actions.c @@ -337,7 +337,7 @@ static int get_next_command(char** command_list, char** alias, int* is_group, ch zabbix_log( LOG_LEVEL_DEBUG, "Run remote commands END"); } -static int check_action_condition(DB_TRIGGER *trigger,int alarmid,int new_trigger_value, DB_CONDITION *condition) +static int check_action_condition(DB_TRIGGER *trigger,int eventid,int new_trigger_value, DB_CONDITION *condition) { DB_RESULT result; DB_ROW row; @@ -533,7 +533,7 @@ static int check_action_condition(DB_TRIGGER *trigger,int alarmid,int new_trigge return ret; } -static int check_action_conditions(DB_TRIGGER *trigger,int alarmid,int new_trigger_value, int actionid) +static int check_action_conditions(DB_TRIGGER *trigger,int eventid,int new_trigger_value, int actionid) { DB_RESULT result; DB_ROW row; @@ -558,7 +558,7 @@ static int check_action_conditions(DB_TRIGGER *trigger,int alarmid,int new_trigg /* OR conditions */ if(old_type == condition.conditiontype) { - if(check_action_condition(trigger, alarmid, new_trigger_value, &condition) == SUCCEED) + if(check_action_condition(trigger, eventid, new_trigger_value, &condition) == SUCCEED) ret = SUCCEED; } /* AND conditions */ @@ -566,7 +566,7 @@ static int check_action_conditions(DB_TRIGGER *trigger,int alarmid,int new_trigg { /* Break if PREVIOUS AND condition is FALSE */ if(ret == FAIL) break; - if(check_action_condition(trigger, alarmid, new_trigger_value, &condition) == FAIL) + if(check_action_condition(trigger, eventid, new_trigger_value, &condition) == FAIL) ret = FAIL; } @@ -586,7 +586,7 @@ static int check_action_conditions(DB_TRIGGER *trigger,int alarmid,int new_trigg return ret; } -void apply_actions(DB_TRIGGER *trigger,int alarmid,int trigger_value) +void apply_actions(DB_TRIGGER *trigger,int eventid,int trigger_value) { DB_RESULT result; DB_ROW row; @@ -595,7 +595,7 @@ void apply_actions(DB_TRIGGER *trigger,int alarmid,int trigger_value) /* int now;*/ - zabbix_log( LOG_LEVEL_DEBUG, "In apply_actions(triggerid:%d,alarmid:%d,trigger_value:%d)",trigger->triggerid, alarmid, trigger_value); + zabbix_log( LOG_LEVEL_DEBUG, "In apply_actions(triggerid:%d,eventid:%d,trigger_value:%d)",trigger->triggerid, eventid, trigger_value); if(TRIGGER_VALUE_TRUE == trigger_value) { @@ -629,7 +629,7 @@ void apply_actions(DB_TRIGGER *trigger,int alarmid,int trigger_value) { action.actionid=atoi(row[0]); - if(check_action_conditions(trigger, alarmid, trigger_value, action.actionid) == SUCCEED) + if(check_action_conditions(trigger, eventid, trigger_value, action.actionid) == SUCCEED) { zabbix_log( LOG_LEVEL_DEBUG, "Conditions match our trigger. Do apply actions."); action.userid=atoi(row[1]); diff --git a/src/zabbix_server/housekeeper/housekeeper.c b/src/zabbix_server/housekeeper/housekeeper.c index 5e516cd1..f1df28be 100644 --- a/src/zabbix_server/housekeeper/housekeeper.c +++ b/src/zabbix_server/housekeeper/housekeeper.c @@ -158,19 +158,19 @@ static int housekeeping_alerts(int now) return res; } -static int housekeeping_alarms(int now) +static int housekeeping_events(int now) { - int alarm_history; + int event_history; DB_RESULT result; DB_RESULT result2; DB_ROW row1; DB_ROW row2; - int alarmid; + int eventid; int res = SUCCEED; - zabbix_log( LOG_LEVEL_DEBUG, "In housekeeping_alarms(%d)", now); + zabbix_log( LOG_LEVEL_DEBUG, "In housekeeping_events(%d)", now); - result = DBselect("select alarm_history from config"); + result = DBselect("select event_history from config"); row1=DBfetch(result); @@ -181,16 +181,16 @@ static int housekeeping_alarms(int now) } else { - alarm_history=atoi(row1[0]); + event_history=atoi(row1[0]); - result2 = DBselect("select alarmid from alarms where clock<%d", now-24*3600*alarm_history); + result2 = DBselect("select eventid from events where clock<%d", now-24*3600*event_history); while((row2=DBfetch(result2))) { - alarmid=atoi(row2[0]); + eventid=atoi(row2[0]); - DBexecute("delete from acknowledges where alarmid=%d",alarmid); + DBexecute("delete from acknowledges where eventid=%d",eventid); - DBexecute("delete from alarms where alarmid=%d",alarmid); + DBexecute("delete from events where eventid=%d",eventid); } DBfree_result(result2); @@ -318,9 +318,9 @@ int main_housekeeper_loop() housekeeping_process_log(now); - zbx_setproctitle("housekeeper [removing old alarms]"); + zbx_setproctitle("housekeeper [removing old events]"); - housekeeping_alarms(now); + housekeeping_events(now); zbx_setproctitle("housekeeper [removing old alerts]"); diff --git a/src/zabbix_server/nodewatcher/.deps/nodewatcher.Po b/src/zabbix_server/nodewatcher/.deps/nodewatcher.Po index a2e2b8df..2e746cf1 100644 --- a/src/zabbix_server/nodewatcher/.deps/nodewatcher.Po +++ b/src/zabbix_server/nodewatcher/.deps/nodewatcher.Po @@ -8,15 +8,14 @@ nodewatcher.o nodewatcher.o: nodewatcher.c ../../../include/config.h \ /usr/include/gconv.h \ /usr/lib/gcc-lib/x86_64-linux-gnu/3.3.6/include/stdarg.h \ /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ - /usr/include/bits/stdio.h /usr/include/stdlib.h \ - /usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \ - /usr/include/bits/endian.h /usr/include/sys/select.h \ - /usr/include/bits/select.h /usr/include/bits/sigset.h \ - /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ - /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ - /usr/include/unistd.h /usr/include/bits/posix_opt.h \ - /usr/include/bits/confname.h /usr/include/getopt.h \ - /usr/include/sys/stat.h /usr/include/bits/stat.h \ + /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/sys/select.h /usr/include/bits/select.h \ + /usr/include/bits/sigset.h /usr/include/bits/time.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ + /usr/include/alloca.h /usr/include/unistd.h \ + /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \ + /usr/include/getopt.h /usr/include/sys/stat.h /usr/include/bits/stat.h \ /usr/include/sys/socket.h /usr/include/sys/uio.h \ /usr/include/bits/uio.h /usr/include/bits/socket.h \ /usr/lib/gcc-lib/x86_64-linux-gnu/3.3.6/include/limits.h \ @@ -34,7 +33,6 @@ nodewatcher.o nodewatcher.o: nodewatcher.c ../../../include/config.h \ /usr/include/bits/sigthread.h /usr/include/sys/resource.h \ /usr/include/bits/resource.h /usr/include/bits/waitflags.h \ /usr/include/bits/waitstatus.h /usr/include/string.h \ - /usr/include/bits/string.h /usr/include/bits/string2.h \ /usr/include/netdb.h /usr/include/rpc/netdb.h /usr/include/bits/netdb.h \ /usr/include/pwd.h /usr/include/errno.h /usr/include/bits/errno.h \ /usr/include/linux/errno.h /usr/include/asm/errno.h \ @@ -64,8 +62,8 @@ nodewatcher.o nodewatcher.o: nodewatcher.c ../../../include/config.h \ /usr/include/sys/sem.h /usr/include/bits/sem.h /usr/include/sys/shm.h \ /usr/include/bits/shm.h /usr/include/math.h \ /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \ - /usr/include/bits/mathcalls.h /usr/include/bits/mathinline.h \ - /usr/include/regex.h /usr/include/arpa/inet.h /usr/include/sys/mount.h \ + /usr/include/bits/mathcalls.h /usr/include/regex.h \ + /usr/include/arpa/inet.h /usr/include/sys/mount.h \ /usr/include/sys/ioctl.h /usr/include/bits/ioctls.h \ /usr/include/asm/ioctls.h /usr/include/asm-x86_64/ioctls.h \ /usr/include/asm/ioctl.h /usr/include/asm-x86_64/ioctl.h \ @@ -112,8 +110,6 @@ nodewatcher.o nodewatcher.o: nodewatcher.c ../../../include/config.h \ /usr/include/bits/sys_errlist.h: -/usr/include/bits/stdio.h: - /usr/include/stdlib.h: /usr/include/sys/types.h: @@ -216,10 +212,6 @@ nodewatcher.o nodewatcher.o: nodewatcher.c ../../../include/config.h \ /usr/include/string.h: -/usr/include/bits/string.h: - -/usr/include/bits/string2.h: - /usr/include/netdb.h: /usr/include/rpc/netdb.h: @@ -354,8 +346,6 @@ nodewatcher.o nodewatcher.o: nodewatcher.c ../../../include/config.h \ /usr/include/bits/mathcalls.h: -/usr/include/bits/mathinline.h: - /usr/include/regex.h: /usr/include/arpa/inet.h: diff --git a/src/zabbix_server/nodewatcher/nodesender.c b/src/zabbix_server/nodewatcher/nodesender.c index a01eef64..10ef78ef 100644 --- a/src/zabbix_server/nodewatcher/nodesender.c +++ b/src/zabbix_server/nodewatcher/nodesender.c @@ -214,7 +214,7 @@ static int send_to_node(int dest_nodeid, int nodeid, char *xml) * Comments: * * * ******************************************************************************/ -static int send_config_data(int nodeid, int dest_nodeid, int maxlogid, int node_type) +static int send_config_data(int nodeid, int dest_nodeid, zbx_uint64_t maxlogid, int node_type) { DB_RESULT result; DB_RESULT result2; @@ -237,11 +237,11 @@ static int send_config_data(int nodeid, int dest_nodeid, int maxlogid, int node_ /* Begin work */ if(node_type == ZBX_NODE_MASTER) { - result=DBselect("select tablename,recordid,operation from node_configlog where nodeid=%d and sync_master=0 and conflogid<=%d order by tablename,operation", nodeid, maxlogid); + result=DBselect("select tablename,recordid,operation from node_configlog where nodeid=" ZBX_FS_UI64 " and sync_master=0 and conflogid<=" ZBX_FS_UI64 " order by tablename,operation", nodeid, maxlogid); } else { - result=DBselect("select tablename,recordid,operation from node_configlog where nodeid=%d and sync_slave=0 and conflogid<=%d order by tablename,operation", nodeid, maxlogid); + result=DBselect("select tablename,recordid,operation from node_configlog where nodeid=" ZBX_FS_UI64 " and sync_slave=0 and conflogid<=" ZBX_FS_UI64 " order by tablename,operation", nodeid, maxlogid); } // snprintf(tmp,sizeof(tmp),"<Data type='config'>\n<Node id='%d'>\n</Node>\n<Version>1.4</Version>\n<Records>\n", nodeid); @@ -334,11 +334,11 @@ static int send_config_data(int nodeid, int dest_nodeid, int maxlogid, int node_ { if(node_type == ZBX_NODE_MASTER) { - DBexecute("update node_configlog set sync_master=1 where nodeid=%d and sync_master=0 and conflogid<=%d", nodeid, maxlogid); + DBexecute("update node_configlog set sync_master=1 where nodeid=%d and sync_master=0 and conflogid<=" ZBX_FS_UI64, nodeid, maxlogid); } else { - DBexecute("update node_configlog set sync_slave=1 where nodeid=%d and sync_slave=0 and conflogid<=%d", nodeid, maxlogid); + DBexecute("update node_configlog set sync_slave=1 where nodeid=%d and sync_slave=0 and conflogid<=" ZBX_FS_UI64, nodeid, maxlogid); } } @@ -453,12 +453,12 @@ static int send_to_master_and_slave(int nodeid) DB_ROW row; int master_nodeid, slave_nodeid; int master_result, slave_result; - int maxlogid; + zbx_uint64_t maxlogid; // zabbix_log( LOG_LEVEL_WARNING, "In send_to_master_and_slave(local:%d,node:%d)",local_nodeid, nodeid); /* Begin work */ - result = DBselect("select min(conflogid),max(conflogid) from node_configlog where nodeid=%d", nodeid); + result = DBselect("select max(conflogid) from node_configlog where nodeid=%d", nodeid); row = DBfetch(result); @@ -468,16 +468,7 @@ static int send_to_master_and_slave(int nodeid) DBfree_result(result); return SUCCEED; } - if(atoi(row[1])-atoi(row[0])>200) - { -// Limit number of config changes to send in one go -// maxlogid = atoi(row[0])+200; - maxlogid = atoi(row[1]); - } - else - { - maxlogid = atoi(row[1]); - } + sscanf(row[0], ZBX_FS_UI64, &maxlogid); DBfree_result(result); @@ -503,7 +494,7 @@ static int send_to_master_and_slave(int nodeid) { if((master_result == SUCCEED) && (slave_result == SUCCEED)) { - DBexecute("delete from node_configlog where nodeid=%d and sync_slave=1 and sync_master=1 and conflogid<=%d", nodeid, maxlogid); + DBexecute("delete from node_configlog where nodeid=%d and sync_slave=1 and sync_master=1 and conflogid<=" ZBX_FS_UI64, nodeid, maxlogid); // zabbix_log(LOG_LEVEL_WARNING,"delete from node_configlog where nodeid=%d and sync_slave=1 and sync_master=1 and conflogid<=%d", nodeid, maxlogid); } } @@ -512,7 +503,7 @@ static int send_to_master_and_slave(int nodeid) { if(master_result == SUCCEED) { - DBexecute("delete from node_configlog where nodeid=%d and sync_master=1 and conflogid<=%d", nodeid, maxlogid); + DBexecute("delete from node_configlog where nodeid=%d and sync_master=1 and conflogid<=" ZBX_FS_UI64, nodeid, maxlogid); // zabbix_log(LOG_LEVEL_WARNING,"delete from node_configlog where nodeid=%d and sync_master=1 and conflogid<=%d", nodeid, maxlogid); } } @@ -521,7 +512,7 @@ static int send_to_master_and_slave(int nodeid) { if(slave_result == SUCCEED) { - DBexecute("delete from node_configlog where nodeid=%d and sync_slave=1 and conflogid<=%d", nodeid, maxlogid); + DBexecute("delete from node_configlog where nodeid=%d and sync_slave=1 and conflogid<=" ZBX_FS_UI64, nodeid, maxlogid); // zabbix_log(LOG_LEVEL_WARNING,"delete from node_configlog where nodeid=%d and sync_slave=1 and conflogid<=%d", nodeid, maxlogid); } } diff --git a/src/zabbix_server/nodewatcher/nodewatcher.c b/src/zabbix_server/nodewatcher/nodewatcher.c index 3ec605eb..66a147de 100644 --- a/src/zabbix_server/nodewatcher/nodewatcher.c +++ b/src/zabbix_server/nodewatcher/nodewatcher.c @@ -82,6 +82,9 @@ static int calculate_checksums() DB_RESULT result2; DB_ROW row; DB_ROW row2; + int nodeid; + + int now; // zabbix_log( LOG_LEVEL_WARNING, "In calculate_checksums"); DBexecute("delete from node_cksum where cksumtype=%d", NODE_CKSUM_TYPE_NEW); @@ -92,6 +95,9 @@ static int calculate_checksums() result =DBselect(sql); while((row=DBfetch(result))) { + now = time(NULL); + nodeid = atoi(row[0]); + zbx_snprintf(sql,sizeof(sql),"select 'table ','field ',itemid, '012345678901234' from items where 1=0\n"); for(i=0;tables[i].table!=0;i++) @@ -119,22 +125,31 @@ static int calculate_checksums() if(fields[0]!=0) fields[strlen(fields)-1] = 0; // select table,recid,md5(fields) from table union all ... - zbx_snprintf(tmp,sizeof(tmp),"union all select '%s','%s',%s,md5(concat(%s)) from %s where mod(%s,100)=%s\n", - tables[i].table, tables[i].recid, tables[i].recid, fields, tables[i].table, tables[i].recid, row[0]); + zbx_snprintf(tmp,sizeof(tmp),"union all select '%s','%s',%s,md5(concat(%s)) from %s where %s>=" ZBX_FS_UI64 " and %s<=" ZBX_FS_UI64 "\n", + tables[i].table, tables[i].recid, tables[i].recid, fields, tables[i].table, + tables[i].recid, (zbx_uint64_t)100000000000000*(zbx_uint64_t)nodeid, + tables[i].recid, (zbx_uint64_t)100000000000000*(zbx_uint64_t)nodeid+99999999999999); +// zabbix_log( LOG_LEVEL_WARNING, "TMP [%s]", tmp); strncat(sql,tmp,sizeof(sql)); } // zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql); result2 =DBselect(sql); + + zabbix_log( LOG_LEVEL_WARNING, "Selected records in %d seconds", time(NULL)-now); + now = time(NULL); + i=0; while((row2=DBfetch(result2))) { // zabbix_log( LOG_LEVEL_WARNING, "Cksum [%s]", row2[3]); DBexecute("insert into node_cksum (cksumid,nodeid,tablename,fieldname,recordid,cksumtype,cksum)"\ - "values (" ZBX_FS_UI64 ",%s,'%s','%s',%s,%d,'%s')", + "values (" ZBX_FS_UI64 ",%d,'%s','%s',%s,%d,'%s')", DBget_nextid("node_cksum","cksumid"), - row[0],row2[0],row2[1],row2[2],NODE_CKSUM_TYPE_NEW,row2[3]); + nodeid,row2[0],row2[1],row2[2],NODE_CKSUM_TYPE_NEW,row2[3]); + i++; } DBfree_result(result2); + zabbix_log( LOG_LEVEL_WARNING, "Added %d records in %d seconds", i, time(NULL)-now); } DBfree_result(result); @@ -264,6 +279,7 @@ int main_nodewatcher_loop() { zbx_setproctitle("connecting to the database"); +// zabbix_log( LOG_LEVEL_WARNING, "Starting sync with nodes"); DBconnect(); calculate_checksums(); diff --git a/src/zabbix_server/trapper/nodesync.c b/src/zabbix_server/trapper/nodesync.c index 8462701a..a85d1eef 100644 --- a/src/zabbix_server/trapper/nodesync.c +++ b/src/zabbix_server/trapper/nodesync.c @@ -89,7 +89,7 @@ static int process_record(int nodeid, char *record) { char tablename[MAX_STRING_LEN]; char fieldname[MAX_STRING_LEN]; - int recid; + zbx_uint64_t recid; int op; int valuetype; char value[MAX_STRING_LEN]; @@ -108,7 +108,7 @@ static int process_record(int nodeid, char *record) get_field(record,tablename,0); get_field(record,tmp,1); - recid=atoi(tmp); + sscanf(tmp,ZBX_FS_UI64,&recid); get_field(record,tmp,2); op=atoi(tmp); @@ -128,7 +128,7 @@ static int process_record(int nodeid, char *record) } if(op==NODE_CONFIGLOG_OP_DELETE) { - zbx_snprintf(tmp,sizeof(tmp),"delete from %s where %s=%d and nodeid=%d", tablename, key, recid, nodeid); + zbx_snprintf(tmp,sizeof(tmp),"delete from %s where %s=" ZBX_FS_UI64 " and nodeid=%d", tablename, key, recid, nodeid); zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql); return SUCCEED; } @@ -193,15 +193,15 @@ static int process_record(int nodeid, char *record) { // zbx_snprintf(tmp,sizeof(tmp),"%s='%s',", fieldname, value); // strncat(fields,tmp,sizeof(fields)); - zbx_snprintf(sql,sizeof(sql),"update %s set %s where %s=%d", tablename, fields_update, key, recid); + zbx_snprintf(sql,sizeof(sql),"update %s set %s where %s=" ZBX_FS_UI64, tablename, fields_update, key, recid); } else if(op==NODE_CONFIGLOG_OP_ADD) { - result = DBselect("select 0 from %s where %s=%d", tablename, key, recid); + result = DBselect("select 0 from %s where %s=" ZBX_FS_UI64, tablename, key, recid); row = DBfetch(result); if(row) { - zbx_snprintf(sql,sizeof(sql),"update %s set %s where %s=%d", tablename, fields_update, key, recid); + zbx_snprintf(sql,sizeof(sql),"update %s set %s where %s=" ZBX_FS_UI64, tablename, fields_update, key, recid); } else { |