summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--create/schema/schema.sql1
-rw-r--r--include/common.h8
-rw-r--r--include/db.h1
-rw-r--r--src/zabbix_server/actions.c90
-rw-r--r--upgrades/dbpatches/1.3/mysql/patch/actions.sql3
-rw-r--r--upgrades/dbpatches/1.3/postgresql/patch/actions.sql3
7 files changed, 86 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index 311f5348..2f27efb5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
Changes for 1.3.4:
+ - added actions.evaltype (Alexei)
+ - added support of all AND, all OR and AND/OR action conditions (Alexei)
- fixed processing of Text items (Alexei)
- NetBSD compilation fixes (Alexei)
diff --git a/create/schema/schema.sql b/create/schema/schema.sql
index 0afd7953..26f4221f 100644
--- a/create/schema/schema.sql
+++ b/create/schema/schema.sql
@@ -240,6 +240,7 @@ FIELD |maxrepeats |t_integer |'0' |NOT NULL |ZBX_SYNC
FIELD |repeatdelay |t_integer |'600' |NOT NULL |ZBX_SYNC
FIELD |source |t_integer |'0' |NOT NULL |ZBX_SYNC
FIELD |actiontype |t_integer |'0' |NOT NULL |ZBX_SYNC
+FIELD |evaltype |t_integer |'0' |NOT NULL |ZBX_SYNC
FIELD |status |t_integer |'0' |NOT NULL |ZBX_SYNC
FIELD |scripts |t_blob |'' |NOT NULL |ZBX_SYNC
diff --git a/include/common.h b/include/common.h
index 64f8e7bc..dadc78e1 100644
--- a/include/common.h
+++ b/include/common.h
@@ -155,6 +155,14 @@ typedef enum
/* Condition types */
typedef enum
{
+ ACTION_EVAL_TYPE_AND_OR = 0,
+ ACTION_EVAL_TYPE_AND,
+ ACTION_EVAL_TYPE_OR,
+} zbx_action_eval_type_t;
+
+/* Condition types */
+typedef enum
+{
CONDITION_TYPE_HOST_GROUP = 0,
CONDITION_TYPE_HOST,
CONDITION_TYPE_TRIGGER,
diff --git a/include/db.h b/include/db.h
index 178ac91a..990cae7d 100644
--- a/include/db.h
+++ b/include/db.h
@@ -271,6 +271,7 @@ DB_ACTION
{
zbx_uint64_t actionid;
int actiontype;
+ int evaltype;
zbx_uint64_t userid;
/* int delay;*/
int lastcheck;
diff --git a/src/zabbix_server/actions.c b/src/zabbix_server/actions.c
index f36a4394..8670e44e 100644
--- a/src/zabbix_server/actions.c
+++ b/src/zabbix_server/actions.c
@@ -607,47 +607,96 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition)
* Comments: *
* *
******************************************************************************/
-static int check_action_conditions(DB_EVENT *event, zbx_uint64_t actionid)
+static int check_action_conditions(DB_EVENT *event, DB_ACTION *action)
{
DB_RESULT result;
DB_ROW row;
DB_CONDITION condition;
-
+
+ /* SUCCEED required for ACTION_EVAL_TYPE_AND_OR */
int ret = SUCCEED;
int old_type = -1;
+ int cond;
+ int num = 0;
+ int exit = 0;
- zabbix_log( LOG_LEVEL_DEBUG, "In check_action_conditions (actionid:%d)", actionid);
+ zabbix_log( LOG_LEVEL_DEBUG, "In check_action_conditions (actionid:" ZBX_FS_UI64 ")",
+ action->actionid);
- result = DBselect("select conditionid,actionid,conditiontype,operator,value from conditions where actionid=" ZBX_FS_UI64 " order by conditiontype", actionid);
+ result = DBselect("select conditionid,actionid,conditiontype,operator,value from conditions where actionid=" ZBX_FS_UI64 " order by conditiontype", action->actionid);
while((row=DBfetch(result)))
{
+ num++;
+
ZBX_STR2UINT64(condition.conditionid, row[0]);
ZBX_STR2UINT64(condition.actionid, row[1]);
condition.conditiontype=atoi(row[2]);
condition.operator=atoi(row[3]);
condition.value=row[4];
- /* OR conditions */
- if(old_type == condition.conditiontype)
- {
- if(check_action_condition(event, &condition) == SUCCEED)
- ret = SUCCEED;
- }
- /* AND conditions */
- else
- {
- /* Break if PREVIOUS AND condition is FALSE */
- if(ret == FAIL) break;
- if(check_action_condition(event, &condition) == FAIL)
+ switch (action->evaltype) {
+ case ACTION_EVAL_TYPE_AND_OR:
+ /* OR conditions */
+ if(old_type == condition.conditiontype)
+ {
+ if(check_action_condition(event, &condition) == SUCCEED)
+ ret = SUCCEED;
+ }
+ /* AND conditions */
+ else
+ {
+ /* Break if PREVIOUS AND condition is FALSE */
+ if(ret == FAIL)
+ {
+ exit = 1;
+ }
+ else if(check_action_condition(event, &condition) == FAIL)
+ {
+ ret = FAIL;
+ }
+ }
+
+ old_type = condition.conditiontype;
+ break;
+ case ACTION_EVAL_TYPE_AND:
+ cond = check_action_condition(event, &condition);
+ /* Break if any of AND conditions is FALSE */
+ if(cond == FAIL)
+ {
+ ret = FAIL; exit = 1;
+ }
+ else
+ {
+ ret = SUCCEED;
+ }
+ break;
+ case ACTION_EVAL_TYPE_OR:
+ cond = check_action_condition(event, &condition);
+ /* Break if any of OR conditions is TRUE */
+ if(cond == SUCCEED)
+ {
+ ret = SUCCEED; exit = 1;
+ }
+ else
+ {
+ ret = FAIL;
+ }
+ break;
+ default:
+ zabbix_log( LOG_LEVEL_DEBUG, "End check_action_conditions (result:%d)", (FAIL==ret)?"FALSE":"TRUE");
ret = FAIL;
+ break;
+
}
-
- old_type = condition.conditiontype;
+
}
DBfree_result(result);
+ /* Ifnot conditions defined, return SUCCEED*/
+ if(num == 0) ret = SUCCEED;
+
zabbix_log( LOG_LEVEL_DEBUG, "End check_action_conditions (result:%d)", (FAIL==ret)?"FALSE":"TRUE");
return ret;
@@ -703,13 +752,14 @@ void apply_actions(DB_EVENT *event)
/* zbx_snprintf(sql,sizeof(sql),"select actionid,userid,delay,subject,message,recipient,maxrepeats,repeatdelay,scripts,actiontype from actions where nextcheck<=%d and status=%d", now, ACTION_STATUS_ACTIVE);*/
/* No support of action delay anymore */
- result = DBselect("select actionid,userid,subject,message,recipient,maxrepeats,repeatdelay,scripts,actiontype from actions where status=%d and" ZBX_COND_NODEID, ACTION_STATUS_ACTIVE, LOCAL_NODE("actionid"));
+ result = DBselect("select actionid,userid,subject,message,recipient,maxrepeats,repeatdelay,scripts,actiontype,evaltype from actions where status=%d and" ZBX_COND_NODEID, ACTION_STATUS_ACTIVE, LOCAL_NODE("actionid"));
while((row=DBfetch(result)))
{
ZBX_STR2UINT64(action.actionid, row[0]);
+ action.evaltype = atoi(row[9]);
- if(check_action_conditions(event, action.actionid) == SUCCEED)
+ if(check_action_conditions(event, &action) == SUCCEED)
{
zabbix_log( LOG_LEVEL_DEBUG, "Conditions match our trigger. Do apply actions.");
diff --git a/upgrades/dbpatches/1.3/mysql/patch/actions.sql b/upgrades/dbpatches/1.3/mysql/patch/actions.sql
index 7581dd2c..cde11926 100644
--- a/upgrades/dbpatches/1.3/mysql/patch/actions.sql
+++ b/upgrades/dbpatches/1.3/mysql/patch/actions.sql
@@ -8,11 +8,12 @@ CREATE TABLE actions_tmp (
repeatdelay integer DEFAULT '600' NOT NULL,
source integer DEFAULT '0' NOT NULL,
actiontype integer DEFAULT '0' NOT NULL,
+ evaltype integer DEFAULT '0' NOT NULL,
status integer DEFAULT '0' NOT NULL,
scripts blob DEFAULT '' NOT NULL,
PRIMARY KEY (actionid)
) ENGINE=InnoDB ;
-insert into actions_tmp select * from actions;
+insert into actions_tmp select actionid,userid,subject,message,recipient,maxrepeats,repeatdelay,source,actiontype,0,status,scripts from actions;
drop table actions;
alter table actions_tmp rename actions;
diff --git a/upgrades/dbpatches/1.3/postgresql/patch/actions.sql b/upgrades/dbpatches/1.3/postgresql/patch/actions.sql
index 36042556..6a9c5778 100644
--- a/upgrades/dbpatches/1.3/postgresql/patch/actions.sql
+++ b/upgrades/dbpatches/1.3/postgresql/patch/actions.sql
@@ -8,11 +8,12 @@ CREATE TABLE actions_tmp (
repeatdelay integer DEFAULT '600' NOT NULL,
source integer DEFAULT '0' NOT NULL,
actiontype integer DEFAULT '0' NOT NULL,
+ evaltype integer DEFAULT '0' NOT NULL,
status integer DEFAULT '0' NOT NULL,
scripts text DEFAULT '' NOT NULL,
PRIMARY KEY (actionid)
);
-insert into actions_tmp select * from actions;
+insert into actions_tmp select actionid,userid,subject,message,recipient,maxrepeats,repeatdelay,source,actiontype,0,status,scripts from actions;
drop table actions;
alter table actions_tmp rename to actions;