diff options
| author | alex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-03-19 20:39:45 +0000 |
|---|---|---|
| committer | alex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-03-19 20:39:45 +0000 |
| commit | 80e1c36d1b3ae7593d368ca1e4d7bee2ff8f40f7 (patch) | |
| tree | a8bca294692cb6daa0b15fd41979dba43ce0cd05 /src/zabbix_server | |
| parent | 7434fa236e1a6d52f9d98d79f01cd69fcfdffc24 (diff) | |
| download | zabbix-80e1c36d1b3ae7593d368ca1e4d7bee2ff8f40f7.tar.gz zabbix-80e1c36d1b3ae7593d368ca1e4d7bee2ff8f40f7.tar.xz zabbix-80e1c36d1b3ae7593d368ca1e4d7bee2ff8f40f7.zip | |
Beautification of code.
git-svn-id: svn://svn.zabbix.com/trunk@3899 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_server')
31 files changed, 1316 insertions, 477 deletions
diff --git a/src/zabbix_server/actions.c b/src/zabbix_server/actions.c index 1664500a..5b1a26a8 100644 --- a/src/zabbix_server/actions.c +++ b/src/zabbix_server/actions.c @@ -393,8 +393,9 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition) zbx_uint64_t groupid; zbx_uint64_t hostid; zbx_uint64_t condition_value; + int value_int; - char *tmp_str = NULL; + char *tmp_str = NULL; int ret = FAIL; @@ -609,6 +610,65 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition) condition->conditionid); } } + else if(condition->conditiontype == CONDITION_TYPE_DHOST_IP) + { + /* Not implemente yet */ + } + else if(condition->conditiontype == CONDITION_TYPE_DSERVICE_TYPE) + { + zabbix_log( LOG_LEVEL_DEBUG, "CONDITION_TYPE_DSERVICE_TYPE [%d:%s]", + event->value, + condition->value); + value_int = atoi(condition->value); + result = DBselect("select dserviceid from dservices where type=%d and dserviceid=" ZBX_FS_UI64, + value_int, + event->objectid); + if(condition->operator == CONDITION_OPERATOR_EQUAL) + { + if(row && DBis_null(row[0]) != SUCCEED) + { + ret = SUCCEED; + } + } + else + { + zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [" ZBX_FS_UI64 "]", + condition->operator, + condition->conditionid); + } + DBfree_result(result); + } + else if(condition->conditiontype == CONDITION_TYPE_DSERVICE_PORT) + { + zabbix_log( LOG_LEVEL_DEBUG, "CONDITION_TYPE_DSERVICE_TYPE [%d:%s]", + event->value, + condition->value); + value_int = atoi(condition->value); + result = DBselect("select port from dservices where dserviceid=" ZBX_FS_UI64, + event->objectid); + if(row && DBis_null(row[0]) != SUCCEED) + { + if(condition->operator == CONDITION_OPERATOR_EQUAL) + { + if(value_int == atoi(row[0])) ret = SUCCEED; + } + else if(condition->operator == CONDITION_OPERATOR_LESS_EQUAL) + { + if(atoi(row[0]) <= value_int) ret = SUCCEED; + } + else if(condition->operator == CONDITION_OPERATOR_MORE_EQUAL) + { + if(atoi(row[0]) >= value_int) ret = SUCCEED; + } + else + { + zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [" ZBX_FS_UI64 "]", + condition->operator, + condition->conditionid); + } + } + DBfree_result(result); + } else { zabbix_log( LOG_LEVEL_ERR, "Condition type [%d] is unknown for condition id [" ZBX_FS_UI64 "]", @@ -802,7 +862,7 @@ void apply_actions(DB_EVENT *event) if(check_action_conditions(event, &action) == SUCCEED) { - zabbix_log( LOG_LEVEL_DEBUG, "Conditions match our trigger. Do apply actions."); + zabbix_log( LOG_LEVEL_DEBUG, "Conditions match our event. Do apply actions."); ZBX_STR2UINT64(action.userid, row[1]); diff --git a/src/zabbix_server/alerter/alerter.c b/src/zabbix_server/alerter/alerter.c index 92157b08..4525f05f 100644 --- a/src/zabbix_server/alerter/alerter.c +++ b/src/zabbix_server/alerter/alerter.c @@ -65,7 +65,8 @@ int execute_action(DB_ALERT *alert,DB_MEDIATYPE *mediatype, char *error, int max (char *)0 }; - zabbix_log( LOG_LEVEL_DEBUG, "In execute_action(%s)", mediatype->smtp_server); + zabbix_log( LOG_LEVEL_DEBUG, "In execute_action(%s)", + mediatype->smtp_server); if(mediatype->type==ALERT_TYPE_EMAIL) { @@ -85,7 +86,9 @@ int execute_action(DB_ALERT *alert,DB_MEDIATYPE *mediatype, char *error, int max else if(mediatype->type==ALERT_TYPE_EXEC) { /* if(-1 == execl(CONFIG_ALERT_SCRIPTS_PATH,mediatype->exec_path,alert->sendto,alert->subject,alert->message))*/ - zabbix_log( LOG_LEVEL_DEBUG, "Before execl([%s],[%s])",CONFIG_ALERT_SCRIPTS_PATH,mediatype->exec_path); + zabbix_log( LOG_LEVEL_DEBUG, "Before execl([%s],[%s])", + CONFIG_ALERT_SCRIPTS_PATH, + mediatype->exec_path); /* if(-1 == execl("/home/zabbix/bin/lmt.sh","lmt.sh",alert->sendto,alert->subject,alert->message,(char *)0))*/ @@ -100,23 +103,37 @@ int execute_action(DB_ALERT *alert,DB_MEDIATYPE *mediatype, char *error, int max zbx_strlcat(full_path,"/",MAX_STRING_LEN); zbx_strlcat(full_path,mediatype->exec_path,MAX_STRING_LEN); ltrim_spaces(full_path); - zabbix_log( LOG_LEVEL_DEBUG, "Before executing [%s]", full_path); - - zbx_snprintf(env_alertid,127,"ZABBIX_ALERT_ID=%d",alert->alertid); - zbx_snprintf(env_actionid,127,"ZABBIX_ACTION_ID=%d",alert->actionid); - zbx_snprintf(env_clock,127,"ZABBIX_ALERT_TIME=%d",alert->clock); - zbx_snprintf(env_mediatypeid,127,"ZABBIX_ALERT_MEDIATYPEID=%d",alert->mediatypeid); - zbx_snprintf(env_status,127,"ZABBIX_ALERT_STATUS=%d",alert->status); - zbx_snprintf(env_retries,127,"ZABBIX_ALERT_RETRIES=%d",alert->retries); - zbx_snprintf(env_delay,127,"ZABBIX_ALERT_DELAY=%d",alert->delay); + zabbix_log( LOG_LEVEL_DEBUG, "Before executing [%s]", + full_path); + + zbx_snprintf(env_alertid,127,"ZABBIX_ALERT_ID=%d", + alert->alertid); + zbx_snprintf(env_actionid,127,"ZABBIX_ACTION_ID=%d", + alert->actionid); + zbx_snprintf(env_clock,127,"ZABBIX_ALERT_TIME=%d", + alert->clock); + zbx_snprintf(env_mediatypeid,127,"ZABBIX_ALERT_MEDIATYPEID=%d", + alert->mediatypeid); + zbx_snprintf(env_status,127,"ZABBIX_ALERT_STATUS=%d", + alert->status); + zbx_snprintf(env_retries,127,"ZABBIX_ALERT_RETRIES=%d", + alert->retries); + zbx_snprintf(env_delay,127,"ZABBIX_ALERT_DELAY=%d", + alert->delay); /* if(-1 == execl(full_path,mediatype->exec_path,alert->sendto,alert->subject,alert->message,(char *)0))*/ if(-1 == execle(full_path,mediatype->exec_path,alert->sendto,alert->subject,alert->message,(char *)0, zbxenv)) { - zabbix_log( LOG_LEVEL_ERR, "Error executing [%s] [%s]", full_path, strerror(errno)); - zabbix_syslog("Error executing [%s] [%s]", full_path, strerror(errno)); - zbx_snprintf(error,max_error_len,"Error executing [%s] [%s]", full_path, strerror(errno)); + zabbix_log( LOG_LEVEL_ERR, "Error executing [%s] [%s]", + full_path, + strerror(errno)); + zabbix_syslog("Error executing [%s] [%s]", + full_path, + strerror(errno)); + zbx_snprintf(error,max_error_len,"Error executing [%s] [%s]", + full_path, + strerror(errno)); res = FAIL; } else @@ -131,9 +148,14 @@ int execute_action(DB_ALERT *alert,DB_MEDIATYPE *mediatype, char *error, int max } else { - zabbix_log( LOG_LEVEL_ERR, "Unsupported media type [%d] for alert ID [%d]", mediatype->type,alert->alertid); - zabbix_syslog("Unsupported media type [%d] for alert ID [%d]", mediatype->type,alert->alertid); - zbx_snprintf(error,max_error_len,"Unsupported media type [%d]", mediatype->type); + zabbix_log( LOG_LEVEL_ERR, "Unsupported media type [%d] for alert ID [%d]", + mediatype->type, + alert->alertid); + zabbix_syslog("Unsupported media type [%d] for alert ID [%d]", + mediatype->type, + alert->alertid); + zbx_snprintf(error,max_error_len,"Unsupported media type [%d]", + mediatype->type); res=FAIL; } @@ -180,7 +202,9 @@ int main_alerter_loop() now = time(NULL); - result = DBselect("select a.alertid,a.mediatypeid,a.sendto,a.subject,a.message,a.status,a.retries,mt.mediatypeid,mt.type,mt.description,mt.smtp_server,mt.smtp_helo,mt.smtp_email,mt.exec_path,a.delay,mt.gsm_modem,mt.username,mt.passwd from alerts a,media_type mt where a.status=%d and a.retries<3 and a.mediatypeid=mt.mediatypeid and " ZBX_COND_NODEID " order by a.clock", ALERT_STATUS_NOT_SENT, LOCAL_NODE("mt.mediatypeid")); + result = DBselect("select a.alertid,a.mediatypeid,a.sendto,a.subject,a.message,a.status,a.retries,mt.mediatypeid,mt.type,mt.description,mt.smtp_server,mt.smtp_helo,mt.smtp_email,mt.exec_path,a.delay,mt.gsm_modem,mt.username,mt.passwd from alerts a,media_type mt where a.status=%d and a.retries<3 and a.mediatypeid=mt.mediatypeid and " ZBX_COND_NODEID " order by a.clock", + ALERT_STATUS_NOT_SENT, + LOCAL_NODE("mt.mediatypeid")); while((row=DBfetch(result))) { @@ -219,16 +243,23 @@ int main_alerter_loop() if(res==SUCCEED) { - zabbix_log( LOG_LEVEL_DEBUG, "Alert ID [" ZBX_FS_UI64 "] was sent successfully", alert.alertid); + zabbix_log( LOG_LEVEL_DEBUG, "Alert ID [" ZBX_FS_UI64 "] was sent successfully", + alert.alertid); DBexecute("update alerts set status=%d where status=%d and alertid=" ZBX_FS_UI64, - ALERT_STATUS_SENT, ALERT_STATUS_NOT_SENT, alert.alertid); + ALERT_STATUS_SENT, + ALERT_STATUS_NOT_SENT, + alert.alertid); } else { - zabbix_log( LOG_LEVEL_DEBUG, "Error sending alert ID [" ZBX_FS_UI64 "]", alert.alertid); - zabbix_syslog("Error sending alert ID [" ZBX_FS_UI64 "]", alert.alertid); + zabbix_log( LOG_LEVEL_DEBUG, "Error sending alert ID [" ZBX_FS_UI64 "]", + alert.alertid); + zabbix_syslog("Error sending alert ID [" ZBX_FS_UI64 "]", + alert.alertid); DBescape_string(error,error_esc,MAX_STRING_LEN); - DBexecute("update alerts set retries=retries+1,error='%s' where alertid=" ZBX_FS_UI64, error_esc, alert.alertid); + DBexecute("update alerts set retries=retries+1,error='%s' where alertid=" ZBX_FS_UI64, + error_esc, + alert.alertid); } } @@ -236,7 +267,8 @@ int main_alerter_loop() DBclose(); - zbx_setproctitle("sender [sleeping for %d seconds]", CONFIG_SENDER_FREQUENCY); + zbx_setproctitle("sender [sleeping for %d seconds]", + CONFIG_SENDER_FREQUENCY); sleep(CONFIG_SENDER_FREQUENCY); } diff --git a/src/zabbix_server/discoverer/discoverer.c b/src/zabbix_server/discoverer/discoverer.c index e916093b..08dd1a89 100644 --- a/src/zabbix_server/discoverer/discoverer.c +++ b/src/zabbix_server/discoverer/discoverer.c @@ -187,12 +187,13 @@ static void register_host(DB_DHOST *host,DB_DCHECK *check, zbx_uint64_t druleid, /* Add host only if service is up */ if(check->status == SERVICE_UP) { + zabbix_log(LOG_LEVEL_WARNING, "New host discovered at %s", + ip); host->dhostid = DBget_maxid("dhosts","dhostid"); DBexecute("insert into dhosts (dhostid,druleid,ip) values (" ZBX_FS_UI64 "," ZBX_FS_UI64 ",'%s')", host->dhostid, druleid, ip); - zabbix_log(LOG_LEVEL_WARNING, "New host discovered at %s", ip); host->druleid = druleid; strscpy(host->ip,ip); host->status = 0; @@ -239,7 +240,9 @@ static void update_service(DB_DRULE *rule, DB_DCHECK *check, char *ip, int port) DB_DHOST host; zabbix_log(LOG_LEVEL_WARNING, "In update_check(ip:%s, port:%d, status:%s)", - ip, port, (check->status==SERVICE_UP?"up":"down")); + ip, + port, + (check->status==SERVICE_UP?"up":"down")); /* Register host if is not registered yet */ register_host(&host,check,rule->druleid,ip); @@ -299,7 +302,8 @@ static void update_service(DB_DRULE *rule, DB_DCHECK *check, char *ip, int port) { if(host.status == SERVICE_UP && (host.lastup<=now-rule->upevent)) { - zabbix_log(LOG_LEVEL_WARNING, "Generating host event for %s", host.ip); + zabbix_log(LOG_LEVEL_WARNING, "Generating host event for %s", + host.ip); host.eventsent=1; update_dhost(&host); @@ -307,7 +311,8 @@ static void update_service(DB_DRULE *rule, DB_DCHECK *check, char *ip, int port) } if(host.status == SERVICE_DOWN && (host.lastdown<=now-rule->downevent)) { - zabbix_log(LOG_LEVEL_WARNING, "Generating host event for %s", host.ip); + zabbix_log(LOG_LEVEL_WARNING, "Generating host event for %s", + host.ip); host.eventsent=1; update_dhost(&host); } @@ -338,37 +343,57 @@ static int discover_service(zbx_dservice_type_t type, char *ip, int port) zabbix_log(LOG_LEVEL_DEBUG, "In discover_service(ip:%s, port:%d, type:%d)", - ip, port, type); + ip, + port, + type); init_result(&value); switch(type) { case SVC_SSH: - zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[ssh,%s,%d]", ip, port); + zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[ssh,%s,%d]", + ip, + port); break; case SVC_LDAP: - zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[ldap,%s,%d]", ip, port); + zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[ldap,%s,%d]", + ip, + port); break; case SVC_SMTP: - zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[smtp,%s,%d]", ip, port); + zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[smtp,%s,%d]", + ip, + port); break; case SVC_FTP: - zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[ftp,%s,%d]", ip, port); + zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[ftp,%s,%d]", + ip, + port); break; case SVC_HTTP: - zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[http,%s,%d]", ip, port); + zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[http,%s,%d]", + ip, + port); break; case SVC_POP: - zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[pop,%s,%d]", ip, port); + zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[pop,%s,%d]", + ip, + port); break; case SVC_NNTP: - zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[nntp,%s,%d]", ip, port); + zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[nntp,%s,%d]", + ip, + port); break; case SVC_IMAP: - zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[imap,%s,%d]", ip, port); + zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[imap,%s,%d]", + ip, + port); break; case SVC_TCP: - zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[tcp,%s,%d]", ip, port); + zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[tcp,%s,%d]", + ip, + port); break; default: ret = FAIL; @@ -423,9 +448,12 @@ static void process_check(DB_DRULE *rule, DB_DCHECK *check, char *ip) int first,last; zabbix_log(LOG_LEVEL_WARNING, "In process_check(ip:%s, ports:%s, type:%d)", - ip, check->ports, check->type); + ip, + check->ports, + check->type); - zbx_snprintf(tmp,sizeof(tmp)-1,"%s",check->ports); + zbx_snprintf(tmp,sizeof(tmp)-1,"%s", + check->ports); s=(char *)strtok(tmp,","); while(s!=NULL) @@ -446,7 +474,8 @@ static void process_check(DB_DRULE *rule, DB_DCHECK *check, char *ip) for(port=first;port<=last;port++) { - zabbix_log(LOG_LEVEL_WARNING, "Port %d", port); + zabbix_log(LOG_LEVEL_WARNING, "Port %d", + port); check->status = discover_service(check->type,ip,port); update_service(rule, check, ip, port); } @@ -484,7 +513,8 @@ static void process_rule(DB_DRULE *rule) int i; - zabbix_log( LOG_LEVEL_DEBUG, "In process_rule(name:%s)", rule->name); + zabbix_log( LOG_LEVEL_DEBUG, "In process_rule(name:%s)", + rule->name); result = DBselect("select dcheckid,druleid,type,ports from dchecks where druleid=" ZBX_FS_UI64, rule->druleid); @@ -502,7 +532,9 @@ static void process_rule(DB_DRULE *rule) c[0] = 0; for(i=first;i<=last;i++) { - zbx_snprintf(ip,MAX_STRING_LEN-1,"%s.%d",rule->ipfirst, i); + zbx_snprintf(ip,MAX_STRING_LEN-1,"%s.%d", + rule->ipfirst, + i); process_check(rule, &check, ip); } @@ -536,7 +568,8 @@ void main_discoverer_loop(int num) DB_ROW row; DB_DRULE rule; - zabbix_log( LOG_LEVEL_DEBUG, "In main_discoverer_loop(num:%d)", num); + zabbix_log( LOG_LEVEL_DEBUG, "In main_discoverer_loop(num:%d)", + num); discoverer_num = num; diff --git a/src/zabbix_server/expression.c b/src/zabbix_server/expression.c index 3f04b00d..e4de517a 100644 --- a/src/zabbix_server/expression.c +++ b/src/zabbix_server/expression.c @@ -675,14 +675,18 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i if(!row || DBis_null(row[0])==SUCCEED) { - zabbix_log( LOG_LEVEL_ERR, "No PROFILE.DEVECETYPE in substitute_simple_macros. Triggerid [%d]", event->objectid); - zabbix_syslog("No PROFILE.DEVECETYPE in substitute_simple_macros. Triggerid [%d]", event->objectid); + zabbix_log( LOG_LEVEL_ERR, "No PROFILE.DEVECETYPE in substitute_simple_macros. Triggerid [%d]", + event->objectid); + zabbix_syslog("No PROFILE.DEVECETYPE in substitute_simple_macros. Triggerid [%d]", + event->objectid); - replace_to = zbx_dsprintf(replace_to, "%s", STR_UNKNOWN_VARIABLE); + replace_to = zbx_dsprintf(replace_to, "%s", + STR_UNKNOWN_VARIABLE); } else { - replace_to = zbx_dsprintf(replace_to, "%s", row[0]); + replace_to = zbx_dsprintf(replace_to, "%s", + row[0]); } DBfree_result(result); } @@ -699,14 +703,18 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i if(!row || DBis_null(row[0])==SUCCEED) { - zabbix_log( LOG_LEVEL_ERR, "No PROFILE.NAME in substitute_simple_macros. Triggerid [%d]", event->objectid); - zabbix_syslog("No PROFILE.NAME in substitute_simple_macros. Triggerid [%d]", event->objectid); + zabbix_log( LOG_LEVEL_ERR, "No PROFILE.NAME in substitute_simple_macros. Triggerid [%d]", + event->objectid); + zabbix_syslog("No PROFILE.NAME in substitute_simple_macros. Triggerid [%d]", + event->objectid); - replace_to = zbx_dsprintf(replace_to, "%s", STR_UNKNOWN_VARIABLE); + replace_to = zbx_dsprintf(replace_to, "%s", + STR_UNKNOWN_VARIABLE); } else { - replace_to = zbx_dsprintf(replace_to, "%s", row[0]); + replace_to = zbx_dsprintf(replace_to, "%s", + row[0]); } DBfree_result(result); } @@ -723,14 +731,18 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i if(!row || DBis_null(row[0])==SUCCEED) { - zabbix_log( LOG_LEVEL_ERR, "No PROFILE.OS in substitute_simple_macros. Triggerid [%d]", event->objectid); - zabbix_syslog("No PROFILE.OS in substitute_simple_macros. Triggerid [%d]", event->objectid); + zabbix_log( LOG_LEVEL_ERR, "No PROFILE.OS in substitute_simple_macros. Triggerid [%d]", + event->objectid); + zabbix_syslog("No PROFILE.OS in substitute_simple_macros. Triggerid [%d]", + event->objectid); - replace_to = zbx_dsprintf(replace_to, "%s", STR_UNKNOWN_VARIABLE); + replace_to = zbx_dsprintf(replace_to, "%s", + STR_UNKNOWN_VARIABLE); } else { - replace_to = zbx_dsprintf(replace_to, "%s", row[0]); + replace_to = zbx_dsprintf(replace_to, "%s", + row[0]); } DBfree_result(result); } @@ -747,14 +759,18 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i if(!row || DBis_null(row[0])==SUCCEED) { - zabbix_log( LOG_LEVEL_ERR, "No PROFILE.SERIALNO in substitute_simple_macros. Triggerid [%d]", event->objectid); - zabbix_syslog("No PROFILE.SERIALNO in substitute_simple_macros. Triggerid [%d]", event->objectid); + zabbix_log( LOG_LEVEL_ERR, "No PROFILE.SERIALNO in substitute_simple_macros. Triggerid [%d]", + event->objectid); + zabbix_syslog("No PROFILE.SERIALNO in substitute_simple_macros. Triggerid [%d]", + event->objectid); - replace_to = zbx_dsprintf(replace_to, "%s", STR_UNKNOWN_VARIABLE); + replace_to = zbx_dsprintf(replace_to, "%s", + STR_UNKNOWN_VARIABLE); } else { - replace_to = zbx_dsprintf(replace_to, "%s", row[0]); + replace_to = zbx_dsprintf(replace_to, "%s", + row[0]); } DBfree_result(result); } @@ -771,14 +787,18 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i if(!row || DBis_null(row[0])==SUCCEED) { - zabbix_log( LOG_LEVEL_ERR, "No PROFILE.TAG in substitute_simple_macros. Triggerid [%d]", event->objectid); - zabbix_syslog("No PROFILE.TAG in substitute_simple_macros. Triggerid [%d]", event->objectid); + zabbix_log( LOG_LEVEL_ERR, "No PROFILE.TAG in substitute_simple_macros. Triggerid [%d]", + event->objectid); + zabbix_syslog("No PROFILE.TAG in substitute_simple_macros. Triggerid [%d]", + event->objectid); - replace_to = zbx_dsprintf(replace_to, "%s", STR_UNKNOWN_VARIABLE); + replace_to = zbx_dsprintf(replace_to, "%s", + STR_UNKNOWN_VARIABLE); } else { - replace_to = zbx_dsprintf(replace_to, "%s", row[0]); + replace_to = zbx_dsprintf(replace_to, "%s", + row[0]); } DBfree_result(result); } @@ -795,14 +815,18 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i if(!row || DBis_null(row[0])==SUCCEED) { - zabbix_log( LOG_LEVEL_ERR, "No PROFILE.MACADDRESS in substitute_simple_macros. Triggerid [%d]", event->objectid); - zabbix_syslog("No PROFILE.MACADDRESS in substitute_simple_macros. Triggerid [%d]", event->objectid); + zabbix_log( LOG_LEVEL_ERR, "No PROFILE.MACADDRESS in substitute_simple_macros. Triggerid [%d]", + event->objectid); + zabbix_syslog("No PROFILE.MACADDRESS in substitute_simple_macros. Triggerid [%d]", + event->objectid); - replace_to = zbx_dsprintf(replace_to, "%s", STR_UNKNOWN_VARIABLE); + replace_to = zbx_dsprintf(replace_to, "%s", + STR_UNKNOWN_VARIABLE); } else { - replace_to = zbx_dsprintf(replace_to, "%s", row[0]); + replace_to = zbx_dsprintf(replace_to, "%s", + row[0]); } DBfree_result(result); } @@ -819,14 +843,18 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i if(!row || DBis_null(row[0])==SUCCEED) { - zabbix_log( LOG_LEVEL_ERR, "No PROFILE.HARDWARE in substitute_simple_macros. Triggerid [%d]", event->objectid); - zabbix_syslog("No PROFILE.HARDWARE in substitute_simple_macros. Triggerid [%d]", event->objectid); + zabbix_log( LOG_LEVEL_ERR, "No PROFILE.HARDWARE in substitute_simple_macros. Triggerid [%d]", + event->objectid); + zabbix_syslog("No PROFILE.HARDWARE in substitute_simple_macros. Triggerid [%d]", + event->objectid); - replace_to = zbx_dsprintf(replace_to, "%s", STR_UNKNOWN_VARIABLE); + replace_to = zbx_dsprintf(replace_to, "%s", + STR_UNKNOWN_VARIABLE); } else { - replace_to = zbx_dsprintf(replace_to, "%s", row[0]); + replace_to = zbx_dsprintf(replace_to, "%s", + row[0]); } DBfree_result(result); } @@ -843,14 +871,18 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i if(!row || DBis_null(row[0])==SUCCEED) { - zabbix_log( LOG_LEVEL_ERR, "No PROFILE.SOFTWARE in substitute_simple_macros. Triggerid [%d]", event->objectid); - zabbix_syslog("No PROFILE.SOFTWARE in substitute_simple_macros. Triggerid [%d]", event->objectid); + zabbix_log( LOG_LEVEL_ERR, "No PROFILE.SOFTWARE in substitute_simple_macros. Triggerid [%d]", + event->objectid); + zabbix_syslog("No PROFILE.SOFTWARE in substitute_simple_macros. Triggerid [%d]", + event->objectid); - replace_to = zbx_dsprintf(replace_to, "%s", STR_UNKNOWN_VARIABLE); + replace_to = zbx_dsprintf(replace_to, "%s", + STR_UNKNOWN_VARIABLE); } else { - replace_to = zbx_dsprintf(replace_to, "%s", row[0]); + replace_to = zbx_dsprintf(replace_to, "%s", + row[0]); } DBfree_result(result); } @@ -867,14 +899,18 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i if(!row || DBis_null(row[0])==SUCCEED) { - zabbix_log( LOG_LEVEL_ERR, "No PROFILE.CONTACT in substitute_simple_macros. Triggerid [%d]", event->objectid); - zabbix_syslog("No PROFILE.CONTACT in substitute_simple_macros. Triggerid [%d]", event->objectid); + zabbix_log( LOG_LEVEL_ERR, "No PROFILE.CONTACT in substitute_simple_macros. Triggerid [%d]", + event->objectid); + zabbix_syslog("No PROFILE.CONTACT in substitute_simple_macros. Triggerid [%d]", + event->objectid); - replace_to = zbx_dsprintf(replace_to, "%s", STR_UNKNOWN_VARIABLE); + replace_to = zbx_dsprintf(replace_to, "%s", + STR_UNKNOWN_VARIABLE); } else { - replace_to = zbx_dsprintf(replace_to, "%s", row[0]); + replace_to = zbx_dsprintf(replace_to, "%s", + row[0]); } DBfree_result(result); } @@ -891,14 +927,18 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i if(!row || DBis_null(row[0])==SUCCEED) { - zabbix_log( LOG_LEVEL_ERR, "No PROFILE.LOCATION in substitute_simple_macros. Triggerid [%d]", event->objectid); - zabbix_syslog("No PROFILE.LOCATION in substitute_simple_macros. Triggerid [%d]", event->objectid); + zabbix_log( LOG_LEVEL_ERR, "No PROFILE.LOCATION in substitute_simple_macros. Triggerid [%d]", + event->objectid); + zabbix_syslog("No PROFILE.LOCATION in substitute_simple_macros. Triggerid [%d]", + event->objectid); - replace_to = zbx_dsprintf(replace_to, "%s", STR_UNKNOWN_VARIABLE); + replace_to = zbx_dsprintf(replace_to, "%s", + STR_UNKNOWN_VARIABLE); } else { - replace_to = zbx_dsprintf(replace_to, "%s", row[0]); + replace_to = zbx_dsprintf(replace_to, "%s", + row[0]); } DBfree_result(result); } @@ -915,14 +955,18 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i if(!row || DBis_null(row[0])==SUCCEED) { - zabbix_log( LOG_LEVEL_ERR, "No PROFILE.NOTES in substitute_simple_macros. Triggerid [%d]", event->objectid); - zabbix_syslog("No PROFILE.NOTES in substitute_simple_macros. Triggerid [%d]", event->objectid); + zabbix_log( LOG_LEVEL_ERR, "No PROFILE.NOTES in substitute_simple_macros. Triggerid [%d]", + event->objectid); + zabbix_syslog("No PROFILE.NOTES in substitute_simple_macros. Triggerid [%d]", + event->objectid); - replace_to = zbx_dsprintf(replace_to, "%s", STR_UNKNOWN_VARIABLE); + replace_to = zbx_dsprintf(replace_to, "%s", + STR_UNKNOWN_VARIABLE); } else { - replace_to = zbx_dsprintf(replace_to, "%s", row[0]); + replace_to = zbx_dsprintf(replace_to, "%s", + row[0]); } DBfree_result(result); } @@ -944,11 +988,13 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i zabbix_syslog("No hostname in substitute_simple_macros. Triggerid [" ZBX_FS_UI64 "]", event->objectid); - replace_to = zbx_dsprintf(replace_to, "%s", STR_UNKNOWN_VARIABLE); + replace_to = zbx_dsprintf(replace_to, "%s", + STR_UNKNOWN_VARIABLE); } else { - replace_to = zbx_dsprintf(replace_to, "%s", row[0]); + replace_to = zbx_dsprintf(replace_to, "%s", + row[0]); } DBfree_result(result); } @@ -959,7 +1005,8 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i result = DBselect("select distinct i.description from triggers t, functions f,items i, hosts h" " where t.triggerid=" ZBX_FS_UI64 " and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid" - " order by i.description", event->objectid); + " order by i.description", + event->objectid); row=DBfetch(result); @@ -970,11 +1017,13 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i zabbix_syslog("No ITEM.NAME in substitute_simple_macros. Triggerid [" ZBX_FS_UI64 "]", event->objectid); - replace_to = zbx_dsprintf(replace_to, STR_UNKNOWN_VARIABLE); + replace_to = zbx_dsprintf(replace_to, "%S", + STR_UNKNOWN_VARIABLE); } else { - replace_to = zbx_dsprintf(replace_to, "%s", row[0]); + replace_to = zbx_dsprintf(replace_to, "%s", + row[0]); } DBfree_result(result); @@ -986,7 +1035,8 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i result = DBselect("select distinct i.key_ from triggers t, functions f,items i, hosts h" " 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_", event->objectid); + " order by i.key_", + event->objectid); row=DBfetch(result); @@ -997,11 +1047,13 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i zabbix_syslog("No TRIGGER.KEY in substitute_simple_macros. Triggerid [" ZBX_FS_UI64 "]", event->objectid); - replace_to = zbx_dsprintf(replace_to, STR_UNKNOWN_VARIABLE); + replace_to = zbx_dsprintf(replace_to, "%s", + STR_UNKNOWN_VARIABLE); } else { - replace_to = zbx_dsprintf(replace_to, "%s", row[0]); + replace_to = zbx_dsprintf(replace_to, "%s", + row[0]); } DBfree_result(result); @@ -1024,11 +1076,13 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i zabbix_syslog("No hostname in substitute_simple_macros. Triggerid [" ZBX_FS_UI64 "]", event->objectid); - replace_to = zbx_dsprintf(replace_to, "%s", STR_UNKNOWN_VARIABLE); + replace_to = zbx_dsprintf(replace_to, "%s", + STR_UNKNOWN_VARIABLE); } else { - replace_to = zbx_dsprintf(replace_to, "%s", row[0]); + replace_to = zbx_dsprintf(replace_to, "%s", + row[0]); } DBfree_result(result); } @@ -1039,7 +1093,10 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i now = time(NULL); tm = localtime(&now); - replace_to = zbx_dsprintf(replace_to, "%.4d.%.2d.%.2d", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday); + replace_to = zbx_dsprintf(replace_to, "%.4d.%.2d.%.2d", + tm->tm_year+1900, + tm->tm_mon+1, + tm->tm_mday); } else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY)&& strncmp(pr, MVAR_TIME, strlen(MVAR_TIME)) == 0) @@ -1048,7 +1105,10 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i now = time(NULL); tm = localtime(&now); - replace_to = zbx_dsprintf(replace_to, "%.2d:%.2d:%.2d",tm->tm_hour,tm->tm_min,tm->tm_sec); + replace_to = zbx_dsprintf(replace_to, "%.2d:%.2d:%.2d", + tm->tm_hour, + tm->tm_min, + tm->tm_sec); } else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) && @@ -1075,14 +1135,16 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i /* NOTE: if you make changes for this bloc, don't forgot MVAR_TRIGGER_STATUS block */ var_len = strlen(MVAR_TRIGGER_ID); - replace_to = zbx_dsprintf(replace_to, ZBX_FS_UI64, event->objectid); + replace_to = zbx_dsprintf(replace_to, ZBX_FS_UI64, + event->objectid); } else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY | MACRO_TYPE_TRIGGER_EXPRESSION) && strncmp(pr, MVAR_TRIGGER_VALUE, strlen(MVAR_TRIGGER_VALUE)) == 0) { var_len = strlen(MVAR_TRIGGER_VALUE); - replace_to = zbx_dsprintf(replace_to, ZBX_FS_UI64, event->value); + replace_to = zbx_dsprintf(replace_to, ZBX_FS_UI64, + event->value); } else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) && strncmp(pr, MVAR_TRIGGER_URL, strlen(MVAR_TRIGGER_URL)) == 0) @@ -1090,7 +1152,8 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i /* NOTE: if you make changes for this bloc, don't forgot MVAR_TRIGGER_STATUS block */ var_len = strlen(MVAR_TRIGGER_URL); - replace_to = zbx_dsprintf(replace_to, "%s", event->trigger_url); + replace_to = zbx_dsprintf(replace_to, "%s", + event->trigger_url); } else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) && strncmp(pr, MVAR_EVENT_ID, strlen(MVAR_EVENT_ID)) == 0) @@ -1098,7 +1161,8 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i /* NOTE: if you make changes for this bloc, don't forgot MVAR_TRIGGER_STATUS block */ var_len = strlen(MVAR_EVENT_ID); - replace_to = zbx_dsprintf(replace_to, ZBX_FS_UI64, event->eventid); + replace_to = zbx_dsprintf(replace_to, ZBX_FS_UI64, + event->eventid); } else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) && strncmp(pr, MVAR_TRIGGER_SEVERITY, strlen(MVAR_TRIGGER_SEVERITY)) == 0) @@ -1125,7 +1189,8 @@ void substitute_simple_macros(DB_EVENT *event, DB_ACTION *action, char **data, i *data = str_out; - zabbix_log(LOG_LEVEL_DEBUG, "In substitute_simple_macros [result:%s]",*data); + zabbix_log(LOG_LEVEL_DEBUG, "In substitute_simple_macros (result:%s)", + *data); } /****************************************************************************** @@ -1163,7 +1228,8 @@ void substitute_macros(DB_EVENT *event, DB_ACTION *action, char **data) if(!data || !*data) return; - zabbix_log(LOG_LEVEL_DEBUG, "In substitute_macros([%s])",*data); + zabbix_log(LOG_LEVEL_DEBUG, "In substitute_macros(data:%s)", + *data); if('\0' == *data[0]) return; @@ -1239,7 +1305,8 @@ void substitute_macros(DB_EVENT *event, DB_ACTION *action, char **data) *data = str_out; - zabbix_log( LOG_LEVEL_DEBUG, "Result expression:%s", *data ); + zabbix_log( LOG_LEVEL_DEBUG, "End substitute_macros(result:%s)", + *data ); } /****************************************************************************** @@ -1269,7 +1336,8 @@ int substitute_functions(char **exp, char *error, int maxerrlen) char *out = NULL; char c; - zabbix_log(LOG_LEVEL_DEBUG, "In substitute_functions(%s)", *exp); + zabbix_log(LOG_LEVEL_DEBUG, "In substitute_functions(%s)", + *exp); i = 0; len = strlen(*exp); @@ -1285,9 +1353,12 @@ int substitute_functions(char **exp, char *error, int maxerrlen) if( DBget_function_result( &value, functionid ) != SUCCEED ) { /* It may happen because of functions.lastvalue is NULL, so this is not warning */ - zbx_snprintf(error,maxerrlen, "Unable to get value for functionid [%s]", functionid); - zabbix_log( LOG_LEVEL_DEBUG, "%s", error); - zabbix_syslog("%s", error); + zbx_snprintf(error,maxerrlen, "Unable to get value for functionid [%s]", + functionid); + zabbix_log( LOG_LEVEL_DEBUG, "%s", + error); + zabbix_syslog("%s", + error); return FAIL; } out = zbx_strdcat(out,value); @@ -1305,7 +1376,8 @@ int substitute_functions(char **exp, char *error, int maxerrlen) zbx_free(*exp); *exp = out; - zabbix_log( LOG_LEVEL_DEBUG, "End substitute_functions [%s]", *exp ); + zabbix_log( LOG_LEVEL_DEBUG, "End substitute_functions [%s]", + *exp); return SUCCEED; } @@ -1336,7 +1408,8 @@ int evaluate_expression(int *result,char **expression, int trigger_value, char * DB_EVENT event; DB_ACTION action; - zabbix_log(LOG_LEVEL_DEBUG, "In evaluate_expression(%s)", *expression ); + zabbix_log(LOG_LEVEL_DEBUG, "In evaluate_expression(%s)", + *expression); /* Substitute macros first */ memset(&event,0,sizeof(DB_EVENT)); @@ -1351,12 +1424,17 @@ int evaluate_expression(int *result,char **expression, int trigger_value, char * { if( evaluate(result, *expression, error, maxerrlen) == SUCCEED) { - zabbix_log(LOG_LEVEL_DEBUG, "End evaluate_expression(result:%d)", *result); + zabbix_log(LOG_LEVEL_DEBUG, "End evaluate_expression(result:%d)", + *result); return SUCCEED; } } - zabbix_log(LOG_LEVEL_DEBUG, "Evaluation of expression [%s] failed [%s]", *expression, error ); - zabbix_syslog("Evaluation of expression [%s] failed [%s]", *expression, error ); + zabbix_log(LOG_LEVEL_DEBUG, "Evaluation of expression [%s] failed [%s]", + *expression, + error); + zabbix_syslog("Evaluation of expression [%s] failed [%s]", + *expression, + error); zabbix_log(LOG_LEVEL_DEBUG, "End evaluate_expression(result:FAIL)"); return FAIL; diff --git a/src/zabbix_server/functions.c b/src/zabbix_server/functions.c index fece277e..62f9ebed 100644 --- a/src/zabbix_server/functions.c +++ b/src/zabbix_server/functions.c @@ -93,12 +93,15 @@ void update_functions(DB_ITEM *item) lastvalue=row[3]; zabbix_log( LOG_LEVEL_DEBUG, "ItemId:" ZBX_FS_UI64 " Evaluating %s(%d)", - function.itemid,function.function,function.parameter); + function.itemid, + function.function, + function.parameter); ret = evaluate_function(value,item,function.function,function.parameter); if( FAIL == ret) { - zabbix_log( LOG_LEVEL_DEBUG, "Evaluation failed for function:%s",function.function); + zabbix_log( LOG_LEVEL_DEBUG, "Evaluation failed for function:%s", + function.function); continue; } if (ret == SUCCEED) @@ -108,7 +111,10 @@ void update_functions(DB_ITEM *item) { DBescape_string(value,value_esc,MAX_STRING_LEN); 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 ); + value_esc, + function.itemid, + function.function, + function.parameter ); } else { @@ -199,12 +205,15 @@ void update_services_rec(zbx_uint64_t serviceid) now=time(NULL); DBadd_service_alarm(serviceupid,status,now); DBexecute("update services set status=%d where serviceid=" ZBX_FS_UI64, - status,serviceupid); + status, + serviceupid); } else { - zabbix_log( LOG_LEVEL_ERR, "Unknown calculation algorithm of service status [%d]", algorithm); - zabbix_syslog("Unknown calculation algorithm of service status [%d]", algorithm); + zabbix_log( LOG_LEVEL_ERR, "Unknown calculation algorithm of service status [%d]", + algorithm); + zabbix_syslog("Unknown calculation algorithm of service status [%d]", + algorithm); } } DBfree_result(result); @@ -244,7 +253,8 @@ void update_services(zbx_uint64_t triggerid, int status) DB_RESULT result; DBexecute("update services set status=%d where triggerid=" ZBX_FS_UI64, - status,triggerid); + status, + triggerid); result = DBselect("select serviceid from services where triggerid=" ZBX_FS_UI64, triggerid); @@ -283,9 +293,13 @@ void update_triggers(zbx_uint64_t itemid) DB_RESULT result; DB_ROW row; - zabbix_log( LOG_LEVEL_DEBUG, "In update_triggers [itemid:" ZBX_FS_UI64 "]", itemid); + zabbix_log( LOG_LEVEL_DEBUG, "In update_triggers [itemid:" ZBX_FS_UI64 "]", + itemid); - result = DBselect("select distinct t.triggerid,t.expression,t.status,t.dep_level,t.priority,t.value,t.description from triggers t,functions f,items i where i.status<>%d and i.itemid=f.itemid and t.status=%d and f.triggerid=t.triggerid and f.itemid=" ZBX_FS_UI64,ITEM_STATUS_NOTSUPPORTED, TRIGGER_STATUS_ENABLED, itemid); + result = DBselect("select distinct t.triggerid,t.expression,t.status,t.dep_level,t.priority,t.value,t.description from triggers t,functions f,items i where i.status<>%d and i.itemid=f.itemid and t.status=%d and f.triggerid=t.triggerid and f.itemid=" ZBX_FS_UI64, + ITEM_STATUS_NOTSUPPORTED, + TRIGGER_STATUS_ENABLED, + itemid); while((row=DBfetch(result))) { @@ -301,8 +315,12 @@ void update_triggers(zbx_uint64_t itemid) exp = strdup(trigger.expression); if( evaluate_expression(&exp_value, &exp, trigger.value, error, sizeof(error)) != 0 ) { - zabbix_log( LOG_LEVEL_WARNING, "Expression [%s] cannot be evaluated [%s]",trigger.expression, error); - zabbix_syslog("Expression [%s] cannot be evaluated [%s]",trigger.expression, error); + zabbix_log( LOG_LEVEL_WARNING, "Expression [%s] cannot be evaluated [%s]", + trigger.expression, + error); + zabbix_syslog("Expression [%s] cannot be evaluated [%s]", + trigger.expression, + error); /* DBupdate_trigger_value(&trigger, exp_value, time(NULL), error);*//* We shouldn't update triggervalue if expressions failed */ } else @@ -312,7 +330,8 @@ void update_triggers(zbx_uint64_t itemid) zbx_free(exp); } DBfree_result(result); - zabbix_log( LOG_LEVEL_DEBUG, "End update_triggers [%d]", itemid); + zabbix_log( LOG_LEVEL_DEBUG, "End update_triggers [" ZBX_FS_UI64 "]", + itemid); } void calc_timestamp(char *line,int *timestamp, char *format) @@ -360,7 +379,13 @@ void calc_timestamp(char *line,int *timestamp, char *format) } } - zabbix_log( LOG_LEVEL_DEBUG, "hh [%d] mm [%d] ss [%d] yyyy [%d] dd [%d] MM [%d]",hh,mm,ss,yyyy,dd,MM); + zabbix_log( LOG_LEVEL_DEBUG, "hh [%d] mm [%d] ss [%d] yyyy [%d] dd [%d] MM [%d]", + hh, + mm, + ss, + yyyy, + dd, + MM); if(hh!=0&&mm!=0&&ss!=0&&yyyy!=0&&dd!=0&&MM!=0) { @@ -377,8 +402,10 @@ void calc_timestamp(char *line,int *timestamp, char *format) *timestamp=t; } } - zabbix_log( LOG_LEVEL_DEBUG, "end timestamp [%d]", t); - zabbix_log( LOG_LEVEL_DEBUG, "end timestamp [%d]", *timestamp); + zabbix_log( LOG_LEVEL_DEBUG, "End timestamp [%d]", + t); + zabbix_log( LOG_LEVEL_DEBUG, "End timestamp [%d]", + *timestamp); } /****************************************************************************** @@ -414,27 +441,48 @@ int process_data(zbx_sock_t *sock,char *server,char *key,char *value,char *lastl char server_esc[MAX_STRING_LEN]; char key_esc[MAX_STRING_LEN]; - zabbix_log( LOG_LEVEL_DEBUG, "In process_data([%s],[%s],[%s],[%s])",server,key,value,lastlogsize); + zabbix_log( LOG_LEVEL_DEBUG, "In process_data([%s],[%s],[%s],[%s])", + server, + key, + value, + lastlogsize); init_result(&agent); DBescape_string(server, server_esc, MAX_STRING_LEN); DBescape_string(key, key_esc, MAX_STRING_LEN); - result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type in (%d,%d) and" ZBX_COND_NODEID, ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, server_esc, key_esc, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, LOCAL_NODE("h.hostid")); + result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type in (%d,%d) and" ZBX_COND_NODEID, + ZBX_SQL_ITEM_SELECT, + HOST_STATUS_MONITORED, + server_esc, + key_esc, + ITEM_STATUS_ACTIVE, + ITEM_TYPE_TRAPPER, + ITEM_TYPE_ZABBIX_ACTIVE, + LOCAL_NODE("h.hostid")); row=DBfetch(result); if(!row) { - zabbix_log( LOG_LEVEL_DEBUG, "Before checking autoregistration for [%s]",server); + zabbix_log( LOG_LEVEL_DEBUG, "Before checking autoregistration for [%s]", + server); if(autoregister(server) == SUCCEED) { DBfree_result(result); /* Same SQL */ - result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type in (%d,%d) and" ZBX_COND_NODEID, ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, server_esc, key_esc, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, LOCAL_NODE("h.hostid")); + result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type in (%d,%d) and" ZBX_COND_NODEID, + ZBX_SQL_ITEM_SELECT, + HOST_STATUS_MONITORED, + server_esc, + key_esc, + ITEM_STATUS_ACTIVE, + ITEM_TYPE_TRAPPER, + ITEM_TYPE_ZABBIX_ACTIVE, + LOCAL_NODE("h.hostid")); row = DBfetch(result); if(!row) { @@ -457,12 +505,17 @@ int process_data(zbx_sock_t *sock,char *server,char *key,char *value,char *lastl return FAIL; } - zabbix_log( LOG_LEVEL_DEBUG, "Processing [%s]", value); + zabbix_log( LOG_LEVEL_DEBUG, "Processing [%s]", + value); if(strcmp(value,"ZBX_NOTSUPPORTED") ==0) { - zabbix_log( LOG_LEVEL_WARNING, "Active parameter [%s] is not supported by agent on host [%s]", item.key, item.host_name); - zabbix_syslog("Active parameter [%s] is not supported by agent on host [%s]", item.key, item.host_name); + zabbix_log( LOG_LEVEL_WARNING, "Active parameter [%s] is not supported by agent on host [%s]", + item.key, + item.host_name); + zabbix_syslog("Active parameter [%s] is not supported by agent on host [%s]", + item.key, + item.host_name); DBupdate_item_status_to_notsupported(item.itemid, "Not supported by agent"); } @@ -478,7 +531,10 @@ int process_data(zbx_sock_t *sock,char *server,char *key,char *value,char *lastl item.eventlog_severity=atoi(severity); item.eventlog_source=source; - zabbix_log(LOG_LEVEL_DEBUG, "Value [%s] Lastlogsize [%s] Timestamp [%s]", value, lastlogsize, timestamp); + zabbix_log(LOG_LEVEL_DEBUG, "Value [%s] Lastlogsize [%s] Timestamp [%s]", + value, + lastlogsize, + timestamp); } if(set_result_type(&agent, item.value_type, value) == SUCCEED) @@ -488,8 +544,14 @@ int process_data(zbx_sock_t *sock,char *server,char *key,char *value,char *lastl } else { - zabbix_log( LOG_LEVEL_WARNING, "Type of received value [%s] is not suitable for [%s@%s]", value, item.key, item.host_name); - zabbix_syslog("Type of received value [%s] is not suitable for [%s@%s]", value, item.key, item.host_name); + zabbix_log( LOG_LEVEL_WARNING, "Type of received value [%s] is not suitable for [%s@%s]", + value, + item.key, + item.host_name); + zabbix_syslog("Type of received value [%s] is not suitable for [%s@%s]", + value, + item.key, + item.host_name); } DBfree_result(result); @@ -518,16 +580,27 @@ static int add_history(DB_ITEM *item, AGENT_RESULT *value, int now) { int ret = SUCCEED; - zabbix_log( LOG_LEVEL_DEBUG, "In add_history(%s,,%X,%X)", item->key, item->value_type,value->type); + zabbix_log( LOG_LEVEL_DEBUG, "In add_history(%s,,%X,%X)", + item->key, + item->value_type, + value->type); if(value->type & AR_UINT64) - zabbix_log( LOG_LEVEL_DEBUG, "In add_history(%d,UINT64:" ZBX_FS_UI64 ")", item->itemid, value->ui64); + zabbix_log( LOG_LEVEL_DEBUG, "In add_history(%d,UINT64:" ZBX_FS_UI64 ")", + item->itemid, + value->ui64); if(value->type & AR_STRING) - zabbix_log( LOG_LEVEL_DEBUG, "In add_history(%d,STRING:%s)", item->itemid, value->str); + zabbix_log( LOG_LEVEL_DEBUG, "In add_history(%d,STRING:%s)", + item->itemid, + value->str); if(value->type & AR_DOUBLE) - zabbix_log( LOG_LEVEL_DEBUG, "In add_history(%d,DOUBLE:" ZBX_FS_DBL ")", item->itemid, value->dbl); + zabbix_log( LOG_LEVEL_DEBUG, "In add_history(%d,DOUBLE:" ZBX_FS_DBL ")", + item->itemid, + value->dbl); if(value->type & AR_TEXT) - zabbix_log( LOG_LEVEL_DEBUG, "In add_history(%d,TEXT:[%s])", item->itemid, value->text); + zabbix_log( LOG_LEVEL_DEBUG, "In add_history(%d,TEXT:[%s])", + item->itemid, + value->text); if(item->history>0) { @@ -593,8 +666,12 @@ static int add_history(DB_ITEM *item, AGENT_RESULT *value, int now) } else { - zabbix_log(LOG_LEVEL_ERR, "Value not stored for itemid [%d]. Unknown delta [%d]", item->itemid, item->delta); - zabbix_syslog("Value not stored for itemid [%d]. Unknown delta [%d]", item->itemid, item->delta); + zabbix_log(LOG_LEVEL_ERR, "Value not stored for itemid [%d]. Unknown delta [%d]", + item->itemid, + item->delta); + zabbix_syslog("Value not stored for itemid [%d]. Unknown delta [%d]", + item->itemid, + item->delta); ret = FAIL; } } @@ -608,7 +685,8 @@ static int add_history(DB_ITEM *item, AGENT_RESULT *value, int now) if(GET_STR_RESULT(value)) DBadd_history_log(item->itemid,value->str,now,item->timestamp,item->eventlog_source,item->eventlog_severity); DBexecute("update items set lastlogsize=%d where itemid=" ZBX_FS_UI64, - item->lastlogsize,item->itemid); + item->lastlogsize, + item->itemid); } else if(item->value_type==ITEM_VALUE_TYPE_TEXT) { @@ -618,7 +696,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 [" ZBX_FS_UI64 "]", - item->value_type,item->itemid); + item->value_type, + item->itemid); } } @@ -781,10 +860,16 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, time_t now) /* Update item status if required */ if(item->status == ITEM_STATUS_NOTSUPPORTED) { - zabbix_log( LOG_LEVEL_WARNING, "Parameter [%s] became supported by agent on host [%s]", item->key, item->host_name); - zabbix_syslog("Parameter [%s] became supported by agent on host [%s]", item->key, item->host_name); + zabbix_log( LOG_LEVEL_WARNING, "Parameter [%s] became supported by agent on host [%s]", + item->key, + item->host_name); + zabbix_syslog("Parameter [%s] became supported by agent on host [%s]", + item->key, + item->host_name); item->status = ITEM_STATUS_ACTIVE; - DBexecute("update items set status=%d where itemid=" ZBX_FS_UI64, ITEM_STATUS_ACTIVE, item->itemid); + DBexecute("update items set status=%d where itemid=" ZBX_FS_UI64, + ITEM_STATUS_ACTIVE, + item->itemid); } /* Required for nodata() */ @@ -813,7 +898,8 @@ void process_new_value(DB_ITEM *item, AGENT_RESULT *value) { time_t now; - zabbix_log( LOG_LEVEL_DEBUG, "In process_new_value(%s)", item->key); + zabbix_log( LOG_LEVEL_DEBUG, "In process_new_value(%s)", + item->key); now = time(NULL); diff --git a/src/zabbix_server/housekeeper/housekeeper.c b/src/zabbix_server/housekeeper/housekeeper.c index a1948953..0df5b952 100644 --- a/src/zabbix_server/housekeeper/housekeeper.c +++ b/src/zabbix_server/housekeeper/housekeeper.c @@ -63,7 +63,10 @@ static int housekeeping_process_log() ZBX_STR2UINT64(housekeeper.value,row[3]); #ifdef HAVE_ORACLE - deleted = DBexecute("delete from %s where %s=" ZBX_FS_UI64 " and rownum<500",housekeeper.tablename, housekeeper.field,housekeeper.value); + deleted = DBexecute("delete from %s where %s=" ZBX_FS_UI64 " and rownum<500", + housekeeper.tablename, + housekeeper.field, + housekeeper.value); #elif defined(HAVE_POSTGRESQL) deleted = DBexecute("delete from %s where oid in (select oid from %s where %s=" ZBX_FS_UI64 " limit 500)", housekeeper.tablename, @@ -71,15 +74,21 @@ static int housekeeping_process_log() housekeeper.field, housekeeper.value); #else - deleted = DBexecute("delete from %s where %s=" ZBX_FS_UI64 " limit 500",housekeeper.tablename, housekeeper.field,housekeeper.value); + deleted = DBexecute("delete from %s where %s=" ZBX_FS_UI64 " limit 500", + housekeeper.tablename, + housekeeper.field, + housekeeper.value); #endif if(deleted == 0) { - DBexecute("delete from housekeeper where housekeeperid=%d",housekeeper.housekeeperid); + DBexecute("delete from housekeeper where housekeeperid=%d", + housekeeper.housekeeperid); } else { - zabbix_log( LOG_LEVEL_DEBUG, "Deleted [%ld] records from table [%s]", deleted, housekeeper.tablename); + zabbix_log( LOG_LEVEL_DEBUG, "Deleted [%ld] records from table [%s]", + deleted, + housekeeper.tablename); } } DBfree_result(result); @@ -92,11 +101,14 @@ static int housekeeping_sessions(int now) { int deleted; - zabbix_log( LOG_LEVEL_DEBUG, "In housekeeping_sessions(%d)", now); + zabbix_log( LOG_LEVEL_DEBUG, "In housekeeping_sessions(%d)", + now); - deleted = DBexecute("delete from sessions where lastaccess<%d",now-24*3600); + deleted = DBexecute("delete from sessions where lastaccess<%d", + now-24*3600); - zabbix_log( LOG_LEVEL_DEBUG, "Deleted [%ld] records from table [sessions]", deleted); + zabbix_log( LOG_LEVEL_DEBUG, "Deleted [%ld] records from table [sessions]", + deleted); return SUCCEED; } @@ -109,7 +121,8 @@ static int housekeeping_alerts(int now) int res = SUCCEED; int deleted; - zabbix_log( LOG_LEVEL_DEBUG, "In housekeeping_alerts(%d)", now); + zabbix_log( LOG_LEVEL_DEBUG, "In housekeeping_alerts(%d)", + now); result = DBselect("select alert_history from config"); @@ -124,8 +137,10 @@ static int housekeeping_alerts(int now) { alert_history=atoi(row[0]); - deleted = DBexecute("delete from alerts where clock<%d",now-24*3600*alert_history); - zabbix_log( LOG_LEVEL_DEBUG, "Deleted [%ld] records from table [alerts]", deleted); + deleted = DBexecute("delete from alerts where clock<%d", + now-24*3600*alert_history); + zabbix_log( LOG_LEVEL_DEBUG, "Deleted [%ld] records from table [alerts]", + deleted); } DBfree_result(result); @@ -142,7 +157,8 @@ static int housekeeping_events(int now) zbx_uint64_t eventid; int res = SUCCEED; - zabbix_log( LOG_LEVEL_DEBUG, "In housekeeping_events(%d)", now); + zabbix_log( LOG_LEVEL_DEBUG, "In housekeeping_events(%d)", + now); result = DBselect("select event_history from config"); @@ -157,14 +173,17 @@ static int housekeeping_events(int now) { event_history=atoi(row1[0]); - result2 = DBselect("select eventid from events where clock<%d", now-24*3600*event_history); + result2 = DBselect("select eventid from events where clock<%d", + now-24*3600*event_history); while((row2=DBfetch(result2))) { ZBX_STR2UINT64(eventid,row2[0]); - DBexecute("delete from acknowledges where eventid=" ZBX_FS_UI64,eventid); + DBexecute("delete from acknowledges where eventid=" ZBX_FS_UI64, + eventid); - DBexecute("delete from events where eventid=" ZBX_FS_UI64,eventid); + DBexecute("delete from events where eventid=" ZBX_FS_UI64, + eventid); } DBfree_result(result2); @@ -196,9 +215,15 @@ static int delete_history(char *table, int itemid, int keep_history, int now) DB_ROW row; int min_clock; - zabbix_log( LOG_LEVEL_DEBUG, "In delete_history(%s," ZBX_FS_UI64 ",%d,%d)", table, itemid, keep_history, now); + zabbix_log( LOG_LEVEL_DEBUG, "In delete_history(%s," ZBX_FS_UI64 ",%d,%d)", + table, + itemid, + keep_history, + now); - zbx_snprintf(sql,sizeof(sql)-1,"select min(clock) from %s where itemid=" ZBX_FS_UI64, table, itemid); + zbx_snprintf(sql,sizeof(sql)-1,"select min(clock) from %s where itemid=" ZBX_FS_UI64, + table, + itemid); result = DBselect(sql); row=DBfetch(result); @@ -247,7 +272,8 @@ static int housekeeping_history_and_trends(int now) int deleted = 0; - zabbix_log( LOG_LEVEL_DEBUG, "In housekeeping_history_and_trends(%d)", now); + zabbix_log( LOG_LEVEL_DEBUG, "In housekeeping_history_and_trends(%d)", + now); zbx_snprintf(sql,sizeof(sql)-1,"select itemid,history,trends from items"); result = DBselect(sql); @@ -307,7 +333,8 @@ int main_housekeeper_loop() /* zbx_setproctitle("housekeeper [removing old history]");*/ d = housekeeping_history_and_trends(now); - zabbix_log( LOG_LEVEL_WARNING, "Deleted %d records from history and trends", d); + zabbix_log( LOG_LEVEL_WARNING, "Deleted %d records from history and trends", + d); zbx_setproctitle("housekeeper [removing old history]"); @@ -331,12 +358,15 @@ int main_housekeeper_loop() DBvacuum(); - zabbix_log( LOG_LEVEL_DEBUG, "Sleeping for %d hours", CONFIG_HOUSEKEEPING_FREQUENCY); + zabbix_log( LOG_LEVEL_DEBUG, "Sleeping for %d hours", + CONFIG_HOUSEKEEPING_FREQUENCY); - zbx_setproctitle("housekeeper [sleeping for %d hour(s)]", CONFIG_HOUSEKEEPING_FREQUENCY); + zbx_setproctitle("housekeeper [sleeping for %d hour(s)]", + CONFIG_HOUSEKEEPING_FREQUENCY); DBclose(); - zabbix_log( LOG_LEVEL_DEBUG, "Next housekeeper run is after %dh", CONFIG_HOUSEKEEPING_FREQUENCY); + zabbix_log( LOG_LEVEL_DEBUG, "Next housekeeper run is after %dh", + CONFIG_HOUSEKEEPING_FREQUENCY); sleep(3660*CONFIG_HOUSEKEEPING_FREQUENCY); } } diff --git a/src/zabbix_server/httppoller/httpmacro.c b/src/zabbix_server/httppoller/httpmacro.c index cf96b66c..4e14fe9b 100644 --- a/src/zabbix_server/httppoller/httpmacro.c +++ b/src/zabbix_server/httppoller/httpmacro.c @@ -55,7 +55,8 @@ void http_substitute_macros(DB_HTTPTEST *httptest, char *data, int data_max_len) var_len; zabbix_log(LOG_LEVEL_DEBUG, "In http_substitute_macros(httptestid:" ZBX_FS_UI64 ", data:%s)", - httptest->httptestid, data); + httptest->httptestid, + data); assert(data); @@ -127,5 +128,6 @@ void http_substitute_macros(DB_HTTPTEST *httptest, char *data, int data_max_len) zbx_snprintf(data, data_max_len, "%s", str_out); - zabbix_log( LOG_LEVEL_DEBUG, "Result expression [%s]", data ); + zabbix_log( LOG_LEVEL_DEBUG, "Result expression [%s]", + data); } diff --git a/src/zabbix_server/httppoller/httppoller.c b/src/zabbix_server/httppoller/httppoller.c index baac238a..05635686 100644 --- a/src/zabbix_server/httppoller/httppoller.c +++ b/src/zabbix_server/httppoller/httppoller.c @@ -56,7 +56,11 @@ static int get_minnextcheck(int now) int res; - result = DBselect("select count(*),min(nextcheck) from httptest t where t.status=%d and " ZBX_SQL_MOD(t.httptestid,%d) "=%d and " ZBX_COND_NODEID, HTTPTEST_STATUS_MONITORED, CONFIG_HTTPPOLLER_FORKS, httppoller_num-1, LOCAL_NODE("t.httptestid")); + result = DBselect("select count(*),min(nextcheck) from httptest t where t.status=%d and " ZBX_SQL_MOD(t.httptestid,%d) "=%d and " ZBX_COND_NODEID, + HTTPTEST_STATUS_MONITORED, + CONFIG_HTTPPOLLER_FORKS, + httppoller_num-1, + LOCAL_NODE("t.httptestid")); row=DBfetch(result); @@ -101,7 +105,8 @@ void main_httppoller_loop(int num) int now; int nextcheck,sleeptime; - zabbix_log( LOG_LEVEL_DEBUG, "In main_httppoller_loop(num:%d)", num); + zabbix_log( LOG_LEVEL_DEBUG, "In main_httppoller_loop(num:%d)", + num); httppoller_num = num; @@ -114,10 +119,13 @@ void main_httppoller_loop(int num) now=time(NULL); process_httptests(now); - zabbix_log( LOG_LEVEL_DEBUG, "Spent %d seconds while processing HTTP tests", (int)time(NULL)-now ); + zabbix_log( LOG_LEVEL_DEBUG, "Spent %d seconds while processing HTTP tests", + (int)time(NULL)-now); nextcheck=get_minnextcheck(now); - zabbix_log( LOG_LEVEL_DEBUG, "Nextcheck:%d Time:%d", nextcheck, (int)time(NULL) ); + zabbix_log( LOG_LEVEL_DEBUG, "Nextcheck:%d Time:%d", + nextcheck, + (int)time(NULL)); if( FAIL == nextcheck) { diff --git a/src/zabbix_server/httppoller/httptest.c b/src/zabbix_server/httppoller/httptest.c index fb9eff82..b8531522 100644 --- a/src/zabbix_server/httppoller/httptest.c +++ b/src/zabbix_server/httppoller/httptest.c @@ -55,9 +55,16 @@ static int process_value(zbx_uint64_t itemid, AGENT_RESULT *value) DB_ROW row; DB_ITEM item; - zabbix_log( LOG_LEVEL_DEBUG, "In process_value(itemid:" ZBX_FS_UI64 ")", itemid); - - result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and i.status=%d and i.type=%d and i.itemid=" ZBX_FS_UI64 " and " ZBX_COND_NODEID, ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, ITEM_STATUS_ACTIVE, ITEM_TYPE_HTTPTEST, itemid, LOCAL_NODE("h.hostid")); + zabbix_log( LOG_LEVEL_DEBUG, "In process_value(itemid:" ZBX_FS_UI64 ")", + itemid); + + result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and i.status=%d and i.type=%d and i.itemid=" ZBX_FS_UI64 " and " ZBX_COND_NODEID, + ZBX_SQL_ITEM_SELECT, + HOST_STATUS_MONITORED, + ITEM_STATUS_ACTIVE, + ITEM_TYPE_HTTPTEST, + itemid, + LOCAL_NODE("h.hostid")); row=DBfetch(result); if(!row) @@ -123,7 +130,9 @@ static void process_test_data(DB_HTTPTEST *httptest, S_ZBX_HTTPSTAT *stat) AGENT_RESULT value; zabbix_log(LOG_LEVEL_DEBUG, "In process_test_data(test:%s,time:" ZBX_FS_DBL ",last step:%d)", - httptest->name, stat->test_total_time, stat->test_last_step); + httptest->name, + stat->test_total_time, + stat->test_last_step); result = DBselect("select httptestitemid,httptestid,itemid,type from httptestitem where httptestid=" ZBX_FS_UI64, httptest->httptestid); @@ -169,7 +178,11 @@ static void process_step_data(DB_HTTPTEST *httptest, DB_HTTPSTEP *httpstep, S_ZB AGENT_RESULT value; zabbix_log(LOG_LEVEL_DEBUG, "In process_step_data(step:%s,url:%s,rsp:%d,time:" ZBX_FS_DBL ",speed:" ZBX_FS_DBL ")", - httpstep->name, httpstep->url, stat->rspcode, stat->total_time, stat->speed_download); + httpstep->name, + httpstep->url, + stat->rspcode, + stat->total_time, + stat->speed_download); result = DBselect("select httpstepitemid,httpstepid,itemid,type from httpstepitem where httpstepid=" ZBX_FS_UI64, httpstep->httpstepid); @@ -269,7 +282,8 @@ static int process_httptest(DB_HTTPTEST *httptest) CURL *easyhandle = NULL; zabbix_log(LOG_LEVEL_DEBUG, "In process_httptest(httptestid:" ZBX_FS_UI64 ",name:%s)", - httptest->httptestid, httptest->name); + httptest->httptestid, + httptest->name); DBexecute("update httptest set lastcheck=%d where httptestid=" ZBX_FS_UI64, now, @@ -284,40 +298,46 @@ static int process_httptest(DB_HTTPTEST *httptest) } if(CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_COOKIEFILE, ""))) { - zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_COOKIEFILE [%s]", curl_easy_strerror(err)); + zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_COOKIEFILE [%s]", + curl_easy_strerror(err)); return FAIL; } if(CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_USERAGENT, httptest->agent))) { - zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_USERAGENT [%s]", curl_easy_strerror(err)); + zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_USERAGENT [%s]", + curl_easy_strerror(err)); return FAIL; } if(CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_FOLLOWLOCATION, 1))) { - zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_FOLLOWLOCATION [%s]", curl_easy_strerror(err)); + zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_FOLLOWLOCATION [%s]", + curl_easy_strerror(err)); return FAIL; } if(CURLE_OK != (err = curl_easy_setopt(easyhandle,CURLOPT_WRITEFUNCTION ,WRITEFUNCTION2))) { - zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", curl_easy_strerror(err)); + zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", + curl_easy_strerror(err)); return FAIL; } if(CURLE_OK != (err = curl_easy_setopt(easyhandle,CURLOPT_HEADERFUNCTION ,HEADERFUNCTION2))) { - zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", curl_easy_strerror(err)); + zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", + curl_easy_strerror(err)); return FAIL; } /* Process self-signed certificates. Do not verify certificate. */ if(CURLE_OK != (err = curl_easy_setopt(easyhandle,CURLOPT_SSL_VERIFYPEER , 0))) { - zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", curl_easy_strerror(err)); + zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", + curl_easy_strerror(err)); return FAIL; } lastfailedstep=0; httptest->time = 0; result = DBselect("select httpstepid,httptestid,no,name,url,timeout,posts,required from httpstep where httptestid=" ZBX_FS_UI64 " order by no", - httptest->httptestid); + httptest->httptestid); now=time(NULL); while((row=DBfetch(result))) { @@ -348,14 +368,16 @@ static int process_httptest(DB_HTTPTEST *httptest) { if(CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, httpstep.posts))) { - zabbix_log(LOG_LEVEL_ERR, "Cannot set POST vars [%s]", curl_easy_strerror(err)); + zabbix_log(LOG_LEVEL_ERR, "Cannot set POST vars [%s]", + curl_easy_strerror(err)); ret = FAIL; break; } } if(CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_URL, httpstep.url))) { - zabbix_log(LOG_LEVEL_ERR, "Cannot set URL [%s]", curl_easy_strerror(err)); + zabbix_log(LOG_LEVEL_ERR, "Cannot set URL [%s]", + curl_easy_strerror(err)); ret = FAIL; break; } @@ -369,7 +391,8 @@ static int process_httptest(DB_HTTPTEST *httptest) memset(&page, 0, sizeof(page)); if(CURLE_OK != (err = curl_easy_perform(easyhandle))) { - zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", curl_easy_strerror(err)); + zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", + curl_easy_strerror(err)); ret = FAIL; break; } @@ -386,19 +409,22 @@ zabbix_log(LOG_LEVEL_DEBUG, "[%s]", page.data); if(CURLE_OK != (err = curl_easy_getinfo(easyhandle,CURLINFO_RESPONSE_CODE ,&stat.rspcode))) { - zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", curl_easy_strerror(err)); + zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", + curl_easy_strerror(err)); ret = FAIL; break; } if(CURLE_OK != (err = curl_easy_getinfo(easyhandle,CURLINFO_TOTAL_TIME ,&stat.total_time))) { - zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", curl_easy_strerror(err)); + zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", + curl_easy_strerror(err)); ret = FAIL; break; } if(CURLE_OK != (err = curl_easy_getinfo(easyhandle,CURLINFO_SPEED_DOWNLOAD ,&stat.speed_download))) { - zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", curl_easy_strerror(err)); + zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", + curl_easy_strerror(err)); ret = FAIL; break; } @@ -457,7 +483,12 @@ void process_httptests(int now) zabbix_log(LOG_LEVEL_DEBUG, "In process_httptests()"); - result = DBselect("select httptestid,name,applicationid,nextcheck,status,delay,macros,agent from httptest where status=%d and nextcheck<=%d and " ZBX_SQL_MOD(httptestid,%d) "=%d and " ZBX_COND_NODEID, HTTPTEST_STATUS_MONITORED, now, CONFIG_HTTPPOLLER_FORKS, httppoller_num-1, LOCAL_NODE("httptestid")); + result = DBselect("select httptestid,name,applicationid,nextcheck,status,delay,macros,agent from httptest where status=%d and nextcheck<=%d and " ZBX_SQL_MOD(httptestid,%d) "=%d and " ZBX_COND_NODEID, + HTTPTEST_STATUS_MONITORED, + now, + CONFIG_HTTPPOLLER_FORKS, + httppoller_num-1, + LOCAL_NODE("httptestid")); while((row=DBfetch(result))) { ZBX_STR2UINT64(httptest.httptestid, row[0]); diff --git a/src/zabbix_server/nodewatcher/events.c b/src/zabbix_server/nodewatcher/events.c index 50ad141b..2b0cfde2 100644 --- a/src/zabbix_server/nodewatcher/events.c +++ b/src/zabbix_server/nodewatcher/events.c @@ -59,13 +59,17 @@ static int process_node(int nodeid, int master_nodeid, zbx_uint64_t event_lastid zbx_uint64_t eventid; - zabbix_log( LOG_LEVEL_DEBUG, "In process_node(local:%d, event_lastid:" ZBX_FS_UI64 ")",nodeid, event_lastid); + zabbix_log( LOG_LEVEL_DEBUG, "In process_node(local:%d, event_lastid:" ZBX_FS_UI64 ")", + nodeid, + event_lastid); /* Begin work */ data = malloc(allocated); memset(data,0,allocated); - zbx_snprintf_alloc(&data, &allocated, &offset, 128, "Events|%d|%d", CONFIG_NODEID, nodeid); + zbx_snprintf_alloc(&data, &allocated, &offset, 128, "Events|%d|%d", + CONFIG_NODEID, + nodeid); result = DBselect("select eventid,source,object,objectid,clock,value,acknowledged from events where eventid>" ZBX_FS_UI64 " and " ZBX_COND_NODEID " order by eventid", event_lastid, @@ -75,15 +79,24 @@ static int process_node(int nodeid, int master_nodeid, zbx_uint64_t event_lastid ZBX_STR2UINT64(eventid,row[0]) found = 1; zbx_snprintf_alloc(&data, &allocated, &offset, 1024, "\n%s|%s|%s|%s|%s|%s|%s", - row[0],row[1],row[2],row[3],row[4],row[5],row[6]); + row[0], + row[1], + row[2], + row[3], + row[4], + row[5], + row[6]); } if(found == 1) { - zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]",data); + zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]", + data); if(send_to_node(master_nodeid, nodeid, data) == SUCCEED) { zabbix_log( LOG_LEVEL_DEBUG, "Updating nodes.event_lastid"); - DBexecute("update nodes set event_lastid=" ZBX_FS_UI64 " where nodeid=%d", eventid, nodeid); + DBexecute("update nodes set event_lastid=" ZBX_FS_UI64 " where nodeid=%d", + eventid, + nodeid); } else { diff --git a/src/zabbix_server/nodewatcher/history.c b/src/zabbix_server/nodewatcher/history.c index 1893fc3e..c17807ab 100644 --- a/src/zabbix_server/nodewatcher/history.c +++ b/src/zabbix_server/nodewatcher/history.c @@ -56,15 +56,20 @@ static int process_node_history_str(int nodeid, int master_nodeid) zbx_uint64_t id; - zabbix_log( LOG_LEVEL_DEBUG, "In process_node_history_str(nodeid:%d, master_nodeid:%d",nodeid, master_nodeid); + zabbix_log( LOG_LEVEL_DEBUG, "In process_node_history_str(nodeid:%d, master_nodeid:%d", + nodeid, + master_nodeid); /* Begin work */ data = malloc(allocated); memset(data,0,allocated); - zbx_snprintf_alloc(&data, &allocated, &offset, 128, "History|%d|%d", CONFIG_NODEID, nodeid); + zbx_snprintf_alloc(&data, &allocated, &offset, 128, "History|%d|%d", + CONFIG_NODEID, + nodeid); - zbx_snprintf(sql,sizeof(sql),"select id,itemid,clock,value from history_str_sync where nodeid=%d order by id", nodeid); + zbx_snprintf(sql,sizeof(sql),"select id,itemid,clock,value from history_str_sync where nodeid=%d order by id", + nodeid); result = DBselectN(sql, 10000); while((row=DBfetch(result))) @@ -72,15 +77,22 @@ static int process_node_history_str(int nodeid, int master_nodeid) ZBX_STR2UINT64(id,row[0]) found = 1; zbx_snprintf_alloc(&data, &allocated, &offset, 1024, "\n%d|%s|%s|%s", - ZBX_TABLE_HISTORY_STR,row[1],row[2],row[3]); + ZBX_TABLE_HISTORY_STR, + row[1], + row[2], + row[3]); } if(found == 1) { if(send_to_node(master_nodeid, nodeid, data) == SUCCEED) { /* zabbix_log( LOG_LEVEL_WARNING, "Updating nodes.history_lastid");*/ - DBexecute("update nodes set history_str_lastid=" ZBX_FS_UI64 " where nodeid=%d", id, nodeid); - DBexecute("delete from history_str_sync where nodeid=%d and id<=" ZBX_FS_UI64, nodeid, id); + DBexecute("update nodes set history_str_lastid=" ZBX_FS_UI64 " where nodeid=%d", + id, + nodeid); + DBexecute("delete from history_str_sync where nodeid=%d and id<=" ZBX_FS_UI64, + nodeid, + id); } else { @@ -123,7 +135,9 @@ static int process_node_history_uint(int nodeid, int master_nodeid) zbx_uint64_t id; - zabbix_log( LOG_LEVEL_DEBUG, "In process_node_history_uint(nodeid:%d, master_nodeid:%d)",nodeid, master_nodeid); + zabbix_log( LOG_LEVEL_DEBUG, "In process_node_history_uint(nodeid:%d, master_nodeid:%d)", + nodeid, + master_nodeid); /* Begin work */ start = time(NULL); @@ -131,9 +145,12 @@ static int process_node_history_uint(int nodeid, int master_nodeid) data = malloc(allocated); memset(data,0,allocated); - zbx_snprintf_alloc(&data, &allocated, &offset, 128, "History|%d|%d", CONFIG_NODEID, nodeid); + zbx_snprintf_alloc(&data, &allocated, &offset, 128, "History|%d|%d", + CONFIG_NODEID, + nodeid); - zbx_snprintf(sql,sizeof(sql),"select id,itemid,clock,value from history_uint_sync where nodeid=%d order by id", nodeid); + zbx_snprintf(sql,sizeof(sql),"select id,itemid,clock,value from history_uint_sync where nodeid=%d order by id", + nodeid); result = DBselectN(sql, 10000); while((row=DBfetch(result))) @@ -141,15 +158,22 @@ static int process_node_history_uint(int nodeid, int master_nodeid) ZBX_STR2UINT64(id,row[0]) found = 1; zbx_snprintf_alloc(&data, &allocated, &offset, 128, "\n%d|%s|%s|%s", - ZBX_TABLE_HISTORY_UINT,row[1],row[2],row[3]); + ZBX_TABLE_HISTORY_UINT, + row[1], + row[2], + row[3]); } if(found == 1) { if(send_to_node(master_nodeid, nodeid, data) == SUCCEED) { /* zabbix_log( LOG_LEVEL_WARNING, "Updating nodes.history_lastid"); */ - DBexecute("update nodes set history_uint_lastid=" ZBX_FS_UI64 " where nodeid=%d", id, nodeid); - DBexecute("delete from history_uint_sync where nodeid=%d and id<=" ZBX_FS_UI64, nodeid, id); + DBexecute("update nodes set history_uint_lastid=" ZBX_FS_UI64 " where nodeid=%d", + id, + nodeid); + DBexecute("delete from history_uint_sync where nodeid=%d and id<=" ZBX_FS_UI64, + nodeid, + id); } else { @@ -161,7 +185,8 @@ static int process_node_history_uint(int nodeid, int master_nodeid) end = time(NULL); - zabbix_log( LOG_LEVEL_DEBUG, "Spent %d seconds in process_node_history_uint",end-start); + zabbix_log( LOG_LEVEL_DEBUG, "Spent %d seconds in process_node_history_uint", + end-start); return SUCCEED; } @@ -196,16 +221,21 @@ static int process_node_history(int nodeid, int master_nodeid) zbx_uint64_t id; - zabbix_log( LOG_LEVEL_DEBUG, "In process_node_history(nodeid:%d, master_nodeid:%d",nodeid, master_nodeid); + zabbix_log( LOG_LEVEL_DEBUG, "In process_node_history(nodeid:%d, master_nodeid:%d", + nodeid, + master_nodeid); /* Begin work */ start = time(NULL); data = malloc(allocated); memset(data,0,allocated); - zbx_snprintf_alloc(&data, &allocated, &offset, 128, "History|%d|%d", CONFIG_NODEID, nodeid); + zbx_snprintf_alloc(&data, &allocated, &offset, 128, "History|%d|%d", + CONFIG_NODEID, + nodeid); - zbx_snprintf(sql,sizeof(sql),"select id,itemid,clock,value from history_sync where nodeid=%d order by id", nodeid); + zbx_snprintf(sql,sizeof(sql),"select id,itemid,clock,value from history_sync where nodeid=%d order by id", + nodeid); result = DBselectN(sql, 10000); while((row=DBfetch(result))) @@ -213,16 +243,24 @@ static int process_node_history(int nodeid, int master_nodeid) ZBX_STR2UINT64(id,row[0]) found = 1; zbx_snprintf_alloc(&data, &allocated, &offset, 128, "\n%d|%s|%s|%s", - ZBX_TABLE_HISTORY,row[1],row[2],row[3]); + ZBX_TABLE_HISTORY, + row[1], + row[2], + row[3]); } if(found == 1) { - zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]",data); + zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]", + data); if(send_to_node(master_nodeid, nodeid, data) == SUCCEED) { /* zabbix_log( LOG_LEVEL_WARNING, "Updating nodes.history_lastid=" ZBX_FS_UI64, id); */ - 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); + 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 { @@ -234,7 +272,8 @@ static int process_node_history(int nodeid, int master_nodeid) end = time(NULL); - zabbix_log( LOG_LEVEL_DEBUG, "Spent %d seconds in process_node_history",end-start); + zabbix_log( LOG_LEVEL_DEBUG, "Spent %d seconds in process_node_history", + end-start); return SUCCEED; } @@ -257,7 +296,9 @@ static int process_node_history(int nodeid, int master_nodeid) ******************************************************************************/ static void process_node(int nodeid, int master_nodeid) { - zabbix_log( LOG_LEVEL_DEBUG, "In process_node(local:%d, master_nodeid:" ZBX_FS_UI64 ")",nodeid, master_nodeid); + zabbix_log( LOG_LEVEL_DEBUG, "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); diff --git a/src/zabbix_server/nodewatcher/nodecomms.c b/src/zabbix_server/nodewatcher/nodecomms.c index 7f99f3cd..b2cab7cd 100644 --- a/src/zabbix_server/nodewatcher/nodecomms.c +++ b/src/zabbix_server/nodewatcher/nodecomms.c @@ -56,15 +56,21 @@ int send_to_node(int dest_nodeid, int nodeid, char *data) zbx_sock_t sock; char *answer; - zabbix_log( LOG_LEVEL_WARNING, "NODE %d: Sending data of node %d to node %d datalen %d", CONFIG_NODEID, nodeid, dest_nodeid, strlen(data)); + zabbix_log( LOG_LEVEL_WARNING, "NODE %d: Sending data of node %d to node %d datalen %d", + CONFIG_NODEID, + nodeid, + dest_nodeid, + strlen(data)); /* zabbix_log( LOG_LEVEL_WARNING, "Data [%s]", data);*/ - result = DBselect("select ip, port from nodes where nodeid=%d", dest_nodeid); + result = DBselect("select ip, port from nodes where nodeid=%d", + dest_nodeid); row = DBfetch(result); if(!row) { DBfree_result(result); - zabbix_log( LOG_LEVEL_WARNING, "Node [%d] in unknown", dest_nodeid); + zabbix_log( LOG_LEVEL_WARNING, "Node [%d] is unknown", + dest_nodeid); return FAIL; } zbx_strlcpy(ip,row[0],sizeof(ip)); @@ -73,26 +79,30 @@ int send_to_node(int dest_nodeid, int nodeid, char *data) if( FAIL == zbx_tcp_connect(&sock, ip, port)) { - zabbix_log( LOG_LEVEL_WARNING, "Unable to connect to Node [%d]", dest_nodeid); + zabbix_log( LOG_LEVEL_WARNING, "Unable to connect to Node [%d]", + dest_nodeid); return FAIL; } if( FAIL == zbx_tcp_send(&sock, data)) { - zabbix_log( LOG_LEVEL_WARNING, "Error while sending data to Node [%d]", dest_nodeid); + zabbix_log( LOG_LEVEL_WARNING, "Error while sending data to Node [%d]", + dest_nodeid); zbx_tcp_close(&sock); return FAIL; } if( FAIL == zbx_tcp_recv(&sock, &answer)) { - zabbix_log( LOG_LEVEL_WARNING, "Error while receiving answer from Node [%d]", dest_nodeid); + zabbix_log( LOG_LEVEL_WARNING, "Error while receiving answer from Node [%d]", + dest_nodeid); zbx_tcp_close(&sock); return FAIL; } - zabbix_log( LOG_LEVEL_DEBUG, "Answer [%s]", answer); + zabbix_log( LOG_LEVEL_DEBUG, "Answer [%s]", + answer); if(strcmp(answer,"OK") == 0) { diff --git a/src/zabbix_server/nodewatcher/nodesender.c b/src/zabbix_server/nodewatcher/nodesender.c index b3697bea..e07d115a 100644 --- a/src/zabbix_server/nodewatcher/nodesender.c +++ b/src/zabbix_server/nodewatcher/nodesender.c @@ -67,19 +67,29 @@ static int send_config_data(int nodeid, int dest_nodeid, zbx_uint64_t maxlogid, memset(xml,0,allocated); - zabbix_log( LOG_LEVEL_DEBUG, "In send_config_data(nodeid:%d,dest_node:%d,maxlogid:" ZBX_FS_UI64 ",type:%d)",nodeid, dest_nodeid,maxlogid,node_type); + zabbix_log( LOG_LEVEL_DEBUG, "In send_config_data(nodeid:%d,dest_node:%d,maxlogid:" ZBX_FS_UI64 ",type:%d)", + nodeid, + dest_nodeid, + maxlogid, + node_type); /* Begin work */ if(node_type == ZBX_NODE_MASTER) { - result=DBselect("select tablename,recordid,operation from node_configlog where nodeid=" ZBX_FS_UI64 " and sync_master=0 and conflogid<=" ZBX_FS_UI64 " order by tablename,operation", nodeid, maxlogid); + result=DBselect("select tablename,recordid,operation from node_configlog where nodeid=" ZBX_FS_UI64 " and sync_master=0 and conflogid<=" ZBX_FS_UI64 " order by tablename,operation", + nodeid, + maxlogid); } else { - result=DBselect("select tablename,recordid,operation from node_configlog where nodeid=" ZBX_FS_UI64 " and sync_slave=0 and conflogid<=" ZBX_FS_UI64 " order by tablename,operation", nodeid, maxlogid); + result=DBselect("select tablename,recordid,operation from node_configlog where nodeid=" ZBX_FS_UI64 " and sync_slave=0 and conflogid<=" ZBX_FS_UI64 " order by tablename,operation", + nodeid, + maxlogid); } - zbx_snprintf_alloc(&xml, &allocated, &offset, 128, "Data|%d|%d", CONFIG_NODEID, nodeid); + zbx_snprintf_alloc(&xml, &allocated, &offset, 128, "Data|%d|%d", + CONFIG_NODEID, + nodeid); while((row=DBfetch(result))) { @@ -103,7 +113,11 @@ static int send_config_data(int nodeid, int dest_nodeid, zbx_uint64_t maxlogid, } if(fields[0]!=0) fields[strlen(fields)-1]=0; - result2=DBselect("select %s from %s where %s=%s", fields, row[0], tables[i].recid,row[1]); + result2=DBselect("select %s from %s where %s=%s", + fields, + row[0], + tables[i].recid, + row[1]); /* zabbix_log( LOG_LEVEL_WARNING,"select %s from %s where %s=%s",fields, row[0], tables[i].recid,row[1]);*/ row2=DBfetch(result2); @@ -111,7 +125,9 @@ static int send_config_data(int nodeid, int dest_nodeid, zbx_uint64_t maxlogid, if(row2) { zbx_snprintf_alloc(&xml, &allocated, &offset, 16*1024, "\n%s|%s|%s", - row[0], row[1], row[2]); + row[0], + row[1], + row[2]); /* for each field */ for(j=0;tables[i].fields[j].name!=0;j++) { @@ -121,36 +137,47 @@ static int send_config_data(int nodeid, int dest_nodeid, zbx_uint64_t maxlogid, { /* zabbix_log( LOG_LEVEL_WARNING, "Field name [%s] [%s]",tables[i].fields[j].name,row2[j]);*/ zbx_snprintf_alloc(&xml, &allocated, &offset, 16*1024, "|%d|%d|NULL", - tables[i].fields[j].name,tables[i].fields[j].type); + tables[i].fields[j].name, + tables[i].fields[j].type); } else { zbx_snprintf_alloc(&xml, &allocated, &offset, 16*1024, "|%s|%d|%s", - tables[i].fields[j].name,tables[i].fields[j].type,row2[j]); + tables[i].fields[j].name, + tables[i].fields[j].type, + row2[j]); } } } else { - zabbix_log( LOG_LEVEL_WARNING, "Cannot select %s from table [%s]",tables[i].fields[j],row[0]); + zabbix_log( LOG_LEVEL_WARNING, "Cannot select %s from table [%s]", + tables[i].fields[j], + row[0]); } DBfree_result(result2); } else { - zabbix_log( LOG_LEVEL_WARNING, "Cannot find table [%s]",row[0]); + zabbix_log( LOG_LEVEL_WARNING, "Cannot find table [%s]", + row[0]); } } - zabbix_log( LOG_LEVEL_DEBUG, "DATA [%s]",xml); + zabbix_log( LOG_LEVEL_DEBUG, "DATA [%s]", + xml); if( (found == 1) && send_to_node(dest_nodeid, nodeid, xml) == SUCCEED) { if(node_type == ZBX_NODE_MASTER) { - DBexecute("update node_configlog set sync_master=1 where nodeid=%d and sync_master=0 and conflogid<=" ZBX_FS_UI64, nodeid, maxlogid); + DBexecute("update node_configlog set sync_master=1 where nodeid=%d and sync_master=0 and conflogid<=" ZBX_FS_UI64, + nodeid, + maxlogid); } else { - DBexecute("update node_configlog set sync_slave=1 where nodeid=%d and sync_slave=0 and conflogid<=" ZBX_FS_UI64, nodeid, maxlogid); + DBexecute("update node_configlog set sync_slave=1 where nodeid=%d and sync_slave=0 and conflogid<=" ZBX_FS_UI64, + nodeid, + maxlogid); } } @@ -184,9 +211,11 @@ static int get_slave_node(int nodeid) int ret = 0; int m; - zabbix_log( LOG_LEVEL_DEBUG, "In get_slave_node(%d)", nodeid); + zabbix_log( LOG_LEVEL_DEBUG, "In get_slave_node(%d)", + nodeid); - result = DBselect("select masterid from nodes where nodeid=%d", nodeid); + result = DBselect("select masterid from nodes where nodeid=%d", + nodeid); row = DBfetch(result); if(row) { @@ -228,9 +257,11 @@ int get_master_node(int nodeid) DB_ROW row; int ret = 0; - zabbix_log( LOG_LEVEL_DEBUG, "In get_master_node(%d)", nodeid); + zabbix_log( LOG_LEVEL_DEBUG, "In get_master_node(%d)", + nodeid); - result = DBselect("select masterid from nodes where nodeid=%d", CONFIG_NODEID); + result = DBselect("select masterid from nodes where nodeid=%d", + CONFIG_NODEID); row = DBfetch(result); if(row) { @@ -265,15 +296,18 @@ static int send_to_master_and_slave(int nodeid) int master_result, slave_result; zbx_uint64_t maxlogid; - zabbix_log( LOG_LEVEL_DEBUG, "In send_to_master_and_slave(node:%d)", nodeid); + zabbix_log( LOG_LEVEL_DEBUG, "In send_to_master_and_slave(node:%d)", + nodeid); - result = DBselect("select max(conflogid) from node_configlog where nodeid=%d", nodeid); + result = DBselect("select max(conflogid) from node_configlog where nodeid=%d", + nodeid); row = DBfetch(result); if(DBis_null(row[0]) == SUCCEED) { - zabbix_log( LOG_LEVEL_DEBUG, "No configuration changes of node %d", nodeid); + zabbix_log( LOG_LEVEL_DEBUG, "No configuration changes of node %d", + nodeid); DBfree_result(result); return SUCCEED; } @@ -298,7 +332,9 @@ static int send_to_master_and_slave(int nodeid) { if((master_result == SUCCEED) && (slave_result == SUCCEED)) { - DBexecute("delete from node_configlog where nodeid=%d and sync_slave=1 and sync_master=1 and conflogid<=" ZBX_FS_UI64, nodeid, maxlogid); + DBexecute("delete from node_configlog where nodeid=%d and sync_slave=1 and sync_master=1 and conflogid<=" ZBX_FS_UI64, + nodeid, + maxlogid); } } @@ -306,7 +342,9 @@ static int send_to_master_and_slave(int nodeid) { if(master_result == SUCCEED) { - DBexecute("delete from node_configlog where nodeid=%d and sync_master=1 and conflogid<=" ZBX_FS_UI64, nodeid, maxlogid); + DBexecute("delete from node_configlog where nodeid=%d and sync_master=1 and conflogid<=" ZBX_FS_UI64, + nodeid, + maxlogid); } } @@ -314,7 +352,9 @@ static int send_to_master_and_slave(int nodeid) { if(slave_result == SUCCEED) { - DBexecute("delete from node_configlog where nodeid=%d and sync_slave=1 and conflogid<=" ZBX_FS_UI64, nodeid, maxlogid); + DBexecute("delete from node_configlog where nodeid=%d and sync_slave=1 and conflogid<=" ZBX_FS_UI64, + nodeid, + maxlogid); } } @@ -343,11 +383,13 @@ static int process_node(int nodeid) DB_RESULT result; DB_ROW row; - zabbix_log( LOG_LEVEL_DEBUG, "In process_node(node:%d)", nodeid); + zabbix_log( LOG_LEVEL_DEBUG, "In process_node(node:%d)", + nodeid); send_to_master_and_slave(nodeid); - result = DBselect("select nodeid from nodes where masterid=%d", nodeid); + result = DBselect("select nodeid from nodes where masterid=%d", + nodeid); while((row=DBfetch(result))) { process_node(atoi(row[0])); @@ -379,7 +421,8 @@ void main_nodesender() zabbix_log( LOG_LEVEL_DEBUG, "In main_nodesender()"); - result = DBselect("select nodeid from nodes where nodetype=%d", ZBX_NODE_TYPE_LOCAL); + result = DBselect("select nodeid from nodes where nodetype=%d", + ZBX_NODE_TYPE_LOCAL); row = DBfetch(result); diff --git a/src/zabbix_server/nodewatcher/nodewatcher.c b/src/zabbix_server/nodewatcher/nodewatcher.c index b6421dac..0024a181 100644 --- a/src/zabbix_server/nodewatcher/nodewatcher.c +++ b/src/zabbix_server/nodewatcher/nodewatcher.c @@ -64,7 +64,8 @@ static int calculate_checksums() zabbix_log( LOG_LEVEL_DEBUG, "In calculate_checksums"); - DBexecute("delete from node_cksum where cksumtype=%d", NODE_CKSUM_TYPE_NEW); + DBexecute("delete from node_cksum where cksumtype=%d", + NODE_CKSUM_TYPE_NEW); /* Select all nodes */ result =DBselect("select nodeid from nodes"); @@ -92,7 +93,9 @@ static int calculate_checksums() #else "union all select '%s','%s',%s,md5(", #endif - tables[i].table, tables[i].recid, tables[i].recid); + tables[i].table, + tables[i].recid, + tables[i].recid); j=0; while(tables[i].fields[j].name != 0) @@ -103,9 +106,11 @@ static int calculate_checksums() continue; } #ifdef HAVE_MYSQL - zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 128, "coalesce(%s,'1234567890'),", tables[i].fields[j].name); + zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 128, "coalesce(%s,'1234567890'),", + tables[i].fields[j].name); #else - zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 128, "coalesce(%s,'1234567890')||", tables[i].fields[j].name); + zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 128, "coalesce(%s,'1234567890')||", + tables[i].fields[j].name); #endif j++; } @@ -123,8 +128,10 @@ static int calculate_checksums() ") from %s where %s>=" ZBX_FS_UI64 " and %s<=" ZBX_FS_UI64 "\n", #endif tables[i].table, - tables[i].recid, (zbx_uint64_t)__UINT64_C(100000000000000)*(zbx_uint64_t)nodeid, - tables[i].recid, (zbx_uint64_t)__UINT64_C(100000000000000)*(zbx_uint64_t)nodeid+__UINT64_C(99999999999999)); + tables[i].recid, + (zbx_uint64_t)__UINT64_C(100000000000000)*(zbx_uint64_t)nodeid, + tables[i].recid, + (zbx_uint64_t)__UINT64_C(100000000000000)*(zbx_uint64_t)nodeid+__UINT64_C(99999999999999)); } /* zabbix_log( LOG_LEVEL_WARNING, "SQL DUMP [%s]", sql); */ @@ -139,7 +146,12 @@ static int calculate_checksums() DBexecute("insert into node_cksum (cksumid,nodeid,tablename,fieldname,recordid,cksumtype,cksum) "\ "values (" ZBX_FS_UI64 ",%d,'%s','%s',%s,%d,'%s')", DBget_nextid("node_cksum","cksumid"), - nodeid,row2[0],row2[1],row2[2],NODE_CKSUM_TYPE_NEW,row2[3]); + nodeid, + row2[0], + row2[1], + row2[2], + NODE_CKSUM_TYPE_NEW, + row2[3]); i++; } DBfree_result(result2); @@ -168,8 +180,11 @@ static int calculate_checksums() ******************************************************************************/ static int update_checksums() { - DBexecute("delete from node_cksum where cksumtype=%d", NODE_CKSUM_TYPE_OLD); - DBexecute("update node_cksum set cksumtype=%d where cksumtype=%d", NODE_CKSUM_TYPE_OLD, NODE_CKSUM_TYPE_NEW); + DBexecute("delete from node_cksum where cksumtype=%d", + NODE_CKSUM_TYPE_OLD); + DBexecute("update node_cksum set cksumtype=%d where cksumtype=%d", + NODE_CKSUM_TYPE_OLD, + NODE_CKSUM_TYPE_NEW); return SUCCEED; } @@ -197,14 +212,19 @@ static int compare_checksums() DB_ROW row; /* Find updated records */ - result = DBselect("select curr.nodeid,curr.tablename,curr.recordid from node_cksum prev, node_cksum curr where curr.tablename=prev.tablename and curr.recordid=prev.recordid and curr.fieldname=prev.fieldname and curr.nodeid=prev.nodeid and curr.cksum<>prev.cksum and curr.cksumtype=%d and prev.cksumtype=%d", NODE_CKSUM_TYPE_NEW, NODE_CKSUM_TYPE_OLD); + result = DBselect("select curr.nodeid,curr.tablename,curr.recordid from node_cksum prev, node_cksum curr where curr.tablename=prev.tablename and curr.recordid=prev.recordid and curr.fieldname=prev.fieldname and curr.nodeid=prev.nodeid and curr.cksum<>prev.cksum and curr.cksumtype=%d and prev.cksumtype=%d", + NODE_CKSUM_TYPE_NEW, + NODE_CKSUM_TYPE_OLD); while((row=DBfetch(result))) { /* zabbix_log( LOG_LEVEL_WARNING, "Adding record to node_configlog");*/ DBexecute("insert into node_configlog (conflogid,nodeid,tablename,recordid,operation)" \ "values (" ZBX_FS_UI64 ",%s,'%s',%s,%d)", DBget_nextid("node_configlog","conflogid"), - row[0],row[1],row[2],NODE_CONFIGLOG_OP_UPDATE); + row[0], + row[1], + row[2], + NODE_CONFIGLOG_OP_UPDATE); } DBfree_result(result); @@ -212,7 +232,8 @@ static int compare_checksums() result = DBselect("select curr.nodeid,curr.tablename,curr.recordid from node_cksum curr" \ " left join node_cksum prev" \ " on curr.tablename=prev.tablename and curr.recordid=prev.recordid and curr.fieldname=prev.fieldname and curr.nodeid=prev.nodeid and curr.cksumtype<>prev.cksumtype" \ - " where prev.cksumid is null and curr.cksumtype=%d", NODE_CKSUM_TYPE_NEW); + " where prev.cksumid is null and curr.cksumtype=%d", + NODE_CKSUM_TYPE_NEW); while((row=DBfetch(result))) { @@ -220,7 +241,10 @@ static int compare_checksums() DBexecute("insert into node_configlog (conflogid,nodeid,tablename,recordid,operation)" \ "values (" ZBX_FS_UI64 ",%s,'%s',%s,%d)", DBget_nextid("node_configlog","conflogid"), - row[0],row[1],row[2],NODE_CONFIGLOG_OP_ADD); + row[0], + row[1], + row[2], + NODE_CONFIGLOG_OP_ADD); } DBfree_result(result); @@ -228,7 +252,8 @@ static int compare_checksums() result = DBselect("select curr.nodeid,curr.tablename,curr.recordid from node_cksum curr" \ " left join node_cksum prev" \ " on curr.tablename=prev.tablename and curr.recordid=prev.recordid and curr.fieldname=prev.fieldname and curr.nodeid=prev.nodeid and curr.cksumtype<>prev.cksumtype" \ - " where prev.cksumid is null and curr.cksumtype=%d", NODE_CKSUM_TYPE_OLD); + " where prev.cksumid is null and curr.cksumtype=%d", + NODE_CKSUM_TYPE_OLD); while((row=DBfetch(result))) { @@ -236,7 +261,10 @@ static int compare_checksums() DBexecute("insert into node_configlog (conflogid,nodeid,tablename,recordid,operation)" \ "values (" ZBX_FS_UI64 ",%s,'%s',%s,%d)", DBget_nextid("node_configlog","conflogid"), - row[0],row[1],row[2],NODE_CONFIGLOG_OP_DELETE); + row[0], + row[1], + row[2], + NODE_CONFIGLOG_OP_DELETE); } DBfree_result(result); @@ -299,10 +327,12 @@ int main_nodewatcher_loop() end = time(NULL); - if(end-start<5) + if(end-start<10) { - zbx_setproctitle("sender [sleeping for %d seconds]", 5-(end-start)); - zabbix_log( LOG_LEVEL_DEBUG, "Sleeping %d seconds", 5-(end-start)); + zbx_setproctitle("sender [sleeping for %d seconds]", + 10-(end-start)); + zabbix_log( LOG_LEVEL_DEBUG, "Sleeping %d seconds", + 10-(end-start)); sleep(10-(end-start)); } } diff --git a/src/zabbix_server/pinger/pinger.c b/src/zabbix_server/pinger/pinger.c index 798c6b9d..4181a5f5 100644 --- a/src/zabbix_server/pinger/pinger.c +++ b/src/zabbix_server/pinger/pinger.c @@ -52,7 +52,8 @@ static int is_ip(char *ip) int dots=0; int res = SUCCEED; - zabbix_log( LOG_LEVEL_DEBUG, "In process_ip([%s])", ip); + zabbix_log( LOG_LEVEL_DEBUG, "In process_ip([%s])", + ip); for(i=0;ip[i]!=0;i++) { @@ -75,7 +76,8 @@ static int is_ip(char *ip) { res = FAIL; } - zabbix_log( LOG_LEVEL_DEBUG, "End of process_ip([%d])", res); + zabbix_log( LOG_LEVEL_DEBUG, "End of process_ip(result:%d)", + res); return res; } @@ -103,16 +105,32 @@ static int process_value(char *key, char *host, AGENT_RESULT *value) DB_ROW row; DB_ITEM item; - zabbix_log( LOG_LEVEL_DEBUG, "In process_value(%s@%s)", key, host); + zabbix_log( LOG_LEVEL_DEBUG, "In process_value(%s@%s)", + key, + host); /* IP address? */ if(is_ip(host) == SUCCEED) { - result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.ip='%s' and i.key_='%s' and i.status=%d and i.type=%d and" ZBX_COND_NODEID, ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, host, key, ITEM_STATUS_ACTIVE, ITEM_TYPE_SIMPLE, LOCAL_NODE("h.hostid")); + result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.ip='%s' and i.key_='%s' and i.status=%d and i.type=%d and" ZBX_COND_NODEID, + ZBX_SQL_ITEM_SELECT, + HOST_STATUS_MONITORED, + host, + key, + ITEM_STATUS_ACTIVE, + ITEM_TYPE_SIMPLE, + LOCAL_NODE("h.hostid")); } else { - result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type=%d and" ZBX_COND_NODEID, ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, host, key, ITEM_STATUS_ACTIVE, ITEM_TYPE_SIMPLE, LOCAL_NODE("configid")); + result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type=%d and" ZBX_COND_NODEID, + ZBX_SQL_ITEM_SELECT, + HOST_STATUS_MONITORED, + host, + key, + ITEM_STATUS_ACTIVE, + ITEM_TYPE_SIMPLE, + LOCAL_NODE("configid")); } row=DBfetch(result); @@ -163,18 +181,34 @@ static int create_host_file(void) zabbix_log( LOG_LEVEL_DEBUG, "In create_host_file()"); - zbx_snprintf(str,sizeof(str),"/tmp/zabbix_server_%d.pinger",getpid()); + zbx_snprintf(str,sizeof(str),"/tmp/zabbix_server_%d.pinger", + getpid()); if(NULL == (f = fopen(str, "w") )) { - zabbix_log( LOG_LEVEL_ERR, "Cannot open file [%s] [%s]", str, strerror(errno)); - zabbix_syslog("Cannot open file [%s] [%s]", str, strerror(errno)); + zabbix_log( LOG_LEVEL_ERR, "Cannot open file [%s] [%s]", + str, + strerror(errno)); + zabbix_syslog("Cannot open file [%s] [%s]", + str, + strerror(errno)); return FAIL; } now=time(NULL); /* Select hosts monitored by IP */ - result = DBselect("select distinct h.ip from hosts h,items i where " ZBX_SQL_MOD(h.hostid,%d) "=%d and i.hostid=h.hostid and (h.status=%d or (h.status=%d and h.available=%d and h.disable_until<=%d)) and (i.key_='%s' or i.key_='%s') and i.type=%d and i.status=%d and h.useip=1 and" ZBX_COND_NODEID, CONFIG_PINGER_FORKS, pinger_num-1, HOST_STATUS_MONITORED, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, ITEM_TYPE_SIMPLE, ITEM_STATUS_ACTIVE, LOCAL_NODE("h.hostid")); + result = DBselect("select distinct h.ip from hosts h,items i where " ZBX_SQL_MOD(h.hostid,%d) "=%d and i.hostid=h.hostid and (h.status=%d or (h.status=%d and h.available=%d and h.disable_until<=%d)) and (i.key_='%s' or i.key_='%s') and i.type=%d and i.status=%d and h.useip=1 and" ZBX_COND_NODEID, + CONFIG_PINGER_FORKS, + pinger_num-1, + HOST_STATUS_MONITORED, + HOST_STATUS_MONITORED, + HOST_AVAILABLE_FALSE, + now, + SERVER_ICMPPING_KEY, + SERVER_ICMPPINGSEC_KEY, + ITEM_TYPE_SIMPLE, + ITEM_STATUS_ACTIVE, + LOCAL_NODE("h.hostid")); while((row=DBfetch(result))) { @@ -188,15 +222,28 @@ static int create_host_file(void) DBfree_result(result); /* Select hosts monitored by hostname */ - result = DBselect("select distinct h.host from hosts h,items i where " ZBX_SQL_MOD(h.hostid,%d) "=%d and i.hostid=h.hostid and (h.status=%d or (h.status=%d and h.available=%d and h.disable_until<=%d)) and (i.key_='%s' or i.key_='%s') and i.type=%d and i.status=%d and h.useip=0 and" ZBX_COND_NODEID, CONFIG_PINGER_FORKS, pinger_num-1, HOST_STATUS_MONITORED, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, ITEM_TYPE_SIMPLE, ITEM_STATUS_ACTIVE, LOCAL_NODE("h.hostid")); + result = DBselect("select distinct h.host from hosts h,items i where " ZBX_SQL_MOD(h.hostid,%d) "=%d and i.hostid=h.hostid and (h.status=%d or (h.status=%d and h.available=%d and h.disable_until<=%d)) and (i.key_='%s' or i.key_='%s') and i.type=%d and i.status=%d and h.useip=0 and" ZBX_COND_NODEID, + CONFIG_PINGER_FORKS, + pinger_num-1, + HOST_STATUS_MONITORED, + HOST_STATUS_MONITORED, + HOST_AVAILABLE_FALSE, + now, + SERVER_ICMPPING_KEY, + SERVER_ICMPPINGSEC_KEY, + ITEM_TYPE_SIMPLE, + ITEM_STATUS_ACTIVE, + LOCAL_NODE("h.hostid")); while((row=DBfetch(result))) { strscpy(host.host,row[0]); - fprintf(f,"%s\n",host.host); + fprintf(f,"%s\n", + host.host); - zabbix_log( LOG_LEVEL_DEBUG, "HOSTNAME [%s]", host.host); + zabbix_log( LOG_LEVEL_DEBUG, "HOSTNAME [%s]", + host.host); } DBfree_result(result); @@ -235,13 +282,19 @@ static int do_ping(void) zabbix_log( LOG_LEVEL_DEBUG, "In do_ping()"); - zbx_snprintf(str,sizeof(str),"cat /tmp/zabbix_server_%d.pinger | %s -e 2>/dev/null",getpid(),CONFIG_FPING_LOCATION); + zbx_snprintf(str,sizeof(str),"cat /tmp/zabbix_server_%d.pinger | %s -e 2>/dev/null", + getpid(), + CONFIG_FPING_LOCATION); f=popen(str,"r"); if(f==0) { - zabbix_log( LOG_LEVEL_ERR, "Cannot execute [%s] [%s]", CONFIG_FPING_LOCATION, strerror(errno)); - zabbix_syslog("Cannot execute [%s] [%s]", CONFIG_FPING_LOCATION, strerror(errno)); + zabbix_log( LOG_LEVEL_ERR, "Cannot execute [%s] [%s]", + CONFIG_FPING_LOCATION, + strerror(errno)); + zabbix_syslog("Cannot execute [%s] [%s]", + CONFIG_FPING_LOCATION, + strerror(errno)); return FAIL; } @@ -250,13 +303,17 @@ static int do_ping(void) /* zabbix_log( LOG_LEVEL_WARNING, "PING: [%s]", ip);*/ ip[strlen(ip)-1]=0; - zabbix_log( LOG_LEVEL_DEBUG, "Update IP [%s]", ip); + zabbix_log( LOG_LEVEL_DEBUG, "Update IP [%s]", + ip); if(strstr(ip,"alive") != NULL) { alive=1; - sscanf(ip,"%s is alive (%lf ms)", tmp, &mseconds); - zabbix_log( LOG_LEVEL_DEBUG, "Mseconds [%lf]", mseconds); + sscanf(ip,"%s is alive (%lf ms)", + tmp, + &mseconds); + zabbix_log( LOG_LEVEL_DEBUG, "Mseconds [%lf]", + mseconds); } else { @@ -266,7 +323,9 @@ static int do_ping(void) if(c != NULL) { *c=0; - zabbix_log( LOG_LEVEL_DEBUG, "IP [%s] alive [%d]", ip, alive); + zabbix_log( LOG_LEVEL_DEBUG, "IP [%s] alive [%d]", + ip, + alive); if(0 == alive) { @@ -322,7 +381,8 @@ void main_pinger_loop(int num) char str[MAX_STRING_LEN]; - zabbix_log( LOG_LEVEL_DEBUG, "In main_pinger_loop(num:%d)", num); + zabbix_log( LOG_LEVEL_DEBUG, "In main_pinger_loop(num:%d)", + num); pinger_num = num; @@ -342,14 +402,16 @@ void main_pinger_loop(int num) ret = do_ping(); } - zbx_snprintf(str,sizeof(str),"/tmp/zabbix_server_%d.pinger",getpid()); + zbx_snprintf(str,sizeof(str),"/tmp/zabbix_server_%d.pinger", + getpid()); unlink(str); /* zabbix_set_log_level(LOG_LEVEL_WARNING); */ DBclose(); - zbx_setproctitle("pinger [sleeping for %d seconds]", CONFIG_PINGER_FREQUENCY); + zbx_setproctitle("pinger [sleeping for %d seconds]", + CONFIG_PINGER_FREQUENCY); sleep(CONFIG_PINGER_FREQUENCY); } diff --git a/src/zabbix_server/poller/checks_agent.c b/src/zabbix_server/poller/checks_agent.c index 77006de3..c6dd1705 100644 --- a/src/zabbix_server/poller/checks_agent.c +++ b/src/zabbix_server/poller/checks_agent.c @@ -56,7 +56,9 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result) init_result(result); zabbix_log( LOG_LEVEL_DEBUG, "In get_value_agent(host:%s,ip:%s,key:%s", - item->host_name, item->host_ip, item->key ); + item->host_name, + item->host_ip, + item->key ); servaddr_in.sin_family=AF_INET; if(item->useip==1) @@ -71,10 +73,12 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result) if(hp==NULL) { #ifdef HAVE_HSTRERROR - zbx_snprintf(error,sizeof(error),"gethost() failed [%s]", hstrerror(h_errno)); + zbx_snprintf(error,sizeof(error),"gethost() failed [%s]", + hstrerror(h_errno)); result->msg=strdup(error); #else - zbx_snprintf(error,sizeof(error),"gethost() failed [%d]", h_errno); + zbx_snprintf(error,sizeof(error),"gethost() failed [%d]", + h_errno); result->msg=strdup(error); #endif return NETWORK_ERROR; @@ -97,8 +101,10 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result) }*/ if(s == -1) { - zbx_snprintf(error,sizeof(error),"Cannot create socket [%s]", strerror(errno)); - zabbix_log(LOG_LEVEL_WARNING, "%s", error); + zbx_snprintf(error,sizeof(error),"Cannot create socket [%s]", + strerror(errno)); + zabbix_log(LOG_LEVEL_WARNING, "%s", + error); result->msg=strdup(error); return FAIL; } @@ -108,18 +114,25 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result) switch (errno) { case EINTR: - zbx_snprintf(error,sizeof(error),"Timeout while connecting to [%s]",item->host_name); - zabbix_log(LOG_LEVEL_WARNING, "%s", error); + zbx_snprintf(error,sizeof(error),"Timeout while connecting to [%s]", + item->host_name); + zabbix_log(LOG_LEVEL_WARNING, "%s", + error); result->msg=strdup(error); break; case EHOSTUNREACH: - zbx_snprintf(error,sizeof(error),"No route to host [%s]",item->host_name); - zabbix_log(LOG_LEVEL_WARNING, "%s", error); + zbx_snprintf(error,sizeof(error),"No route to host [%s]", + item->host_name); + zabbix_log(LOG_LEVEL_WARNING, "%s", + error); result->msg=strdup(error); break; default: - zbx_snprintf(error,sizeof(error),"Cannot connect to [%s] [%s]",item->host_name, strerror(errno)); - zabbix_log(LOG_LEVEL_WARNING, "%s", error); + zbx_snprintf(error,sizeof(error),"Cannot connect to [%s] [%s]", + item->host_name, + strerror(errno)); + zabbix_log(LOG_LEVEL_WARNING, "%s", + error); result->msg=strdup(error); } close(s); @@ -132,13 +145,18 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result) switch (errno) { case EINTR: - zbx_snprintf(error,sizeof(error),"Timeout while sending data to [%s]",item->host_name); - zabbix_log(LOG_LEVEL_WARNING, "%s", error); + zbx_snprintf(error,sizeof(error),"Timeout while sending data to [%s]", + item->host_name); + zabbix_log(LOG_LEVEL_WARNING, "%s", + error); result->msg=strdup(error); break; default: - zbx_snprintf(error,sizeof(error),"Error while sending data to [%s] [%s]",item->host_name, strerror(errno)); - zabbix_log(LOG_LEVEL_WARNING, "%s", error); + zbx_snprintf(error,sizeof(error),"Error while sending data to [%s] [%s]", + item->host_name, + strerror(errno)); + zabbix_log(LOG_LEVEL_WARNING, "%s", + error); result->msg=strdup(error); } close(s); @@ -152,19 +170,25 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result) switch (errno) { case EINTR: - zbx_snprintf(error,sizeof(error),"Timeout while receiving data from [%s]",item->host_name); - zabbix_log(LOG_LEVEL_WARNING, "%s", error); + zbx_snprintf(error,sizeof(error),"Timeout while receiving data from [%s]", + item->host_name); + zabbix_log(LOG_LEVEL_WARNING, "%s", + error); result->msg=strdup(error); break; case ECONNRESET: zbx_snprintf(error,sizeof(error),"Connection reset by peer."); - zabbix_log(LOG_LEVEL_WARNING, "%s", error); + zabbix_log(LOG_LEVEL_WARNING, "%s", + error); result->msg=strdup(error); close(s); return NETWORK_ERROR; default: - zbx_snprintf(error,sizeof(error),"Error while receiving data from [%s] [%s]",item->host_name, strerror(errno)); - zabbix_log(LOG_LEVEL_WARNING, "%s", error); + zbx_snprintf(error,sizeof(error),"Error while receiving data from [%s] [%s]", + item->host_name, + strerror(errno)); + zabbix_log(LOG_LEVEL_WARNING, "%s", + error); result->msg=strdup(error); } close(s); @@ -173,7 +197,8 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result) if( close(s)!=0 ) { - zabbix_log(LOG_LEVEL_WARNING, "Problem with close [%s]", strerror(errno)); + zabbix_log(LOG_LEVEL_WARNING, "Problem with close [%s]", + strerror(errno)); } delete_reol(c); @@ -202,8 +227,12 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result) /* The section should be improved */ else if(c[0]==0) { - zbx_snprintf(error,sizeof(error),"Got empty string from [%s] IP [%s] Parameter [%s]", item->host_name, item->host_ip, item->key); - zabbix_log( LOG_LEVEL_WARNING, "%s", error); + zbx_snprintf(error,sizeof(error),"Got empty string from [%s] IP [%s] Parameter [%s]", + item->host_name, + item->host_ip, + item->key); + zabbix_log( LOG_LEVEL_WARNING, "%s", + error); zabbix_log( LOG_LEVEL_WARNING, "Assuming that agent dropped connection because of access permissions"); result->msg=strdup(error); return NETWORK_ERROR; @@ -211,14 +240,20 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result) if(set_result_type(result, item->value_type, c) == FAIL) { - zbx_snprintf(error,sizeof(error), "Type of received value [%s] is not sutable for [%s@%s] having type [%d]", c, item->key, item->host_name, item->value_type); - zabbix_log( LOG_LEVEL_WARNING, "%s", error); + zbx_snprintf(error,sizeof(error), "Type of received value [%s] is not sutable for [%s@%s] having type [%d]", + c, + item->key, + item->host_name, + item->value_type); + zabbix_log( LOG_LEVEL_WARNING, "%s", + error); zabbix_log( LOG_LEVEL_WARNING, "Returning NOTSUPPORTED"); result->msg=strdup(error); return NOTSUPPORTED; } - zabbix_log( LOG_LEVEL_DEBUG, "End get_value_agent(result:%s)", c); + zabbix_log( LOG_LEVEL_DEBUG, "End get_value_agent(result:%s)", + c); return SUCCEED; } diff --git a/src/zabbix_server/poller/checks_aggregate.c b/src/zabbix_server/poller/checks_aggregate.c index 1b1ab3e1..9b55ad63 100644 --- a/src/zabbix_server/poller/checks_aggregate.c +++ b/src/zabbix_server/poller/checks_aggregate.c @@ -70,7 +70,8 @@ static int evaluate_one(double *result, int *num, char *grpfunc, char const *val } else { - zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])",grpfunc); + zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])", + grpfunc); ret = FAIL; } @@ -99,18 +100,31 @@ static int evaluate_aggregate(AGENT_RESULT *res,char *grpfunc, char *hostgroup, now=time(NULL); - zabbix_log( LOG_LEVEL_DEBUG, "In evaluate_aggregate('%s','%s','%s','%s','%s')",grpfunc,hostgroup,itemkey,itemfunc,param); + zabbix_log( LOG_LEVEL_DEBUG, "In evaluate_aggregate('%s','%s','%s','%s','%s')", + grpfunc, + hostgroup, + itemkey, + itemfunc, + param); + init_result(res); DBescape_string(itemkey,itemkey_esc,MAX_STRING_LEN); DBescape_string(hostgroup,hostgroup_esc,MAX_STRING_LEN); /* Get list of affected item IDs */ strscpy(items,"0"); - result = DBselect("select itemid from items i,hosts_groups hg,hosts h,groups g where hosts_groups.groupid=groups.groupid and items.hostid=hosts.hostid and hosts_groups.hostid=hosts.hostid and groups.name='%s' and items.key_='%s' and items.status=%d and hosts.status=%d and" ZBX_COND_NODEID,hostgroup_esc, itemkey_esc, ITEM_STATUS_ACTIVE, HOST_STATUS_MONITORED, LOCAL_NODE("h.hostid")); + result = DBselect("select itemid from items i,hosts_groups hg,hosts h,groups g where hosts_groups.groupid=groups.groupid and items.hostid=hosts.hostid and hosts_groups.hostid=hosts.hostid and groups.name='%s' and items.key_='%s' and items.status=%d and hosts.status=%d and" ZBX_COND_NODEID, + hostgroup_esc, + itemkey_esc, + ITEM_STATUS_ACTIVE, + HOST_STATUS_MONITORED, + LOCAL_NODE("h.hostid")); while((row=DBfetch(result))) { - zbx_snprintf(items2,sizeof(items2),"%s,%s",items, row[0]); + zbx_snprintf(items2,sizeof(items2),"%s,%s", + items, + row[0]); /* zabbix_log( LOG_LEVEL_WARNING, "ItemIDs items2[%s])",items2);*/ strscpy(items,items2); /* zabbix_log( LOG_LEVEL_WARNING, "ItemIDs items[%s])",items2);*/ @@ -119,7 +133,8 @@ static int evaluate_aggregate(AGENT_RESULT *res,char *grpfunc, char *hostgroup, if(strcmp(itemfunc,"last") == 0) { - zbx_snprintf(sql,sizeof(sql),"select itemid,value_type,lastvalue from items where lastvalue is not NULL and items.itemid in (%s)",items); + zbx_snprintf(sql,sizeof(sql),"select itemid,value_type,lastvalue from items where lastvalue is not NULL and items.itemid in (%s)", + items); zbx_snprintf(sql2,sizeof(sql2),"select itemid,value_type,lastvalue from items where 0=1"); } /* The SQL works very very slow on MySQL 4.0. That's why it has been split into two. */ @@ -131,12 +146,19 @@ static int evaluate_aggregate(AGENT_RESULT *res,char *grpfunc, char *hostgroup, (strcmp(itemfunc,"sum") == 0) ) { - zbx_snprintf(sql,sizeof(sql),"select h.itemid,i.value_type,%s(h.value) from items i,history h where h.itemid=i.itemid and h.itemid in (%s) and h.clock>%d group by h.itemid,i.value_type",itemfunc, items, now - atoi(param)); - zbx_snprintf(sql2,sizeof(sql),"select h.itemid,i.value_type,%s(h.value) from items i,history_uint h where h.itemid=i.itemid and h.itemid in (%s) and h.clock>%d group by h.itemid,i.value_type",itemfunc, items, now - atoi(param)); + zbx_snprintf(sql,sizeof(sql),"select h.itemid,i.value_type,%s(h.value) from items i,history h where h.itemid=i.itemid and h.itemid in (%s) and h.clock>%d group by h.itemid,i.value_type", + itemfunc, + items, + now - atoi(param)); + zbx_snprintf(sql2,sizeof(sql),"select h.itemid,i.value_type,%s(h.value) from items i,history_uint h where h.itemid=i.itemid and h.itemid in (%s) and h.clock>%d group by h.itemid,i.value_type", + itemfunc, + items, + now - atoi(param)); } else { - zabbix_log( LOG_LEVEL_WARNING, "Unsupported item function [%s])",itemfunc); + zabbix_log( LOG_LEVEL_WARNING, "Unsupported item function [%s])", + itemfunc); return FAIL; } zabbix_log( LOG_LEVEL_DEBUG, "SQL [%s]",sql); @@ -149,7 +171,8 @@ static int evaluate_aggregate(AGENT_RESULT *res,char *grpfunc, char *hostgroup, value = row[2]; if(FAIL == evaluate_one(&d, &num, grpfunc, value, valuetype)) { - zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])",grpfunc); + zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])", + grpfunc); DBfree_result(result); return FAIL; } @@ -163,7 +186,8 @@ static int evaluate_aggregate(AGENT_RESULT *res,char *grpfunc, char *hostgroup, value = row[2]; if(FAIL == evaluate_one(&d, &num, grpfunc, value, valuetype)) { - zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])",grpfunc); + zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])", + grpfunc); DBfree_result(result); return FAIL; } @@ -171,7 +195,9 @@ static int evaluate_aggregate(AGENT_RESULT *res,char *grpfunc, char *hostgroup, if(num==0) { - zabbix_log( LOG_LEVEL_WARNING, "No values for group[%s] key[%s])",hostgroup,itemkey); + zabbix_log( LOG_LEVEL_WARNING, "No values for group[%s] key[%s])", + hostgroup, + itemkey); return FAIL; } @@ -184,7 +210,8 @@ static int evaluate_aggregate(AGENT_RESULT *res,char *grpfunc, char *hostgroup, SET_DBL_RESULT(res, d); } - zabbix_log( LOG_LEVEL_DEBUG, "Result([" ZBX_FS_DBL "])",d); + zabbix_log( LOG_LEVEL_DEBUG, "End evaluate_aggregate(result:" ZBX_FS_DBL ")", + d); return SUCCEED; } @@ -218,7 +245,8 @@ int get_value_aggregate(DB_ITEM *item, AGENT_RESULT *result) int ret = SUCCEED; - zabbix_log( LOG_LEVEL_DEBUG, "In get_value_aggregate([%s])",item->key); + zabbix_log( LOG_LEVEL_DEBUG, "In get_value_aggregate([%s])", + item->key); init_result(result); @@ -311,7 +339,13 @@ int get_value_aggregate(DB_ITEM *item, AGENT_RESULT *result) else ret = NOTSUPPORTED; } - zabbix_log( LOG_LEVEL_DEBUG, "Evaluating aggregate[%s] grpfunc[%s] group[%s] itemkey[%s] itemfunc [%s] parameter [%s]",item->key, function_grp, group, itemkey, function_item, parameter); + zabbix_log( LOG_LEVEL_DEBUG, "Evaluating aggregate[%s] grpfunc[%s] group[%s] itemkey[%s] itemfunc [%s] parameter [%s]", + item->key, + function_grp, + group, + itemkey, + function_item, + parameter); if( (ret == SUCCEED) && (evaluate_aggregate(result,function_grp, group, itemkey, function_item, parameter) != SUCCEED) diff --git a/src/zabbix_server/poller/checks_internal.c b/src/zabbix_server/poller/checks_internal.c index 435657d4..ed53c36e 100644 --- a/src/zabbix_server/poller/checks_internal.c +++ b/src/zabbix_server/poller/checks_internal.c @@ -81,8 +81,10 @@ int get_value_internal(DB_ITEM *item, AGENT_RESULT *result) } else { - zbx_snprintf(error,sizeof(error),"Internal check [%s] is not supported", item->key); - zabbix_log( LOG_LEVEL_WARNING, "%s", error); + zbx_snprintf(error,sizeof(error),"Internal check [%s] is not supported", + item->key); + zabbix_log( LOG_LEVEL_WARNING, "%s", + error); SET_STR_RESULT(result, strdup(error)); return NOTSUPPORTED; } diff --git a/src/zabbix_server/poller/checks_simple.c b/src/zabbix_server/poller/checks_simple.c index 396e3f4c..d0ac092c 100644 --- a/src/zabbix_server/poller/checks_simple.c +++ b/src/zabbix_server/poller/checks_simple.c @@ -36,24 +36,30 @@ int get_value_simple(DB_ITEM *item, AGENT_RESULT *result) init_result(result); - zabbix_log( LOG_LEVEL_DEBUG, "In get_value_simple([%s]", item->key); + zabbix_log( LOG_LEVEL_DEBUG, "In get_value_simple([%s]", + item->key); if(0 == strncmp(item->key,"service.ntp",11)) { l=strstr(item->key,"["); r=strstr(item->key,"]"); if(l==NULL || r==NULL) - zbx_snprintf(c,sizeof(c),"net.tcp.service[%s]",item->key); + zbx_snprintf(c,sizeof(c),"net.tcp.service[%s]", + item->key); else { zbx_strlcpy( param,l+1, r-l-1); if(item->useip==1) { - zbx_snprintf(c,sizeof(c),"net.tcp.service[%s,%s]",item->key,item->host_ip); + zbx_snprintf(c,sizeof(c),"net.tcp.service[%s,%s]", + item->key, + item->host_ip); } else { - zbx_snprintf(c,sizeof(c),"net.tcp.service[%s,%s]",item->key,item->host_ip); + zbx_snprintf(c,sizeof(c),"net.tcp.service[%s,%s]", + item->key, + item->host_ip); } } } @@ -64,18 +70,22 @@ int get_value_simple(DB_ITEM *item, AGENT_RESULT *result) l=strstr(item->key,"["); r=strstr(item->key,"]"); if(l==NULL || r==NULL) - zbx_snprintf(c,sizeof(c),"%s",item->key); + zbx_snprintf(c,sizeof(c),"%s", + item->key); else { zbx_strlcpy( param,l+1, r-l-1); /* zbx_snprintf(c,sizeof(c),"dns[%s,%s]",item->ip,param);*/ - zbx_snprintf(c,sizeof(c),"dns[%s]",param); + zbx_snprintf(c,sizeof(c),"dns[%s]", + param); } } else { - zbx_snprintf(error,sizeof(error),"You must use IP address in Host %s definition", item->host_name); - zabbix_log( LOG_LEVEL_WARNING, "%s", error); + zbx_snprintf(error,sizeof(error),"You must use IP address in Host %s definition", + item->host_name); + zabbix_log( LOG_LEVEL_WARNING, "%s", + error); result->str=strdup(error); return NOTSUPPORTED; } @@ -108,16 +118,20 @@ int get_value_simple(DB_ITEM *item, AGENT_RESULT *result) } else { - zbx_snprintf(error,sizeof(error),"Port number must be numeric in [%s]", item->key); - zabbix_log( LOG_LEVEL_WARNING, "%s", error); + zbx_snprintf(error,sizeof(error),"Port number must be numeric in [%s]", + item->key); + zabbix_log( LOG_LEVEL_WARNING, "%s", + error); result->str=strdup(error); ret = NOTSUPPORTED; } } else { - zbx_snprintf(error,sizeof(error),"Too many parameters in [%s]", item->key); - zabbix_log( LOG_LEVEL_WARNING, "%s", error); + zbx_snprintf(error,sizeof(error),"Too many parameters in [%s]", + item->key); + zabbix_log( LOG_LEVEL_WARNING, "%s", + error); result->str=strdup(error); ret = NOTSUPPORTED; } @@ -143,13 +157,21 @@ int get_value_simple(DB_ITEM *item, AGENT_RESULT *result) if(port_int == 0) { - zbx_snprintf(c,sizeof(c),"%s[%s,%s]",service_sysinfo,service,ip); + zbx_snprintf(c,sizeof(c),"%s[%s,%s]", + service_sysinfo, + service, + ip); } else { - zbx_snprintf(c,sizeof(c),"%s[%s,%s,%d]",service_sysinfo,service,ip,port_int); + zbx_snprintf(c,sizeof(c),"%s[%s,%s,%d]", + service_sysinfo, + service, + ip, + port_int); } - zabbix_log( LOG_LEVEL_DEBUG, "Sysinfo [%s]", c); + zabbix_log( LOG_LEVEL_DEBUG, "Sysinfo [%s]", + c); } else { @@ -187,8 +209,10 @@ int get_value_simple(DB_ITEM *item, AGENT_RESULT *result) if(process(c, 0, result) == NOTSUPPORTED) { - zbx_snprintf(error,sizeof(error),"Simple check [%s] is not supported", c); - zabbix_log( LOG_LEVEL_WARNING, "%s", error); + zbx_snprintf(error,sizeof(error),"Simple check [%s] is not supported", + c); + zabbix_log( LOG_LEVEL_WARNING, "%s", + error); result->str=strdup(error); ret = NOTSUPPORTED; } diff --git a/src/zabbix_server/poller/checks_snmp.c b/src/zabbix_server/poller/checks_snmp.c index 4b512d40..360ae987 100644 --- a/src/zabbix_server/poller/checks_snmp.c +++ b/src/zabbix_server/poller/checks_snmp.c @@ -72,9 +72,10 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value) } else { - zbx_snprintf(error,sizeof(error),"Error in get_value_SNMP. Wrong item type [%d]. Must be SNMP.", item->type); - - zabbix_log( LOG_LEVEL_ERR, "%s", error); + zbx_snprintf(error,sizeof(error),"Error in get_value_SNMP. Wrong item type [%d]. Must be SNMP.", + item->type); + zabbix_log( LOG_LEVEL_ERR, "%s", + error); SET_MSG_RESULT(value, strdup(error)); return FAIL; @@ -84,7 +85,9 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value) if(item->useip == 1) { #ifdef NEW_APPROACH - zbx_snprintf(temp,sizeof(temp),"%s:%d", item->host_ip, item->snmp_port); + zbx_snprintf(temp,sizeof(temp),"%s:%d", + item->host_ip, + item->snmp_port); session.peername = temp; session.remote_port = item->snmp_port; #else @@ -95,7 +98,9 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value) else { #ifdef NEW_APPROACH - zbx_snprintf(temp, sizeof(temp), "%s:%d", item->host_dns, item->snmp_port); + zbx_snprintf(temp, sizeof(temp), "%s:%d", + item->host_dns, + item->snmp_port); session.peername = temp; session.remote_port = item->snmp_port; #else @@ -108,7 +113,10 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value) { session.community = (u_char *)item->snmp_community; session.community_len = strlen((void *)session.community); - zabbix_log( LOG_LEVEL_DEBUG, "SNMP [%s@%s:%d]",session.community, session.peername, session.remote_port); + zabbix_log( LOG_LEVEL_DEBUG, "SNMP [%s@%s:%d]", + session.community, + session.peername, + session.remote_port); } else if(session.version == SNMP_VERSION_3) { @@ -187,18 +195,24 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value) return FAIL; } } - zabbix_log( LOG_LEVEL_DEBUG, "SNMPv3 [%s@%s:%d]",session.securityName, session.peername, session.remote_port); + zabbix_log( LOG_LEVEL_DEBUG, "SNMPv3 [%s@%s:%d]", + session.securityName, + session.peername, + session.remote_port); } else { - zbx_snprintf(error,sizeof(error),"Error in get_value_SNMP. Unsupported session.version [%d]",(int)session.version); - zabbix_log( LOG_LEVEL_ERR, "%s", error); + zbx_snprintf(error,sizeof(error),"Error in get_value_SNMP. Unsupported session.version [%d]", + (int)session.version); + zabbix_log( LOG_LEVEL_ERR, "%s", + error); SET_MSG_RESULT(value, strdup(error)); return FAIL; } - zabbix_log( LOG_LEVEL_DEBUG, "OID [%s]", item->snmp_oid); + zabbix_log( LOG_LEVEL_DEBUG, "OID [%s]", + item->snmp_oid); SOCK_STARTUP; ss = snmp_open(&session); @@ -208,7 +222,8 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value) SOCK_CLEANUP; zbx_snprintf(error,sizeof(error),"Error doing snmp_open()"); - zabbix_log( LOG_LEVEL_ERR, "%s", error); + zabbix_log( LOG_LEVEL_ERR, "%s", + error); SET_MSG_RESULT(value, strdup(error)); return FAIL; @@ -270,8 +285,14 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value) /* Not correct. Returns huge values. */ /* SET_UI64_RESULT(value, (zbx_uint64_t)*vars->val.integer);*/ SET_UI64_RESULT(value, (unsigned long)*vars->val.integer); - zabbix_log( LOG_LEVEL_DEBUG, "OID [%s] Type [%d] UI64[" ZBX_FS_UI64 "]", item->snmp_oid, vars->type, (zbx_uint64_t)*vars->val.integer); - zabbix_log( LOG_LEVEL_DEBUG, "OID [%s] Type [%d] ULONG[%lu]", item->snmp_oid, vars->type, (uint64_t)(unsigned long)*vars->val.integer); + zabbix_log( LOG_LEVEL_DEBUG, "OID [%s] Type [%d] UI64[" ZBX_FS_UI64 "]", + item->snmp_oid, + vars->type, + (zbx_uint64_t)*vars->val.integer); + zabbix_log( LOG_LEVEL_DEBUG, "OID [%s] Type [%d] ULONG[%lu]", + item->snmp_oid, + vars->type, + (uint64_t)(unsigned long)*vars->val.integer); } else if(vars->type == ASN_COUNTER64) { @@ -322,7 +343,8 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value) else if(item->value_type != ITEM_VALUE_TYPE_STR) { zbx_snprintf(error,sizeof(error),"Cannot store SNMP string value (ASN_OCTET_STR) in item having numeric type"); - zabbix_log( LOG_LEVEL_ERR, "%s", error); + zabbix_log( LOG_LEVEL_ERR, "%s", + error); SET_MSG_RESULT(value, strdup(error)); ret = NOTSUPPORTED; @@ -356,7 +378,8 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value) if(item->value_type != ITEM_VALUE_TYPE_STR) { zbx_snprintf(error,sizeof(error),"Cannot store SNMP string value (ASN_IPADDRESS) in item having numeric type"); - zabbix_log( LOG_LEVEL_ERR, "%s", error); + zabbix_log( LOG_LEVEL_ERR, "%s", + error); SET_MSG_RESULT(value, strdup(error)); ret = NOTSUPPORTED; } @@ -366,13 +389,18 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value) if(p) { ip = vars->val.string; - zbx_snprintf(p,MAX_STRING_LEN-1,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]); + zbx_snprintf(p,MAX_STRING_LEN-1,"%d.%d.%d.%d", + ip[0], + ip[1], + ip[2], + ip[3]); SET_STR_RESULT(value, p); } else { zbx_snprintf(error,MAX_STRING_LEN-1,"Cannot allocate required memory"); - zabbix_log( LOG_LEVEL_ERR, "%s", error); + zabbix_log( LOG_LEVEL_ERR, "%s", + error); SET_MSG_RESULT(value, strdup(error)); } } @@ -382,9 +410,13 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value) /* count is not really used. Has to be removed */ count++; - zbx_snprintf(error,sizeof(error),"OID [%s] value #%d has unknow type [%X]",item->snmp_oid, count,vars->type); + zbx_snprintf(error,sizeof(error),"OID [%s] value #%d has unknow type [%X]", + item->snmp_oid, + count, + vars->type); - zabbix_log( LOG_LEVEL_ERR, "%s", error); + zabbix_log( LOG_LEVEL_ERR, "%s", + error); SET_MSG_RESULT(value, strdup(error)); ret = NOTSUPPORTED; @@ -399,18 +431,22 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value) snmp_errstring(response->errstat)); if(response->errstat == SNMP_ERR_NOSUCHNAME) { - zbx_snprintf(error,sizeof(error),"SNMP error [%s]", snmp_errstring(response->errstat)); + zbx_snprintf(error,sizeof(error),"SNMP error [%s]", + snmp_errstring(response->errstat)); - zabbix_log( LOG_LEVEL_ERR, "%s", error); + zabbix_log( LOG_LEVEL_ERR, "%s", + error); SET_MSG_RESULT(value, strdup(error)); ret=NOTSUPPORTED; } else { - zbx_snprintf(error,sizeof(error),"SNMP error [%s]", snmp_errstring(response->errstat)); + zbx_snprintf(error,sizeof(error),"SNMP error [%s]", + snmp_errstring(response->errstat)); - zabbix_log( LOG_LEVEL_ERR, "%s", error); + zabbix_log( LOG_LEVEL_ERR, "%s", + error); SET_MSG_RESULT(value, strdup(error)); ret=FAIL; @@ -418,19 +454,23 @@ int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value) } else if(status == STAT_TIMEOUT) { - zbx_snprintf(error,sizeof(error),"Timeout while connecting to [%s]",session.peername); + zbx_snprintf(error,sizeof(error),"Timeout while connecting to [%s]", + session.peername); /* snmp_sess_perror("snmpget", ss);*/ - zabbix_log( LOG_LEVEL_ERR, "%s", error); + zabbix_log( LOG_LEVEL_ERR, "%s", + error); SET_MSG_RESULT(value, strdup(error)); ret = NETWORK_ERROR; } else { - zbx_snprintf(error,sizeof(error),"SNMP error [%d]",status); + zbx_snprintf(error,sizeof(error),"SNMP error [%d]", + status); - zabbix_log( LOG_LEVEL_ERR, "%s", error); + zabbix_log( LOG_LEVEL_ERR, "%s", + error); SET_MSG_RESULT(value, strdup(error)); ret=FAIL; diff --git a/src/zabbix_server/poller/poller.c b/src/zabbix_server/poller/poller.c index 9b6307e8..c4e56d4a 100644 --- a/src/zabbix_server/poller/poller.c +++ b/src/zabbix_server/poller/poller.c @@ -63,7 +63,9 @@ int get_value(DB_ITEM *item, AGENT_RESULT *result) res=get_value_snmp(item, result); #else zabbix_log(LOG_LEVEL_WARNING, "Support of SNMP parameters was not compiled in"); - zabbix_syslog("Support of SNMP parameters was not compiled in. Cannot process [%s:%s]", item->host_name, item->key); + zabbix_syslog("Support of SNMP parameters was not compiled in. Cannot process [%s:%s]", + item->host_name, + item->key); res=NOTSUPPORTED; #endif } @@ -81,8 +83,10 @@ int get_value(DB_ITEM *item, AGENT_RESULT *result) } else { - zabbix_log(LOG_LEVEL_WARNING, "Not supported item type:%d",item->type); - zabbix_syslog("Not supported item type:%d",item->type); + zabbix_log(LOG_LEVEL_WARNING, "Not supported item type:%d", + item->type); + zabbix_syslog("Not supported item type:%d", + item->type); res=NOTSUPPORTED; } alarm(0); @@ -178,10 +182,13 @@ static void update_key_status(zbx_uint64_t hostid,int host_status) int update; zabbix_log(LOG_LEVEL_DEBUG, "In update_key_status(" ZBX_FS_UI64 ",%d)", - hostid,host_status); + hostid, + host_status); 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); + ZBX_SQL_ITEM_SELECT, + hostid, + SERVER_STATUS_KEY); row = DBfetch(result); @@ -305,8 +312,10 @@ int get_values(void) /* if(HOST_STATUS_UNREACHABLE == item.host_status)*/ if(HOST_AVAILABLE_TRUE != item.host_available) { - zabbix_log( LOG_LEVEL_WARNING, "Enabling host [%s]", item.host_name); - zabbix_syslog("Enabling host [%s]", item.host_name); + zabbix_log( LOG_LEVEL_WARNING, "Enabling host [%s]", + item.host_name); + zabbix_syslog("Enabling host [%s]", + item.host_name); DBupdate_host_availability(item.hostid,HOST_AVAILABLE_TRUE,now,agent.msg); update_key_status(item.hostid, HOST_STATUS_MONITORED); /* 0 */ item.host_available=HOST_AVAILABLE_TRUE; @@ -329,18 +338,27 @@ 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=" ZBX_FS_UI64, - CONFIG_REFRESH_UNSUPPORTED+now, now, item.itemid); + CONFIG_REFRESH_UNSUPPORTED+now, + now, + item.itemid); } else { - zabbix_log( LOG_LEVEL_WARNING, "Parameter [%s] is not supported by agent on host [%s] Old status [%d]", item.key, item.host_name, item.status); - zabbix_syslog("Parameter [%s] is not supported by agent on host [%s]", item.key, item.host_name); + zabbix_log( LOG_LEVEL_WARNING, "Parameter [%s] is not supported by agent on host [%s] Old status [%d]", + item.key, + item.host_name, + item.status); + zabbix_syslog("Parameter [%s] is not supported by agent on host [%s]", + item.key, + item.host_name); DBupdate_item_status_to_notsupported(item.itemid, agent.str); /* if(HOST_STATUS_UNREACHABLE == item.host_status)*/ if(HOST_AVAILABLE_TRUE != item.host_available) { - zabbix_log( LOG_LEVEL_WARNING, "Enabling host [%s]", item.host_name); - zabbix_syslog("Enabling host [%s]", item.host_name); + zabbix_log( LOG_LEVEL_WARNING, "Enabling host [%s]", + item.host_name); + zabbix_syslog("Enabling host [%s]", + item.host_name); DBupdate_host_availability(item.hostid,HOST_AVAILABLE_TRUE,now,agent.msg); update_key_status(item.hostid, HOST_STATUS_MONITORED); /* 0 */ item.host_available=HOST_AVAILABLE_TRUE; @@ -354,35 +372,51 @@ int get_values(void) /* First error */ if(item.host_errors_from==0) { - zabbix_log( LOG_LEVEL_WARNING, "Host [%s]: first network error, wait for %d seconds", item.host_name, CONFIG_UNREACHABLE_DELAY); - zabbix_syslog("Host [%s]: first network error, wait for %d seconds", item.host_name, CONFIG_UNREACHABLE_DELAY); + zabbix_log( LOG_LEVEL_WARNING, "Host [%s]: first network error, wait for %d seconds", + item.host_name, + CONFIG_UNREACHABLE_DELAY); + zabbix_syslog("Host [%s]: first network error, wait for %d seconds", + item.host_name, + CONFIG_UNREACHABLE_DELAY); item.host_errors_from=now; DBexecute("update hosts set errors_from=%d,disable_until=%d where hostid=" ZBX_FS_UI64, - now, now+CONFIG_UNREACHABLE_DELAY, item.hostid); + now, + now+CONFIG_UNREACHABLE_DELAY, + item.hostid); } else { if(now-item.host_errors_from>CONFIG_UNREACHABLE_PERIOD) { - zabbix_log( LOG_LEVEL_WARNING, "Host [%s] will be checked after %d seconds", item.host_name, CONFIG_UNAVAILABLE_DELAY); - zabbix_syslog("Host [%s] will be checked after %d seconds", item.host_name, CONFIG_UNAVAILABLE_DELAY); + zabbix_log( LOG_LEVEL_WARNING, "Host [%s] will be checked after %d seconds", + item.host_name, + CONFIG_UNAVAILABLE_DELAY); + zabbix_syslog("Host [%s] will be checked after %d seconds", + item.host_name, + CONFIG_UNAVAILABLE_DELAY); DBupdate_host_availability(item.hostid,HOST_AVAILABLE_FALSE,now,agent.msg); update_key_status(item.hostid,HOST_AVAILABLE_FALSE); /* 2 */ item.host_available=HOST_AVAILABLE_FALSE; DBexecute("update hosts set disable_until=%d where hostid=" ZBX_FS_UI64, - now+CONFIG_UNAVAILABLE_DELAY, item.hostid); + now+CONFIG_UNAVAILABLE_DELAY, + item.hostid); } /* Still unavailable, but won't change status to UNAVAILABLE yet */ else { - zabbix_log( LOG_LEVEL_WARNING, "Host [%s]: another network error, wait for %d seconds", item.host_name, CONFIG_UNREACHABLE_DELAY); - zabbix_syslog("Host [%s]: another network error, wait for %d seconds", item.host_name, CONFIG_UNREACHABLE_DELAY); + zabbix_log( LOG_LEVEL_WARNING, "Host [%s]: another network error, wait for %d seconds", + item.host_name, + CONFIG_UNREACHABLE_DELAY); + zabbix_syslog("Host [%s]: another network error, wait for %d seconds", + item.host_name, + CONFIG_UNREACHABLE_DELAY); DBexecute("update hosts set disable_until=%d where hostid=" ZBX_FS_UI64, - now+CONFIG_UNREACHABLE_DELAY, item.hostid); + now+CONFIG_UNREACHABLE_DELAY, + item.hostid); } } @@ -391,16 +425,24 @@ int get_values(void) /* Possibly, other logic required? */ else if(res == AGENT_ERROR) { - zabbix_log( LOG_LEVEL_WARNING, "Getting value of [%s] from host [%s] failed (ZBX_ERROR)", item.key, item.host_name); - zabbix_syslog("Getting value of [%s] from host [%s] failed (ZBX_ERROR)", item.key, item.host_name); + zabbix_log( LOG_LEVEL_WARNING, "Getting value of [%s] from host [%s] failed (ZBX_ERROR)", + item.key, + item.host_name); + zabbix_syslog("Getting value of [%s] from host [%s] failed (ZBX_ERROR)", + item.key, + item.host_name); zabbix_log( LOG_LEVEL_WARNING, "The value is not stored in database."); stop=1; } else { - zabbix_log( LOG_LEVEL_WARNING, "Getting value of [%s] from host [%s] failed", item.key, item.host_name ); - zabbix_syslog("Getting value of [%s] from host [%s] failed", item.key, item.host_name); + zabbix_log( LOG_LEVEL_WARNING, "Getting value of [%s] from host [%s] failed", + item.key, + item.host_name ); + zabbix_syslog("Getting value of [%s] from host [%s] failed", + item.key, + item.host_name); zabbix_log( LOG_LEVEL_WARNING, "The value is not stored in database."); } free_result(&agent); @@ -417,7 +459,9 @@ void main_poller_loop(int type, int num) int now; int nextcheck,sleeptime; - zabbix_log( LOG_LEVEL_DEBUG, "In main_poller_loop(type:%d,num:%d)", type, num); + zabbix_log( LOG_LEVEL_DEBUG, "In main_poller_loop(type:%d,num:%d)", + type, + num); poller_type = type; poller_num = num; @@ -431,10 +475,13 @@ void main_poller_loop(int type, int num) now=time(NULL); get_values(); - zabbix_log( LOG_LEVEL_DEBUG, "Spent %d seconds while updating values", (int)time(NULL)-now ); + zabbix_log( LOG_LEVEL_DEBUG, "Spent %d seconds while updating values", + (int)time(NULL)-now ); nextcheck=get_minnextcheck(now); - zabbix_log( LOG_LEVEL_DEBUG, "Nextcheck:%d Time:%d", nextcheck, (int)time(NULL) ); + zabbix_log( LOG_LEVEL_DEBUG, "Nextcheck:%d Time:%d", + nextcheck, + (int)time(NULL) ); if( FAIL == nextcheck) { diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c index 1ad2fe76..660fff6f 100644 --- a/src/zabbix_server/server.c +++ b/src/zabbix_server/server.c @@ -254,7 +254,8 @@ int tcp_listen(const char *host, int port, socklen_t *addrlenp) if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { - zabbix_log( LOG_LEVEL_CRIT, "Cannot bind to port %d. Another zabbix_server running? Shutting down...", port); + zabbix_log( LOG_LEVEL_CRIT, "Cannot bind to port %d. Another zabbix_server running? Shutting down...", + port); exit(FAIL); } @@ -475,7 +476,8 @@ int MAIN_ZABBIX_ENTRY(void) DBconnect(ZBX_DB_CONNECT_EXIT); - result = DBselect("select refresh_unsupported from config where " ZBX_COND_NODEID, LOCAL_NODE("configid")); + result = DBselect("select refresh_unsupported from config where " ZBX_COND_NODEID, + LOCAL_NODE("configid")); row = DBfetch(result); if( (row != NULL) && DBis_null(row[0]) != SUCCEED) @@ -484,7 +486,8 @@ int MAIN_ZABBIX_ENTRY(void) } DBfree_result(result); - result = DBselect("select masterid from nodes where nodeid=%d", CONFIG_NODEID); + result = DBselect("select masterid from nodes where nodeid=%d", + CONFIG_NODEID); row = DBfetch(result); if( (row != NULL) && DBis_null(row[0]) != SUCCEED) @@ -539,7 +542,8 @@ int MAIN_ZABBIX_ENTRY(void) if(server_num == 0) { init_main_process(); - zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Watchdog]",server_num); + zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Watchdog]", + server_num); main_watchdog_loop(); /* for(;;) zbx_sleep(3600);*/ } @@ -549,9 +553,11 @@ int MAIN_ZABBIX_ENTRY(void) { #ifdef HAVE_SNMP init_snmp("zabbix_server"); - zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Poller. SNMP:ON]",server_num); + zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Poller. SNMP:ON]", + server_num); #else - zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Poller. SNMP:OFF]",server_num); + zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Poller. SNMP:OFF]", + server_num); #endif main_poller_loop(ZBX_POLLER_TYPE_NORMAL, server_num); } @@ -570,24 +576,28 @@ int MAIN_ZABBIX_ENTRY(void) } else if(server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS) { - zabbix_log( LOG_LEVEL_WARNING, "server #%d started [ICMP pinger]",server_num); + zabbix_log( LOG_LEVEL_WARNING, "server #%d started [ICMP pinger]", + server_num); main_pinger_loop(server_num-(CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS)); } else if(server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_ALERTER_FORKS) { - zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Alerter]",server_num); + zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Alerter]", + server_num); main_alerter_loop(); } else if(server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_ALERTER_FORKS +CONFIG_HOUSEKEEPER_FORKS) { - zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Housekeeper]",server_num); + zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Housekeeper]", + server_num); main_housekeeper_loop(); } else if(server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_ALERTER_FORKS +CONFIG_HOUSEKEEPER_FORKS + CONFIG_TIMER_FORKS) { - zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Timer]",server_num); + zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Timer]", + server_num); main_timer_loop(); } else if(server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_ALERTER_FORKS @@ -596,9 +606,11 @@ int MAIN_ZABBIX_ENTRY(void) /* zabbix_log( LOG_LEVEL_WARNING, "%d<=%d",server_num, CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_ALERTER_FORKS+CONFIG_HOUSEKEEPER_FORKS + CONFIG_TIMER_FORKS + CONFIG_UNREACHABLE_POLLER_FORKS); */ #ifdef HAVE_SNMP init_snmp("zabbix_server"); - zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Poller for unreachable hosts. SNMP:ON]",server_num); + zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Poller for unreachable hosts. SNMP:ON]", + server_num); #else - zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Poller for unreachable hosts. SNMP:OFF]",server_num); + zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Poller for unreachable hosts. SNMP:OFF]", + server_num); #endif /* zabbix_log( LOG_LEVEL_WARNING, "Before main_poller_loop(%d,%d)",ZBX_POLLER_TYPE_UNREACHABLE,server_num - (CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS +CONFIG_ALERTER_FORKS+CONFIG_HOUSEKEEPER_FORKS + CONFIG_TIMER_FORKS)); */ main_poller_loop(ZBX_POLLER_TYPE_UNREACHABLE, @@ -609,7 +621,8 @@ int MAIN_ZABBIX_ENTRY(void) + CONFIG_NODEWATCHER_FORKS) { zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Node watcher. Node ID:%d]", - server_num, CONFIG_NODEID); + server_num, + CONFIG_NODEID); main_nodewatcher_loop(); } else if(server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_ALERTER_FORKS diff --git a/src/zabbix_server/timer/timer.c b/src/zabbix_server/timer/timer.c index 25aa6a2e..69dbdf57 100644 --- a/src/zabbix_server/timer/timer.c +++ b/src/zabbix_server/timer/timer.c @@ -71,7 +71,11 @@ void main_timer_loop() #endif */ - result = DBselect("select distinct %s, functions f where h.hostid=i.hostid and h.status=%d and i.status=%d and f.function in ('nodata','date','dayofweek','time','now') and i.itemid=f.itemid and" ZBX_COND_NODEID, ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, ITEM_STATUS_ACTIVE, LOCAL_NODE("h.hostid")); + result = DBselect("select distinct %s, functions f where h.hostid=i.hostid and h.status=%d and i.status=%d and f.function in ('nodata','date','dayofweek','time','now') and i.itemid=f.itemid and" ZBX_COND_NODEID, + ZBX_SQL_ITEM_SELECT, + HOST_STATUS_MONITORED, + ITEM_STATUS_ACTIVE, + LOCAL_NODE("h.hostid")); while((row=DBfetch(result))) { diff --git a/src/zabbix_server/trapper/active.c b/src/zabbix_server/trapper/active.c index 1993f2d2..9d626eb2 100644 --- a/src/zabbix_server/trapper/active.c +++ b/src/zabbix_server/trapper/active.c @@ -68,12 +68,21 @@ int send_list_of_active_checks(zbx_sock_t *sock, char *host) zabbix_log( LOG_LEVEL_DEBUG, "In send_list_of_active_checks()"); - result = DBselect("select i.key_,i.delay,i.lastlogsize from items i,hosts h where i.hostid=h.hostid and h.status=%d and i.status=%d and i.type=%d and h.host='%s' and" ZBX_COND_NODEID, HOST_STATUS_MONITORED, ITEM_STATUS_ACTIVE, ITEM_TYPE_ZABBIX_ACTIVE, host, LOCAL_NODE("h.hostid")); + result = DBselect("select i.key_,i.delay,i.lastlogsize from items i,hosts h where i.hostid=h.hostid and h.status=%d and i.status=%d and i.type=%d and h.host='%s' and" ZBX_COND_NODEID, + HOST_STATUS_MONITORED, + ITEM_STATUS_ACTIVE, + ITEM_TYPE_ZABBIX_ACTIVE, + host, + LOCAL_NODE("h.hostid")); while((row=DBfetch(result))) { - zbx_snprintf(s,sizeof(s),"%s:%s:%s\n",row[0],row[1],row[2]); - zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]", s); + zbx_snprintf(s,sizeof(s),"%s:%s:%s\n", + row[0], + row[1], + row[2]); + zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]", + s); /* if( write(sockfd,s,strlen(s)) == -1 ) */ if( zbx_tcp_send(sock,s) != SUCCEED ) { @@ -84,8 +93,10 @@ int send_list_of_active_checks(zbx_sock_t *sock, char *host) } DBfree_result(result); - zbx_snprintf(s,sizeof(s),"%s\n","ZBX_EOF"); - zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]", s); + zbx_snprintf(s,sizeof(s),"%s\n", + "ZBX_EOF"); + zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]", + s); /* if( write(sockfd,s,strlen(s)) == -1 ) */ if( zbx_tcp_send(sock,s) != SUCCEED ) { diff --git a/src/zabbix_server/trapper/autoregister.c b/src/zabbix_server/trapper/autoregister.c index 7cf92f53..186b725a 100644 --- a/src/zabbix_server/trapper/autoregister.c +++ b/src/zabbix_server/trapper/autoregister.c @@ -39,15 +39,18 @@ int autoregister(char *server) int len; int hostid; - zabbix_log( LOG_LEVEL_DEBUG, "In autoregister(%s)",server); + zabbix_log( LOG_LEVEL_DEBUG, "In autoregister(%s)", + server); if(DBhost_exists(server) == SUCCEED) { - zabbix_log( LOG_LEVEL_DEBUG, "Host [%s] already exists. Do nothing.", server); + zabbix_log( LOG_LEVEL_DEBUG, "Host [%s] already exists. Do nothing.", + server); return FAIL; } - result = DBselect("select id,pattern,hostid from autoreg where " ZBX_COND_NODEID " order by priority", LOCAL_NODE("id")); + result = DBselect("select id,pattern,hostid from autoreg where " ZBX_COND_NODEID " order by priority", + LOCAL_NODE("id")); while((row=DBfetch(result))) { @@ -56,13 +59,17 @@ int autoregister(char *server) if(zbx_regexp_match(server, pattern, &len) != 0) { - zabbix_log( LOG_LEVEL_DEBUG, "Matched [%s] [%s]",server,pattern); + zabbix_log( LOG_LEVEL_DEBUG, "Matched [%s] [%s]", + server, + pattern); register_new_host(server, hostid); break; } else { - zabbix_log( LOG_LEVEL_DEBUG, "No match [%s] [%s]",server,pattern); + zabbix_log( LOG_LEVEL_DEBUG, "No match [%s] [%s]", + server, + pattern); } } @@ -75,16 +82,20 @@ static void register_new_host(char *server, int host_templateid) { int hostid; - zabbix_log( LOG_LEVEL_DEBUG, "In register_new_host(%s,%d)", server, host_templateid); + zabbix_log( LOG_LEVEL_DEBUG, "In register_new_host(%s,%d)", + server, + host_templateid); hostid = DBadd_host(server, 10050, HOST_STATUS_MONITORED, 0, "", 0, HOST_AVAILABLE_UNKNOWN); - zabbix_log( LOG_LEVEL_DEBUG, "Added new host with hostid [%d]", hostid); + zabbix_log( LOG_LEVEL_DEBUG, "Added new host with hostid [%d]", + hostid); /* Use hostid as a template */ if( (hostid>0) && (host_templateid!=0)) { - zabbix_log( LOG_LEVEL_DEBUG, "Using hostid [%d] as a template", host_templateid); + zabbix_log( LOG_LEVEL_DEBUG, "Using hostid [%d] as a template", + host_templateid); DBadd_templates_to_host(hostid,host_templateid); DBsync_host_with_templates(hostid); diff --git a/src/zabbix_server/trapper/nodeevents.c b/src/zabbix_server/trapper/nodeevents.c index 73e929a4..f5c832a6 100644 --- a/src/zabbix_server/trapper/nodeevents.c +++ b/src/zabbix_server/trapper/nodeevents.c @@ -67,7 +67,8 @@ static int process_record(int nodeid, char *record) DB_EVENT event; - zabbix_log( LOG_LEVEL_DEBUG, "In process_record [%s]", record); + zabbix_log( LOG_LEVEL_DEBUG, "In process_record [%s]", + record); memset(&event,0,sizeof(DB_EVENT)); @@ -115,7 +116,8 @@ int node_events(char *data) datalen = strlen(data); - zabbix_log( LOG_LEVEL_DEBUG, "In node_events(len:%d)", datalen); + zabbix_log( LOG_LEVEL_DEBUG, "In node_events(len:%d)", + datalen); DBbegin(); s=(char *)strtok(data,"\n"); @@ -130,7 +132,10 @@ int node_events(char *data) nodeid=atoi(tmp); firstline=0; zabbix_log( LOG_LEVEL_WARNING, "NODE %d: Received events from node %d for node %d datalen %d", - CONFIG_NODEID, sender_nodeid, nodeid, datalen); + CONFIG_NODEID, + sender_nodeid, + nodeid, + datalen); } else { diff --git a/src/zabbix_server/trapper/nodehistory.c b/src/zabbix_server/trapper/nodehistory.c index 9d2e85f8..2ef3a950 100644 --- a/src/zabbix_server/trapper/nodehistory.c +++ b/src/zabbix_server/trapper/nodehistory.c @@ -69,7 +69,8 @@ static int process_record(int nodeid, char *record) zbx_uint64_t value_uint; int res = FAIL; - zabbix_log( LOG_LEVEL_DEBUG, "In process_record [%s]", record); + zabbix_log( LOG_LEVEL_DEBUG, "In process_record [%s]", + record); zbx_get_field(record,tmp,0,'|'); table=atoi(tmp); @@ -136,7 +137,8 @@ int node_history(char *data) datalen=strlen(data); - zabbix_log( LOG_LEVEL_DEBUG, "In node_history(len:%d)", datalen); + zabbix_log( LOG_LEVEL_DEBUG, "In node_history(len:%d)", + datalen); DBbegin(); @@ -145,14 +147,18 @@ int node_history(char *data) { if(firstline == 1) { - zabbix_log( LOG_LEVEL_DEBUG, "First line [%s]", s); + zabbix_log( LOG_LEVEL_DEBUG, "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 datalen %d", - CONFIG_NODEID, sender_nodeid, nodeid, datalen); + CONFIG_NODEID, + sender_nodeid, + nodeid, + datalen); } else { diff --git a/src/zabbix_server/trapper/nodesync.c b/src/zabbix_server/trapper/nodesync.c index 3fc3483d..0705edd6 100644 --- a/src/zabbix_server/trapper/nodesync.c +++ b/src/zabbix_server/trapper/nodesync.c @@ -98,13 +98,19 @@ static int process_record(int nodeid, char *record) if(key == NULL) { - zabbix_log( LOG_LEVEL_WARNING, "Cannot find key field for table [%s]",tablename); + zabbix_log( LOG_LEVEL_WARNING, "Cannot find key field for table [%s]", + tablename); return FAIL; } if(op==NODE_CONFIGLOG_OP_DELETE) { - zbx_snprintf(tmp,sizeof(tmp),"delete from %s where %s=" ZBX_FS_UI64 " and nodeid=%d", tablename, key, recid, nodeid); - zabbix_log( LOG_LEVEL_DEBUG, "SQL [%s]", sql); + zbx_snprintf(tmp,sizeof(tmp),"delete from %s where %s=" ZBX_FS_UI64 " and nodeid=%d", + tablename, + key, + recid, + nodeid); + zabbix_log( LOG_LEVEL_DEBUG, "SQL [%s]", + sql); return SUCCEED; } @@ -123,7 +129,8 @@ static int process_record(int nodeid, char *record) { if(strcmp(value,"NULL")==0) { - zbx_snprintf(tmp,sizeof(tmp),"%s=NULL,", fieldname); + zbx_snprintf(tmp,sizeof(tmp),"%s=NULL,", + fieldname); zbx_strlcat(fields_update,tmp,sizeof(fields)); zbx_snprintf(tmp,sizeof(tmp),"NULL,", value); @@ -132,31 +139,39 @@ static int process_record(int nodeid, char *record) { if(valuetype == ZBX_TYPE_INT || valuetype == ZBX_TYPE_UINT || valuetype == ZBX_TYPE_ID) { - zbx_snprintf(tmp,sizeof(tmp),"%s=%s,", fieldname, value); + zbx_snprintf(tmp,sizeof(tmp),"%s=%s,", + fieldname, + value); zbx_strlcat(fields_update,tmp,sizeof(fields)); - zbx_snprintf(tmp,sizeof(tmp),"%s,", value); + zbx_snprintf(tmp,sizeof(tmp),"%s,", + value); } else { DBescape_string(value, value_esc,MAX_STRING_LEN); - zbx_snprintf(tmp,sizeof(tmp),"%s='%s',", fieldname, value_esc); + zbx_snprintf(tmp,sizeof(tmp),"%s='%s',", + fieldname, + value_esc); zbx_strlcat(fields_update,tmp,sizeof(fields)); - zbx_snprintf(tmp,sizeof(tmp),"'%s',", value_esc); + zbx_snprintf(tmp,sizeof(tmp),"'%s',", + value_esc); } } zbx_strlcat(values,tmp,sizeof(values)); /* zabbix_log( LOG_LEVEL_WARNING, "VALUES [%s]", values);*/ - zbx_snprintf(tmp,sizeof(tmp),"%s,", fieldname); + zbx_snprintf(tmp,sizeof(tmp),"%s,", + fieldname); zbx_strlcat(fields,tmp,sizeof(fields)); /* zabbix_log( LOG_LEVEL_WARNING, "FIELDS [%s]", fields);*/ } else { - zabbix_log( LOG_LEVEL_WARNING, "Unknown record operation [%d]",op); + zabbix_log( LOG_LEVEL_WARNING, "Unknown record operation [%d]", + op); return FAIL; } } @@ -166,26 +181,41 @@ static int process_record(int nodeid, char *record) if(op==NODE_CONFIGLOG_OP_UPDATE) { - zbx_snprintf(sql,sizeof(sql),"update %s set %s where %s=" ZBX_FS_UI64, tablename, fields_update, key, recid); + zbx_snprintf(sql,sizeof(sql),"update %s set %s where %s=" ZBX_FS_UI64, + tablename, + fields_update, + key, + recid); } else if(op==NODE_CONFIGLOG_OP_ADD) { - result = DBselect("select 0 from %s where %s=" ZBX_FS_UI64, tablename, key, recid); + result = DBselect("select 0 from %s where %s=" ZBX_FS_UI64, + tablename, + key, + recid); row = DBfetch(result); if(row) { - zbx_snprintf(sql,sizeof(sql),"update %s set %s where %s=" ZBX_FS_UI64, tablename, fields_update, key, recid); + zbx_snprintf(sql,sizeof(sql),"update %s set %s where %s=" ZBX_FS_UI64, + tablename, + fields_update, + key, + recid); } else { - zbx_snprintf(sql,sizeof(sql),"insert into %s (%s) values(%s)", tablename, fields, values); + zbx_snprintf(sql,sizeof(sql),"insert into %s (%s) values(%s)", + tablename, + fields, + values); } DBfree_result(result); } /* zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql);*/ if(FAIL == DBexecute(sql)) { - zabbix_log( LOG_LEVEL_WARNING, "Failed [%s]", record); + zabbix_log( LOG_LEVEL_WARNING, "Failed [%s]", + record); } return SUCCEED; @@ -217,7 +247,8 @@ int node_sync(char *data) datalen=strlen(data); - zabbix_log( LOG_LEVEL_DEBUG, "In node_sync(len:%d)", datalen); + zabbix_log( LOG_LEVEL_DEBUG, "In node_sync(len:%d)", + datalen); DBbegin(); @@ -233,7 +264,10 @@ int node_sync(char *data) nodeid=atoi(tmp); firstline=0; zabbix_log( LOG_LEVEL_WARNING, "NODE %d: Received data from node %d for node %d datalen %d", - CONFIG_NODEID, sender_nodeid, nodeid, datalen); + CONFIG_NODEID, + sender_nodeid, + nodeid, + datalen); } else { diff --git a/src/zabbix_server/trapper/trapper.c b/src/zabbix_server/trapper/trapper.c index edec2236..102c8186 100644 --- a/src/zabbix_server/trapper/trapper.c +++ b/src/zabbix_server/trapper/trapper.c @@ -55,7 +55,9 @@ int process_trap(zbx_sock_t *sock,char *s, int max_len) for( p=s+strlen(s)-1; p>s && ( *p=='\r' || *p =='\n' || *p == ' ' ); --p ); p[1]=0; - zabbix_log( LOG_LEVEL_DEBUG, "Trapper got [%s] len %d", s, strlen(s)); + zabbix_log( LOG_LEVEL_DEBUG, "Trapper got [%s] len %d", + s, + strlen(s)); /* Request for list of active checks */ if(strncmp(s,"ZBX_GET_ACTIVE_CHECKS", strlen("ZBX_GET_ACTIVE_CHECKS")) == 0) @@ -70,11 +72,13 @@ int process_trap(zbx_sock_t *sock,char *s, int max_len) { if(autoregister(host) == SUCCEED) { - zabbix_log( LOG_LEVEL_DEBUG, "New host registered [%s]", host); + zabbix_log( LOG_LEVEL_DEBUG, "New host registered [%s]", + host); } else { - zabbix_log( LOG_LEVEL_DEBUG, "Host already exists [%s]", host); + zabbix_log( LOG_LEVEL_DEBUG, "Host already exists [%s]", + host); } ret=send_list_of_active_checks(sock, host); } @@ -219,7 +223,8 @@ void process_trapper_child(zbx_sock_t *sock) /* alarm(0);*/ gettimeofday(&tv, NULL); - zabbix_log( LOG_LEVEL_DEBUG, "Trap processed in " ZBX_FS_DBL " seconds", (double)(tv.tv_usec-msec)/1000000 ); + zabbix_log( LOG_LEVEL_DEBUG, "Trap processed in " ZBX_FS_DBL " seconds", + (double)(tv.tv_usec-msec)/1000000 ); } void child_trapper_main(int i,int listenfd, int addrlen) @@ -232,7 +237,8 @@ void child_trapper_main(int i,int listenfd, int addrlen) zabbix_log( LOG_LEVEL_DEBUG, "In child_trapper_main()"); /* zabbix_log( LOG_LEVEL_WARNING, "zabbix_trapperd %ld started",(long)getpid());*/ - zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Trapper]", i); + zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Trapper]", + i); DBconnect(ZBX_DB_CONNECT_NORMAL); diff --git a/src/zabbix_server/utils/nodechange.c b/src/zabbix_server/utils/nodechange.c index e63ffe27..917c2702 100644 --- a/src/zabbix_server/utils/nodechange.c +++ b/src/zabbix_server/utils/nodechange.c @@ -146,7 +146,9 @@ int change_nodeid(int old_id, int new_id) if(tables[i].fields[j].type == ZBX_TYPE_ID) { DBexecute("update %s set %s=%s+" ZBX_FS_UI64 " where %s>0\n", - tables[i].table, tables[i].fields[j].name, tables[i].fields[j].name, + tables[i].table, + tables[i].fields[j].name, + tables[i].fields[j].name, (zbx_uint64_t)__UINT64_C(100000000000000)*(zbx_uint64_t)new_id, tables[i].fields[j].name); } @@ -162,11 +164,13 @@ int change_nodeid(int old_id, int new_id) convert_trigger_expression(old_id, new_id, row[0], new_expression); DBescape_string(new_expression, new_expression_esc,MAX_STRING_LEN); DBexecute("update triggers set expression='%s' where triggerid=%s", - new_expression_esc, row[1]); + new_expression_esc, + row[1]); } DBfree_result(result); - DBexecute("insert into nodes (nodeid,name,ip,nodetype) values (%d,'Local node','127.0.0.1',1)", new_id); + DBexecute("insert into nodes (nodeid,name,ip,nodetype) values (%d,'Local node','127.0.0.1',1)", + new_id); DBcommit(); DBclose(); diff --git a/src/zabbix_server/zlog.c b/src/zabbix_server/zlog.c index 654cedcf..8bfb20fe 100644 --- a/src/zabbix_server/zlog.c +++ b/src/zabbix_server/zlog.c @@ -65,7 +65,11 @@ void zabbix_syslog(const char *fmt, ...) /* This is made to disable writing to database for watchdog */ if(CONFIG_ENABLE_LOG == 0) return; - result = DBselect("select %s where h.hostid=i.hostid and i.key_='%s' and i.value_type=%d and" ZBX_COND_NODEID, ZBX_SQL_ITEM_SELECT, SERVER_ZABBIXLOG_KEY, ITEM_VALUE_TYPE_STR, LOCAL_NODE("h.hostid")); + result = DBselect("select %s where h.hostid=i.hostid and i.key_='%s' and i.value_type=%d and" ZBX_COND_NODEID, + ZBX_SQL_ITEM_SELECT, + SERVER_ZABBIXLOG_KEY, + ITEM_VALUE_TYPE_STR, + LOCAL_NODE("h.hostid")); while((row=DBfetch(result))) { |
