summaryrefslogtreecommitdiffstats
path: root/frontends/php/include/escalations.inc.php
diff options
context:
space:
mode:
authorhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-06-04 10:37:48 +0000
committerhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-06-04 10:37:48 +0000
commitc3cb3f34ea615de16fa507271ca61cf5f426b5c1 (patch)
treec375c800742bac451b7049f447082cbd604a3277 /frontends/php/include/escalations.inc.php
parentdee7748ce3a458856713e608569c47c6d5ea65d4 (diff)
downloadzabbix-c3cb3f34ea615de16fa507271ca61cf5f426b5c1.tar.gz
zabbix-c3cb3f34ea615de16fa507271ca61cf5f426b5c1.tar.xz
zabbix-c3cb3f34ea615de16fa507271ca61cf5f426b5c1.zip
Improvements for escalation management.
git-svn-id: svn://svn.zabbix.com/trunk@1813 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include/escalations.inc.php')
-rw-r--r--frontends/php/include/escalations.inc.php196
1 files changed, 22 insertions, 174 deletions
diff --git a/frontends/php/include/escalations.inc.php b/frontends/php/include/escalations.inc.php
index 67a1bd8a..e118ddc2 100644
--- a/frontends/php/include/escalations.inc.php
+++ b/frontends/php/include/escalations.inc.php
@@ -19,210 +19,58 @@
**/
?>
<?php
- # Add Host definition
+ # Add escalation definition
- function add_host($host,$port,$status,$useip,$ip,$host_templateid,$newgroup,$groups)
+ function add_escalation($name,$dflt)
{
- if(!check_right("Host","A",0))
+ if(!check_right("Configuration of Zabbix","U",0))
{
error("Insufficient permissions");
- return 0;
+ return 0;
}
- if (!eregi('^([0-9a-zA-Z\_\.-]+)$', $host, &$arr))
- {
- error("Hostname should contain 0-9a-zA-Z_.- characters only");
- return 0;
- }
-
- $sql="select * from hosts where host='$host'";
- $result=DBexecute($sql);
- if(DBnum_rows($result)>0)
- {
- error("Host '$host' already exists");
- return 0;
- }
-
- if( isset($useip) && ($useip=="on") )
- {
- $useip=1;
- }
- else
- {
- $useip=0;
- }
-
-
- $sql="insert into hosts (host,port,status,useip,ip,disable_until,available) values ('$host',$port,$status,$useip,'$ip',0,".HOST_AVAILABLE_UNKNOWN.")";
+ $sql="insert into escalations (name,dflt) values ('$name',$dflt)";
$result=DBexecute($sql);
if(!$result)
{
return $result;
}
-
- $hostid=DBinsert_id($result,"hosts","hostid");
+ $escalationid=DBinsert_id($result,"escalation","escalationid");
- if($host_templateid != 0)
+ if($dflt==1)
{
- add_templates_to_host($hostid,$host_templateid);
-// $result=add_using_host_template($hostid,$host_templateid);
- sync_host_with_templates($hostid);
+ $sql="update escalations set dflt=0 where escalationid<>$escalationid";
+ $result=DBexecute($sql);
+ info("Default escalation is set to '$name'");
}
- update_host_groups($hostid,$groups);
- if($newgroup != "")
- {
- add_group_to_host($hostid,$newgroup);
- }
-
- update_profile("HOST_PORT",$port);
return $result;
}
- function update_host($hostid,$host,$port,$status,$useip,$ip,$newgroup,$groups)
+ # Delete escalation definition
+
+ function delete_escalation($escalationid)
{
- if(!check_right("Host","U",$hostid))
+ if(!check_right("Configuration of Zabbix","U",0))
{
error("Insufficient permissions");
- return 0;
+ return 0;
}
- if (!eregi('^([0-9a-zA-Z\_\.-]+)$', $host, &$arr))
- {
- error("Hostname should contain 0-9a-zA-Z_.- characters only");
- return 0;
- }
-
- $sql="select * from hosts where host='$host' and hostid<>$hostid";
+ $sql="delete from escalation_rules where escalationid=$escalationid";
$result=DBexecute($sql);
- if(DBnum_rows($result)>0)
+ if(!$result)
{
- error("Host '$host' already exists");
- return 0;
+ return $result;
}
-
- if($useip=="on")
- {
- $useip=1;
- }
- else
- {
- $useip=0;
- }
- $sql="update hosts set host='$host',port=$port,useip=$useip,ip='$ip' where hostid=$hostid";
+ $sql="delete from escalations where escalationid=$escalationid";
$result=DBexecute($sql);
-
-
- update_host_status($hostid, $status);
- update_host_groups($hostid,$groups);
- if($newgroup != "")
- {
- add_group_to_host($hostid,$newgroup);
- }
- return $result;
- }
-
- # Add templates linked to template host to the host
-
- function add_templates_to_host($hostid,$host_templateid)
- {
- $sql="select * from hosts_templates where hostid=$host_templateid";
- $result=DBselect($sql);
- while($row=DBfetch($result))
- {
- add_template_linkage($hostid,$row["templateid"],$row["items"],$row["triggers"],$row["actions"],
- $row["graphs"],$row["screens"]);
- }
- }
-
- function delete_groups_by_hostid($hostid)
- {
- $sql="select groupid from hosts_groups where hostid=$hostid";
- $result=DBselect($sql);
- while($row=DBfetch($result))
- {
- $sql="delete from hosts_groups where hostid=$hostid and groupid=".$row["groupid"];
- DBexecute($sql);
- $sql="select count(*) as count from hosts_groups where groupid=".$row["groupid"];
- $result2=DBselect($sql);
- $row2=DBfetch($result2);
- if($row2["count"]==0)
- {
- $sql="delete from groups where groupid=".$row["groupid"];
- DBexecute($sql);
- }
- }
- }
-
- # Delete Host
-
- function delete_host($hostid)
- {
- global $DB_TYPE;
-
- if($DB_TYPE=="MYSQL")
- {
- $sql="update hosts set status=".HOST_STATUS_DELETED.",host=concat(host,\" [DELETED]\") where hostid=$hostid";
- }
- else
- {
- $sql="update hosts set status=".HOST_STATUS_DELETED.",host=host||' [DELETED]' where hostid=$hostid";
- }
- return DBexecute($sql);
- }
-
- function delete_host_group($groupid)
- {
- $sql="delete from hosts_groups where groupid=$groupid";
- DBexecute($sql);
- $sql="delete from groups where groupid=$groupid";
- return DBexecute($sql);
- }
-
- function get_host_by_hostid($hostid)
- {
- $sql="select hostid,host,useip,ip,port,status from hosts where hostid=$hostid";
- $result=DBselect($sql);
- if(DBnum_rows($result) == 1)
- {
- $host["hostid"]=DBget_field($result,0,0);
- $host["host"]=DBget_field($result,0,1);
- $host["useip"]=DBget_field($result,0,2);
- $host["ip"]=DBget_field($result,0,3);
- $host["port"]=DBget_field($result,0,4);
- $host["status"]=DBget_field($result,0,5);
- }
- else
+ if(!$result)
{
- error("No host with hostid=[$hostid]");
+ return $result;
}
- return $host;
- }
-
- # Update Host status
- function update_host_status($hostid,$status)
- {
- if(!check_right("Host","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
- $sql="select status,host from hosts where hostid=$hostid";
- $result=DBselect($sql);
- $old_status=DBget_field($result,0,0);
- if($status != $old_status)
- {
- update_trigger_value_to_unknown_by_hostid($hostid);
- $sql="update hosts set status=$status where hostid=$hostid and status!=".HOST_STATUS_DELETED;
- info("Updated status of host ".DBget_field($result,0,1));
- return DBexecute($sql);
- }
- else
- {
- return 1;
- }
+ return $result;
}
?>