diff options
author | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2001-11-23 19:07:25 +0000 |
---|---|---|
committer | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2001-11-23 19:07:25 +0000 |
commit | 3013847c08c1b9c6e8941cbaeb0d2da7cdb002b5 (patch) | |
tree | 79ad20349c21c0b8ce5d4c535504677ecbec90d4 /include | |
parent | b38d789919f307b4ad3c7faadfe6f34b469aee9c (diff) | |
download | zabbix-3013847c08c1b9c6e8941cbaeb0d2da7cdb002b5.tar.gz zabbix-3013847c08c1b9c6e8941cbaeb0d2da7cdb002b5.tar.xz zabbix-3013847c08c1b9c6e8941cbaeb0d2da7cdb002b5.zip |
Minor changes
git-svn-id: svn://svn.zabbix.com/trunk@251 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'include')
-rw-r--r-- | include/expression.c | 11 | ||||
-rw-r--r-- | include/functions.c | 129 | ||||
-rw-r--r-- | include/functions.h | 2 |
3 files changed, 14 insertions, 128 deletions
diff --git a/include/expression.c b/include/expression.c index 2d9dc8b1..8ed8c2f2 100644 --- a/include/expression.c +++ b/include/expression.c @@ -8,6 +8,9 @@ #include "common.h" #include "db.h" +/* + * Return 0 if arguments are equal (differs less than 0.000001), 1 - otherwise + */ int cmp_double(double a,double b) { if(fabs(a-b)<0.000001) @@ -19,7 +22,7 @@ int cmp_double(double a,double b) /* * Return SUCEED if parameter has format X.X or X, where X is [0..9]{1,n} - * */ + */ int is_float(char *c) { int i; @@ -50,6 +53,9 @@ int is_float(char *c) return SUCCEED; } +/* + * Delete all spaces from given string + */ void delete_spaces(char *c) { int i,j; @@ -71,6 +77,9 @@ void delete_spaces(char *c) } +/* + * Locate character in given string. FAIL - not found, otherwise character position is returned + */ int find_char(char *str,char c) { int i; diff --git a/include/functions.c b/include/functions.c index a001a8a9..31b510b9 100644 --- a/include/functions.c +++ b/include/functions.c @@ -22,35 +22,6 @@ #include "functions.h" #include "expression.h" -int evaluate_LAST(float *last,int itemid,int parameter) -{ - DB_RESULT *result; - - char c[256]; - char *field; - - sprintf(c,"select lastvalue from items where itemid=%d and lastvalue is not null", itemid ); - - result = DBselect(c); - if((result==NULL)||(DBnum_rows(result)==0)) - { - DBfree_result(result); - return FAIL; - } - - field = DBget_field(result,0,0); - if( field == NULL ) - { - DBfree_result(result); - return FAIL; - } - *last=atof(field); - - DBfree_result(result); - - return SUCCEED; -} - int evaluate_MIN(float *min,int itemid,int parameter) { DB_RESULT *result; @@ -122,68 +93,6 @@ int evaluate_MAX(float *max,int itemid,int parameter) return SUCCEED; } -int evaluate_PREV(float *prev,int itemid,int parameter) -{ - DB_RESULT *result; - - char c[1024]; - char *field; - - sprintf(c,"select prevvalue from items where itemid=%d and prevvalue is not null", itemid ); - - result = DBselect(c); - if((result==NULL)||(DBnum_rows(result)==0)) - { - syslog(LOG_NOTICE, "Result for PREV is empty" ); - DBfree_result(result); - return FAIL; - } - - field = DBget_field(result,0,0); - if( field == NULL ) - { - syslog(LOG_NOTICE, "Result for PREV is empty" ); - DBfree_result(result); - return FAIL; - } - *prev=atof(field); - - DBfree_result(result); - - return SUCCEED; -} - -int evaluate_DIFF(float *diff,int itemid,int parameter) -{ - float prev,last; - float tmp; - - if(evaluate_PREV(&prev,itemid,parameter) == FAIL) - { - *diff=0; - return SUCCEED; - } - - if(evaluate_LAST(&last,itemid,parameter) == FAIL) - { - *diff=0; - return SUCCEED; - } - - tmp=last-prev; - - if((tmp<0.000001)&&(tmp>-0.000001)) - { - *diff=0; - } - else - { - *diff=1; - } - - return SUCCEED; -} - int evaluate_FUNCTION(float *value,DB_ITEM *item,char *function,int parameter) { int ret = SUCCEED; @@ -198,7 +107,6 @@ int evaluate_FUNCTION(float *value,DB_ITEM *item,char *function,int parameter) { *value=item->lastvalue; } -/* ret = evaluate_LAST(value,item->itemid,parameter);*/ } else if(strcmp(function,"prev")==0) { @@ -210,7 +118,6 @@ int evaluate_FUNCTION(float *value,DB_ITEM *item,char *function,int parameter) { *value=item->prevvalue; } -/* ret = evaluate_PREV(value,item->itemid,parameter);*/ } else if(strcmp(function,"min")==0) { @@ -237,7 +144,6 @@ int evaluate_FUNCTION(float *value,DB_ITEM *item,char *function,int parameter) *value=1; } } -/* ret = evaluate_DIFF(value,item->itemid,parameter);*/ } else { @@ -247,15 +153,7 @@ int evaluate_FUNCTION(float *value,DB_ITEM *item,char *function,int parameter) return ret; } -/*int update_functions( int itemid )*/ -/*int update_functions( int sucker_num )*/ - -/* - * Flag: 0 - id==itemid - * 1 - id==sucker_num - * */ -/*void update_functions( DB_ITEM items[] )*/ -void update_functions( DB_ITEM *item ) +void update_functions(DB_ITEM *item) { DB_FUNCTION function; DB_RESULT *result; @@ -263,13 +161,8 @@ void update_functions( DB_ITEM *item ) float value; int ret=SUCCEED; int i,rows; - char *s; -/* for(row=0;items[row].itemid!=0;row++) - {*/ -/* sprintf(c,"select function,parameter,itemid from functions where itemid=%d group by 1,2,3 order by 1,2,3",items[row].itemid );*/ -/* sprintf(c,"select function,parameter,itemid,lastvalue from functions where itemid%%%d=%d group by 1,2,3 order by 1,2,3",SUCKER_FORKS-1,sucker_num-1);*/ - sprintf(c,"select function,parameter,itemid,lastvalue from functions where itemid=%d group by 1,2,3 order by 1,2,3",item->itemid); + sprintf(c,"select function,parameter,itemid from functions where itemid=%d group by 1,2,3 order by 1,2,3",item->itemid); result = DBselect(c); rows=DBnum_rows(result); @@ -287,16 +180,6 @@ void update_functions( DB_ITEM *item ) function.function=DBget_field(result,i,0); function.parameter=atoi(DBget_field(result,i,1)); function.itemid=atoi(DBget_field(result,i,2)); - s=DBget_field(result,i,3); - if(s==NULL) - { - function.lastvalue_null=1; - } - else - { - function.lastvalue_null=0; - function.lastvalue=atof(DBget_field(result,i,3)); - } syslog( LOG_DEBUG, "ItemId:%d Evaluating %s(%d)\n",function.itemid,function.function,function.parameter); @@ -309,12 +192,8 @@ void update_functions( DB_ITEM *item ) syslog( LOG_DEBUG, "Result:%f\n",value); if (ret == SUCCEED) { -// Commented. Otherwise, if we have more than 1 function to update, only one function being updated. Wrong ! - // if((function.lastvalue_null == 1)||(cmp_double(function.lastvalue,value)==1)) - { - sprintf(c,"update functions set lastvalue=%f where itemid=%d and function='%s' and parameter=%d", value, function.itemid, function.function, function.parameter ); - DBexecute(c); - } + sprintf(c,"update functions set lastvalue=%f where itemid=%d and function='%s' and parameter=%d", value, function.itemid, function.function, function.parameter ); + DBexecute(c); } } diff --git a/include/functions.h b/include/functions.h index 9add1f0b..02e727a0 100644 --- a/include/functions.h +++ b/include/functions.h @@ -3,8 +3,6 @@ #include "db.h" -/*void update_functions(DB_ITEM items[]);*/ -void update_functions(DB_ITEM *item); void update_triggers (int flag,int sucker_num,int lastclock); int get_lastvalue(float *Result,char *host,char *key,char *function,char *parameter); int process_data(char *server,char *key, double value); |