diff options
| author | alex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-01-02 08:52:02 +0000 |
|---|---|---|
| committer | alex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-01-02 08:52:02 +0000 |
| commit | 80e0573f75dcd89cabd7c424112ce682bcd8ff4e (patch) | |
| tree | 5d2639c4c76878aa81962ce26c90dd85501c6bea /src | |
| parent | f6eb0b137d3916717cf9cea4461a7a7ddb4829d2 (diff) | |
| download | zabbix-80e0573f75dcd89cabd7c424112ce682bcd8ff4e.tar.gz zabbix-80e0573f75dcd89cabd7c424112ce682bcd8ff4e.tar.xz zabbix-80e0573f75dcd89cabd7c424112ce682bcd8ff4e.zip | |
- fixed calculation of sum(#N) (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@3650 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src')
| -rw-r--r-- | src/zabbix_server/evalfunc.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/zabbix_server/evalfunc.c b/src/zabbix_server/evalfunc.c index 4271431b..4148c025 100644 --- a/src/zabbix_server/evalfunc.c +++ b/src/zabbix_server/evalfunc.c @@ -244,6 +244,7 @@ static int evaluate_SUM(char *value, DB_ITEM *item, int parameter, int flag) char table[MAX_STRING_LEN]; int now; int res = SUCCEED; + int rows = 0; double sum=0; zbx_uint64_t sum_uint64=0; zbx_uint64_t value_uint64; @@ -292,28 +293,29 @@ static int evaluate_SUM(char *value, DB_ITEM *item, int parameter, int flag) zbx_snprintf(sql,sizeof(sql),"select value from %s where itemid=" ZBX_FS_UI64 " order by clock desc", table,item->itemid); result = DBselectN(sql, parameter); - row = DBfetch(result); - if(!row || DBis_null(row[0])==SUCCEED) + if(item->value_type == ITEM_VALUE_TYPE_UINT64) { - zabbix_log(LOG_LEVEL_DEBUG, "Result for SUM is empty" ); - res = FAIL; + while((row=DBfetch(result))) + { + ZBX_STR2UINT64(value_uint64,row[0]); + sum_uint64+=value_uint64; + rows++; + } + if(rows>0) zbx_snprintf(value,MAX_STRING_LEN,ZBX_FS_UI64, sum_uint64); } else { - if(item->value_type == ITEM_VALUE_TYPE_UINT64) + while((row=DBfetch(result))) { - while((row=DBfetch(result))) - { - ZBX_STR2UINT64(value_uint64,row[0]); - sum_uint64+=value_uint64; - } - zbx_snprintf(value,MAX_STRING_LEN,ZBX_FS_UI64, sum_uint64); - } - else - { - while((row=DBfetch(result))) sum+=atof(row[0]); - zbx_snprintf(value,MAX_STRING_LEN,"%f", sum); + sum+=atof(row[0]); + rows++; } + if(rows>0) zbx_snprintf(value,MAX_STRING_LEN,"%f", sum); + } + if(0 == rows) + { + zabbix_log(LOG_LEVEL_DEBUG, "Result for SUM is empty" ); + res = FAIL; } } else |
