summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-08-12 12:35:56 +0000
committeralex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-08-12 12:35:56 +0000
commit8901654871973b4267f106a97183001189189c82 (patch)
treebfc6646c892c49d3759d72d1628451b7e6d7f6cc
parent3610b0d472d116f52256b101308ebc953a900a46 (diff)
downloadzabbix-8901654871973b4267f106a97183001189189c82.tar.gz
zabbix-8901654871973b4267f106a97183001189189c82.tar.xz
zabbix-8901654871973b4267f106a97183001189189c82.zip
- support of new parameter for count(period,value,operator) (Alexei)
[svn merge -r4541:4544 svn://svn.zabbix.com/branches/1.4.2] git-svn-id: svn://svn.zabbix.com/trunk@4545 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r--ChangeLog1
-rw-r--r--frontends/php/include/triggers.inc.php2
-rw-r--r--src/zabbix_server/evalfunc.c82
3 files changed, 82 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 89b824b5..35ae053e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,7 @@ Changes for 1.5:
Changes for 1.4.2:
+ - support of new parameter for count(period,value,operator) (Alexei)
- new trigger function iregexp(), non case-sensitive regexp (Alexei)
- fixed upgrade script to correctly process host-template linkage (Alexei)
- fixed synchronisation of delete operation between nodes (Alexei)
diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php
index 3d5004da..d54dac5a 100644
--- a/frontends/php/include/triggers.inc.php
+++ b/frontends/php/include/triggers.inc.php
@@ -74,7 +74,7 @@
ITEM_VALUE_TYPE_TEXT
),
);
- $ZBX_TR_EXPR_ALLOWED_FUNCTIONS['count'] = array('args' => array( 0 => array('type' => 'sec','mandat' => true), 1 => array('type' => 'str') ),
+ $ZBX_TR_EXPR_ALLOWED_FUNCTIONS['count'] = array('args' => array( 0 => array('type' => 'sec','mandat' => true), 1 => array('type' => 'str'), 1=>array('type' => 'str') ),
'item_types' => array(
ITEM_VALUE_TYPE_FLOAT,
ITEM_VALUE_TYPE_UINT64,
diff --git a/src/zabbix_server/evalfunc.c b/src/zabbix_server/evalfunc.c
index 565ad1af..54491200 100644
--- a/src/zabbix_server/evalfunc.c
+++ b/src/zabbix_server/evalfunc.c
@@ -159,6 +159,7 @@ static int evaluate_COUNT(char *value, DB_ITEM *item, char *parameter)
DB_ROW row;
char period[MAX_STRING_LEN+1];
+ char op[MAX_STRING_LEN+1];
char cmp[MAX_STRING_LEN+1];
char cmp_esc[MAX_STRING_LEN+1];
@@ -201,15 +202,56 @@ static int evaluate_COUNT(char *value, DB_ITEM *item, char *parameter)
}
else
{
+ if(get_param(parameter, 3, op, MAX_STRING_LEN) != 0)
+ {
+ strscpy(op,"eq");
+ }
DBescape_string(cmp, cmp_esc, sizeof(cmp_esc));
- if(item->value_type == ITEM_VALUE_TYPE_UINT64)
+ /* ITEM_VALUE_TYPE_UINT64 */
+ if( (item->value_type == ITEM_VALUE_TYPE_UINT64) && (strcmp(op,"eq") == 0))
{
result = DBselect("select count(value) from history_uint where clock>%d and value=" ZBX_FS_UI64 " and itemid=" ZBX_FS_UI64,
now-atoi(period),
zbx_atoui64(cmp_esc),
item->itemid);
}
- else if(item->value_type == ITEM_VALUE_TYPE_FLOAT)
+ else if( (item->value_type == ITEM_VALUE_TYPE_UINT64) && (strcmp(op,"ne") == 0))
+ {
+ result = DBselect("select count(value) from history_uint where clock>%d and value<>" ZBX_FS_UI64 " and itemid=" ZBX_FS_UI64,
+ now-atoi(period),
+ zbx_atoui64(cmp_esc),
+ item->itemid);
+ }
+ else if( (item->value_type == ITEM_VALUE_TYPE_UINT64) && (strcmp(op,"gt") == 0))
+ {
+ result = DBselect("select count(value) from history_uint where clock>%d and value>" ZBX_FS_UI64 " and itemid=" ZBX_FS_UI64,
+ now-atoi(period),
+ zbx_atoui64(cmp_esc),
+ item->itemid);
+ }
+ else if( (item->value_type == ITEM_VALUE_TYPE_UINT64) && (strcmp(op,"lt") == 0))
+ {
+ result = DBselect("select count(value) from history_uint where clock>%d and value<" ZBX_FS_UI64 " and itemid=" ZBX_FS_UI64,
+ now-atoi(period),
+ zbx_atoui64(cmp_esc),
+ item->itemid);
+ }
+ else if( (item->value_type == ITEM_VALUE_TYPE_UINT64) && (strcmp(op,"ge") == 0))
+ {
+ result = DBselect("select count(value) from history_uint where clock>%d and value>=" ZBX_FS_UI64 " and itemid=" ZBX_FS_UI64,
+ now-atoi(period),
+ zbx_atoui64(cmp_esc),
+ item->itemid);
+ }
+ else if( (item->value_type == ITEM_VALUE_TYPE_UINT64) && (strcmp(op,"le") == 0))
+ {
+ result = DBselect("select count(value) from history_uint where clock>%d and value<=" ZBX_FS_UI64 " and itemid=" ZBX_FS_UI64,
+ now-atoi(period),
+ zbx_atoui64(cmp_esc),
+ item->itemid);
+ }
+ /* ITEM_VALUE_TYPE_FLOAT */
+ else if( (item->value_type == ITEM_VALUE_TYPE_FLOAT) && (strcmp(op,"eq") == 0))
{
result = DBselect("select count(value) from history where clock>%d and value+0.00001>" ZBX_FS_DBL " and value-0.0001<" ZBX_FS_DBL " and itemid=" ZBX_FS_UI64,
now-atoi(period),
@@ -217,6 +259,42 @@ static int evaluate_COUNT(char *value, DB_ITEM *item, char *parameter)
atof(cmp_esc),
item->itemid);
}
+ else if( (item->value_type == ITEM_VALUE_TYPE_FLOAT) && (strcmp(op,"ne") == 0))
+ {
+ result = DBselect("select count(value) from history where clock>%d and ((value+0.00001<" ZBX_FS_DBL ") or (value-0.0001>" ZBX_FS_DBL ")) and itemid=" ZBX_FS_UI64,
+ now-atoi(period),
+ atof(cmp_esc),
+ atof(cmp_esc),
+ item->itemid);
+ }
+ else if( (item->value_type == ITEM_VALUE_TYPE_FLOAT) && (strcmp(op,"gt") == 0))
+ {
+ result = DBselect("select count(value) from history where clock>%d and value>" ZBX_FS_DBL " and itemid=" ZBX_FS_UI64,
+ now-atoi(period),
+ atof(cmp_esc),
+ item->itemid);
+ }
+ else if( (item->value_type == ITEM_VALUE_TYPE_FLOAT) && (strcmp(op,"ge") == 0))
+ {
+ result = DBselect("select count(value) from history where clock>=%d and value>" ZBX_FS_DBL " and itemid=" ZBX_FS_UI64,
+ now-atoi(period),
+ atof(cmp_esc),
+ item->itemid);
+ }
+ else if( (item->value_type == ITEM_VALUE_TYPE_FLOAT) && (strcmp(op,"lt") == 0))
+ {
+ result = DBselect("select count(value) from history where clock>%d and value<" ZBX_FS_DBL " and itemid=" ZBX_FS_UI64,
+ now-atoi(period),
+ atof(cmp_esc),
+ item->itemid);
+ }
+ else if( (item->value_type == ITEM_VALUE_TYPE_FLOAT) && (strcmp(op,"le") == 0))
+ {
+ result = DBselect("select count(value) from history where clock>%d and value<=" ZBX_FS_DBL " and itemid=" ZBX_FS_UI64,
+ now-atoi(period),
+ atof(cmp_esc),
+ item->itemid);
+ }
else if(item->value_type == ITEM_VALUE_TYPE_LOG)
{
result = DBselect("select count(value) from history_log where clock>%d and value like '%s' and itemid=" ZBX_FS_UI64,