summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--frontends/php/include/services.inc.php248
-rw-r--r--frontends/php/include/triggers.inc.php24
-rw-r--r--frontends/php/services_form.php13
-rw-r--r--frontends/php/triggers.php19
4 files changed, 245 insertions, 59 deletions
diff --git a/frontends/php/include/services.inc.php b/frontends/php/include/services.inc.php
index b54eb79b..32100cdd 100644
--- a/frontends/php/include/services.inc.php
+++ b/frontends/php/include/services.inc.php
@@ -1,7 +1,7 @@
<?php
/*
** ZABBIX
-** Copyright (C) 2000-2005 SIA Zabbix
+** Copyright (C) 2000-2007 SIA Zabbix
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@@ -10,7 +10,7 @@
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
@@ -19,7 +19,7 @@
**/
?>
<?php
- function add_service($name,$triggerid,$algorithm,$showsla,$goodsla,$sortorder,$service_times=array(),$parentid,$childs){
+ function add_service($name,$triggerid,$status,$algorithm,$showsla,$goodsla,$sortorder,$service_times=array(),$parentid,$childs){
foreach($childs as $id => $child){ //add childs
if($parentid == $child['serviceid']){
@@ -45,16 +45,19 @@
return FALSE;
}
- $result=DBexecute("insert into services (serviceid,name,status,triggerid,algorithm,showsla,goodsla,sortorder)".
- " values ($serviceid,".zbx_dbstr($name).",0,$triggerid,".zbx_dbstr($algorithm).",$showsla,".zbx_dbstr($goodsla).",$sortorder)");
+ $result=DBexecute('INSERT INTO services (serviceid,name,status,triggerid,algorithm,showsla,goodsla,sortorder)'.
+ ' VALUES ('.$serviceid.','.zbx_dbstr($name).','.$status.' ,'.$triggerid.' ,'.zbx_dbstr($algorithm).
+ ' ,'.$showsla.','.zbx_dbstr($goodsla).','.$sortorder.')');
if(!$result){
return FALSE;
}
+ update_services($triggerid, $status); // updating status to all services by the dependency
+
DBExecute('DELETE FROM services_times WHERE serviceid='.$serviceid);
foreach($service_times as $val){
$timeid = get_dbid('services_times','timeid');
- $result = DBexecute('insert into services_times (timeid, serviceid, type, ts_from, ts_to, note)'.
+ $result = DBexecute('INSERT INTO services_times (timeid, serviceid, type, ts_from, ts_to, note)'.
' values ('.$timeid.','.$serviceid.','.$val['type'].','.$val['from'].','.$val['to'].','.zbx_dbstr($val['note']).')');
if(!$result)
@@ -66,7 +69,7 @@
return $serviceid;
}
- function update_service($serviceid,$name,$triggerid,$algorithm,$showsla,$goodsla,$sortorder,$service_times=array(),$parentid,$childs){
+ function update_service($serviceid,$name,$triggerid,$status,$algorithm,$showsla,$goodsla,$sortorder,$service_times=array(),$parentid,$childs){
foreach($childs as $id => $child){ //add childs
if($parentid == $child['serviceid']){
error('Service can\'t be parent and child in onetime.');
@@ -88,37 +91,45 @@
if(is_null($triggerid) || $triggerid==0) $triggerid = 'NULL';
- $result = DBexecute("update services set name=".zbx_dbstr($name).",triggerid=$triggerid,status=0,algorithm=$algorithm,showsla=$showsla,goodsla=$goodsla,sortorder=$sortorder where serviceid=$serviceid");
+ $result = DBexecute('UPDATE services '.
+ ' SET name='.zbx_dbstr($name).
+ ',triggerid='.$triggerid.', status='.$status.', algorithm='.$algorithm.', '.
+ ' showsla='.$showsla.', goodsla='.$goodsla.', sortorder='.$sortorder.
+ ' WHERE serviceid='.$serviceid);
+
+ update_services($triggerid, $status); // updating status to all services by the dependency
- DBexecute('delete from services_times where serviceid='.$serviceid);
+ DBexecute('DELETE FROM services_times WHERE serviceid='.$serviceid);
foreach($service_times as $val){
$timeid = get_dbid('services_times','timeid');
- DBexecute('insert into services_times (timeid,serviceid, type, ts_from, ts_to, note)'.
- ' values ('.$timeid.','.$serviceid.','.$val['type'].','.$val['from'].','.$val['to'].','.zbx_dbstr($val['note']).')');
+ DBexecute('INSERT INTO services_times (timeid,serviceid, type, ts_from, ts_to, note)'.
+ ' VALUES('.$timeid.','.$serviceid.','.$val['type'].','.$val['from'].','.$val['to'].','.zbx_dbstr($val['note']).')');
}
return $result;
}
-
- function add_host_to_services($hostid, $serviceid)
- {
+
+ function add_host_to_services($hostid, $serviceid){
global $ZBX_CURNODEID;
- $result = DBselect('select distinct h.host,t.triggerid,t.description '.
- ' from triggers t,hosts h,items i,functions f where h.hostid='.$hostid.' and h.hostid=i.hostid '.
- ' and i.itemid=f.itemid and f.triggerid=t.triggerid '.
- ' and '.DBid2nodeid('t.triggerid').'='.$ZBX_CURNODEID);
- while($row=DBfetch($result))
- {
+ $result = DBselect('SELECT distinct h.host,t.triggerid,t.description '.
+ ' FROM triggers t,hosts h,items i,functions f '.
+ ' WHERE h.hostid='.$hostid.
+ ' AND h.hostid=i.hostid '.
+ ' AND i.itemid=f.itemid '.
+ ' AND f.triggerid=t.triggerid '.
+ ' AND '.DBid2nodeid('t.triggerid').'='.$ZBX_CURNODEID
+ );
+
+ while($row=DBfetch($result)){
$serviceid2 = add_service(expand_trigger_description_by_data($row),$row["triggerid"],"on",0,"off",99);
add_service_link($serviceid2,$serviceid,0);
}
return 1;
}
- function is_service_hardlinked($serviceid)
- {
- $row = DBfetch(DBselect("select count(*) as cnt from services_links where servicedownid=".$serviceid." and soft=0"));
+ function is_service_hardlinked($serviceid){
+ $row = DBfetch(DBselect("SELECT count(*) as cnt FROM services_links WHERE servicedownid=".$serviceid." and soft=0"));
if($row["cnt"]>0)
{
return TRUE;
@@ -133,20 +144,20 @@
******************************************************************************/
function delete_service_link($linkid)
{
- $sql="delete from services_links where linkid=$linkid";
+ $sql="DELETE FROM services_links WHERE linkid=$linkid";
return DBexecute($sql);
}
function delete_service($serviceid)
{
- $sql="delete from services_links where servicedownid=$serviceid or serviceupid=$serviceid";
+ $sql="DELETE FROM services_links WHERE servicedownid=$serviceid OR serviceupid=$serviceid";
$result=DBexecute($sql);
if(!$result)
{
return $result;
}
- $sql="delete from services where serviceid=$serviceid";
+ $sql="DELETE FROM services WHERE serviceid=$serviceid";
return DBexecute($sql);
}
@@ -168,7 +179,7 @@
}
- $result=DBselect("select serviceupid from services_links where servicedownid=$serviceid2 and soft=0");
+ $result=DBselect("SELECT serviceupid FROM services_links WHERE servicedownid=$serviceid2 and soft=0");
while($row=DBfetch($result))
{
if(does_service_depend_on_the_service($serviceid,$row["serviceupid"]) == TRUE)
@@ -181,7 +192,7 @@
function service_has_parent($serviceid)
{
- $row = DBfetch(DBselect("select count(*) as cnt from services_links where servicedownid=$serviceid"));
+ $row = DBfetch(DBselect("SELECT count(*) as cnt FROM services_links WHERE servicedownid=$serviceid"));
if($row["cnt"]>0)
{
return TRUE;
@@ -191,7 +202,7 @@
function service_has_no_this_parent($parentid,$serviceid)
{
- $row = DBfetch(DBselect("select count(*) as cnt from services_links where serviceupid=$parentid and servicedownid=$serviceid"));
+ $row = DBfetch(DBselect("SELECT count(*) as cnt FROM services_links WHERE serviceupid=$parentid and servicedownid=$serviceid"));
if($row["cnt"]>0)
{
return FALSE;
@@ -212,7 +223,7 @@
$linkid=get_dbid("services_links","linkid");
- $sql="insert into services_links (linkid,servicedownid,serviceupid,soft) values ($linkid,$servicedownid,$serviceupid,$softlink)";
+ $sql="INSERT INTO services_links (linkid,servicedownid,serviceupid,soft) values ($linkid,$servicedownid,$serviceupid,$softlink)";
$result=DBexecute($sql);
if(!$result)
@@ -231,7 +242,7 @@
return false;
}
- $sql="update services_links set servicedownid=$servicedownid, serviceupid=$serviceupid, soft=$softlink where linkid=$linkid";
+ $sql="UPDATE services_links SET servicedownid=$servicedownid, serviceupid=$serviceupid, soft=$softlink WHERE linkid=$linkid";
return dbexecute($sql);
}
@@ -245,14 +256,14 @@
}
function get_last_service_value($serviceid,$clock){
- $sql="select count(*) as cnt,max(clock) as maxx from service_alarms where serviceid=$serviceid and clock<=$clock";
+ $sql="SELECT count(*) as cnt,max(clock) as maxx FROM service_alarms WHERE serviceid=$serviceid and clock<=$clock";
// echo " $sql<br>";
$result=DBselect($sql);
$row=DBfetch($result);
if($row["cnt"]>0)
{
- $sql="select value from service_alarms where serviceid=$serviceid and clock=".$row["maxx"];
+ $sql="SELECT value FROM service_alarms WHERE serviceid=$serviceid and clock=".$row["maxx"];
$result2=DBselect($sql);
// Assuring that we get very latest service value. There could be several with the same timestamp
// $value=DBget_field($result2,0,0);
@@ -274,7 +285,7 @@
$type='ut' /* 'ut' OR 'dt' */
)
{
- /* calculate period from '-1 week' to know period name for $period_start */
+ /* calculate period FROM '-1 week' to know period name for $period_start */
for($curr = ($period_start - (7*24*36000)); $curr<=$period_end; $curr += 6*3600)
{
$curr_date = getdate($curr);
@@ -313,7 +324,7 @@
{
-// $sql="select count(*),min(clock),max(clock) from service_alarms where serviceid=$serviceid and clock>=$period_start and clock<=$period_end";
+// $sql="SELECT count(*),min(clock),max(clock) FROM service_alarms WHERE serviceid=$serviceid and clock>=$period_start and clock<=$period_end";
/* FILL data */
@@ -328,8 +339,8 @@
$data[$period_start]['alarm'] = get_last_service_value($serviceid,$period_start);
- $service_alarms = DBselect("select clock,value from service_alarms".
- " where serviceid=".$serviceid." and clock>=".$period_start." and clock<=".$period_end." order by clock");
+ $service_alarms = DBselect("SELECT clock,value FROM service_alarms".
+ " WHERE serviceid=".$serviceid." and clock>=".$period_start." and clock<=".$period_end." order by clock");
/* add alarms */
while($db_alarm_row = DBfetch($service_alarms))
@@ -338,7 +349,7 @@
}
/* add periodical downtimes */
- $service_times = DBselect('select ts_from,ts_to from services_times where type='.SERVICE_TIME_TYPE_UPTIME.
+ $service_times = DBselect('SELECT ts_from,ts_to FROM services_times WHERE type='.SERVICE_TIME_TYPE_UPTIME.
' and serviceid='.$serviceid);
if($db_time_row = DBfetch($service_times))
{
@@ -359,7 +370,7 @@
}
/* add periodical downtimes */
- $service_times = DBselect('select ts_from,ts_to from services_times where type='.SERVICE_TIME_TYPE_DOWNTIME.
+ $service_times = DBselect('SELECT ts_from,ts_to FROM services_times WHERE type='.SERVICE_TIME_TYPE_DOWNTIME.
' and serviceid='.$serviceid);
while($db_time_row = DBfetch($service_times))
{
@@ -370,10 +381,9 @@
}
/* add one-time downtimes */
- $service_times = DBselect('select ts_from,ts_to from services_times where type='.SERVICE_TIME_TYPE_ONETIME_DOWNTIME.
- ' and serviceid='.$serviceid);
- while($db_time_row = DBfetch($service_times))
- {
+ $service_times = DBselect('SELECT ts_from,ts_to FROM services_times WHERE type='.SERVICE_TIME_TYPE_ONETIME_DOWNTIME.' and serviceid='.$serviceid);
+ while($db_time_row = DBfetch($service_times)){
+
if( ($db_time_row['ts_to'] < $period_start) || ($db_time_row['ts_from'] > $period_end)) continue;
if($db_time_row['ts_from'] < $period_start) $db_time_row['ts_from'] = $period_start;
@@ -511,14 +521,14 @@ $dt = 0;
function get_num_of_service_childs($serviceid)
{
- $row = DBfetch(DBselect("select count(distinct servicedownid) as cnt from services_links ".
- " where serviceupid=".$serviceid));
+ $row = DBfetch(DBselect("SELECT count(distinct servicedownid) as cnt FROM services_links ".
+ " WHERE serviceupid=".$serviceid));
return $row["cnt"];
}
function get_service_by_serviceid($serviceid)
{
- $res = DBfetch(DBselect("select * from services where serviceid=".$serviceid));
+ $res = DBfetch(DBselect("SELECT * FROM services WHERE serviceid=".$serviceid));
if(!$res)
{
error("No service with serviceid=[".$serviceid."]");
@@ -529,7 +539,7 @@ $dt = 0;
function get_services_links_by_linkid($linkid)
{
- $result=DBselect("select * from services_links where linkid=$linkid");
+ $result=DBselect("SELECT * FROM services_links WHERE linkid=$linkid");
$res = DBfetch($result);
if(!$res)
{
@@ -647,4 +657,148 @@ $dt = 0;
} while(isset($retry));
return $services;
}
+
+/******************************************************************************
+ * *
+ * Function: update_services_rec *
+ * *
+ * Purpose: re-calculate and updates status of the service and its childs *
+ * *
+ * Parameters: serviceid - item to update services for *
+ * *
+ * Return value: *
+ * *
+ * Author: Alexei Vladishev (PHP ver. by Artem Suharev) *
+ * *
+ * Comments: recursive function !!! Don't forget sync code with C !!! *
+ * *
+ ******************************************************************************/
+function update_services_rec($serviceid){
+
+ $result = DBselect("SELECT l.serviceupid,s.algorithm FROM services_links l,services s WHERE s.serviceid=l.serviceupid AND l.servicedownid=".$serviceid);
+ $status=0;
+
+ while($rows=DBfetch($result)){
+ $serviceupid = $rows['serviceupid'];
+ $algorithm = $rows['algorithm'];
+
+ if(SERVICE_ALGORITHM_NONE == $algorithm){
+ /* Do nothing */
+ }
+ else if((SERVICE_ALGORITHM_MAX == $algorithm) || (SERVICE_ALGORITHM_MIN == $algorithm)){
+
+ if(SERVICE_ALGORITHM_MAX == $algorithm){
+
+ $result2 = DBselect('SELECT count(*) as count,max(status) as status'.
+ ' FROM services s,services_links l '.
+ ' WHERE l.serviceupid='.$serviceupid.
+ ' AND s.serviceid=l.servicedownid'
+ );
+ }
+ /* MIN otherwise */
+ else{
+ $result2 = DBselect('SELECT count(*) as count,min(status) as status'.
+ ' FROM services s,services_links l '.
+ ' WHERE l.serviceupid='.$serviceupid.
+ ' AND s.serviceid=l.servicedownid'
+ );
+ }
+
+ $rows2=DBfetch($result2);
+
+ if($rows2 && !is_null($rows2['count']) && !is_null($rows2['status'])){
+ if($row2['count'] > 0){
+ $status=$rows2['status'];
+ }
+ }
+
+ $now=time();
+
+ add_service_alarm($serviceupid,$status,$now);
+ DBexecute('UPDATE services SET status='.$status.' WHERE serviceid='.$serviceupid);
+ }
+ else{
+ error('Unknown calculation algorithm of service status ['.$algorithm.']');
+ return false;
+ }
+ }
+
+ $result = DBselect('SELECT serviceupid FROM services_links WHERE servicedownid='.$serviceid);
+
+ while($rows=DBfetch($result)){
+ $serviceupid = $rows['serviceupid'];
+ update_services_rec($serviceupid);
+ }
+}
+
+/******************************************************************************
+ * *
+ * Function: update_services *
+ * *
+ * Purpose: re-calculate and updates status of the service and its childs *
+ * *
+ * Parameters: serviceid - item to update services for *
+ * status - new status of the service *
+ * *
+ * Return value: *
+ * *
+ * Author: Alexei Vladishev (PHP ver. by Artem Suharev) *
+ * *
+ * Comments: !!! Don't forget sync code with C !!! *
+ * *
+ ******************************************************************************/
+function update_services($triggerid, $status){
+ DBexecute('UPDATE services SET status='.$status.' WHERE triggerid='.$triggerid);
+
+ $result = DBselect('SELECT serviceid FROM services WHERE triggerid='.$triggerid);
+
+ while(($rows=DBfetch($result))){
+ update_services_rec($rows['serviceid']);
+ }
+}
+
+/******************************************************************************
+ * *
+ * Comments: !!! Don't forget sync code with C !!! *
+ * *
+ ******************************************************************************/
+function latest_service_alarm($serviceid, $status){
+ $ret = false;
+
+ $result = DBselect('SELECT max(clock) as clock FROM service_alarms WHERE serviceid='.$serviceid);
+ $rows = DBfetch($result);
+
+ if(!$rows || is_null($rows['clock'])){
+ $ret = false;
+ }
+ else{
+ $clock=$rows['clock'];
+
+ $result = DBselect('SELECT value FROM service_alarms WHERE serviceid='.$serviceid.' AND clock='.$clock);
+ $rows = DBfetch($result);
+ if($rows && !is_null($rows['value'])){
+ if($rows['value'] == $status){
+ $ret = true;
+ }
+ }
+ }
+
+ return $ret;
+}
+
+/******************************************************************************
+ * *
+ * Comments: !!! Don't forget sync code with C !!! *
+ * *
+ ******************************************************************************/
+function add_service_alarm($serviceid,$status,$clock){
+
+ if(latest_service_alarm($serviceid,$status) == true){
+ return true;
+ }
+
+ DBexecute('INSERT INTO service_alarms(servicealarmid,serviceid,clock,value) VALUES('.get_dbid('service_alarms','servicealarmid').','.$serviceid.','.$clock.','.$status);
+
+ return true;
+}
?>
diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php
index 07129425..bdce85a4 100644
--- a/frontends/php/include/triggers.inc.php
+++ b/frontends/php/include/triggers.inc.php
@@ -1,7 +1,7 @@
<?php
/*
** ZABBIX
-** Copyright (C) 2000-2005 SIA Zabbix
+** Copyright (C) 2000-2007 SIA Zabbix
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@@ -263,6 +263,28 @@
}
/*
+ * Function: get_trigger_priority
+ *
+ * Description:
+ * retrive triggers priority
+ *
+ * Author:
+ * Artem Suahrev
+ *
+ * Comments:
+ *
+ */
+
+ function get_trigger_priority($triggerid){
+ $sql = 'SELECT priority FROM triggers WHERE triggerid='.$triggerid;
+ $res = DBselect($sql);
+ while($rows = DBfetch($res)){
+ $status = $rows['priority'];
+ }
+ return $status;
+ }
+
+ /*
* Function: get_realhosts_by_triggerid
*
* Description:
diff --git a/frontends/php/services_form.php b/frontends/php/services_form.php
index 235198bb..6ad1a7ce 100644
--- a/frontends/php/services_form.php
+++ b/frontends/php/services_form.php
@@ -120,10 +120,17 @@ if(isset($_REQUEST['saction'])){
$service_times = get_request('service_times',array());
$childs = get_request('childs',array());
- $triggerid = isset($_REQUEST["linktrigger"]) ? $_REQUEST["triggerid"] : null;
+ if(isset($_REQUEST["linktrigger"])){
+ $triggerid = $_REQUEST["triggerid"];
+ $status = get_trigger_priority($triggerid);
+ }
+ else {
+ $triggerid = null;
+ $status = 0;
+ }
if(isset($service["serviceid"])){
$result = update_service($service["serviceid"],
- $_REQUEST["name"],$triggerid,$_REQUEST["algorithm"],
+ $_REQUEST["name"],$triggerid,$status,$_REQUEST["algorithm"],
$_REQUEST["showsla"],$_REQUEST["goodsla"],$_REQUEST["sortorder"],
$service_times,$_REQUEST['parentid'],$childs);
@@ -133,7 +140,7 @@ if(isset($_REQUEST['saction'])){
} else {
$result = add_service(
- $_REQUEST["name"],$triggerid,$_REQUEST["algorithm"],
+ $_REQUEST["name"],$triggerid,$status,$_REQUEST["algorithm"],
$_REQUEST["showsla"],$_REQUEST["goodsla"],$_REQUEST["sortorder"],
$service_times,$_REQUEST['parentid'],$childs);
show_messages($result, S_SERVICE_ADDED, S_CANNOT_ADD_SERVICE);
diff --git a/frontends/php/triggers.php b/frontends/php/triggers.php
index 7c40152b..b1e78a18 100644
--- a/frontends/php/triggers.php
+++ b/frontends/php/triggers.php
@@ -243,8 +243,11 @@ include_once "include/page_header.php";
$result=DBselect("select triggerid from triggers t where t.triggerid=".zbx_dbstr($triggerid));
if(!($row = DBfetch($result))) continue;
- if($result = update_trigger_status($row["triggerid"],0))
- {
+ if($result = update_trigger_status($row['triggerid'],0)){
+
+ $status = get_trigger_priority($row['triggerid']);
+ update_services($triggerid, $status); // updating status to all services by the dependency
+
add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_TRIGGER,
S_TRIGGER." [".$triggerid."] [".expand_trigger_description($triggerid)."] ".S_ENABLED);
}
@@ -255,16 +258,16 @@ include_once "include/page_header.php";
show_messages($result2, S_STATUS_UPDATED, S_CANNOT_UPDATE_STATUS);
}
}
- elseif(isset($_REQUEST["group_disable"])&&isset($_REQUEST["g_triggerid"]))
- {
- foreach($_REQUEST["g_triggerid"] as $triggerid)
- {
+ elseif(isset($_REQUEST["group_disable"])&&isset($_REQUEST["g_triggerid"])){
+ foreach($_REQUEST["g_triggerid"] as $triggerid){
if(!check_right_on_trigger_by_triggerid(null, $triggerid, $accessible_hosts)) continue;
$result=DBselect("select triggerid from triggers t where t.triggerid=".zbx_dbstr($triggerid));
if(!($row = DBfetch($result))) continue;
- if($result = update_trigger_status($row["triggerid"],1));
- {
+ if($result = update_trigger_status($row["triggerid"],1));{
+
+ update_services($triggerid, 0); // updating status to all services by the dependency
+
add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_TRIGGER,
S_TRIGGER." [".$triggerid."] [".expand_trigger_description($triggerid)."] ".S_DISABLED);
}