summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-09-13 12:58:10 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-09-13 12:58:10 +0000
commit8ca8c03346090ece96b4c4b3da5fe2d41b04eb3e (patch)
treecb08b1a7223db8f51791bb5c4b9ba551721f55c4 /src
parentaf0a329b812599d79e26a59d9d8eaaa4312c2034 (diff)
- fixed trigger description substitution in action comporation (Eugene)
- fixed trigger description substitution in message subject and body (Eugene) git-svn-id: svn://svn.zabbix.com/trunk@3299 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src')
-rw-r--r--src/zabbix_server/actions.c12
-rw-r--r--src/zabbix_server/expression.c39
-rw-r--r--src/zabbix_server/expression.h8
3 files changed, 42 insertions, 17 deletions
diff --git a/src/zabbix_server/actions.c b/src/zabbix_server/actions.c
index 41f0a2f6..86892f4c 100644
--- a/src/zabbix_server/actions.c
+++ b/src/zabbix_server/actions.c
@@ -368,7 +368,7 @@ static int get_next_command(char** command_list, char** alias, int* is_group, ch
char *alias = NULL;
char *command = NULL;
int is_group = 0;
-
+
assert(trigger);
assert(action);
@@ -402,6 +402,8 @@ static int check_action_condition(DB_TRIGGER *trigger,int alarmid,int new_trigge
DB_RESULT result;
DB_ROW row;
+ char tmp_str[MAX_STRING_LEN];
+
int ret = FAIL;
zabbix_log( LOG_LEVEL_DEBUG, "In check_action_condition [actionid:%d,conditionid:%d:cond.value:%s]", condition->actionid, condition->conditionid, condition->value);
@@ -487,16 +489,20 @@ static int check_action_condition(DB_TRIGGER *trigger,int alarmid,int new_trigge
}
else if(condition->conditiontype == CONDITION_TYPE_TRIGGER_NAME)
{
+ zbx_snprintf(tmp_str, sizeof(tmp_str), "%s",trigger->description);
+
+ substitute_simple_macros(trigger, NULL, tmp_str, sizeof(tmp_str), MACRO_TYPE_TRIGGER_DESCRIPTION);
+
if(condition->operator == CONDITION_OPERATOR_LIKE)
{
- if(strstr(trigger->description,condition->value) != NULL)
+ if(strstr(tmp_str, condition->value) != NULL)
{
ret = SUCCEED;
}
}
else if(condition->operator == CONDITION_OPERATOR_NOT_LIKE)
{
- if(strstr(trigger->description,condition->value) == NULL)
+ if(strstr(tmp_str, condition->value) == NULL)
{
ret = SUCCEED;
}
diff --git a/src/zabbix_server/expression.c b/src/zabbix_server/expression.c
index d1f709dc..30c0b41f 100644
--- a/src/zabbix_server/expression.c
+++ b/src/zabbix_server/expression.c
@@ -23,6 +23,7 @@
#include <string.h>
#include <math.h>
+#include "expression.h"
#include "functions.h"
#include "evalfunc.h"
#include "common.h"
@@ -546,7 +547,7 @@ int evaluate(int *result,char *exp, char *error, int maxerrlen)
* Purpose: substitute simple macros in data string with real values *
* *
* Parameters: trigger - trigger structure *
- * action - action structure *
+ * action - action structure (NULL if uncnown) *
* data - data string *
* dala_max_len - max length of data string,include '\0' *
* *
@@ -571,7 +572,8 @@ int evaluate(int *result,char *exp, char *error, int maxerrlen)
#define MVAR_TRIGGER_SEVERITY "{TRIGGER.SEVERITY}"
#define STR_UNKNOWN_VARIAVLE "*UNKNOWN*"
-static void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, char *data, int dala_max_len)
+
+void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, char *data, int dala_max_len, int macro_type)
{
char
@@ -604,19 +606,23 @@ static void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, ch
zbx_snprintf(replace_to, sizeof(replace_to), "{");
var_len = 1;
- if(strncmp(pr, MVAR_TRIGGER_NAME, strlen(MVAR_TRIGGER_NAME)) == 0)
+ if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
+ strncmp(pr, MVAR_TRIGGER_NAME, strlen(MVAR_TRIGGER_NAME)) == 0)
{
var_len = strlen(MVAR_TRIGGER_NAME);
zbx_snprintf(replace_to, sizeof(replace_to), "%s", trigger->description);
+ substitute_simple_macros(trigger, action, replace_to, sizeof(replace_to), MACRO_TYPE_TRIGGER_DESCRIPTION);
}
- else if(strncmp(pr, MVAR_TRIGGER_COMMENT, strlen(MVAR_TRIGGER_COMMENT)) == 0)
+ else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
+ strncmp(pr, MVAR_TRIGGER_COMMENT, strlen(MVAR_TRIGGER_COMMENT)) == 0)
{
var_len = strlen(MVAR_TRIGGER_COMMENT);
zbx_snprintf(replace_to, sizeof(replace_to), "%s", trigger->comments);
}
- else if(strncmp(pr, MVAR_HOST_NAME, strlen(MVAR_HOST_NAME)) == 0)
+ else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY | MACRO_TYPE_TRIGGER_DESCRIPTION) &&
+ strncmp(pr, MVAR_HOST_NAME, strlen(MVAR_HOST_NAME)) == 0)
{
var_len = strlen(MVAR_HOST_NAME);
@@ -639,7 +645,8 @@ static void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, ch
}
DBfree_result(result);
}
- else if(strncmp(pr, MVAR_TRIGGER_KEY, strlen(MVAR_TRIGGER_KEY)) == 0)
+ else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
+ strncmp(pr, MVAR_TRIGGER_KEY, strlen(MVAR_TRIGGER_KEY)) == 0)
{
var_len = strlen(MVAR_TRIGGER_KEY);
@@ -663,7 +670,8 @@ static void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, ch
DBfree_result(result);
}
- if(strncmp(pr, MVAR_IPADDRESS, strlen(MVAR_IPADDRESS)) == 0)
+ else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
+ strncmp(pr, MVAR_IPADDRESS, strlen(MVAR_IPADDRESS)) == 0)
{
var_len = strlen(MVAR_IPADDRESS);
@@ -686,7 +694,8 @@ static void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, ch
}
DBfree_result(result);
}
- else if(strncmp(pr, MVAR_DATE, strlen(MVAR_DATE)) == 0)
+ else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
+ strncmp(pr, MVAR_DATE, strlen(MVAR_DATE)) == 0)
{
var_len = strlen(MVAR_TIME);
@@ -694,7 +703,8 @@ static void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, ch
tm = localtime(&now);
zbx_snprintf(replace_to, sizeof(replace_to)-1, "%.4d.%.2d.%.2d", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday);
}
- else if(strncmp(pr, MVAR_TIME, strlen(MVAR_TIME)) == 0)
+ else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY)&&
+ strncmp(pr, MVAR_TIME, strlen(MVAR_TIME)) == 0)
{
var_len = strlen(MVAR_TIME);
@@ -703,7 +713,8 @@ static void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, ch
zbx_snprintf(replace_to, sizeof(replace_to), "%.2d:%.2d:%.2d",tm->tm_hour,tm->tm_min,tm->tm_sec);
}
- else if(strncmp(pr, MVAR_TRIGGER_STATUS, strlen(MVAR_TRIGGER_STATUS)) == 0)
+ else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
+ strncmp(pr, MVAR_TRIGGER_STATUS, strlen(MVAR_TRIGGER_STATUS)) == 0)
{
/* NOTE: if you make changes for this bloc, don't forgot MVAR_TRIGGER_STATUS_OLD block */
var_len = strlen(MVAR_TRIGGER_STATUS);
@@ -713,7 +724,8 @@ static void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, ch
else
zbx_snprintf(replace_to, sizeof(replace_to), "ON");
}
- else if(strncmp(pr, MVAR_TRIGGER_STATUS_OLD, strlen(MVAR_TRIGGER_STATUS_OLD)) == 0)
+ else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
+ strncmp(pr, MVAR_TRIGGER_STATUS_OLD, strlen(MVAR_TRIGGER_STATUS_OLD)) == 0)
{
/* NOTE: if you make changes for this bloc, don't forgot MVAR_TRIGGER_STATUS block */
var_len = strlen(MVAR_TRIGGER_STATUS_OLD);
@@ -723,7 +735,8 @@ static void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, ch
else
zbx_snprintf(replace_to, sizeof(replace_to), "ON");
}
- else if(strncmp(pr, MVAR_TRIGGER_SEVERITY, strlen(MVAR_TRIGGER_SEVERITY)) == 0)
+ else if(macro_type & (MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY) &&
+ strncmp(pr, MVAR_TRIGGER_SEVERITY, strlen(MVAR_TRIGGER_SEVERITY)) == 0)
{
var_len = strlen(MVAR_TRIGGER_SEVERITY);
@@ -789,7 +802,7 @@ void substitute_macros(DB_TRIGGER *trigger, DB_ACTION *action, char *data, int d
zabbix_log(LOG_LEVEL_DEBUG, "In substitute_macros([%s])",data);
- substitute_simple_macros(trigger, action, data, dala_max_len);
+ substitute_simple_macros(trigger, action, data, dala_max_len, MACRO_TYPE_MESSAGE_SUBJECT | MACRO_TYPE_MESSAGE_BODY);
*str_out = '\0';
outlen = sizeof(str_out) - 1;
diff --git a/src/zabbix_server/expression.h b/src/zabbix_server/expression.h
index 722a9af8..d823983f 100644
--- a/src/zabbix_server/expression.h
+++ b/src/zabbix_server/expression.h
@@ -26,9 +26,15 @@
int cmp_double(double a,double b);
int find_char(char *str,char c);
-int substitute_functions(char *exp);
+int evaluate_expression(int *result,char *expression, char *error, int maxerrlen);
void substitute_macros(DB_TRIGGER *trigger, DB_ACTION *action, char *data, int dala_max_len);
int evaluate_expression (int *result,char *expression,char *error,int maxerrlen);
void delete_reol(char *c);
+#define MACRO_TYPE_TRIGGER_DESCRIPTION 1
+#define MACRO_TYPE_MESSAGE_SUBJECT 2
+#define MACRO_TYPE_MESSAGE_BODY 4
+
+void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, char *data, int dala_max_len, int macro_type);
+
#endif