summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2003-05-10 20:46:57 +0000
committerhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2003-05-10 20:46:57 +0000
commit3af34e029204d721a4eac3c7a9a2727d9e9c6845 (patch)
tree6cda834a5b2cbce6d38261d48a91252f9842e2af
parent1035a6a525509126e089677049437e8699751eb0 (diff)
downloadzabbix-3af34e029204d721a4eac3c7a9a2727d9e9c6845.tar.gz
zabbix-3af34e029204d721a4eac3c7a9a2727d9e9c6845.tar.xz
zabbix-3af34e029204d721a4eac3c7a9a2727d9e9c6845.zip
- added basic support of global alerts (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@764 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r--ChangeLog1
-rw-r--r--frontends/php/actions.php31
-rw-r--r--frontends/php/include/config.inc.php8
-rw-r--r--include/common.h5
-rw-r--r--include/db.h2
-rw-r--r--include/functions.c70
6 files changed, 98 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index a82b63fd..fc929b00 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
Changes for 1.0beta9:
+ - added basic support of global alerts (Alexei)
- added group selection in Item and Trigger definition forms (Alexei)
- added support for functions abschange(),change(),delta(),sum(),
count() and avg() in trigger expressions (Alexei)
diff --git a/frontends/php/actions.php b/frontends/php/actions.php
index 0cedade0..7bd57327 100644
--- a/frontends/php/actions.php
+++ b/frontends/php/actions.php
@@ -20,12 +20,12 @@
{
if($HTTP_GET_VARS["register"]=="add")
{
- $result=add_action( $HTTP_GET_VARS["triggerid"], $HTTP_GET_VARS["userid"], $HTTP_GET_VARS["good"], $HTTP_GET_VARS["delay"], $HTTP_GET_VARS["subject"], $HTTP_GET_VARS["message"] );
+ $result=add_action( $HTTP_GET_VARS["triggerid"], $HTTP_GET_VARS["userid"], $HTTP_GET_VARS["good"], $HTTP_GET_VARS["delay"], $HTTP_GET_VARS["subject"], $HTTP_GET_VARS["message"],$HTTP_GET_VARS["scope"],$HTTP_GET_VARS["severity"]);
show_messages($result,"Action added","Cannot add action");
}
if($HTTP_GET_VARS["register"]=="update")
{
- $result=update_action( $HTTP_GET_VARS["actionid"], $HTTP_GET_VARS["userid"], $HTTP_GET_VARS["good"], $HTTP_GET_VARS["delay"], $HTTP_GET_VARS["subject"], $HTTP_GET_VARS["message"] );
+ $result=update_action( $HTTP_GET_VARS["actionid"], $HTTP_GET_VARS["userid"], $HTTP_GET_VARS["good"], $HTTP_GET_VARS["delay"], $HTTP_GET_VARS["subject"], $HTTP_GET_VARS["message"],$HTTP_GET_VARS["scope"],$HTTP_GET_VARS["severity"]);
show_messages($result,"Action updated","Cannot update action");
unset($HTTP_GET_VARS["actionid"]);
}
@@ -105,7 +105,7 @@
if(isset($HTTP_GET_VARS["actionid"]))
{
- $sql="select a.actionid,a.triggerid,a.good,a.delay,a.subject,a.message,a.userid from actions a where a.actionid=".$HTTP_GET_VARS["actionid"];
+ $sql="select a.actionid,a.triggerid,a.good,a.delay,a.subject,a.message,a.userid,a.scope,a.severity from actions a where a.actionid=".$HTTP_GET_VARS["actionid"];
$result=DBselect($sql);
$actionid=DBget_field($result,0,0);
@@ -115,6 +115,8 @@
$subject=DBget_field($result,0,4);
$message=DBget_field($result,0,5);
$uid=DBget_field($result,0,6);
+ $scope=DBget_field($result,0,7);
+ $severity=DBget_field($result,0,8);
}
else
{
@@ -124,6 +126,8 @@
$good=1;
$delay=30;
$subject=$description;
+ $scope=0;
+ $severity=0;
$sql="select i.description, h.host, i.key_ from hosts h, items i,functions f where f.triggerid=".$HTTP_GET_VARS["triggerid"]." and h.hostid=i.hostid and f.itemid=i.itemid order by i.description";
$result=DBselect($sql);
@@ -189,6 +193,27 @@
show_table2_h_delimiter();
echo "<textarea class=\"biginput\" name=\"message\" cols=70 ROWS=\"7\" wrap=\"soft\">$message</TEXTAREA>";
+ show_table2_v_delimiter();
+ echo "Scope";
+ show_table2_h_delimiter();
+ echo "<select class=\"biginput\" name=\"scope\" size=1>";
+ echo "<OPTION VALUE=\"0\""; if($scope==0) echo "SELECTED"; echo ">This trigger only";
+ echo "<OPTION VALUE=\"1\""; if($scope==1) echo "SELECTED"; echo ">All triggers of this host";
+ echo "<OPTION VALUE=\"2\""; if($scope==2) echo "SELECTED"; echo ">All triggers";
+ echo "</SELECT>";
+
+ show_table2_v_delimiter();
+ echo "Send if trigger's severity equal or more than (for host-based scope only)";
+ show_table2_h_delimiter();
+ echo "<select class=\"biginput\" name=\"severity\" size=1>";
+ echo "<OPTION VALUE=\"0\" "; if($severity==0) echo "SELECTED"; echo ">Not classified";
+ echo "<OPTION VALUE=\"1\" "; if($severity==1) echo "SELECTED"; echo ">Information";
+ echo "<OPTION VALUE=\"2\" "; if($severity==2) echo "SELECTED"; echo ">Warning";
+ echo "<OPTION VALUE=\"3\" "; if($severity==3) echo "SELECTED"; echo ">Average";
+ echo "<OPTION VALUE=\"4\" "; if($severity==4) echo "SELECTED"; echo ">High";
+ echo "<OPTION VALUE=\"5\" "; if($severity==5) echo "SELECTED"; echo ">Disaster";
+ echo "</SELECT>";
+
show_table2_v_delimiter2();
echo "<input type=\"submit\" name=\"register\" value=\"add\">";
if(isset($actionid))
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index 8206a0a8..38772f67 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -1549,7 +1549,7 @@ where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=$triggerid";
# Add Action
- function add_action( $triggerid, $userid, $good, $delay, $subject, $message )
+ function add_action( $triggerid, $userid, $good, $delay, $subject, $message, $scope, $severity)
{
global $ERROR_MSG;
@@ -1559,7 +1559,7 @@ where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=$triggerid";
return 0;
}
- $sql="insert into actions (triggerid,userid,good,delay,nextcheck,subject,message) values ($triggerid,$userid,$good,$delay,0,'$subject','$message')";
+ $sql="insert into actions (triggerid,userid,good,delay,nextcheck,subject,message,scope,severity) values ($triggerid,$userid,$good,$delay,0,'$subject','$message',$scope,$severity)";
return DBexecute($sql);
}
@@ -1737,9 +1737,9 @@ where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=$triggerid";
# Update Action
- function update_action( $actionid, $userid, $good, $delay, $subject, $message )
+ function update_action( $actionid, $userid, $good, $delay, $subject, $message, $scope, $severity )
{
- $sql="update actions set userid=$userid,good=$good,delay=$delay,nextcheck=0,subject='$subject',message='$message' where actionid=$actionid";
+ $sql="update actions set userid=$userid,good=$good,delay=$delay,nextcheck=0,subject='$subject',message='$message',scope=$scope,severity=$severity where actionid=$actionid";
return DBexecute($sql);
}
diff --git a/include/common.h b/include/common.h
index a6e10616..44e45894 100644
--- a/include/common.h
+++ b/include/common.h
@@ -90,6 +90,11 @@
#define SERVICE_ALGORITHM_MAX 1
#define SERVICE_ALGORITHM_MIN 2
+/* Scope of action */
+#define ACTION_SCOPE_TRIGGER 0
+#define ACTION_SCOPE_HOST 1
+#define ACTION_SCOPE_HOSTS 2
+
#define AGENTD_FORKS 5
#define AGENT_MAX_USER_COMMANDS 512
diff --git a/include/db.h b/include/db.h
index 5e0154d8..a8fdd61c 100644
--- a/include/db.h
+++ b/include/db.h
@@ -117,6 +117,8 @@ DB_ACTION
int actionid;
int triggerid;
int userid;
+ int scope;
+ int severity;
int good;
int delay;
int lastcheck;
diff --git a/include/functions.c b/include/functions.c
index 8248c892..dc5d8087 100644
--- a/include/functions.c
+++ b/include/functions.c
@@ -807,9 +807,10 @@ void substitute_hostname(int triggerid,char *s)
/*
* Apply actions if any.
*/
-void apply_actions(int triggerid,int good)
+/*void apply_actions(int triggerid,int good)*/
+void apply_actions(DB_TRIGGER *trigger,int good)
{
- DB_RESULT *result;
+ DB_RESULT *result,*result2;
DB_ACTION action;
@@ -818,13 +819,13 @@ void apply_actions(int triggerid,int good)
int i;
int now;
- zabbix_log( LOG_LEVEL_DEBUG, "In apply_actions(%d,%d)",triggerid, good);
+ zabbix_log( LOG_LEVEL_DEBUG, "In apply_actions(%d,%d)",trigger->triggerid, good);
if(good==1)
{
zabbix_log( LOG_LEVEL_DEBUG, "Check dependencies");
- sprintf(sql,"select count(*) from trigger_depends d,triggers t where d.triggerid_down=%d and d.triggerid_up=t.triggerid and t.value=%d",triggerid, TRIGGER_VALUE_TRUE);
+ sprintf(sql,"select count(*) from trigger_depends d,triggers t where d.triggerid_down=%d and d.triggerid_up=t.triggerid and t.value=%d",trigger->triggerid, TRIGGER_VALUE_TRUE);
result = DBselect(sql);
if(DBnum_rows(result) == 1)
{
@@ -842,7 +843,7 @@ void apply_actions(int triggerid,int good)
now = time(NULL);
- sprintf(sql,"select actionid,userid,delay,subject,message from actions where triggerid=%d and good=%d and nextcheck<=%d",triggerid,good,now);
+ sprintf(sql,"select actionid,userid,delay,subject,message,scope,severity from actions where (scope=%d and triggerid=%d and good=%d and nextcheck<=%d) or (scope=%d) or (scope=%d)",ACTION_SCOPE_TRIGGER,trigger->triggerid,good,now,ACTION_SCOPE_HOST,ACTION_SCOPE_HOSTS);
result = DBselect(sql);
for(i=0;i<DBnum_rows(result);i++)
@@ -856,19 +857,62 @@ void apply_actions(int triggerid,int good)
action.delay=atoi(DBget_field(result,i,2));
strncpy(action.subject,DBget_field(result,i,3),MAX_STRING_LEN);
strncpy(action.message,DBget_field(result,i,4),MAX_STRING_LEN);
+ action.scope=atoi(DBget_field(result,i,5));
+ action.severity=atoi(DBget_field(result,i,6));
- substitute_hostname(triggerid,action.message);
- substitute_hostname(triggerid,action.subject);
+ if(ACTION_SCOPE_TRIGGER==action.scope)
+ {
+ substitute_hostname(trigger->triggerid,action.message);
+ substitute_hostname(trigger->triggerid,action.subject);
- substitute_macros(action.message);
- substitute_macros(action.subject);
+ substitute_macros(action.message);
+ substitute_macros(action.subject);
+ }
+ else if(ACTION_SCOPE_HOSTS==action.scope)
+ {
+ sprintf(sql,"select * from actions a,triggers t,hosts h,functions f,items i where a.triggerid=t.triggerid and f.triggerid=t.triggerid and i.itemid=f.itemid and h.hostid=i.hostid and a.scope=%d",ACTION_SCOPE_HOSTS);
+ result2 = DBselect(sql);
+ if(DBnum_rows(result2)==0)
+ {
+ DBfree_result(result2);
+ continue;
+ }
+ DBfree_result(result2);
+ strncpy(action.subject,trigger->description,MAX_STRING_LEN);
+ if(0==good)
+ {
+ strncat(action.subject," (ON)", MAX_STRING_LEN);
+ }
+ else
+ {
+ strncat(action.subject," (OFF)", MAX_STRING_LEN);
+ }
+ strncpy(action.message,action.subject,MAX_STRING_LEN);
+ }
+ else if(ACTION_SCOPE_HOSTS==action.scope)
+ {
+ strncpy(action.subject,trigger->description,MAX_STRING_LEN);
+ if(0==good)
+ {
+ strncat(action.subject," (ON)", MAX_STRING_LEN);
+ }
+ else
+ {
+ strncat(action.subject," (OFF)", MAX_STRING_LEN);
+ }
+ strncpy(action.message,action.subject,MAX_STRING_LEN);
+ }
+ else
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Unsupported scope [%d] for actionid [%d]", action.scope, action.actionid);
+ }
send_to_user(action.actionid,action.userid,action.subject,action.message);
now = time(NULL);
sprintf(sql,"update actions set nextcheck=%d where actionid=%d",now+action.delay,action.actionid);
DBexecute(sql);
}
- zabbix_log( LOG_LEVEL_DEBUG, "Actions applied for trigger %d %d\n", triggerid, good );
+ zabbix_log( LOG_LEVEL_DEBUG, "Actions applied for trigger %d %d", trigger->triggerid, good );
DBfree_result(result);
}
@@ -1032,7 +1076,8 @@ void update_triggers(int itemid)
))
{
now = time(NULL);
- apply_actions(trigger.triggerid,1);
+/* apply_actions(trigger.triggerid,1);*/
+ apply_actions(&trigger,1);
sprintf(sql,"update actions set nextcheck=0 where triggerid=%d and good=0",trigger.triggerid);
DBexecute(sql);
@@ -1058,7 +1103,8 @@ void update_triggers(int itemid)
(DBget_prev_trigger_value(trigger.triggerid) == TRIGGER_VALUE_TRUE)
))
{
- apply_actions(trigger.triggerid,0);
+/* apply_actions(trigger.triggerid,0);*/
+ apply_actions(&trigger,0);
sprintf(sql,"update actions set nextcheck=0 where triggerid=%d and good=1",trigger.triggerid);
DBexecute(sql);