diff options
author | alex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-09-24 15:36:35 +0000 |
---|---|---|
committer | alex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-09-24 15:36:35 +0000 |
commit | abafe94bd653f8510dba94760607869ff31b248d (patch) | |
tree | c90de20cdc2ffd1be5c327fdce3ef873a6897d2e | |
parent | 027a8968f5e0af59673aaa1e72f09c018fd123bb (diff) | |
download | zabbix-abafe94bd653f8510dba94760607869ff31b248d.tar.gz zabbix-abafe94bd653f8510dba94760607869ff31b248d.tar.xz zabbix-abafe94bd653f8510dba94760607869ff31b248d.zip |
Added basic support of distributed history (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@3322 97f52cf1-0a1b-0410-bd0e-c28be96e8082
30 files changed, 902 insertions, 298 deletions
diff --git a/create/data/data.sql b/create/data/data.sql index 205636d5..50a7e1ef 100644 --- a/create/data/data.sql +++ b/create/data/data.sql @@ -60,8 +60,8 @@ INSERT INTO rights VALUES (3,2,'Default permission','R',0); -- Dumping data for table `hosts` -- -INSERT INTO hosts VALUES (10001,'Unix_t',0,'',10000,3,0,'',0,0,0); ---INSERT INTO hosts VALUES (10001,'Unix_t',1,'127.0.0.1',10050,0,0,'',0,0,0); +--INSERT INTO hosts VALUES (10001,'Unix_t',0,'',10000,3,0,'',0,0,0); +INSERT INTO hosts VALUES (10001,'Unix_t',1,'127.0.0.1',10050,0,0,'',0,0,0); INSERT INTO hosts VALUES (10002,'Windows_t',0,'',10000,3,0,'',0,0,0); INSERT INTO hosts VALUES (10004,'Standalone_t',0,'',10000,3,0,'',0,0,0); INSERT INTO hosts VALUES (10003,'MySQL_t',0,'',10000,3,0,'',0,0,0); diff --git a/create/data/nodes.sql b/create/data/nodes.sql index 4d35fa71..8d48980b 100644 --- a/create/data/nodes.sql +++ b/create/data/nodes.sql @@ -1,68 +1,70 @@ connect node7; delete from nodes; -insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 1, 5); -insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 0, 5); -insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 0, 4); -insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0, 0); -insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 0, 4); -insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 0, 3); -insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 0, 3); +insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 0, 1, 5); +insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 0, 0, 5); +insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 0, 0, 4); +insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0, 0, 0); +insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 0, 0, 4); +insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 0, 0, 3); +insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 0, 0, 3); insert into events values (700000000000001, 700000000000003, 123456789, 0, 0); insert into events values (700000000000002, 700000000000012, 123456789, 0, 0); insert into events values (700000000000003, 700000000000023, 123456789, 0, 0); insert into events values (700000000000004, 700000000000045, 123456789, 0, 0); connect node6; delete from nodes; -insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 0, 5); -insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 1, 5); -insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 0, 4); -insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0, 0); -insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 0, 4); -insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 0, 3); -insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 0, 3); +insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 0, 0, 5); +insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 0, 1, 5); +insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 0, 0, 4); +insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0, 0, 0); +insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 0, 0, 4); +insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 0, 0, 3); +insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 0, 0, 3); +insert into events values (600000000000001, 600000000000103, 123456789, 1, 0); connect node5; delete from nodes; -insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 0, 5); -insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 0, 5); -insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 1, 4); -insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0, 0); -insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 0, 4); -insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 0, 3); -insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 0, 3); +insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 0, 0, 5); +insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 0, 0, 5); +insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 0, 1, 4); +insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0, 0, 0); +insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 0, 0, 4); +insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 0, 0, 3); +insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 0, 0, 3); +insert into events values (500000000000001, 500000000000122, 123456789, 1, 0); connect node4; delete from nodes; -insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 0, 5); -insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 0, 5); -insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 0, 4); -insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 1, 0); -insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 0, 4); -insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 0, 3); -insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 0, 3); +insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 0, 0, 5); +insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 0, 0, 5); +insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 0, 0, 4); +insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0, 1, 0); +insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 0, 0, 4); +insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 0, 0, 3); +insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 0, 0, 3); connect node3; delete from nodes; -insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 0, 5); -insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 0, 5); -insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 0, 4); -insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0, 0); -insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 1, 4); -insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 0, 3); -insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 0, 3); +insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 0, 0, 5); +insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 0, 0, 5); +insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 0, 0, 4); +insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0, 0, 0); +insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 0, 1, 4); +insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 0, 0, 3); +insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 0, 0, 3); connect node2; delete from nodes; -insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 0, 5); -insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 0, 5); -insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 0, 4); -insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0, 0); -insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 0, 4); -insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 1, 3); -insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 0, 3); +insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 0, 0, 5); +insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 0, 0, 5); +insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 0, 0, 4); +insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0, 0, 0); +insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 0, 0, 4); +insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 0, 1, 3); +insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 0, 0, 3); connect node1; delete from nodes; -insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 0, 5); -insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 0, 5); -insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 0, 4); -insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0, 0); -insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 0, 4); -insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 0, 3); -insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 1, 3); +insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 0, 0, 5); +insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 0, 0, 5); +insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 0, 0, 4); +insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0, 0, 0); +insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 0, 0, 4); +insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 0, 0, 3); +insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 0, 1, 3); insert into events values (100000000000001, 100000000000002, 123456789, 0, 0); diff --git a/create/schema/mysql.fmt b/create/schema/mysql.fmt index ffb29893..17114b2e 100644 --- a/create/schema/mysql.fmt +++ b/create/schema/mysql.fmt @@ -1,5 +1,6 @@ {bigint}=>bigint unsigned {integer}=>integer +{serial}=>serial {double}=>double {varchar}=>varchar {char}=>char diff --git a/create/schema/schema.sql b/create/schema/schema.sql index aeb68070..650cfa37 100644 --- a/create/schema/schema.sql +++ b/create/schema/schema.sql @@ -30,6 +30,7 @@ CREATE TABLE nodes ( slave_history {integer} DEFAULT '0' NOT NULL, slave_trends {integer} DEFAULT '0' NOT NULL, event_lastid {bigint} DEFAULT '0' NOT NULL, + history_lastid {bigint} DEFAULT '0' NOT NULL, nodetype {integer} DEFAULT '0' NOT NULL, masterid {bigint} DEFAULT '0' NOT NULL, PRIMARY KEY (nodeid) @@ -282,6 +283,17 @@ CREATE TABLE history ( CREATE INDEX history_1 ON history (itemid, clock); +CREATE TABLE history_sync ( + id {serial}, + nodeid {integer} DEFAULT '0' NOT NULL, + itemid {bigint} DEFAULT '0' NOT NULL, + clock {integer} DEFAULT '0' NOT NULL, + value {double}(16,4) DEFAULT '0.0000' NOT NULL, + PRIMARY KEY (id) +) {create_table_opt}; + +CREATE INDEX history_sync_1 ON history_sync (nodeid, id); + CREATE TABLE history_uint ( itemid {bigint} DEFAULT '0' NOT NULL, clock {integer} DEFAULT '0' NOT NULL, @@ -350,7 +362,7 @@ CREATE TABLE items ( lastlogsize {integer} DEFAULT '0' NOT NULL, logtimefmt {varchar}(64) DEFAULT '' NOT NULL, templateid {integer} DEFAULT '0' NOT NULL, - valuemapid {integer} DEFAULT '0' NOT NULL, + valuemapid {bigint} DEFAULT '0' NOT NULL, delay_flex {varchar}(255) DEFAULT '' NOT NULL, PRIMARY KEY (itemid) diff --git a/include/common.h b/include/common.h index daa3412a..d0413664 100644 --- a/include/common.h +++ b/include/common.h @@ -435,9 +435,12 @@ char *zbx_regexp_match(const char *string, const char *pattern, int *len); /* Misc functions */ int cmp_double(double a,double b); +int zbx_get_field(char *line, char *result, int num, char delim); void zbx_on_exit(); +int get_nodeid_by_id(zbx_uint64_t id); + int SYSTEM_LOCALTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result); int MAIN_ZABBIX_ENTRY(void); diff --git a/include/db.h b/include/db.h index bbb89ee4..a0e7a99e 100644 --- a/include/db.h +++ b/include/db.h @@ -239,7 +239,7 @@ DB_ITEM char *eventlog_source; char *logtimefmt; - int valuemapid; + zbx_uint64_t valuemapid; char *delay_flex; }; @@ -359,16 +359,16 @@ int DBinsert_id(int exec_result, const char *table, const char *field); int DBis_null(char *field); int DBget_function_result(double *result,char *functionid); -void DBupdate_host_availability(int hostid,int available,int clock,char *error); -int DBupdate_item_status_to_notsupported(int itemid, char *error); +void DBupdate_host_availability(zbx_uint64_t hostid,int available,int clock,char *error); +int DBupdate_item_status_to_notsupported(zbx_uint64_t itemid, char *error); int DBadd_trend(int itemid, double value, int clock); -int DBadd_history(int itemid, double value, int clock); -int DBadd_history_log(int itemid, char *value, int clock, int timestamp, char *source, int severity); -int DBadd_history_str(int itemid, char *value, int clock); -int DBadd_history_text(int itemid, char *value, int clock); -int DBadd_history_uint(int itemid, zbx_uint64_t value, int clock); -int DBadd_service_alarm(int serviceid,int status,int clock); -int DBadd_alert(int actionid, int triggerid, int userid, int mediatypeid, char *sendto, char *subject, char *message, int maxrepeats, int repeatdelay); +int DBadd_history(zbx_uint64_t itemid, double value, int clock); +int DBadd_history_log(zbx_uint64_t itemid, char *value, int clock, int timestamp, char *source, int severity); +int DBadd_history_str(zbx_uint64_t itemid, char *value, int clock); +int DBadd_history_text(zbx_uint64_t itemid, char *value, int clock); +int DBadd_history_uint(zbx_uint64_t itemid, zbx_uint64_t value, int clock); +int DBadd_service_alarm(zbx_uint64_t serviceid,int status,int clock); +int DBadd_alert(zbx_uint64_t actionid, zbx_uint64_t triggerid, zbx_uint64_t userid, zbx_uint64_t mediatypeid, char *sendto, char *subject, char *message, int maxrepeats, int repeatdelay); void DBupdate_triggers_status_after_restart(void); int DBget_prev_trigger_value(int triggerid); /*int DBupdate_trigger_value(int triggerid,int value,int clock);*/ @@ -402,8 +402,8 @@ int DBadd_action_to_linked_hosts(int actionid,int hostid); int DBget_trigger_by_triggerid(int triggerid,DB_TRIGGER *trigger); int DBadd_trigger_to_linked_hosts(int triggerid,int hostid); -void DBdelete_triggers_by_itemid(int itemid); -void DBdelete_sysmaps_hosts_by_hostid(int hostid); +void DBdelete_triggers_by_itemid(zbx_uint64_t itemid); +void DBdelete_sysmaps_hosts_by_hostid(zbx_uint64_t hostid); int DBadd_graph(char *name, int width, int height, int yaxistype, double yaxismin, double yaxismax); int DBget_graph_item_by_gitemid(int gitemid, DB_GRAPH_ITEM *graph_item); diff --git a/src/libs/zbxcommon/misc.c b/src/libs/zbxcommon/misc.c index 9fcdfbcf..a4aaaf9d 100644 --- a/src/libs/zbxcommon/misc.c +++ b/src/libs/zbxcommon/misc.c @@ -22,6 +22,27 @@ /****************************************************************************** * * + * Function: get_nodeid_by_id * + * * + * Purpose: Get Node ID by resource ID * + * * + * Parameters: * + * * + * Return value: Node ID * + * * + * Author: Alexei Vladishev * + * * + * Comments: * + * * + ******************************************************************************/ +int get_nodeid_by_id(zbx_uint64_t id) +{ + return (int)(id/100000000000000)%1000; + +} + +/****************************************************************************** + * * * Function: zbx_time * * * * Purpose: Gets the current time. * @@ -134,7 +155,7 @@ int calculate_item_nextcheck(int itemid, int delay, char *delay_flex, time_t now zabbix_log( LOG_LEVEL_DEBUG, "In calculate_item_nextcheck [%d, %d, %s, %d]",itemid,delay,delay_flex,now); - if(delay_flex) + if(delay_flex && *delay_flex) { do { diff --git a/src/libs/zbxcommon/str.c b/src/libs/zbxcommon/str.c index c2b3fd7b..c95efa45 100644 --- a/src/libs/zbxcommon/str.c +++ b/src/libs/zbxcommon/str.c @@ -497,3 +497,45 @@ void lrtrim_spaces(char *c) ltrim_spaces(c); rtrim_spaces(c); } + + +/****************************************************************************** + * * + * Function: zbx_get_field * + * * + * Purpose: return Nth field of characted separated string * + * * + * Parameters: c - string to trim spaces * + * * + * Return value: string without left and right spaces * + * * + * Author: Alexei Vladishev * + * * + * Comments: * + * * + ******************************************************************************/ +int zbx_get_field(char *line, char *result, int num, char separator) +{ + int delim=0; + int ptr=0; + int i; + + int ret = FAIL; + + for(i=0;line[i]!=0;i++) + { + if(line[i]==separator) + { + delim++; + continue; + } + if(delim==num) + { + result[ptr++]=line[i]; + result[ptr]=0; + ret = SUCCEED; + } + } + return ret; +} + diff --git a/src/libs/zbxdbhigh/db.c b/src/libs/zbxdbhigh/db.c index 72ab2a89..c4dda150 100644 --- a/src/libs/zbxdbhigh/db.c +++ b/src/libs/zbxdbhigh/db.c @@ -48,6 +48,7 @@ extern void apply_actions(DB_TRIGGER *trigger,int trigger_value); extern void update_services(int triggerid, int status); extern int CONFIG_NODEID; +extern int CONFIG_MASTER_NODEID; void DBclose(void) { @@ -88,6 +89,11 @@ void DBconnect(void) exit(FAIL); } } + if(mysql_autocommit(&mysql, 1) != 0) + { + zabbix_log(LOG_LEVEL_ERR, "Failed to set autocommit to 1: Error: %s",mysql_error(&mysql)); + exit(FAIL); + } #endif #ifdef HAVE_PGSQL /* conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName); */ @@ -698,7 +704,7 @@ int DBget_function_result(double *result,char *functionid) * Comments: Rewrite required to simplify logic ? * * * ******************************************************************************/ -static void get_latest_event_status(int triggerid, int *prev_status, int *latest_status) +static void get_latest_event_status(zbx_uint64_t triggerid, int *prev_status, int *latest_status) { char sql[MAX_STRING_LEN]; DB_RESULT result; @@ -706,8 +712,8 @@ static void get_latest_event_status(int triggerid, int *prev_status, int *latest zabbix_log(LOG_LEVEL_DEBUG,"In latest_event()"); - 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); + zbx_snprintf(sql,sizeof(sql),"select value from events where triggerid=" ZBX_FS_UI64 " order by clock desc",triggerid); + zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]", sql); result = DBselectN(sql,2); row = DBfetch(result); @@ -821,7 +827,7 @@ static int latest_event(int triggerid, int status) /* SUCCEED if latest service alarm has this status */ /* Rewrite required to simplify logic ?*/ -int latest_service_alarm(int serviceid, int status) +int latest_service_alarm(zbx_uint64_t serviceid, int status) { int clock; DB_RESULT result; @@ -831,7 +837,7 @@ int latest_service_alarm(int serviceid, int status) zabbix_log(LOG_LEVEL_DEBUG,"In latest_service_alarm()"); - result = DBselect("select max(clock) from service_alarms where serviceid=%d",serviceid); + result = DBselect("select max(clock) from service_alarms where serviceid=" ZBX_FS_UI64,serviceid); row = DBfetch(result); if(!row || DBis_null(row[0])==SUCCEED) @@ -844,7 +850,7 @@ int latest_service_alarm(int serviceid, int status) clock=atoi(row[0]); DBfree_result(result); - result = DBselect("select value from service_alarms where serviceid=%d and clock=%d",serviceid,clock); + result = DBselect("select value from service_alarms where serviceid=" ZBX_FS_UI64 " and clock=%d",serviceid,clock); row = DBfetch(result); if(row && DBis_null(row[0]) != SUCCEED) { @@ -890,7 +896,7 @@ int add_event(int triggerid,int status,int clock,int *eventid) } */ -int DBadd_service_alarm(int serviceid,int status,int clock) +int DBadd_service_alarm(zbx_uint64_t serviceid,int status,int clock) { zabbix_log(LOG_LEVEL_DEBUG,"In add_service_alarm()"); @@ -899,7 +905,7 @@ int DBadd_service_alarm(int serviceid,int status,int clock) return SUCCEED; } - DBexecute("insert into service_alarms(serviceid,clock,value) values(%d,%d,%d)", serviceid, clock, status); + DBexecute("insert into service_alarms(serviceid,clock,value) values(" ZBX_FS_UI64 ",%d,%d)", serviceid, clock, status); zabbix_log(LOG_LEVEL_DEBUG,"End of add_service_alarm()"); @@ -915,11 +921,11 @@ int DBupdate_trigger_value(DB_TRIGGER *trigger, int new_value, int now, char *re if(reason==NULL) { - zabbix_log(LOG_LEVEL_DEBUG,"In update_trigger_value[%d,%d,%d]", trigger->triggerid, new_value, now); + zabbix_log(LOG_LEVEL_DEBUG,"In update_trigger_value[" ZBX_FS_UI64 ",%d,%d]", trigger->triggerid, new_value, now); } else { - zabbix_log(LOG_LEVEL_DEBUG,"In update_trigger_value[%d,%d,%d,%s]", trigger->triggerid, new_value, now, reason); + zabbix_log(LOG_LEVEL_DEBUG,"In update_trigger_value[" ZBX_FS_UI64 ",%d,%d,%s]", trigger->triggerid, new_value, now, reason); } /* New trigger value differs from current one */ @@ -932,11 +938,11 @@ int DBupdate_trigger_value(DB_TRIGGER *trigger, int new_value, int now, char *re { if(reason==NULL) { - DBexecute("update triggers set value=%d,lastchange=%d,error='' where triggerid=%d",new_value,now,trigger->triggerid); + DBexecute("update triggers set value=%d,lastchange=%d,error='' where triggerid=" ZBX_FS_UI64,new_value,now,trigger->triggerid); } else { - DBexecute("update triggers set value=%d,lastchange=%d,error='%s' where triggerid=%d",new_value,now,reason, trigger->triggerid); + DBexecute("update triggers set value=%d,lastchange=%d,error='%s' where triggerid=" ZBX_FS_UI64,new_value,now,reason, trigger->triggerid); } if( ((trigger->value == TRIGGER_VALUE_TRUE) && (new_value == TRIGGER_VALUE_FALSE)) || ((trigger->value == TRIGGER_VALUE_FALSE) && (new_value == TRIGGER_VALUE_TRUE)) || @@ -974,14 +980,14 @@ int DBupdate_trigger_value(DB_TRIGGER *trigger, int new_value, int now, char *re } else { - zabbix_log(LOG_LEVEL_DEBUG,"Alarm not added for triggerid [%d]", trigger->triggerid); + zabbix_log(LOG_LEVEL_DEBUG,"Alarm not added for triggerid [" ZBX_FS_UI64 "]", trigger->triggerid); ret = FAIL; } } return ret; } -void update_triggers_status_to_unknown(int hostid,int clock,char *reason) +void update_triggers_status_to_unknown(zbx_uint64_t hostid,int clock,char *reason) { DB_RESULT result; DB_ROW row; @@ -990,11 +996,12 @@ void update_triggers_status_to_unknown(int hostid,int clock,char *reason) zabbix_log(LOG_LEVEL_DEBUG,"In update_triggers_status_to_unknown()"); /* zbx_snprintf(sql,sizeof(sql),"select distinct t.triggerid from hosts h,items i,triggers t,functions f where f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and h.hostid=%d and i.key_<>'%s'",hostid,SERVER_STATUS_KEY);*/ - result = DBselect("select distinct t.triggerid,t.value,t.comments from hosts h,items i,triggers t,functions f where f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and h.hostid=%d and i.key_ not in ('%s','%s','%s')",hostid,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY); + result = DBselect("select distinct t.triggerid,t.value,t.comments from hosts h,items i,triggers t,functions f where f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and h.hostid=" ZBX_FS_UI64 " and i.key_ not in ('%s','%s','%s')",hostid,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY); while((row=DBfetch(result))) { - trigger.triggerid=atoi(row[0]); + ZBX_STR2UINT64(trigger.triggerid,row[0]); +/* trigger.triggerid=atoi(row[0]);*/ trigger.value=atoi(row[1]); strscpy(trigger.comments, row[2]); DBupdate_trigger_value(&trigger,TRIGGER_VALUE_UNKNOWN,clock,reason); @@ -1006,99 +1013,120 @@ void update_triggers_status_to_unknown(int hostid,int clock,char *reason) return; } -void DBdelete_service(int serviceid) +void DBdelete_service(zbx_uint64_t serviceid) { - DBexecute("delete from services_links where servicedownid=%d or serviceupid=%d", serviceid, serviceid); - DBexecute("delete from services where serviceid=%d", serviceid); + DBexecute("delete from services_links where servicedownid=" ZBX_FS_UI64 " or serviceupid=" ZBX_FS_UI64, + serviceid, serviceid); + DBexecute("delete from services where serviceid=" ZBX_FS_UI64, + serviceid); } -void DBdelete_services_by_triggerid(int triggerid) +void DBdelete_services_by_triggerid(zbx_uint64_t triggerid) { - int serviceid; + zbx_uint64_t serviceid; DB_RESULT result; DB_ROW row; - zabbix_log(LOG_LEVEL_DEBUG,"In DBdelete_services_by_triggerid(%d)", triggerid); - result = DBselect("select serviceid from services where triggerid=%d", triggerid); + zabbix_log(LOG_LEVEL_DEBUG,"In DBdelete_services_by_triggerid(" ZBX_FS_UI64 ")", triggerid); + result = DBselect("select serviceid from services where triggerid=" ZBX_FS_UI64, triggerid); while((row=DBfetch(result))) { - serviceid=atoi(row[0]); +/* serviceid=atoi(row[0]);*/ + ZBX_STR2UINT64(serviceid, row[0]); DBdelete_service(serviceid); } DBfree_result(result); - zabbix_log(LOG_LEVEL_DEBUG,"End of DBdelete_services_by_triggerid(%d)", triggerid); + zabbix_log(LOG_LEVEL_DEBUG,"End of DBdelete_services_by_triggerid(" ZBX_FS_UI64 ")", triggerid); } -void DBdelete_trigger(int triggerid) +void DBdelete_trigger(zbx_uint64_t 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 events where triggerid=%d", triggerid); + DBexecute("delete from trigger_depends where triggerid_down=" ZBX_FS_UI64 " or triggerid_up=" ZBX_FS_UI64, + triggerid, triggerid); + DBexecute("delete from functions where triggerid=" ZBX_FS_UI64, + triggerid); + DBexecute("delete from events where triggerid=" ZBX_FS_UI64, + triggerid); /* zbx_snprintf(sql,sizeof(sql),"delete from actions where triggerid=%d and scope=%d", triggerid, ACTION_SCOPE_TRIGGER); DBexecute(sql);*/ DBdelete_services_by_triggerid(triggerid); - DBexecute("update sysmaps_links set triggerid=NULL where triggerid=%d", triggerid); - DBexecute("delete from triggers where triggerid=%d", triggerid); + DBexecute("update sysmaps_links set triggerid=NULL where triggerid=" ZBX_FS_UI64, + triggerid); + DBexecute("delete from triggers where triggerid=" ZBX_FS_UI64, + triggerid); } -void DBdelete_triggers_by_itemid(int itemid) +void DBdelete_triggers_by_itemid(zbx_uint64_t itemid) { - int triggerid; + zbx_uint64_t triggerid; DB_RESULT result; DB_ROW row; - zabbix_log(LOG_LEVEL_DEBUG,"In DBdelete_triggers_by_itemid(%d)", itemid); - result = DBselect("select triggerid from functions where itemid=%d", itemid); + zabbix_log(LOG_LEVEL_DEBUG,"In DBdelete_triggers_by_itemid(" ZBX_FS_UI64 ")", + itemid); + result = DBselect("select triggerid from functions where itemid=" ZBX_FS_UI64, + itemid); while((row=DBfetch(result))) { - triggerid=atoi(row[0]); + ZBX_STR2UINT64(triggerid, row[0]); +/* triggerid=atoi(row[0]);*/ DBdelete_trigger(triggerid); } DBfree_result(result); - DBexecute("delete from functions where itemid=%d", itemid); + DBexecute("delete from functions where itemid=" ZBX_FS_UI64, + itemid); - zabbix_log(LOG_LEVEL_DEBUG,"End of DBdelete_triggers_by_itemid(%d)", itemid); + zabbix_log(LOG_LEVEL_DEBUG,"End of DBdelete_triggers_by_itemid(" ZBX_FS_UI64 ")", + itemid); } -void DBdelete_trends_by_itemid(int itemid) +void DBdelete_trends_by_itemid(zbx_uint64_t itemid) { - DBexecute("delete from trends where itemid=%d", itemid); + DBexecute("delete from trends where itemid=" ZBX_FS_UI64, + itemid); } -void DBdelete_history_by_itemid(int itemid) +void DBdelete_history_by_itemid(zbx_uint64_t itemid) { - DBexecute("delete from history where itemid=%d", itemid); - DBexecute("delete from history_str where itemid=%d", itemid); + DBexecute("delete from history where itemid=" ZBX_FS_UI64, + itemid); + DBexecute("delete from history_str where itemid=" ZBX_FS_UI64, + itemid); } -void DBdelete_sysmaps_links_by_shostid(int shostid) +void DBdelete_sysmaps_links_by_shostid(zbx_uint64_t shostid) { - DBexecute("delete from sysmaps_links where shostid1=%d or shostid2=%d", shostid, shostid); + DBexecute("delete from sysmaps_links where shostid1=" ZBX_FS_UI64 " or shostid2=" ZBX_FS_UI64, + shostid, shostid); } -void DBdelete_sysmaps_hosts_by_hostid(int hostid) +void DBdelete_sysmaps_hosts_by_hostid(zbx_uint64_t hostid) { - int shostid; + zbx_uint64_t shostid; DB_RESULT result; DB_ROW row; - zabbix_log(LOG_LEVEL_DEBUG,"In DBdelete_sysmaps_hosts(%d)", hostid); - result = DBselect("select shostid from sysmaps_elements where elementid=%d", hostid); + zabbix_log(LOG_LEVEL_DEBUG,"In DBdelete_sysmaps_hosts(" ZBX_FS_UI64 ")", + hostid); + result = DBselect("select shostid from sysmaps_elements where elementid=" ZBX_FS_UI64, + hostid); while((row=DBfetch(result))) { - shostid=atoi(row[0]); + ZBX_STR2UINT64(shostid, row[0]); +/* shostid=atoi(row[0]);*/ DBdelete_sysmaps_links_by_shostid(shostid); } DBfree_result(result); - DBexecute("delete from sysmaps_elements where elementid=%d", hostid); + DBexecute("delete from sysmaps_elements where elementid=" ZBX_FS_UI64, + hostid); } /* @@ -1136,7 +1164,8 @@ void DBupdate_triggers_status_after_restart(void) while((row=DBfetch(result))) { - trigger.triggerid=atoi(row[0]); + ZBX_STR2UINT64(trigger.triggerid,row[0]); +/* trigger.triggerid=atoi(row[0]);*/ trigger.value=atoi(row[1]); result2 = DBselect("select min(i.nextcheck+i.delay) from hosts h,items i,triggers t,functions f where f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and i.nextcheck<>0 and t.triggerid=%d and i.type<>%d",trigger.triggerid,ITEM_TYPE_TRAPPER); @@ -1160,7 +1189,7 @@ void DBupdate_triggers_status_after_restart(void) return; } -void DBupdate_host_availability(int hostid,int available,int clock, char *error) +void DBupdate_host_availability(zbx_uint64_t hostid,int available,int clock, char *error) { DB_RESULT result; DB_ROW row; @@ -1178,13 +1207,13 @@ void DBupdate_host_availability(int hostid,int available,int clock, char *error) strscpy(error_esc,""); } - result = DBselect("select available,disable_until from hosts where hostid=%d",hostid); + result = DBselect("select available,disable_until from hosts where hostid=" ZBX_FS_UI64, hostid); row=DBfetch(result); if(!row) { - zabbix_log(LOG_LEVEL_ERR, "Cannot select host with hostid [%d]",hostid); - zabbix_syslog("Cannot select host with hostid [%d]",hostid); + zabbix_log(LOG_LEVEL_ERR, "Cannot select host with hostid [" ZBX_FS_UI64 "]",hostid); + zabbix_syslog("Cannot select host with hostid [" ZBX_FS_UI64 "]",hostid); DBfree_result(result); return; } @@ -1209,7 +1238,7 @@ void DBupdate_host_availability(int hostid,int available,int clock, char *error) if(available==HOST_AVAILABLE_TRUE) { - DBexecute("update hosts set available=%d,error=' ',errors_from=0 where hostid=%d",HOST_AVAILABLE_TRUE,hostid); + DBexecute("update hosts set available=%d,error=' ',errors_from=0 where hostid=" ZBX_FS_UI64,HOST_AVAILABLE_TRUE,hostid); } else if(available==HOST_AVAILABLE_FALSE) { @@ -1222,12 +1251,15 @@ void DBupdate_host_availability(int hostid,int available,int clock, char *error) zbx_snprintf(sql,sizeof(sql),"update hosts set available=%d,disable_until=%d,error='%s' where hostid=%d",HOST_AVAILABLE_FALSE,clock+CONFIG_UNREACHABLE_DELAY,error_esc,hostid); }*/ /* '%s ' - space to make Oracle happy */ - DBexecute("update hosts set available=%d,error='%s ' where hostid=%d",HOST_AVAILABLE_FALSE,error_esc,hostid); + DBexecute("update hosts set available=%d,error='%s ' where hostid=" ZBX_FS_UI64, + HOST_AVAILABLE_FALSE,error_esc,hostid); } else { - zabbix_log( LOG_LEVEL_ERR, "Unknown host availability [%d] for hostid [%d]", available, hostid); - zabbix_syslog("Unknown host availability [%d] for hostid [%d]", available, hostid); + zabbix_log( LOG_LEVEL_ERR, "Unknown host availability [%d] for hostid [" ZBX_FS_UI64 "]", + available, hostid); + zabbix_syslog("Unknown host availability [%d] for hostid [" ZBX_FS_UI64 "]", + available, hostid); return; } @@ -1237,7 +1269,7 @@ void DBupdate_host_availability(int hostid,int available,int clock, char *error) return; } -int DBupdate_item_status_to_notsupported(int itemid, char *error) +int DBupdate_item_status_to_notsupported(zbx_uint64_t itemid, char *error) { char error_esc[MAX_STRING_LEN]; @@ -1253,7 +1285,8 @@ int DBupdate_item_status_to_notsupported(int itemid, char *error) } /* '&s ' to make Oracle happy */ - DBexecute("update items set status=%d,error='%s ' where itemid=%d",ITEM_STATUS_NOTSUPPORTED,error_esc,itemid); + DBexecute("update items set status=%d,error='%s ' where itemid=" ZBX_FS_UI64, + ITEM_STATUS_NOTSUPPORTED,error_esc,itemid); return SUCCEED; } @@ -1270,7 +1303,8 @@ int DBadd_trend(int itemid, double value, int clock) hour=clock-clock%3600; - result = DBselect("select num,value_min,value_avg,value_max from trends where itemid=%d and clock=%d", itemid, hour); + result = DBselect("select num,value_min,value_avg,value_max from trends where itemid=" ZBX_FS_UI64 " and clock=%d", + itemid, hour); row=DBfetch(result); @@ -1286,11 +1320,13 @@ int DBadd_trend(int itemid, double value, int clock) if(value>value_max) value_max=value; value_avg=(num*value_avg+value)/(num+1); num++; - DBexecute("update trends set num=%d, value_min=%f, value_avg=%f, value_max=%f where itemid=%d and clock=%d", num, value_min, value_avg, value_max, itemid, hour); + DBexecute("update trends set num=%d, value_min=%f, value_avg=%f, value_max=%f where itemid=" ZBX_FS_UI64 " and clock=%d", + num, value_min, value_avg, value_max, itemid, hour); } else { - DBexecute("insert into trends (clock,itemid,num,value_min,value_avg,value_max) values (%d,%d,%d,%f,%f,%f)", hour, itemid, 1, value, value, value); + DBexecute("insert into trends (clock,itemid,num,value_min,value_avg,value_max) values (%d," ZBX_FS_UI64 ",%d,%f,%f,%f)", + hour, itemid, 1, value, value, value); } DBfree_result(result); @@ -1298,41 +1334,50 @@ int DBadd_trend(int itemid, double value, int clock) return SUCCEED; } -int DBadd_history(int itemid, double value, int clock) +int DBadd_history(zbx_uint64_t itemid, double value, int clock) { zabbix_log(LOG_LEVEL_DEBUG,"In add_history()"); - DBexecute("insert into history (clock,itemid,value) values (%d,%d,%f)",clock,itemid,value); + DBexecute("insert into history (clock,itemid,value) values (%d," ZBX_FS_UI64 ",%f)", + clock,itemid,value); + + if(CONFIG_MASTER_NODEID>=0) + { + DBexecute("insert into history_sync (nodeid,clock,itemid,value) values (%d,%d," ZBX_FS_UI64 ",%f)", + get_nodeid_by_id(itemid),clock,itemid,value); + } DBadd_trend(itemid, value, clock); return SUCCEED; } -int DBadd_history_uint(int itemid, zbx_uint64_t value, int clock) +int DBadd_history_uint(zbx_uint64_t itemid, zbx_uint64_t value, int clock) { zabbix_log(LOG_LEVEL_DEBUG,"In add_history_uint()"); - DBexecute("insert into history_uint (clock,itemid,value) values (%d,%d," ZBX_FS_UI64 ")",clock,itemid,value); + DBexecute("insert into history_uint (clock,itemid,value) values (%d," ZBX_FS_UI64 "," ZBX_FS_UI64 ")", + clock,itemid,value); DBadd_trend(itemid, (double)value, clock); return SUCCEED; } -int DBadd_history_str(int itemid, char *value, int clock) +int DBadd_history_str(zbx_uint64_t itemid, char *value, int clock) { char value_esc[MAX_STRING_LEN]; zabbix_log(LOG_LEVEL_DEBUG,"In add_history_str()"); DBescape_string(value,value_esc,MAX_STRING_LEN); - DBexecute("insert into history_str (clock,itemid,value) values (%d,%d,'%s')",clock,itemid,value_esc); + DBexecute("insert into history_str (clock,itemid,value) values (%d," ZBX_FS_UI64 ",'%s')", + clock,itemid,value_esc); return SUCCEED; } -int DBadd_history_text(int itemid, char *value, int clock) +int DBadd_history_text(zbx_uint64_t itemid, char *value, int clock) { #ifdef HAVE_ORACLE char sql[MAX_STRING_LEN]; @@ -1366,7 +1411,8 @@ int DBadd_history_text(int itemid, char *value, int clock) } zbx_snprintf(sql, sizeof(sql), "insert into history_text (clock,itemid,value)" - " values (%d,%d, EMPTY_CLOB()) returning value into :1", clock, itemid); + " values (%d," ZBX_FS_UI64 ", EMPTY_CLOB()) returning value into :1", + clock, itemid); zabbix_log(LOG_LEVEL_DEBUG,"Query:%s", sql); @@ -1437,7 +1483,8 @@ lbl_exit: sql_max_len = value_esc_max_len+100; DBescape_string(value,value_esc,value_esc_max_len); - DBexecute("insert into history_text (clock,itemid,value) values (%d,%d,'%s')",clock,itemid,value_esc); + DBexecute("insert into history_text (clock,itemid,value) values (%d," ZBX_FS_UI64 ",'%s')", + clock,itemid,value_esc); free(value_esc); @@ -1447,7 +1494,7 @@ lbl_exit: } -int DBadd_history_log(int itemid, char *value, int clock, int timestamp,char *source, int severity) +int DBadd_history_log(zbx_uint64_t itemid, char *value, int clock, int timestamp,char *source, int severity) { char value_esc[MAX_STRING_LEN]; char source_esc[MAX_STRING_LEN]; @@ -1456,7 +1503,8 @@ int DBadd_history_log(int itemid, char *value, int clock, int timestamp,char *so DBescape_string(value,value_esc,MAX_STRING_LEN); DBescape_string(source,source_esc,MAX_STRING_LEN); - DBexecute("insert into history_log (clock,itemid,timestamp,value,source,severity) values (%d,%d,%d,'%s','%s',%d)",clock,itemid,timestamp,value_esc,source_esc,severity); + DBexecute("insert into history_log (clock,itemid,timestamp,value,source,severity) values (%d," ZBX_FS_UI64 ",%d,'%s','%s',%d)", + clock,itemid,timestamp,value_esc,source_esc,severity); return SUCCEED; } @@ -1655,7 +1703,7 @@ int DBget_queue_count(void) return res; } -int DBadd_alert(int actionid, int userid, int triggerid, int mediatypeid, char *sendto, char *subject, char *message, int maxrepeats, int repeatdelay) +int DBadd_alert(zbx_uint64_t actionid, zbx_uint64_t userid, zbx_uint64_t triggerid, zbx_uint64_t mediatypeid, char *sendto, char *subject, char *message, int maxrepeats, int repeatdelay) { int now; char sendto_esc[MAX_STRING_LEN]; @@ -1670,7 +1718,9 @@ int DBadd_alert(int actionid, int userid, int triggerid, int mediatypeid, char DBescape_string(sendto,sendto_esc,MAX_STRING_LEN); DBescape_string(subject,subject_esc,MAX_STRING_LEN); DBescape_string(message,message_esc,MAX_STRING_LEN); - DBexecute("insert into alerts (actionid,triggerid,userid,clock,mediatypeid,sendto,subject,message,status,retries,maxrepeats,delay) values (%d,%d,%d,%d,%d,'%s','%s','%s',0,0,%d,%d)",actionid,triggerid,userid,now,mediatypeid,sendto_esc,subject_esc,message_esc, maxrepeats, repeatdelay); + DBexecute("insert into alerts (actionid,triggerid,userid,clock,mediatypeid,sendto,subject,message,status,retries,maxrepeats,delay)" + " values (" ZBX_FS_UI64 "," ZBX_FS_UI64 "," ZBX_FS_UI64 ",%d," ZBX_FS_UI64 ",'%s','%s','%s',0,0,%d,%d)", + actionid,triggerid,userid,now,mediatypeid,sendto_esc,subject_esc,message_esc, maxrepeats, repeatdelay); return SUCCEED; } @@ -1842,7 +1892,8 @@ void DBget_item_from_db(DB_ITEM *item,DB_ROW row) item->status=atoi(row[31]); item->trapper_hosts=row[32]; item->logtimefmt=row[33]; - item->valuemapid=atoi(row[34]); + ZBX_STR2UINT64(item->valuemapid, row[34]); +// item->valuemapid=atoi(row[34]); item->delay_flex=row[35]; } diff --git a/src/zabbix_server/actions.c b/src/zabbix_server/actions.c index 59442498..d5fa5f38 100644 --- a/src/zabbix_server/actions.c +++ b/src/zabbix_server/actions.c @@ -68,7 +68,7 @@ * * ******************************************************************************/ //static void send_to_user_medias(DB_TRIGGER *trigger,DB_ACTION *action, int userid) -static void send_to_user_medias(DB_EVENT *event,DB_ACTION *action, int userid) +static void send_to_user_medias(DB_EVENT *event,DB_ACTION *action, zbx_uint64_t userid) { DB_MEDIA media; DB_RESULT result; @@ -78,7 +78,8 @@ static void send_to_user_medias(DB_EVENT *event,DB_ACTION *action, int userid) while((row=DBfetch(result))) { - media.mediatypeid=atoi(row[0]); + ZBX_STR2UINT64(media.mediatypeid, row[0]); +// media.mediatypeid=atoi(row[0]); media.sendto=row[1]; media.active=atoi(row[2]); media.severity=atoi(row[3]); @@ -121,8 +122,9 @@ static void send_to_user_medias(DB_EVENT *event,DB_ACTION *action, int userid) //static void send_to_user(DB_TRIGGER *trigger,DB_ACTION *action) static void send_to_user(DB_EVENT *event, DB_ACTION *action) { - DB_RESULT result; - DB_ROW row; + DB_RESULT result; + DB_ROW row; + zbx_uint64_t userid; if(action->recipient == RECIPIENT_TYPE_USER) { @@ -131,18 +133,23 @@ static void send_to_user(DB_EVENT *event, DB_ACTION *action) } else if(action->recipient == RECIPIENT_TYPE_GROUP) { - result = DBselect("select u.userid from users u, users_groups ug where ug.usrgrpid=%d and ug.userid=u.userid", action->userid); + result = DBselect("select u.userid from users u, users_groups ug where ug.usrgrpid=" ZBX_FS_UI64 " and ug.userid=u.userid", + action->userid); while((row=DBfetch(result))) { // send_to_user_medias(trigger, action, atoi(row[0])); - send_to_user_medias(event, action, atoi(row[0])); + ZBX_STR2UINT64(userid, row[0]); + send_to_user_medias(event, action, userid); +// send_to_user_medias(event, action, atoi(row[0])); } DBfree_result(result); } else { - zabbix_log( LOG_LEVEL_WARNING, "Unknown recipient type [%d] for actionid [%d]",action->recipient,action->actionid); - zabbix_syslog("Unknown recipient type [%d] for actionid [%d]",action->recipient,action->actionid); + zabbix_log( LOG_LEVEL_WARNING, "Unknown recipient type [%d] for actionid [" ZBX_FS_UI64 "]", + action->recipient,action->actionid); + zabbix_syslog("Unknown recipient type [%d] for actionid [" ZBX_FS_UI64 "]", + action->recipient,action->actionid); } } @@ -319,7 +326,8 @@ static void run_commands(DB_EVENT *event, DB_ACTION *action) assert(action); cmd_list = action->scripts; - zabbix_log( LOG_LEVEL_DEBUG, "Run remote commands START [actionid:%d]", action->actionid); + zabbix_log( LOG_LEVEL_DEBUG, "Run remote commands START [actionid:" ZBX_FS_UI64 "]", + action->actionid); while(get_next_command(&cmd_list,&alias,&is_group,&command)!=1) { if(!alias || !command) continue; @@ -348,22 +356,26 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition) { DB_RESULT result; DB_ROW row; + zbx_uint64_t groupid; + zbx_uint64_t hostid; char tmp_str[MAX_STRING_LEN]; int ret = FAIL; - zabbix_log( LOG_LEVEL_DEBUG, "In check_action_condition [actionid:%d,conditionid:%d:cond.value:%s]", condition->actionid, condition->conditionid, condition->value); + zabbix_log( LOG_LEVEL_DEBUG, "In check_action_condition [actionid:" ZBX_FS_UI64 ",conditionid:" ZBX_FS_UI64 ",cond.value:%s]", condition->actionid, condition->conditionid, condition->value); if(condition->conditiontype == CONDITION_TYPE_HOST_GROUP) { // result = DBselect("select distinct hg.groupid from hosts_groups hg,hosts h, items i, functions f, triggers t where hg.hostid=h.hostid and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid and t.triggerid=%d", trigger->triggerid); - result = DBselect("select distinct hg.groupid from hosts_groups hg,hosts h, items i, functions f, triggers t where hg.hostid=h.hostid and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid and t.triggerid=%d", event->triggerid); + result = DBselect("select distinct hg.groupid from hosts_groups hg,hosts h, items i, functions f, triggers t where hg.hostid=h.hostid and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid and t.triggerid=" ZBX_FS_UI64, + event->triggerid); while((row=DBfetch(result))) { + ZBX_STR2UINT64(groupid, row[0]); if(condition->operator == CONDITION_OPERATOR_EQUAL) { - if(atoi(condition->value) == atoi(row[0])) + if(atoi(condition->value) == groupid) { ret = SUCCEED; break; @@ -371,7 +383,7 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition) } else if(condition->operator == CONDITION_OPERATOR_NOT_EQUAL) { - if(atoi(condition->value) != atoi(row[0])) + if(atoi(condition->value) != groupid) { ret = SUCCEED; break; @@ -379,7 +391,7 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition) } else { - zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [%d]", condition->operator, condition->conditionid); + zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [" ZBX_FS_UI64 "]", condition->operator, condition->conditionid); break; } } @@ -391,9 +403,10 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition) result = DBselect("select distinct h.hostid from hosts h, items i, functions f, triggers t where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid and t.triggerid=%d", event->triggerid); while((row=DBfetch(result))) { + ZBX_STR2UINT64(hostid, row[0]); if(condition->operator == CONDITION_OPERATOR_EQUAL) { - if(atoi(condition->value) == atoi(row[0])) + if(atoi(condition->value) == hostid) { ret = SUCCEED; break; @@ -401,7 +414,7 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition) } else if(condition->operator == CONDITION_OPERATOR_NOT_EQUAL) { - if(atoi(condition->value) != atoi(row[0])) + if(atoi(condition->value) != hostid) { ret = SUCCEED; break; @@ -409,7 +422,7 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition) } else { - zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [%d]", condition->operator, condition->conditionid); + zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [" ZBX_FS_UI64 "]", condition->operator, condition->conditionid); break; } } @@ -462,7 +475,8 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition) } else { - zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [%d]", condition->operator, condition->conditionid); + zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [" ZBX_FS_UI64 "]", + condition->operator, condition->conditionid); } } else if(condition->conditiontype == CONDITION_TYPE_TRIGGER_SEVERITY) @@ -501,7 +515,8 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition) } else { - zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [%d]", condition->operator, condition->conditionid); + zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [" ZBX_FS_UI64 "]", + condition->operator, condition->conditionid); } } else if(condition->conditiontype == CONDITION_TYPE_TRIGGER_VALUE) @@ -516,7 +531,8 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition) } else { - zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [%d]", condition->operator, condition->conditionid); + zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [" ZBX_FS_UI64 "]", + condition->operator, condition->conditionid); } } else if(condition->conditiontype == CONDITION_TYPE_TIME_PERIOD) @@ -531,12 +547,14 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition) } else { - zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [%d]", condition->operator, condition->conditionid); + zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [" ZBX_FS_UI64 "]", + condition->operator, condition->conditionid); } } else { - zabbix_log( LOG_LEVEL_ERR, "Condition type [%d] is unknown for condition id [%d]", condition->conditiontype, condition->conditionid); + zabbix_log( LOG_LEVEL_ERR, "Condition type [%d] is unknown for condition id [" ZBX_FS_UI64 "]", + condition->conditiontype, condition->conditionid); } if(FAIL==ret) @@ -552,7 +570,7 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition) } //static int check_action_conditions(DB_TRIGGER *trigger,int new_trigger_value, int actionid) -static int check_action_conditions(DB_EVENT *event, int actionid) +static int check_action_conditions(DB_EVENT *event, zbx_uint64_t actionid) { DB_RESULT result; DB_ROW row; @@ -568,8 +586,10 @@ static int check_action_conditions(DB_EVENT *event, int actionid) while((row=DBfetch(result))) { - condition.conditionid=atoi(row[0]); - condition.actionid=atoi(row[1]); + ZBX_STR2UINT64(condition.conditionid, row[0]); +// condition.conditionid=atoi(row[0]); + ZBX_STR2UINT64(condition.actionid, row[1]); +// condition.actionid=atoi(row[1]); condition.conditiontype=atoi(row[2]); condition.operator=atoi(row[3]); condition.value=row[4]; @@ -648,13 +668,15 @@ void apply_actions(DB_EVENT *event) while((row=DBfetch(result))) { - action.actionid=atoi(row[0]); + ZBX_STR2UINT64(action.actionid, row[0]); +// action.actionid=atoi(row[0]); // if(check_action_conditions(trigger, trigger_value, action.actionid) == SUCCEED) if(check_action_conditions(event, action.actionid) == SUCCEED) { zabbix_log( LOG_LEVEL_DEBUG, "Conditions match our trigger. Do apply actions."); - action.userid=atoi(row[1]); + ZBX_STR2UINT64(action.userid, row[1]); +// action.userid=atoi(row[1]); strscpy(action.subject,row[2]); strscpy(action.message,row[3]); diff --git a/src/zabbix_server/evalfunc.c b/src/zabbix_server/evalfunc.c index 29b7a1d6..5996a20e 100644 --- a/src/zabbix_server/evalfunc.c +++ b/src/zabbix_server/evalfunc.c @@ -79,7 +79,8 @@ static int evaluate_LOGSOURCE(char *value, DB_ITEM *item, char *parameter) now=time(NULL); - zbx_snprintf(sql,sizeof(sql),"select source from history_log where itemid=%d order by clock desc",item->itemid); + zbx_snprintf(sql,sizeof(sql),"select source from history_log where itemid=" ZBX_FS_UI64 " order by clock desc", + item->itemid); result = DBselectN(sql,1); row = DBfetch(result); @@ -138,7 +139,8 @@ static int evaluate_LOGSEVERITY(char *value, DB_ITEM *item, char *parameter) now=time(NULL); - zbx_snprintf(sql,sizeof(sql),"select severity from history_log where itemid=%d order by clock desc",item->itemid); + zbx_snprintf(sql,sizeof(sql),"select severity from history_log where itemid=" ZBX_FS_UI64 " order by clock desc", + item->itemid); result = DBselectN(sql,1); row = DBfetch(result); @@ -197,7 +199,8 @@ static int evaluate_COUNT(char *value, DB_ITEM *item, int parameter) { strscpy(table,"history"); } - result = DBselect("select count(value) from %s where clock>%d and itemid=%d",table,now-parameter,item->itemid); + result = DBselect("select count(value) from %s where clock>%d and itemid=" ZBX_FS_UI64, + table,now-parameter,item->itemid); row = DBfetch(result); @@ -261,7 +264,8 @@ static int evaluate_SUM(char *value, DB_ITEM *item, int parameter, int flag) { strscpy(table,"history"); } - result = DBselect("select sum(value) from %s where clock>%d and itemid=%d",table, now-parameter,item->itemid); + result = DBselect("select sum(value) from %s where clock>%d and itemid=" ZBX_FS_UI64, + table, now-parameter,item->itemid); row = DBfetch(result); if(!row || DBis_null(row[0])==SUCCEED) @@ -284,7 +288,8 @@ static int evaluate_SUM(char *value, DB_ITEM *item, int parameter, int flag) { strscpy(table,"history"); } - zbx_snprintf(sql,sizeof(sql),"select value from %s where itemid=%d order by clock desc",table,item->itemid); + zbx_snprintf(sql,sizeof(sql),"select value from %s where itemid=" ZBX_FS_UI64 " order by clock desc", + table,item->itemid); result = DBselectN(sql, parameter); row = DBfetch(result); if(!row || DBis_null(row[0])==SUCCEED) @@ -359,7 +364,8 @@ static int evaluate_AVG(char *value,DB_ITEM *item,int parameter,int flag) if(flag == ZBX_FLAG_SEC) { - result = DBselect("select avg(value) from history where clock>%d and itemid=%d",now-parameter,item->itemid); + result = DBselect("select avg(value) from history where clock>%d and itemid=" ZBX_FS_UI64, + now-parameter,item->itemid); row = DBfetch(result); @@ -376,7 +382,8 @@ static int evaluate_AVG(char *value,DB_ITEM *item,int parameter,int flag) } else if(flag == ZBX_FLAG_VALUES) { - zbx_snprintf(sql,sizeof(sql),"select value from history where itemid=%d order by clock desc",item->itemid); + zbx_snprintf(sql,sizeof(sql),"select value from history where itemid=" ZBX_FS_UI64 " order by clock desc", + item->itemid); result = DBselectN(sql, parameter); rows=0; while((row=DBfetch(result))) @@ -456,7 +463,8 @@ static int evaluate_MIN(char *value,DB_ITEM *item,int parameter, int flag) { strscpy(table,"history"); } - result = DBselect("select min(value) from %s where clock>%d and itemid=%d",table, now-parameter,item->itemid); + result = DBselect("select min(value) from %s where clock>%d and itemid=" ZBX_FS_UI64, + table, now-parameter,item->itemid); row = DBfetch(result); if(!row || DBis_null(row[0])==SUCCEED) { @@ -479,7 +487,8 @@ static int evaluate_MIN(char *value,DB_ITEM *item,int parameter, int flag) { strscpy(table,"history"); } - zbx_snprintf(sql,sizeof(sql),"select value from %s where itemid=%d order by clock desc",table,item->itemid); + zbx_snprintf(sql,sizeof(sql),"select value from %s where itemid=" ZBX_FS_UI64 " order by clock desc", + table,item->itemid); result = DBselectN(sql,parameter); rows=0; @@ -584,7 +593,8 @@ static int evaluate_MAX(char *value,DB_ITEM *item,int parameter,int flag) { strscpy(table,"history"); } - result = DBselect("select max(value) from %s where clock>%d and itemid=%d",table,now-parameter,item->itemid); + result = DBselect("select max(value) from %s where clock>%d and itemid=" ZBX_FS_UI64, + table,now-parameter,item->itemid); row = DBfetch(result); @@ -609,7 +619,8 @@ static int evaluate_MAX(char *value,DB_ITEM *item,int parameter,int flag) { strscpy(table,"history"); } - zbx_snprintf(sql,sizeof(sql),"select value from %s where itemid=%d order by clock desc",table,item->itemid); + zbx_snprintf(sql,sizeof(sql),"select value from %s where itemid=" ZBX_FS_UI64 " order by clock desc", + table,item->itemid); result = DBselectN(sql,parameter); rows=0; while((row=DBfetch(result))) @@ -702,7 +713,8 @@ static int evaluate_DELTA(char *value,DB_ITEM *item,int parameter, int flag) if(flag == ZBX_FLAG_SEC) { - result = DBselect("select max(value)-min(value) from history where clock>%d and itemid=%d",now-parameter,item->itemid); + result = DBselect("select max(value)-min(value) from history where clock>%d and itemid=" ZBX_FS_UI64, + now-parameter,item->itemid); row = DBfetch(result); if(!row || DBis_null(row[0])==SUCCEED) @@ -718,7 +730,8 @@ static int evaluate_DELTA(char *value,DB_ITEM *item,int parameter, int flag) } else if(flag == ZBX_FLAG_VALUES) { - zbx_snprintf(sql,sizeof(sql),"select value from history where itemid=%d order by clock desc",item->itemid); + zbx_snprintf(sql,sizeof(sql),"select value from history where itemid=" ZBX_FS_UI64 " order by clock desc", + item->itemid); result = DBselectN(sql,parameter); rows=0; while((row=DBfetch(result))) @@ -1202,7 +1215,7 @@ int add_value_suffix(char *value, DB_ITEM *item) * Comments: * * * ******************************************************************************/ -int replace_value_by_map(char *value, int valuemapid) +int replace_value_by_map(char *value, zbx_uint64_t valuemapid) { DB_RESULT result; DB_ROW row; @@ -1215,7 +1228,7 @@ int replace_value_by_map(char *value, int valuemapid) if(valuemapid == 0) return FAIL; - result = DBselect("select newvalue from mappings where valuemapid=%d and value='%s'", + result = DBselect("select newvalue from mappings where valuemapid=" ZBX_FS_UI64 " and value='%s'", valuemapid, value); row = DBfetch(result); @@ -1277,7 +1290,7 @@ int evaluate_FUNCTION2(char *value,char *host,char *key,char *function,char *par DBget_item_from_db(&item,row); - zabbix_log(LOG_LEVEL_DEBUG, "Itemid:%d", item.itemid ); + zabbix_log(LOG_LEVEL_DEBUG, "Itemid:" ZBX_FS_UI64, item.itemid ); zabbix_log(LOG_LEVEL_DEBUG, "Before evaluate_FUNCTION()" ); diff --git a/src/zabbix_server/events.c b/src/zabbix_server/events.c index d1669fc2..1462e3a8 100644 --- a/src/zabbix_server/events.c +++ b/src/zabbix_server/events.c @@ -68,7 +68,8 @@ static void add_trigger_info(DB_EVENT *event) if(event->triggerid == 0) return; - result = DBselect("select description,priority,comments from triggers where triggerid=" ZBX_FS_UI64, event->triggerid); + result = DBselect("select description,priority,comments from triggers where triggerid=" ZBX_FS_UI64, + event->triggerid); row = DBfetch(result); if(row) @@ -98,27 +99,28 @@ static void add_trigger_info(DB_EVENT *event) ******************************************************************************/ int process_event(DB_EVENT *event) { - zabbix_log(LOG_LEVEL_WARNING,"In process_event(" ZBX_FS_UI64 ")",event->eventid); + zabbix_log(LOG_LEVEL_DEBUG,"In process_event(" ZBX_FS_UI64 ")",event->eventid); add_trigger_info(event); if(event->eventid == 0) { event->eventid = DBinsert_id( - DBexecute("insert into events(triggerid,clock,value) values(%d,%d,%d)", + DBexecute("insert into events(triggerid,clock,value) values(" ZBX_FS_UI64 ",%d,%d)", event->triggerid, event->clock, event->value), "events", "eventid"); } else { - DBexecute("insert into events(eventid,triggerid,clock,value) values(" ZBX_FS_UI64 ",%d,%d,%d)", + DBexecute("insert into events(eventid,triggerid,clock,value) values(" ZBX_FS_UI64 "," ZBX_FS_UI64 ",%d,%d)", event->eventid,event->triggerid, event->clock, event->value); } /* Cancel currently active alerts */ if(event->value == TRIGGER_VALUE_FALSE || event->value == 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", event->triggerid, ALERT_STATUS_NOT_SENT); + DBexecute("update alerts set retries=3,error='Trigger changed its status. WIll not send repeats.' where triggerid=" ZBX_FS_UI64 " and repeats>0 and status=%d", + event->triggerid, ALERT_STATUS_NOT_SENT); } apply_actions(event); diff --git a/src/zabbix_server/expression.c b/src/zabbix_server/expression.c index 0232a28a..5cae3c78 100644 --- a/src/zabbix_server/expression.c +++ b/src/zabbix_server/expression.c @@ -631,7 +631,7 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in var_len = strlen(MVAR_HOST_NAME); result = DBselect("select distinct h.host from triggers t, functions f,items i, hosts h " - "where t.triggerid=%d and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid", + "where t.triggerid=" ZBX_FS_UI64 " and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid", // trigger->triggerid); event->triggerid); @@ -640,9 +640,11 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in if(!row || DBis_null(row[0])==SUCCEED) { // zabbix_log( LOG_LEVEL_ERR, "No hostname in substitute_simple_macros. Triggerid [%d]", trigger->triggerid); - zabbix_log( LOG_LEVEL_ERR, "No hostname in substitute_simple_macros. Triggerid [%d]", event->triggerid); + zabbix_log( LOG_LEVEL_ERR, "No hostname in substitute_simple_macros. Triggerid [" ZBX_FS_UI64 "]", + event->triggerid); // zabbix_syslog("No hostname in substitute_simple_macros. Triggerid [%d]", trigger->triggerid); - zabbix_syslog("No hostname in substitute_simple_macros. Triggerid [%d]", event->triggerid); + zabbix_syslog("No hostname in substitute_simple_macros. Triggerid [" ZBX_FS_UI64 "]", + event->triggerid); zbx_snprintf(replace_to, sizeof(replace_to), "%s", STR_UNKNOWN_VARIAVLE); } @@ -658,7 +660,7 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in var_len = strlen(MVAR_TRIGGER_KEY); result = DBselect("select distinct i.key_ from triggers t, functions f,items i, hosts h" - " where t.triggerid=%d and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid" + " where t.triggerid=" ZBX_FS_UI64 " and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid" // " order by i.key_", trigger->triggerid); " order by i.key_", event->triggerid); @@ -667,9 +669,11 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in if(!row || DBis_null(row[0])==SUCCEED) { // zabbix_log( LOG_LEVEL_ERR, "No TRIGGER.KEY in substitute_simple_macros. Triggerid [%d]", trigger->triggerid); - zabbix_log( LOG_LEVEL_ERR, "No TRIGGER.KEY in substitute_simple_macros. Triggerid [%d]", event->triggerid); + zabbix_log( LOG_LEVEL_ERR, "No TRIGGER.KEY in substitute_simple_macros. Triggerid [" ZBX_FS_UI64 "]", + event->triggerid); // zabbix_syslog("No TRIGGER.KEY in substitute_simple_macros. Triggerid [%d]", trigger->triggerid); - zabbix_syslog("No TRIGGER.KEY in substitute_simple_macros. Triggerid [%d]", event->triggerid); + zabbix_syslog("No TRIGGER.KEY in substitute_simple_macros. Triggerid [" ZBX_FS_UI64 "]", + event->triggerid); /* remove variable */ *replace_to = '\0'; } @@ -686,7 +690,7 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in var_len = strlen(MVAR_IPADDRESS); result = DBselect("select distinct h.ip from triggers t, functions f,items i, hosts h" - " where t.triggerid=%d and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and h.useip=1", + " where t.triggerid=" ZBX_FS_UI64 " and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and h.useip=1", // trigger->triggerid); event->triggerid); @@ -695,9 +699,11 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char *data, in if(!row || DBis_null(row[0])==SUCCEED) { // zabbix_log( LOG_LEVEL_ERR, "No hostname in substitute_simple_macros. Triggerid [%d]", trigger->triggerid); - zabbix_log( LOG_LEVEL_ERR, "No hostname in substitute_simple_macros. Triggerid [%d]", event->triggerid); + zabbix_log( LOG_LEVEL_ERR, "No hostname in substitute_simple_macros. Triggerid [" ZBX_FS_UI64 "]", + event->triggerid); // zabbix_syslog("No hostname in substitute_simple_macros. Triggerid [%d]", trigger->triggerid); - zabbix_syslog("No hostname in substitute_simple_macros. Triggerid [%d]", event->triggerid); + zabbix_syslog("No hostname in substitute_simple_macros. Triggerid [" ZBX_FS_UI64 "]", + event->triggerid); zbx_snprintf(replace_to, sizeof(replace_to), "%s", STR_UNKNOWN_VARIAVLE); } diff --git a/src/zabbix_server/functions.c b/src/zabbix_server/functions.c index c5a3f577..805fd12d 100644 --- a/src/zabbix_server/functions.c +++ b/src/zabbix_server/functions.c @@ -77,20 +77,24 @@ void update_functions(DB_ITEM *item) char *lastvalue; int ret=SUCCEED; - zabbix_log( LOG_LEVEL_DEBUG, "In update_functions(%d)",item->itemid); + zabbix_log( LOG_LEVEL_DEBUG, "In update_functions(" ZBX_FS_UI64 ")", + item->itemid); /* Oracle does'n support this */ /* zbx_snprintf(sql,sizeof(sql),"select function,parameter,itemid,lastvalue from functions where itemid=%d group by function,parameter,itemid order by function,parameter,itemid",item->itemid);*/ - result = DBselect("select distinct function,parameter,itemid,lastvalue from functions where itemid=%d",item->itemid); + result = DBselect("select distinct function,parameter,itemid,lastvalue from functions where itemid=" ZBX_FS_UI64, + item->itemid); while((row=DBfetch(result))) { function.function=row[0]; function.parameter=row[1]; - function.itemid=atoi(row[2]); + ZBX_STR2UINT64(function.itemid,row[2]); +// function.itemid=atoi(row[2]); lastvalue=row[3]; - zabbix_log( LOG_LEVEL_DEBUG, "ItemId:%d Evaluating %s(%d)",function.itemid,function.function,function.parameter); + zabbix_log( LOG_LEVEL_DEBUG, "ItemId:" ZBX_FS_UI64 " Evaluating %s(%d)", + function.itemid,function.function,function.parameter); ret = evaluate_FUNCTION(value,item,function.function,function.parameter); if( FAIL == ret) @@ -105,7 +109,8 @@ void update_functions(DB_ITEM *item) if( (lastvalue == NULL) || (strcmp(lastvalue,value) != 0)) { DBescape_string(value,value_esc,MAX_STRING_LEN); - DBexecute("update functions set lastvalue='%s' where itemid=%d and function='%s' and parameter='%s'", value_esc, function.itemid, function.function, function.parameter ); + DBexecute("update functions set lastvalue='%s' where itemid=" ZBX_FS_UI64 " and function='%s' and parameter='%s'", + value_esc, function.itemid, function.function, function.parameter ); } else { @@ -132,10 +137,11 @@ void update_functions(DB_ITEM *item) * Comments: recursive function * * * ******************************************************************************/ -void update_services_rec(int serviceid) +void update_services_rec(zbx_uint64_t serviceid) { int status; - int serviceupid, algorithm; + zbx_uint64_t serviceupid; + int algorithm; time_t now; DB_RESULT result; @@ -143,11 +149,13 @@ void update_services_rec(int serviceid) DB_ROW row; DB_ROW row2; - result = DBselect("select l.serviceupid,s.algorithm from services_links l,services s where s.serviceid=l.serviceupid and l.servicedownid=%d",serviceid); + result = DBselect("select l.serviceupid,s.algorithm from services_links l,services s where s.serviceid=l.serviceupid and l.servicedownid=" ZBX_FS_UI64, + serviceid); status=0; while((row=DBfetch(result))) { - serviceupid=atoi(row[0]); + ZBX_STR2UINT64(serviceupid,row[0]); +// serviceupid=atoi(row[0]); algorithm=atoi(row[1]); if(SERVICE_ALGORITHM_NONE == algorithm) { @@ -170,12 +178,14 @@ void update_services_rec(int serviceid) if(SERVICE_ALGORITHM_MAX == algorithm) { - result2 = DBselect("select count(*),max(status) from services s,services_links l where l.serviceupid=%d and s.serviceid=l.servicedownid",serviceupid); + result2 = DBselect("select count(*),max(status) from services s,services_links l where l.serviceupid=" ZBX_FS_UI64 " and s.serviceid=l.servicedownid", + serviceupid); } /* MIN otherwise */ else { - result2 = DBselect("select count(*),min(status) from services s,services_links l where l.serviceupid=%d and s.serviceid=l.servicedownid",serviceupid); + result2 = DBselect("select count(*),min(status) from services s,services_links l where l.serviceupid=" ZBX_FS_UI64 " and s.serviceid=l.servicedownid", + serviceupid); } row2=DBfetch(result2); if(row2 && DBis_null(row2[0]) != SUCCEED && DBis_null(row2[1]) != SUCCEED) @@ -188,8 +198,9 @@ void update_services_rec(int serviceid) DBfree_result(result2); now=time(NULL); - DBadd_service_alarm(atoi(row[0]),status,now); - DBexecute("update services set status=%d where serviceid=%d",status,atoi(row[0])); + DBadd_service_alarm(serviceupid,status,now); + DBexecute("update services set status=%d where serviceid=" ZBX_FS_UI64, + status,serviceupid); } else { @@ -199,11 +210,13 @@ void update_services_rec(int serviceid) } DBfree_result(result); - result = DBselect("select serviceupid from services_links where servicedownid=%d",serviceid); + result = DBselect("select serviceupid from services_links where servicedownid=" ZBX_FS_UI64, + serviceid); while((row=DBfetch(result))) { - update_services_rec(atoi(row[0])); + ZBX_STR2UINT64(serviceupid,row[0]); + update_services_rec(serviceupid); } DBfree_result(result); } @@ -224,19 +237,23 @@ void update_services_rec(int serviceid) * Comments: * * * ******************************************************************************/ -void update_services(int triggerid, int status) +void update_services(zbx_uint64_t triggerid, int status) { DB_ROW row; + zbx_uint64_t serviceid; DB_RESULT result; - DBexecute("update services set status=%d where triggerid=%d",status,triggerid); + DBexecute("update services set status=%d where triggerid=" ZBX_FS_UI64, + status,triggerid); - result = DBselect("select serviceid from services where triggerid=%d", triggerid); + result = DBselect("select serviceid from services where triggerid=" ZBX_FS_UI64, + triggerid); while((row=DBfetch(result))) { - update_services_rec(atoi(row[0])); + ZBX_STR2UINT64(serviceid,row[0]); + update_services_rec(serviceid); } DBfree_result(result); @@ -258,7 +275,7 @@ void update_services(int triggerid, int status) * Comments: * * * ******************************************************************************/ -void update_triggers(int itemid) +void update_triggers(zbx_uint64_t itemid) { char exp[MAX_STRING_LEN]; char error[MAX_STRING_LEN]; @@ -277,7 +294,8 @@ void update_triggers(int itemid) while((row=DBfetch(result))) { - trigger.triggerid=atoi(row[0]); + ZBX_STR2UINT64(trigger.triggerid,row[0]); +// trigger.triggerid=atoi(row[0]); strscpy(trigger.expression,row[1]); trigger.status=atoi(row[2]); trigger.priority=atoi(row[4]); @@ -607,7 +625,8 @@ static int add_history(DB_ITEM *item, AGENT_RESULT *value, int now) { if(value->type & AR_STRING) DBadd_history_log(item->itemid,value->str,now,item->timestamp,item->eventlog_source,item->eventlog_severity); - DBexecute("update items set lastlogsize=%d where itemid=%d",item->lastlogsize,item->itemid); + DBexecute("update items set lastlogsize=%d where itemid=" ZBX_FS_UI64, + item->lastlogsize,item->itemid); } else if(item->value_type==ITEM_VALUE_TYPE_TEXT) { @@ -616,7 +635,8 @@ static int add_history(DB_ITEM *item, AGENT_RESULT *value, int now) } else { - zabbix_log(LOG_LEVEL_ERR, "Unknown value type [%d] for itemid [%d]", item->value_type,item->itemid); + zabbix_log(LOG_LEVEL_ERR, "Unknown value type [%d] for itemid [" ZBX_FS_UI64 "]", + item->value_type,item->itemid); } } @@ -682,7 +702,8 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, time_t now) { DBescape_string(value_str,value_esc,MAX_STRING_LEN); /* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevvalue=lastvalue,lastvalue='%s',lastclock=%d where itemid=%d",now+item->delay,value_esc,now,item->itemid);*/ - DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,lastvalue='%s',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay, item->delay_flex, now),value_esc,(int)now,item->itemid); + DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,lastvalue='%s',lastclock=%d where itemid=" ZBX_FS_UI64, + calculate_item_nextcheck(item->itemid, item->delay, item->delay_flex, now),value_esc,(int)now,item->itemid); item->prevvalue=item->lastvalue; item->lastvalue=value_double; @@ -695,7 +716,8 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, time_t now) else { /* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,lastclock=%d where itemid=%d",now+item->delay,now,item->itemid);*/ - DBexecute("update items set nextcheck=%d,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay, item->delay_flex, now),(int)now,item->itemid); + DBexecute("update items set nextcheck=%d,lastclock=%d where itemid=" ZBX_FS_UI64, + calculate_item_nextcheck(item->itemid, item->delay, item->delay_flex, now),(int)now,item->itemid); } } /* Logic for delta as speed of change */ @@ -704,12 +726,14 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, time_t now) if((item->prevorgvalue_null == 0) && (item->prevorgvalue <= value_double) ) { /* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",now+item->delay,value_double,(value_double - item->prevorgvalue)/(now-item->lastclock),now,item->itemid);*/ - DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay,item->delay_flex,now),value_double,(value_double - item->prevorgvalue)/(now-item->lastclock),(int)now,item->itemid); + DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=" ZBX_FS_UI64, + calculate_item_nextcheck(item->itemid, item->delay,item->delay_flex,now),value_double,(value_double - item->prevorgvalue)/(now-item->lastclock),(int)now,item->itemid); } else { /* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",now+item->delay,value_double,now,item->itemid);*/ - DBexecute("update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay,item->delay_flex,now),value_double,(int)now,item->itemid); + DBexecute("update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=" ZBX_FS_UI64, + calculate_item_nextcheck(item->itemid, item->delay,item->delay_flex,now),value_double,(int)now,item->itemid); } item->prevvalue=item->lastvalue; @@ -725,11 +749,13 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, time_t now) { if((item->prevorgvalue_null == 0) && (item->prevorgvalue <= value_double) ) { - DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay,item->delay_flex,now),value_double,(value_double - item->prevorgvalue),(int)now,item->itemid); + DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=" ZBX_FS_UI64, + calculate_item_nextcheck(item->itemid, item->delay,item->delay_flex,now),value_double,(value_double - item->prevorgvalue),(int)now,item->itemid); } else { - DBexecute("update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay,item->delay_flex, now),value_double,(int)now,item->itemid); + DBexecute("update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=" ZBX_FS_UI64, + calculate_item_nextcheck(item->itemid, item->delay,item->delay_flex, now),value_double,(int)now,item->itemid); } item->prevvalue=item->lastvalue; @@ -747,7 +773,8 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, time_t now) zabbix_log( LOG_LEVEL_WARNING, "Parameter [%s] became supported by agent on host [%s]", item->key, item->host ); zabbix_syslog("Parameter [%s] became supported by agent on host [%s]", item->key, item->host ); item->status = ITEM_STATUS_ACTIVE; - DBexecute("update items set status=%d where itemid=%d", ITEM_STATUS_ACTIVE, item->itemid); + DBexecute("update items set status=%d where itemid=" ZBX_FS_UI64, + ITEM_STATUS_ACTIVE, item->itemid); } return ret; diff --git a/src/zabbix_server/functions.h b/src/zabbix_server/functions.h index 34009f1e..52d6defc 100644 --- a/src/zabbix_server/functions.h +++ b/src/zabbix_server/functions.h @@ -24,7 +24,7 @@ #include "common.h" #include "db.h" -void update_triggers (int itemid); +void update_triggers (zbx_uint64_t itemid); int process_data(int sockfd,char *server,char *key, char *value,char *lastlogsize,char *timestamp, char *source, char *severity); void process_new_value(DB_ITEM *item, AGENT_RESULT *value); diff --git a/src/zabbix_server/nodewatcher/.deps/nodewatcher.Po b/src/zabbix_server/nodewatcher/.deps/nodewatcher.Po index 2e746cf1..26446355 100644 --- a/src/zabbix_server/nodewatcher/.deps/nodewatcher.Po +++ b/src/zabbix_server/nodewatcher/.deps/nodewatcher.Po @@ -70,11 +70,12 @@ nodewatcher.o nodewatcher.o: nodewatcher.c ../../../include/config.h \ /usr/include/bits/ioctl-types.h /usr/include/sys/ttydefaults.h \ /usr/include/sys/timeb.h ../../../include/zbxtypes.h \ ../../../include/cfg.h ../../../include/db.h /usr/include/mysql/mysql.h \ - /usr/include/mysql/mysql_com.h /usr/include/mysql/mysql_version.h \ - /usr/include/mysql/my_alloc.h /usr/include/mysql/errmsg.h \ - /usr/include/mysql/mysqld_error.h ../../../include/log.h \ - ../../../include/zlog.h ../../../include/dbsync.h nodewatcher.h \ - nodesender.h + /usr/include/mysql/mysql_com.h /usr/include/mysql/mysql_time.h \ + /usr/include/mysql/mysql_version.h /usr/include/mysql/typelib.h \ + /usr/include/mysql/my_list.h /usr/include/mysql/my_alloc.h \ + /usr/include/mysql/errmsg.h /usr/include/mysql/mysqld_error.h \ + ../../../include/log.h ../../../include/zlog.h \ + ../../../include/dbsync.h events.h history.h nodewatcher.h nodesender.h ../../../include/config.h: @@ -380,8 +381,14 @@ nodewatcher.o nodewatcher.o: nodewatcher.c ../../../include/config.h \ /usr/include/mysql/mysql_com.h: +/usr/include/mysql/mysql_time.h: + /usr/include/mysql/mysql_version.h: +/usr/include/mysql/typelib.h: + +/usr/include/mysql/my_list.h: + /usr/include/mysql/my_alloc.h: /usr/include/mysql/errmsg.h: @@ -394,6 +401,10 @@ nodewatcher.o nodewatcher.o: nodewatcher.c ../../../include/config.h \ ../../../include/dbsync.h: +events.h: + +history.h: + nodewatcher.h: nodesender.h: diff --git a/src/zabbix_server/nodewatcher/Makefile.am b/src/zabbix_server/nodewatcher/Makefile.am index bf3ef9c2..dd144c9c 100644 --- a/src/zabbix_server/nodewatcher/Makefile.am +++ b/src/zabbix_server/nodewatcher/Makefile.am @@ -1,4 +1,4 @@ SUBDIRS= INCLUDES=-I@top_srcdir@/include @MYSQL_INCLUDE@ @ORACLE_INCLUDE@ @PGSQL_INCLUDE@ lib_LIBRARIES=libzbxnodewatcher.a -libzbxnodewatcher_a_SOURCES=nodewatcher.c nodesender.c nodecomms.c events.c +libzbxnodewatcher_a_SOURCES=nodewatcher.c nodesender.c nodecomms.c events.c history.c diff --git a/src/zabbix_server/nodewatcher/events.c b/src/zabbix_server/nodewatcher/events.c index 275b941c..9f2fe65f 100644 --- a/src/zabbix_server/nodewatcher/events.c +++ b/src/zabbix_server/nodewatcher/events.c @@ -49,7 +49,6 @@ #include "log.h" #include "zlog.h" -#include "dbsync.h" #include "nodecomms.h" #include "events.h" @@ -99,7 +98,7 @@ static int process_node(int nodeid, int master_nodeid, zbx_uint64_t event_lastid while((row=DBfetch(result))) { ZBX_STR2UINT64(eventid,row[0]) - zabbix_log( LOG_LEVEL_WARNING, "Processing eventid " ZBX_FS_UI64, eventid); +// zabbix_log( LOG_LEVEL_WARNING, "Processing eventid " ZBX_FS_UI64, eventid); found = 1; zbx_snprintf(tmp,sizeof(tmp),"%s|%s|%s|%s|%s\n", row[0],row[1],row[2],row[3],row[4]); strncat(data,tmp,DATA_MAX); diff --git a/src/zabbix_server/nodewatcher/history.c b/src/zabbix_server/nodewatcher/history.c new file mode 100644 index 00000000..53828ba4 --- /dev/null +++ b/src/zabbix_server/nodewatcher/history.c @@ -0,0 +1,195 @@ +/* +** ZABBIX +** Copyright (C) 2000-2006 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ + +#include "config.h" + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/socket.h> +#include <netinet/in.h> + +#include <sys/wait.h> + +#include <string.h> + +#ifdef HAVE_NETDB_H + #include <netdb.h> +#endif + +/* Required for getpwuid */ +#include <pwd.h> + +#include <signal.h> +#include <errno.h> + +#include <time.h> + +#include "common.h" +#include "cfg.h" +#include "db.h" +#include "log.h" +#include "zlog.h" + +#include "nodecomms.h" +#include "history.h" + +extern int CONFIG_NODEID; + +/****************************************************************************** + * * + * Function: process_node_history * + * * + * Purpose: process new history data * + * * + * Parameters: * + * * + * Return value: SUCCESS - processed succesfully * + * FAIL - an error occured * + * * + * Author: Alexei Vladishev * + * * + * Comments: * + * * + ******************************************************************************/ +static int process_node_history(int nodeid, int master_nodeid) +{ + DB_RESULT result; + DB_ROW row; + char *data; + char tmp[MAX_STRING_LEN]; + char sql[MAX_STRING_LEN]; + int found = 0; + + zbx_uint64_t id; + zbx_uint64_t itemid; + +#define DATA_MAX 1024*1024 + +// zabbix_log( LOG_LEVEL_WARNING, "In process_node(local:%d, event_lastid:" ZBX_FS_UI64 ")",nodeid, event_lastid); + /* Begin work */ + + data = malloc(DATA_MAX); + memset(data,0,DATA_MAX); + + zbx_snprintf(tmp,sizeof(tmp),"History|%d|%d\n", CONFIG_NODEID, nodeid); + strncat(data,tmp,DATA_MAX); + + zbx_snprintf(sql,sizeof(sql),"select id,itemid,clock,value from history_sync where nodeid=%d order by id", nodeid); + + result = DBselectN(sql, 100000); + while((row=DBfetch(result))) + { + ZBX_STR2UINT64(id,row[0]) + ZBX_STR2UINT64(itemid,row[1]) +// zabbix_log( LOG_LEVEL_WARNING, "Processing itemid " ZBX_FS_UI64, itemid); + found = 1; + zbx_snprintf(tmp,sizeof(tmp),"%s|%s|%s\n", row[1],row[2],row[3]); + strncat(data,tmp,DATA_MAX); + } + if(found == 1) + { +// zabbix_log( LOG_LEVEL_WARNING, "Sending [%s]",data); + if(send_to_node(master_nodeid, nodeid, data) == SUCCEED) + { +// zabbix_log( LOG_LEVEL_WARNING, "Updating nodes.history_lastid"); + DBexecute("update nodes set history_lastid=" ZBX_FS_UI64 " where nodeid=%d", id, nodeid); + DBexecute("delete from history_sync where nodeid=%d and id<=" ZBX_FS_UI64, nodeid, id); + } + else + { + zabbix_log( LOG_LEVEL_WARNING, "Not updating nodes.history_lastid"); + } + } + DBfree_result(result); + free(data); + + return SUCCEED; +} + +/****************************************************************************** + * * + * Function: process_node * + * * + * Purpose: process all history tables for this node * + * * + * Parameters: * + * * + * Return value: SUCCESS - processed succesfully * + * FAIL - an error occured * + * * + * Author: Alexei Vladishev * + * * + * Comments: * + * * + ******************************************************************************/ +static void process_node(int nodeid, int master_nodeid) +{ +// zabbix_log( LOG_LEVEL_WARNING, "In process_node(local:%d, master_nodeid:" ZBX_FS_UI64 ")",nodeid, master_nodeid); + + process_node_history(nodeid, master_nodeid); +/* process_node_history_uint(nodeid, master_nodeid); + process_node_history_str(nodeid, master_nodeid); + process_node_history_log(nodeid, master_nodeid); + process_node_trends(nodeid, master_nodeid);*/ +} + +/****************************************************************************** + * * + * Function: main_eventsender * + * * + * Purpose: periodically sends new events to master node * + * * + * Parameters: * + * * + * Return value: * + * * + * Author: Alexei Vladishev * + * * + * Comments: never returns * + * * + ******************************************************************************/ +void main_historysender() +{ + DB_RESULT result; + DB_ROW row; + zbx_uint64_t lastid; + int nodeid; + int master_nodeid; + + zabbix_log( LOG_LEVEL_DEBUG, "In main_eventsender()"); + + master_nodeid = get_master_node(CONFIG_NODEID); + + if(master_nodeid == 0) return; + + result = DBselect("select nodeid from nodes"); + + while((row = DBfetch(result))) + { + nodeid=atoi(row[0]); + ZBX_STR2UINT64(lastid,row[1]) + + process_node(nodeid, master_nodeid); + } + + DBfree_result(result); +} diff --git a/src/zabbix_server/nodewatcher/history.h b/src/zabbix_server/nodewatcher/history.h new file mode 100644 index 00000000..cf064cc3 --- /dev/null +++ b/src/zabbix_server/nodewatcher/history.h @@ -0,0 +1,25 @@ +/* +** ZABBIX +** Copyright (C) 2000-2005 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ + +#ifndef ZABBIX_NODEWATCHER_HISTORY_H +#define ZABBIX_NODEWATCHER_HISTORY_H + +void main_historysender(); + +#endif diff --git a/src/zabbix_server/nodewatcher/nodecomms.c b/src/zabbix_server/nodewatcher/nodecomms.c index 7a181c50..5bde4ac4 100644 --- a/src/zabbix_server/nodewatcher/nodecomms.c +++ b/src/zabbix_server/nodewatcher/nodecomms.c @@ -49,7 +49,6 @@ #include "log.h" #include "zlog.h" -#include "dbsync.h" #include "nodecomms.h" /****************************************************************************** diff --git a/src/zabbix_server/nodewatcher/nodewatcher.c b/src/zabbix_server/nodewatcher/nodewatcher.c index 1675d392..0e3468a1 100644 --- a/src/zabbix_server/nodewatcher/nodewatcher.c +++ b/src/zabbix_server/nodewatcher/nodewatcher.c @@ -50,6 +50,8 @@ #include "zlog.h" #include "dbsync.h" +#include "events.h" +#include "history.h" #include "nodewatcher.h" #include "nodesender.h" @@ -136,7 +138,7 @@ static int calculate_checksums() result2 =DBselect(sql); - zabbix_log( LOG_LEVEL_WARNING, "Selected records in %d seconds", time(NULL)-now); +// zabbix_log( LOG_LEVEL_WARNING, "Selected records in %d seconds", time(NULL)-now); now = time(NULL); i=0; while((row2=DBfetch(result2))) @@ -149,7 +151,7 @@ static int calculate_checksums() i++; } DBfree_result(result2); - zabbix_log( LOG_LEVEL_WARNING, "Added %d records in %d seconds", i, time(NULL)-now); +// zabbix_log( LOG_LEVEL_WARNING, "Added %d records in %d seconds", i, time(NULL)-now); } DBfree_result(result); @@ -292,6 +294,9 @@ int main_nodewatcher_loop() /* Send new events to master node */ main_eventsender(); + /* Send new history data to master node */ + main_historysender(); + DBclose(); zbx_setproctitle("sender [sleeping for %d seconds]", 30); diff --git a/src/zabbix_server/poller/poller.c b/src/zabbix_server/poller/poller.c index 34c90582..e5353916 100644 --- a/src/zabbix_server/poller/poller.c +++ b/src/zabbix_server/poller/poller.c @@ -159,7 +159,7 @@ static int get_minnextcheck(int now) } /* Update special host's item - "status" */ -static void update_key_status(int hostid,int host_status) +static void update_key_status(zbx_uint64_t hostid,int host_status) { /* char value_str[MAX_STRING_LEN];*/ AGENT_RESULT agent; @@ -168,9 +168,11 @@ static void update_key_status(int hostid,int host_status) DB_RESULT result; DB_ROW row; - zabbix_log(LOG_LEVEL_DEBUG, "In update_key_status(%d,%d)",hostid,host_status); + zabbix_log(LOG_LEVEL_DEBUG, "In update_key_status(" ZBX_FS_UI64 ",%d)", + hostid,host_status); - result = DBselect("select %s where h.hostid=i.hostid and h.hostid=%d and i.key_='%s'", ZBX_SQL_ITEM_SELECT, hostid,SERVER_STATUS_KEY); + result = DBselect("select %s where h.hostid=i.hostid and h.hostid=" ZBX_FS_UI64 " and i.key_='%s'", + ZBX_SQL_ITEM_SELECT, hostid,SERVER_STATUS_KEY); row = DBfetch(result); @@ -268,7 +270,8 @@ int get_values(void) } if(item.host_errors_from!=0) { - DBexecute("update hosts set errors_from=0 where hostid=%d", item.hostid); + DBexecute("update hosts set errors_from=0 where hostid=" ZBX_FS_UI64, + item.hostid); stop=1; } @@ -280,7 +283,8 @@ int get_values(void) { /* It is not correct */ /* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d, lastclock=%d where itemid=%d",calculate_item_nextcheck(item.itemid, CONFIG_REFRESH_UNSUPPORTED,now), now, item.itemid);*/ - DBexecute("update items set nextcheck=%d, lastclock=%d where itemid=%d",CONFIG_REFRESH_UNSUPPORTED+now, now, item.itemid); + DBexecute("update items set nextcheck=%d, lastclock=%d where itemid=" ZBX_FS_UI64, + CONFIG_REFRESH_UNSUPPORTED+now, now, item.itemid); } else { @@ -309,7 +313,8 @@ int get_values(void) zabbix_syslog("Host [%s]: first network error, wait for %d seconds", item.host, CONFIG_UNREACHABLE_DELAY); item.host_errors_from=now; - DBexecute("update hosts set errors_from=%d,disable_until=%d where hostid=%d", now, now+CONFIG_UNREACHABLE_DELAY, item.hostid); + DBexecute("update hosts set errors_from=%d,disable_until=%d where hostid=" ZBX_FS_UI64, + now, now+CONFIG_UNREACHABLE_DELAY, item.hostid); } else { @@ -322,7 +327,8 @@ int get_values(void) update_key_status(item.hostid,HOST_AVAILABLE_FALSE); /* 2 */ item.host_available=HOST_AVAILABLE_FALSE; - DBexecute("update hosts set disable_until=%d where hostid=%d", now+CONFIG_UNAVAILABLE_DELAY, item.hostid); + DBexecute("update hosts set disable_until=%d where hostid=" ZBX_FS_UI64, + now+CONFIG_UNAVAILABLE_DELAY, item.hostid); } /* Still unavailable, but won't change status to UNAVAILABLE yet */ else @@ -330,7 +336,8 @@ int get_values(void) zabbix_log( LOG_LEVEL_WARNING, "Host [%s]: another network error, wait for %d seconds", item.host, CONFIG_UNREACHABLE_DELAY); zabbix_syslog("Host [%s]: another network error, wait for %d seconds", item.host, CONFIG_UNREACHABLE_DELAY); - DBexecute("update hosts set disable_until=%d where hostid=%d", now+CONFIG_UNREACHABLE_DELAY, item.hostid); + DBexecute("update hosts set disable_until=%d where hostid=" ZBX_FS_UI64, + now+CONFIG_UNREACHABLE_DELAY, item.hostid); } } @@ -411,4 +418,3 @@ void main_poller_loop(int _server_num) } } } - diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c index bfd185cd..2a55889c 100644 --- a/src/zabbix_server/server.c +++ b/src/zabbix_server/server.c @@ -125,6 +125,7 @@ int CONFIG_DBPORT = 3306; int CONFIG_ENABLE_REMOTE_COMMANDS = 0; int CONFIG_NODEID = 0; +int CONFIG_MASTER_NODEID = -1; /* From table config */ int CONFIG_REFRESH_UNSUPPORTED = 0; @@ -451,7 +452,6 @@ int MAIN_ZABBIX_ENTRY(void) DBconnect(); - zabbix_log( LOG_LEVEL_WARNING, "Cond1 " ZBX_COND_NODEID, LOCAL_NODE("configid")); result = DBselect("select refresh_unsupported from config where " ZBX_COND_NODEID, LOCAL_NODE("configid")); row = DBfetch(result); @@ -461,6 +461,15 @@ int MAIN_ZABBIX_ENTRY(void) } DBfree_result(result); + result = DBselect("select masterid from nodes where nodeid=%d", CONFIG_NODEID); + row = DBfetch(result); + + if( (row != NULL) && DBis_null(row[0]) != SUCCEED) + { + CONFIG_MASTER_NODEID = atoi(row[0]); + } + DBfree_result(result); + /* Need to set trigger status to UNKNOWN since last run */ /* DBconnect() already made in init_config() */ /* DBconnect();*/ diff --git a/src/zabbix_server/trapper/Makefile.am b/src/zabbix_server/trapper/Makefile.am index 48a863b9..14ef010b 100644 --- a/src/zabbix_server/trapper/Makefile.am +++ b/src/zabbix_server/trapper/Makefile.am @@ -1,5 +1,5 @@ SUBDIRS= INCLUDES=-I@top_srcdir@/include @MYSQL_INCLUDE@ @ORACLE_INCLUDE@ @PGSQL_INCLUDE@ lib_LIBRARIES=libzbxtrapper.a -libzbxtrapper_a_SOURCES=active.c autoregister.h autoregister.c trapper.c nodesync.c nodeevents.c +libzbxtrapper_a_SOURCES=active.c autoregister.h autoregister.c trapper.c nodesync.c nodeevents.c nodehistory.c libzbxtrapper_a_LIBADD = ../../libs/zbxdbhigh/libzbxdbhigh.a diff --git a/src/zabbix_server/trapper/nodeevents.c b/src/zabbix_server/trapper/nodeevents.c index f370b96c..dcacfdc6 100644 --- a/src/zabbix_server/trapper/nodeevents.c +++ b/src/zabbix_server/trapper/nodeevents.c @@ -41,9 +41,10 @@ #include "log.h" #include "zlog.h" -#include "dbsync.h" #include "nodeevents.h" +extern int process_event(DB_EVENT *event); + /****************************************************************************** * * * Function: process_record * @@ -66,17 +67,19 @@ static int process_record(int nodeid, char *record) DB_EVENT event; - zabbix_log( LOG_LEVEL_WARNING, "In process_record [%s]", record); + zabbix_log( LOG_LEVEL_DEBUG, "In process_record [%s]", record); + + memset(&event,0,sizeof(DB_EVENT)); - get_field(record,tmp,0); + zbx_get_field(record,tmp,0,'|'); sscanf(tmp,ZBX_FS_UI64,&event.eventid); - get_field(record,tmp,1); + zbx_get_field(record,tmp,1,'|'); sscanf(tmp,ZBX_FS_UI64,&event.triggerid); - get_field(record,tmp,2); + zbx_get_field(record,tmp,2,'|'); event.clock=atoi(tmp); - get_field(record,tmp,3); + zbx_get_field(record,tmp,3,'|'); event.value=atoi(tmp); - get_field(record,tmp,4); + zbx_get_field(record,tmp,4,'|'); event.acknowledged=atoi(tmp); return process_event(&event); @@ -113,16 +116,16 @@ int node_events(char *data) if(firstline == 1) { // zabbix_log( LOG_LEVEL_WARNING, "First line [%s]", s); - get_field(s,tmp,1); + zbx_get_field(s,tmp,1,'|'); sender_nodeid=atoi(tmp); - get_field(s,tmp,2); + zbx_get_field(s,tmp,2,'|'); nodeid=atoi(tmp); firstline=0; zabbix_log( LOG_LEVEL_WARNING, "NODE %d: Received events from node %d for node %d", CONFIG_NODEID, sender_nodeid, nodeid); } else { - zabbix_log( LOG_LEVEL_WARNING, "Got line [%s]", s); +// zabbix_log( LOG_LEVEL_WARNING, "Got line [%s]", s); process_record(nodeid, s); } diff --git a/src/zabbix_server/trapper/nodehistory.c b/src/zabbix_server/trapper/nodehistory.c new file mode 100644 index 00000000..2fdfa700 --- /dev/null +++ b/src/zabbix_server/trapper/nodehistory.c @@ -0,0 +1,131 @@ +/* +** ZABBIX +** Copyright (C) 2000-2005 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ + + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <netinet/in.h> +#include <netdb.h> + +#include <string.h> + +#include <time.h> + +#include <sys/socket.h> +#include <errno.h> + +/* Functions: pow(), round() */ +#include <math.h> + +#include "common.h" +#include "db.h" +#include "log.h" +#include "zlog.h" + +#include "nodeevents.h" + +extern int process_event(DB_EVENT *event); + +/****************************************************************************** + * * + * Function: process_record * + * * + * Purpose: process record update * + * * + * Parameters: * + * * + * Return value: SUCCEED - processed successfully * + * FAIL - an error occured * + * * + * Author: Alexei Vladishev * + * * + * Comments: * + * * + ******************************************************************************/ +static int process_record(int nodeid, char *record) +{ + char tmp[MAX_STRING_LEN]; + zbx_uint64_t itemid; + int timestamp; + double value; + + zabbix_log( LOG_LEVEL_DEBUG, "In process_record [%s]", record); + + zbx_get_field(record,tmp,0,'|'); + sscanf(tmp,ZBX_FS_UI64,&itemid); + zbx_get_field(record,tmp,1,'|'); + timestamp=atoi(tmp); + zbx_get_field(record,tmp,2,'|'); + value=atof(tmp); + + return DBadd_history(itemid, value, clock); +} + +/****************************************************************************** + * * + * Function: node_events * + * * + * Purpose: process new events received from a salve node * + * * + * Parameters: * + * * + * Return value: SUCCEED - processed successfully * + * FAIL - an error occured * + * * + * Author: Alexei Vladishev * + * * + * Comments: * + * * + ******************************************************************************/ +int node_history(char *data) +{ + char *s; + int firstline=1; + int nodeid=0; + int sender_nodeid=0; + char tmp[MAX_STRING_LEN]; + +// zabbix_log( LOG_LEVEL_WARNING, "In node_history(len:%d)", strlen(data)); + + s=(char *)strtok(data,"\n"); + while(s!=NULL) + { + if(firstline == 1) + { +// zabbix_log( LOG_LEVEL_WARNING, "First line [%s]", s); + zbx_get_field(s,tmp,1,'|'); + sender_nodeid=atoi(tmp); + zbx_get_field(s,tmp,2,'|'); + nodeid=atoi(tmp); + firstline=0; + zabbix_log( LOG_LEVEL_WARNING, "NODE %d: Received history from node %d for node %d", CONFIG_NODEID, sender_nodeid, nodeid); + } + else + { +// zabbix_log( LOG_LEVEL_WARNING, "Got line [%s]", s); + process_record(nodeid, s); + } + + s=(char *)strtok(NULL,"\n"); + } + return SUCCEED; +} diff --git a/src/zabbix_server/trapper/nodehistory.h b/src/zabbix_server/trapper/nodehistory.h new file mode 100644 index 00000000..ba7e6ed9 --- /dev/null +++ b/src/zabbix_server/trapper/nodehistory.h @@ -0,0 +1,28 @@ +/* +** ZABBIX +** Copyright (C) 2000-2005 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ + + +#ifndef ZABBIX_NODEEVENTS_H +#define ZABBIX_NODEEVENTS_H + +extern int CONFIG_NODEID; + +int node_history(char *data); + +#endif diff --git a/src/zabbix_server/trapper/nodesync.c b/src/zabbix_server/trapper/nodesync.c index a85d1eef..775bce2b 100644 --- a/src/zabbix_server/trapper/nodesync.c +++ b/src/zabbix_server/trapper/nodesync.c @@ -44,31 +44,6 @@ #include "dbsync.h" #include "nodesync.h" -int get_field(char *line, char *result, int num) -{ - int delim=0; - int ptr=0; - int i; - - int ret = FAIL; - - for(i=0;line[i]!=0;i++) - { - if(line[i]=='|') - { - delim++; - continue; - } - if(delim==num) - { - result[ptr++]=line[i]; - result[ptr]=0; - ret = SUCCEED; - } - } - return ret; -} - /****************************************************************************** * * * Function: process_record * @@ -106,10 +81,10 @@ static int process_record(int nodeid, char *record) // zabbix_log( LOG_LEVEL_WARNING, "In process_record [%s]", record); - get_field(record,tablename,0); - get_field(record,tmp,1); + zbx_get_field(record,tablename,0,'|'); + zbx_get_field(record,tmp,1,'|'); sscanf(tmp,ZBX_FS_UI64,&recid); - get_field(record,tmp,2); + zbx_get_field(record,tmp,2,'|'); op=atoi(tmp); for(i=0;tables[i].table!=0;i++) @@ -137,13 +112,13 @@ static int process_record(int nodeid, char *record) fields[0]=0; fields_update[0]=0; values[0]=0; - while(get_field(record,fieldname,i++)==SUCCEED) + while(zbx_get_field(record,fieldname,i++,'|')==SUCCEED) { tmp[0]=0; - get_field(record,tmp,i++); + zbx_get_field(record,tmp,i++,'|'); valuetype=atoi(tmp); value[0]=0; - get_field(record,value,i++); + zbx_get_field(record,value,i++,'|'); if(op==NODE_CONFIGLOG_OP_UPDATE || op==NODE_CONFIGLOG_OP_ADD) { if(strcmp(value,"NULL")==0) @@ -198,7 +173,7 @@ static int process_record(int nodeid, char *record) else if(op==NODE_CONFIGLOG_OP_ADD) { result = DBselect("select 0 from %s where %s=" ZBX_FS_UI64, tablename, key, recid); - row = DBfetch(result); + row = DBfetch(result); if(row) { zbx_snprintf(sql,sizeof(sql),"update %s set %s where %s=" ZBX_FS_UI64, tablename, fields_update, key, recid); @@ -249,9 +224,9 @@ int node_sync(char *data) if(firstline == 1) { // zabbix_log( LOG_LEVEL_WARNING, "First line [%s]", s); - get_field(s,tmp,1); + zbx_get_field(s,tmp,1,'|'); sender_nodeid=atoi(tmp); - get_field(s,tmp,2); + zbx_get_field(s,tmp,2,'|'); nodeid=atoi(tmp); firstline=0; zabbix_log( LOG_LEVEL_WARNING, "NODE %d: Received data from node %d for node %d", CONFIG_NODEID, sender_nodeid, nodeid); diff --git a/src/zabbix_server/trapper/trapper.c b/src/zabbix_server/trapper/trapper.c index 46559548..25623294 100644 --- a/src/zabbix_server/trapper/trapper.c +++ b/src/zabbix_server/trapper/trapper.c @@ -52,6 +52,7 @@ #include "autoregister.h" #include "nodesync.h" #include "nodeevents.h" +#include "nodehistory.h" #include "trapper.h" #include "daemon.h" @@ -132,6 +133,21 @@ int process_trap(int sockfd,char *s, int max_len) } return ret; } + /* Slave node history ? */ + if(strncmp(s,"History",7) == 0) + { +// zabbix_log( LOG_LEVEL_WARNING, "Slave node history received [len:%d]", strlen(s)); + if(node_history(s) == SUCCEED) + { + zbx_snprintf(result,sizeof(result),"OK\n"); + if( write(sockfd,result,strlen(result)) == -1) + { + zabbix_log( LOG_LEVEL_WARNING, "Error sending confirmation to node [%s]",strerror(errno)); + zabbix_syslog("Trapper: error sending confirmation to node [%s]",strerror(errno)); + } + } + return ret; + } /* New XML protocol? */ else if(s[0]=='<') { |