From 2f691b3628c4589fe258def9564d78cd134d3ebb Mon Sep 17 00:00:00 2001 From: hugetoad Date: Sun, 4 Aug 2002 16:53:24 +0000 Subject: - added upgrades/dbpatches/1.0beta4_to_1.0beta5/ with patches (Alexei) - added support for disktotal[*] (Alexei) - added support for inodetotal[*] (Alexei) - added support for *,/,+, and - in trigger expressions (Alexei) - removed frontends/php/chart4.php (Alexei) - update item status to UNSUPPORTED in case if SNMP support was not included into zabbix_suckerd (Alexei) - added mysql_init() to DBconnect() (Alexei) - fixed Next100 and Prev100 for case if some hosts are hidden (Alexei) - added select for latest values (Alexei) - delete related services if trigger is deleted (Alexei) - fixed problem with substitution of macros for messages (Alexei) - eliminated DBis_empty() by replacing to DBnum_rows() (Alexei) - MAX_STRING_LEN increased to 4096 (Alexei) - fixed zabbix_log(). Possible coredump if data contains %s, etc (Alexei) git-svn-id: svn://svn.zabbix.com/trunk@445 97f52cf1-0a1b-0410-bd0e-c28be96e8082 --- include/functions.c | 137 +++++++++++++++++++--------------------------------- 1 file changed, 49 insertions(+), 88 deletions(-) (limited to 'include/functions.c') diff --git a/include/functions.c b/include/functions.c index 5102db45..1e9f7212 100644 --- a/include/functions.c +++ b/include/functions.c @@ -31,8 +31,8 @@ int evaluate_MIN(char *value,DB_ITEM *item,int parameter) DB_RESULT *result; char sql[MAX_STRING_LEN+1]; - int now; + int res = SUCCEED; if(item->value_type != 0) { @@ -44,18 +44,18 @@ int evaluate_MIN(char *value,DB_ITEM *item,int parameter) sprintf(sql,"select min(value) from history where clock>%d and itemid=%d",now-parameter,item->itemid); result = DBselect(sql); - if(DBis_empty(result) == SUCCEED) + if(DBnum_rows(result) == 0) { zabbix_log(LOG_LEVEL_DEBUG, "Result for MIN is empty" ); - DBfree_result(result); - return FAIL; + res = FAIL; + } + else + { + strncpy(value,DBget_field(result,0,0),MAX_STRING_LEN); } - - strncpy(value,DBget_field(result,0,0),MAX_STRING_LEN); - DBfree_result(result); - return SUCCEED; + return res; } /* @@ -66,8 +66,8 @@ int evaluate_MAX(char *value,DB_ITEM *item,int parameter) DB_RESULT *result; char sql[MAX_STRING_LEN+1]; - int now; + int res = SUCCEED; if(item->value_type != 0) { @@ -79,18 +79,18 @@ int evaluate_MAX(char *value,DB_ITEM *item,int parameter) sprintf(sql,"select max(value) from history where clock>%d and itemid=%d",now-parameter,item->itemid); result = DBselect(sql); - if(DBis_empty(result) == SUCCEED) + if(DBnum_rows(result) == 0) { zabbix_log(LOG_LEVEL_DEBUG, "Result for MAX is empty" ); - DBfree_result(result); - return FAIL; + res = FAIL; + } + else + { + strncpy(value,DBget_field(result,0,0),MAX_STRING_LEN); } - - strncpy(value,DBget_field(result,0,0),MAX_STRING_LEN); - DBfree_result(result); - return SUCCEED; + return res; } /* @@ -210,13 +210,6 @@ void update_functions(DB_ITEM *item) result = DBselect(sql); - if(DBis_empty(result) == SUCCEED) - { - zabbix_log( LOG_LEVEL_DEBUG, "No functions to update."); - DBfree_result(result); - return; - } - for(i=0;i0) { @@ -582,25 +571,17 @@ void apply_actions(int triggerid,int good) sprintf(sql,"select actionid,userid,delay,subject,message from actions where triggerid=%d and good=%d and nextcheck<=%d",triggerid,good,now); result = DBselect(sql); - if(DBis_empty(result) == SUCCEED) + for(i=0;istatus) { - if(atoi(DBget_field(result2,j,0))>status) - { - status=atoi(DBget_field(result2,j,0)); - } + status=atoi(DBget_field(result2,j,0)); } - sprintf(sql,"update services set status=%d where serviceid=%d",status,atoi(DBget_field(result,i,0))); - DBexecute(sql); - DBfree_result(result2); - } - else - { - zabbix_log( LOG_LEVEL_ERR, "Unknown calculation algorithm of service status [%d]", algorithm); } + sprintf(sql,"update services set status=%d where serviceid=%d",status,atoi(DBget_field(result,i,0))); + DBexecute(sql); + DBfree_result(result2); + } + else + { + zabbix_log( LOG_LEVEL_ERR, "Unknown calculation algorithm of service status [%d]", algorithm); } - } + } DBfree_result(result); sprintf(sql,"select serviceupid from services_links where servicedownid=%d",serviceid); result=DBselect(sql); - if(DBis_empty(result) != SUCCEED) + for(i=0;i