From c9d422200ca8d3b4db66a56c5d4dc3fc3c35b15d Mon Sep 17 00:00:00 2001 From: osmiy Date: Fri, 23 Dec 2005 13:27:21 +0000 Subject: - added 'update' operation for triggers of template hosts (Eugene) - added 'update' operation for operations of template hosts (Eugene) git-svn-id: svn://svn.zabbix.com/trunk@2422 97f52cf1-0a1b-0410-bd0e-c28be96e8082 --- frontends/php/actions.php | 4 +- frontends/php/include/actions.inc.php | 99 +++++++++++++++++++++++++++++----- frontends/php/include/triggers.inc.php | 73 +++++++++++++++++++++++++ frontends/php/triggers.php | 1 + 4 files changed, 164 insertions(+), 13 deletions(-) (limited to 'frontends') diff --git a/frontends/php/actions.php b/frontends/php/actions.php index f524d813..d1c19d82 100644 --- a/frontends/php/actions.php +++ b/frontends/php/actions.php @@ -70,7 +70,9 @@ $_REQUEST["maxrepeats"]=0; $_REQUEST["repeatdelay"]=600; } + $result=update_action( $_REQUEST["actionid"], $_REQUEST["triggerid"], $_REQUEST["userid"], $_REQUEST["good"], $_REQUEST["delay"], $_REQUEST["subject"], $_REQUEST["message"],$_REQUEST["scope"],$_REQUEST["severity"],$_REQUEST["recipient"],$_REQUEST["usrgrpid"],$_REQUEST["maxrepeats"],$_REQUEST["repeatdelay"]); + update_action_from_linked_hosts($_REQUEST["actionid"]); show_messages($result,S_ACTION_UPDATED,S_CANNOT_UPDATE_ACTION); if($result) { @@ -226,7 +228,7 @@ // Otherwise symbols like ",' will not be shown $subject=htmlspecialchars($action["subject"]); $message=$action["message"]; - $uid=$action["uid"]; + $uid=$action["userid"]; $scope=@iif(isset($_REQUEST["scope"]),$_REQUEST["scope"],$action["scope"]); $severity=$action["severity"]; $recipient=@iif(isset($_REQUEST["recipient"]),$_REQUEST["recipient"],$action["recipient"]); diff --git a/frontends/php/include/actions.inc.php b/frontends/php/include/actions.inc.php index 551cf25c..f3f4df21 100644 --- a/frontends/php/include/actions.inc.php +++ b/frontends/php/include/actions.inc.php @@ -38,8 +38,28 @@ function update_action( $actionid, $triggerid, $userid, $good, $delay, $subject, $message, $scope, $severity, $recipient, $usrgrpid, $maxrepeats, $repeatdelay) { - delete_action($actionid); - return add_action( $triggerid, $userid, $good, $delay, $subject, $message, $scope, $severity, $recipient, $usrgrpid, $maxrepeats, $repeatdelay); + if(!check_right_on_trigger("A",$triggerid)) + { + error("Insufficient permissions"); + return 0; + } + + if($recipient == RECIPIENT_TYPE_USER) + { + $id = $userid; + } + else + { + $id = $usrgrpid; + } + $subject=addslashes($subject); + $message=addslashes($message); + + $sql="update actions set triggerid=$triggerid,userid=$id,good=$good,delay=$delay,nextcheck=0,subject='$subject',message='$message',scope=$scope,severity=$severity,recipient=$recipient,maxrepeats=$maxrepeats,repeatdelay=$repeatdelay where actionid=$actionid"; + $result=DBexecute($sql); + $trigger=get_trigger_by_triggerid($triggerid); + info("Action '$subject' for trigger '".$trigger["description"]."' updated"); + return $result; } # Add Action @@ -86,6 +106,8 @@ $result=DBexecute($sql); return DBinsert_id($result,"actions","actionid"); } + $trigger=get_trigger_by_triggerid($triggerid); + info("Action '$subject' for trigger '".$trigger["description"]."' added"); } # Delete Action by userid @@ -172,33 +194,86 @@ $trigger=get_trigger_by_triggerid($action["triggerid"]); $sql="select distinct h.hostid from hosts h,functions f, items i where i.itemid=f.itemid and h.hostid=i.hostid and f.triggerid=".$action["triggerid"]; - $result=DBselect($sql); - if(DBnum_rows($result)!=1) + $result=dbselect($sql); + if(dbnum_rows($result)!=1) { return; } - $row=DBfetch($result); + $row=dbfetch($result); $hostid=$row["hostid"]; $sql="select hostid,templateid,actions from hosts_templates where templateid=$hostid"; - $result=DBselect($sql); - while($row=DBfetch($result)) + $result=dbselect($sql); + #enumerate hosts + while($row=dbfetch($result)) { if($row["actions"]&4 == 0) continue; $sql="select distinct f.triggerid from functions f,items i,triggers t where t.description='".addslashes($trigger["description"])."' and t.triggerid=f.triggerid and i.itemid=f.itemid and i.hostid=".$row["hostid"]; - $result2=DBselect($sql); - while($row2=DBfetch($result2)) + $result2=dbselect($sql); + #enumerate triggers + while($row2=dbfetch($result2)) { - $sql="select actionid from actions where triggerid=".$row2["triggerid"]." and subject='".addslashes($action["subject"])."' and message='".addslashes($action["message"])."' and userid=".$action["userid"]." and good=".$action["good"]." and scope=".$action["scope"]." and recipient=".$action["recipient"]." and severity=".$action["severity"]; - $result3=DBselect($sql); - while($row3=DBfetch($result3)) + $sql="select actionid from actions where triggerid=".$row2["triggerid"]." and subject='".addslashes($action["subject"])."' and userid=".$action["userid"]." and good=".$action["good"]." and scope=".$action["scope"]." and recipient=".$action["recipient"]." and severity=".$action["severity"]; + $result3=dbselect($sql); + #enumerate actions + while($row3=dbfetch($result3)) { delete_action($row3["actionid"]); } } } } + + # Update action from hardlinked hosts + + function update_action_from_linked_hosts($actionid) + { + if($actionid<=0) + { + return; + } + + $action=get_action_by_actionid($actionid); + $trigger=get_trigger_by_triggerid($action["triggerid"]); + + $sql="select distinct h.hostid from hosts h,functions f, items i where i.itemid=f.itemid and h.hostid=i.hostid and f.triggerid=".$action["triggerid"]; + $result=dbselect($sql); + if(dbnum_rows($result)!=1) + { + return; + } + + $row=dbfetch($result); + + $hostid=$row["hostid"]; + $host_template=get_host_by_hostid($hostid); + + $sql="select hostid,templateid,actions from hosts_templates where templateid=$hostid"; + $result=dbselect($sql); + #enumerate hosts + while($row=dbfetch($result)) + { + if($row["actions"]&2 == 0) continue; + + $sql="select distinct f.triggerid from functions f,items i,triggers t where t.description='".addslashes($trigger["description"])."' and t.triggerid=f.triggerid and i.itemid=f.itemid and i.hostid=".$row["hostid"]; + $result2=dbselect($sql); + #enumerate triggers + while($row2=dbfetch($result2)) + { + $sql="select actionid from actions where triggerid=".$row2["triggerid"]." and subject='".addslashes($action["subject"])."'"; + $result3=dbselect($sql); + #enumerate actions + while($row3=dbfetch($result3)) + { + $host=get_host_by_hostid($row["hostid"]); + $message=str_replace("{".$host_template["host"].":", "{".$host["host"].":", $action["message"]); + update_action($row3["actionid"], $row2["triggerid"], $action["userid"], $action["good"], $action["delay"], $action["subject"], $message, $action["scope"], $action["severity"], $action["recipient"], $action["userid"], $action["maxrepeats"],$action["repeatdelay"]); + + } + } + } + } ?> diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php index 19ebead0..6d89fbe5 100644 --- a/frontends/php/include/triggers.inc.php +++ b/frontends/php/include/triggers.inc.php @@ -321,6 +321,79 @@ where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=$triggerid"; return TRUE; } + # Update triger from + function update_trigger_from_linked_hosts($triggerid) + { + if($triggerid<=0) + { + return; + } + + $trigger=get_trigger_by_triggerid($triggerid); + +# get hostid by triggerid + + $sql="select distinct h.hostid from hosts h,functions f, items i where i.itemid=f.itemid and h.hostid=i.hostid and f.triggerid=$triggerid"; + $result=DBselect($sql); + if(DBnum_rows($result)!=1){ return; } + $row0=DBfetch($result); + +#get linked hosts + $sql="select hostid,templateid,triggers from hosts_templates where templateid=".$row0["hostid"]; + $result=DBselect($sql); + // Loop: linked hosts + while($row=DBfetch($result)) + { + if($row["triggers"]&3 == 0) continue; +#get triggers + $sql="select distinct f.triggerid from functions f,items i,triggers t where t.description='".addslashes($trigger["description"])."' and t.triggerid=f.triggerid and i.itemid=f.itemid and i.hostid=".$row["hostid"]; + $result2=DBselect($sql); + // Loop: triggers + while($row2=DBfetch($result2)) + { + delete_function_by_triggerid($row2["triggerid"]); + + $expression_old=$trigger["expression"]; +#get functions + $sql="select i.key_,f.parameter,f.function,f.functionid from functions f,items i where i.itemid=f.itemid and f.triggerid=".$trigger["triggerid"]; + $result2=DBselect($sql); + // Loop: functions + while($row3=DBfetch($result2)) + { + + $sql="select itemid from items where key_=\"".$row3["key_"]."\" and hostid=".$row["hostid"]; + $result3=DBselect($sql); + if(DBnum_rows($result3)!=1) + { + $sql="delete from triggers where triggerid=".$row2["triggerid"]; + DBexecute($sql); + $sql="delete from functions where triggerid=".$row2["triggerid"]; + DBexecute($sql); + break; + } + $row4=DBfetch($result3); + + $item=get_item_by_itemid($row4["itemid"]); + + $sql="insert into functions (itemid,triggerid,function,parameter) values (".$item["itemid"].",".$row2["triggerid"].",'".$row3["function"]."','".$row3["parameter"]."')"; + $result5=DBexecute($sql); + $functionid=DBinsert_id($result5,"functions","functionid"); + + $sql="update triggers set expression='$expression_old' where triggerid=".$row2["triggerid"]; + DBexecute($sql); + $expression=str_replace("{".$row3["functionid"]."}","{".$functionid."}",$expression_old); + $expression_old=$expression; + $sql="update triggers set expression='$expression' where triggerid=".$row2["triggerid"]; + DBexecute($sql); + } + + $host=get_host_by_hostid($row["hostid"]); + info("Updated trigger from linked host ".$host["host"]); + } + + } + } + # Add item to hardlinked hosts function add_trigger_to_linked_hosts($triggerid,$hostid=0) diff --git a/frontends/php/triggers.php b/frontends/php/triggers.php index 542b3b34..96186bd0 100644 --- a/frontends/php/triggers.php +++ b/frontends/php/triggers.php @@ -119,6 +119,7 @@ else { $status=0; } $result=update_trigger($_REQUEST["triggerid"],$_REQUEST["expression"],$_REQUEST["description"],$_REQUEST["priority"],$status,$_REQUEST["comments"],$_REQUEST["url"]); + update_trigger_from_linked_hosts($_REQUEST["triggerid"]); show_messages($result, S_TRIGGER_UPDATED, S_CANNOT_UPDATE_TRIGGER); } else -- cgit