diff options
| author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-03-14 15:21:27 +0000 |
|---|---|---|
| committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-03-14 15:21:27 +0000 |
| commit | 25036c9384fcec4d36f4cfc69fe2b86e4ef2c9c6 (patch) | |
| tree | 01e08dad83c7671bb8a19b9c40f2f786b033d99e /frontends/php/include | |
| parent | f35b829723124ac2c15defd1d5cce44b40b1c8ec (diff) | |
| download | zabbix-25036c9384fcec4d36f4cfc69fe2b86e4ef2c9c6.tar.gz zabbix-25036c9384fcec4d36f4cfc69fe2b86e4ef2c9c6.tar.xz zabbix-25036c9384fcec4d36f4cfc69fe2b86e4ef2c9c6.zip | |
- added "Data overview" for screens
- added "Triggers overview" for screens (Eugene)
- added blinking into Trigger overview (Eugene)
- added screen displaying in other screen (Eugene)
- improved Overview table header, vertical text added (Eugene)
- developed "ZABBIX Clock" module for screens (Eugene)
- developed "ZABBIX server info" module for screens (Eugene)
- developed "Triggers info" module for screens (Eugene)
- developed "Host info" module for screens (Eugene)
- improved screens displaying, added item alignment (Eugene)
- improved ZABBIX server report (Eugene)
- improved images configuration (Eugene)
- added onserver image resizing for thumbs by php (Eugene)
- developed acknowledges system (Eugene)
- added icons displaying for maps (Eugene)
- added maps displaying for maps (Eugene)
- improved maps (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@2699 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
30 files changed, 2027 insertions, 406 deletions
diff --git a/frontends/php/include/acknow.inc.php b/frontends/php/include/acknow.inc.php new file mode 100644 index 00000000..2db7d35c --- /dev/null +++ b/frontends/php/include/acknow.inc.php @@ -0,0 +1,49 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2005 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 +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +?> +<?php + function get_last_alarm_by_triggerid($triggerid) + { + $db_alarms = DBselect("select * from alarms where triggerid=$triggerid". + " order by clock desc limit 1"); + if(DBnum_rows($db_alarms)!=1) return FALSE; + return DBfetch($db_alarms); + } + + function get_acknowledges_by_alarmid($alarmid) + { + return DBselect("select * from acknowledges where alarmid=$alarmid"); + } + + function add_acknowledge_coment($alarmid, $userid, $message) + { + $result = set_alarm_acnowledged($alarmid); + if(!$result) + return $result; + + return DBexecute("insert into acknowledges (userid,alarmid,clock,message)". + " values ($userid,$alarmid,".time().",".zbx_dbstr($message).")"); + } + + function set_alarm_acnowledged($alarmid) + { + return DBexecute("update alarms set acknowledged=1 where alarmid=$alarmid"); + } +?> diff --git a/frontends/php/include/classes/ccombobox.inc.php b/frontends/php/include/classes/ccombobox.inc.php index 849f2e5a..69a17636 100644 --- a/frontends/php/include/classes/ccombobox.inc.php +++ b/frontends/php/include/classes/ccombobox.inc.php @@ -22,18 +22,24 @@ class CComboItem extends CTag { /* public */ - function CComboItem($value,$caption=NULL,$selected='no') + function CComboItem($value,$caption=NULL,$selected=NULL, $enabled=NULL) { parent::CTag('option','yes'); $this->tag_body_start = ""; $this->SetCaption($caption); $this->SetValue($value); $this->SetSelected($selected); + $this->SetEnabled($enabled); + } function SetValue($value) { return parent::AddOption('value',$value); } + function GetValue() + { + return parent::GetOption('value'); + } function SetCaption($value=NULL) { if(is_null($value)) @@ -47,7 +53,7 @@ function SetSelected($value='yes') { if(is_null($value)) - return 0; + return $this->DelOption('selected'); elseif((is_string($value) && ($value == 'yes' || $value == "selected" || $value=='on')) || (is_int($value) && $value<>0)) return $this->AddOption('selected','selected'); @@ -111,21 +117,26 @@ } function AddItem($value, $caption, $selected=NULL, $enabled='yes') { - if(is_null($selected)) - { - $selected = 'no'; - if(!is_null($this->value)) - if($this->value==$value) - $selected = 'yes'; - } - // if($enabled=='no') return; /* disable item method 1 */ - $cmbItem = new CComboItem($value,$caption,$selected); + $cmbItem = new CComboItem($value,$caption,$selected,$enabled); + return parent::AddItem($cmbItem); + } - $cmbItem->SetEnable($enabled); /* disable item method 2 */ + function SetSelectedByValue(&$item) + { + if(!is_null($this->value)) + { + $selected = 'no'; + if($item->GetValue() == $this->value) $selected = 'yes'; + $item->SetSelected($selected); + } + } - return parent::AddItem($cmbItem); + function ShowTagItem(&$item) + { + $this->SetSelectedByValue($item); + parent::ShowTagItem($item); } function Show() { diff --git a/frontends/php/include/classes/cflash.inc.php b/frontends/php/include/classes/cflash.inc.php new file mode 100644 index 00000000..fa8886a7 --- /dev/null +++ b/frontends/php/include/classes/cflash.inc.php @@ -0,0 +1,136 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2005 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 +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +?> +<?php + class CFlashEmbed extends CTag + { + function CFlashEmbed($src=NULL, $width = NULL, $height = NULL) + { + parent::CTag("embed"); + $this->AddOption("allowScriptAccess","sameDomain"); + $this->AddOption("type","application/x-shockwave-flash"); + $this->AddOption("pluginspage","http://www.macromedia.com/go/getflashplayer"); + $this->AddOption("align","middle"); + $this->AddOption("quality","high"); + + $this->SetWidth($width); + $this->SetHeight($height); + $this->SetSrc($src); + } + function SetWidth($value) + { + if(is_null($value)) + return $this->DelOption("width"); + if(!is_numeric($value)) + return $this->error("Incorrect value for SetWidth [$value]"); + + $this->AddOption("width",$value); + } + function SetHeight($value) + { + if(is_null($value)) + return $this->DelOption("height"); + if(!is_numeric($value)) + return $this->error("Incorrect value for SetHeight [$value]"); + + $this->AddOption("height",$value); + } + function SetSrc($value) + { + if(is_null($value)) + return $this->DelOption("src"); + if(!is_string($value)) + return $this->error("Incorrect value for SetSrc[$value]"); + + $this->AddOption("src",$value); + } + } + + class CParam extends CTag + { + function CParam($name,$value) + { + parent::CTag("param","no"); + + $this->SetName($name); + $this->SetValue($value); + } + function SetName($value) + { + $this->AddOption("name",$value); + } + function SetValue($value) + { + $this->AddOption("value",$value); + } + } + + class CFlash extends CTag + { + var $timetype; + function CFlash($src=NULL, $width = NULL, $height = NULL) + { + parent::CTag("object",'yes'); + $this->AddOption("classid","clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"); + $this->AddOption("codebase","http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"); + $this->AddOption("align","middle"); + + $this->AddItem(new CParam("allowScriptAccess","sameDomain")); + $this->AddItem(new CParam("quality","high")); + $this->items["src"] = new CParam("movie",$src); + + $this->items["embeded"] = new CFlashEmbed(); + + $this->SetWidth($width); + $this->SetHeight($height); + $this->SetSrc($src); + } + function SetWidth($value) + { + if(is_null($value)) + return $this->DelOption("width"); + if(!is_numeric($value)) + return $this->error("Incorrect value for SetWidth [$value]"); + + $this->AddOption("width",$value); + $this->items["embeded"]->SetWidth($value); + } + function SetHeight($value) + { + if(is_null($value)) + return $this->DelOption("height"); + if(!is_numeric($value)) + return $this->error("Incorrect value for SetHeight [$value]"); + + $this->AddOption("height",$value); + $this->items["embeded"]->SetHeight($value); + } + function SetSrc($value) + { + if(is_null($value)) + return $this->DelOption("src"); + if(!is_string($value)) + return $this->error("Incorrect value for SetSrc[$value]"); + + $this->items["src"]->SetValue($value); + $this->items["embeded"]->SetSrc($value); + } + } +?> diff --git a/frontends/php/include/classes/cflashclock.mod.php b/frontends/php/include/classes/cflashclock.mod.php new file mode 100644 index 00000000..b5e4cdab --- /dev/null +++ b/frontends/php/include/classes/cflashclock.mod.php @@ -0,0 +1,51 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2005 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 +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +?> +<?php + class CFlashClock extends CFlash + { + var $timetype; + var $src; + function CFlashClock($width = 200, $height = 200, $timetype = TIME_TYPE_LOCAL, $url = NULL) + { + if(!is_numeric($width) || $width < 24) $width = 200; + if(!is_numeric($height) || $height< 24) $height = 200; + + $this->src = "images/flash/zbxclock.swf?analog=1&smooth=1"; + if(!is_null($url)) $this->src .= "&url=".urlencode($url); + + parent::CFlash($this->src,$width,$height); + $this->SetTimeType($timetype); + } + function SetTimeType($value) + { + if($value != TIME_TYPE_LOCAL && $value != TIME_TYPE_SERVER) + return $this->error("Incorrect value vor SetTimeType [$value]"); + + $this->timetype = $value; + } + function Show() + { + if($this->timetype == TIME_TYPE_SERVER) + $this->SetSrc($this->src."×tamp=".time()); + parent::Show(); + } + } +?> diff --git a/frontends/php/include/classes/cformtable.inc.php b/frontends/php/include/classes/cformtable.inc.php index e1f4b44b..170dc881 100644 --- a/frontends/php/include/classes/cformtable.inc.php +++ b/frontends/php/include/classes/cformtable.inc.php @@ -39,7 +39,9 @@ $this->SetAlign('center'); $this->SetHelp(); - $this->AddItemToTopRow("<a name=\"form\"></a>"); + $frm_link = new CLink(); + $frm_link->SetName("formtable"); + $this->AddItemToTopRow($frm_link); $this->AddVar("form",get_request("form",1)); $this->AddVar("form_refresh",get_request("form_refresh",0)+1); @@ -51,7 +53,7 @@ { if(is_string($value)) - return parent::SetAction($value."#form"); + return parent::SetAction($value); elseif(is_null($value)) return parent::SetAction($value); else @@ -130,7 +132,7 @@ { parent::ShowTagBody(); - $tbl = new CTable(NULL,'form'); + $tbl = new CTable(NULL,'formtable'); $tbl->SetOddRowClass('form_odd_row'); $tbl->SetEvenRowClass('form_even_row'); $tbl->SetCellSpacing(0); diff --git a/frontends/php/include/classes/chostsinfo.mod.php b/frontends/php/include/classes/chostsinfo.mod.php new file mode 100644 index 00000000..b570f7e2 --- /dev/null +++ b/frontends/php/include/classes/chostsinfo.mod.php @@ -0,0 +1,82 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2005 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 +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +?> +<?php + class CHostsInfo extends CTable + { + var $style; + function CHostsInfo($style = STYLE_HORISONTAL) + { + parent::CTable(NULL,"hosts_info"); + $this->SetOrientation($style); + } + + function SetOrientation($value) + { + if($value != STYLE_HORISONTAL && $value != STYLE_VERTICAL) + return $this->error("Incorrect value for SetOrientation [$value]"); + + $this->style = $value; + } + + function UpdateInfo() + { + $this->CleanItems(); + + $db_host_cnt = DBselect("select count(*) as cnt from hosts where available=".HOST_AVAILABLE_TRUE); + $host_cnt = DBfetch($db_host_cnt); + $avail = $host_cnt["cnt"]; + + $db_host_cnt = DBselect("select count(*) as cnt from hosts where available=".HOST_AVAILABLE_FALSE); + $host_cnt = DBfetch($db_host_cnt); + $notav = $host_cnt["cnt"]; + + $db_host_cnt = DBselect("select count(*) as cnt from hosts where available=".HOST_AVAILABLE_UNKNOWN); + $host_cnt = DBfetch($db_host_cnt); + $uncn = $host_cnt["cnt"]; + + $header = new CCol(S_HOSTS_INFO,"header"); + if($this->style == STYLE_HORISONTAL) + $header->SetColspan(3); + + $this->AddRow($header); + + $avail = new CCol($avail." ".S_AVAILABLE, "avail"); + $notav = new CCol($notav." ".S_NOT_AVAILABLE, "notav"); + $uncn = new CCol($uncn." ".S_UNKNOWN, "uncn"); + + if($this->style == STYLE_HORISONTAL) + { + $this->AddRow(array($avail, $notav, $uncn)); + } + else + { + $this->AddRow($avail); + $this->AddRow($notav); + $this->AddRow($uncn); + } + } + function Show() + { + $this->UpdateInfo(); + parent::Show(); + } + } +?> diff --git a/frontends/php/include/classes/cimg.inc.php b/frontends/php/include/classes/cimg.inc.php index 472a52ab..f7cb42c8 100644 --- a/frontends/php/include/classes/cimg.inc.php +++ b/frontends/php/include/classes/cimg.inc.php @@ -57,6 +57,19 @@ } return $this->AddOption("alt",$value); } + function SetMap($value=NULL) + { + if(is_null($value)) + $this->DeleteOption("usemup"); + + if(!is_string($value)) + { + return $this->error("Incorrect value for SetMap [$value]"); + } + + $value = '#'.ltrim($value,'#'); + return $this->AddOption("usemap",$value); + } function SetWidth($value=NULL){ if(is_null($value)) return $this->DelOption("width"); diff --git a/frontends/php/include/classes/clink.inc.php b/frontends/php/include/classes/clink.inc.php index 118f5063..dd32db42 100644 --- a/frontends/php/include/classes/clink.inc.php +++ b/frontends/php/include/classes/clink.inc.php @@ -22,7 +22,7 @@ class CLink extends CTag { /* public */ - function CLink($item="www.zabbix.com",$url="http://www.zabbix.com",$class=NULL) + function CLink($item=NULL,$url=NULL,$class=NULL) { parent::CTag("a","yes"); @@ -37,7 +37,11 @@ } function SetUrl($value) { - if(!is_string($value)) + if(is_null($value)) + { + return $this->DelOption("href"); + } + elseif(!is_string($value)) { return $this->error("Incorrect value for SetUrl [$value]"); } diff --git a/frontends/php/include/classes/clistbox.inc.php b/frontends/php/include/classes/clistbox.inc.php index a5db8b3d..bec590f7 100644 --- a/frontends/php/include/classes/clistbox.inc.php +++ b/frontends/php/include/classes/clistbox.inc.php @@ -19,26 +19,40 @@ **/ ?> <?php - class CListItem extends CComboItem - { -/* public */ - } - class CListBox extends CComboBox { -/* private */ - var $caption; - /* public */ - function CListBox($name='combobox',$size=5,$action=NULL) + function CListBox($name='combobox',$value=NULL,$size=5,$action=NULL) { parent::CComboBox($name,NULL,$action); - $this->AddOption("size",$size); $this->AddOption("multiple","multiple"); + $this->SetSize($size); + $this->SetValue($value); + } + function SetSize($value) + { + if(is_null($value)) + return $this->DelOption("size"); + if(!is_numeric($value)) + return $this->error("Incorrect value for SetSize [$value]"); + $this->AddOption("size",$value); } - function AddItem($value, $caption, $selected='no', $enabled='yes') + function SetSelectedByValue(&$item) { - return parent::AddItem($value, $caption, $selected, $enabled); + if(!is_null($this->value)) + { + if(is_array($this->value)) + { + $selected = 'no'; + if(in_array($item->GetValue(),$this->value)) $selected = 'yes'; + return $item->SetSelected($selected); + } + else + { + return parent::SetSelectedByValue($item); + } + } + return false; } } ?> diff --git a/frontends/php/include/classes/cmap.inc.php b/frontends/php/include/classes/cmap.inc.php new file mode 100644 index 00000000..662b4936 --- /dev/null +++ b/frontends/php/include/classes/cmap.inc.php @@ -0,0 +1,96 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2005 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 +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +?> +<?php + class CMap extends CTag + { +/* public */ + function CMap($name="") + { + parent::CTag("map","yes"); + $this->SetName($name); + } + function AddRectArea($x1,$y1,$x2,$y2,$href,$alt) + { + return $this->AddArea(array($x1,$y1,$x2,$y2),$href,$alt,'rect'); + } + function AddArea($coords,$href,$alt,$shape) + { + return $this->AddItem(new CArea($coords,$href,$alt,$shape)); + } + function AddItem($value) + { + if(!is_a($value,'carea')) + return $this->error("Incorrect value for AddItem [$value]"); + + return parent::AddItem($value); + } + } + + class CArea extends CTag + { + function CArea($coords,$href,$alt,$shape) + { + parent::CTag("area","no"); + $this->SetCoords($coords); + $this->SetShape($shape); + $this->SetHref($href); + $this->SetAlt($alt); + } + function SetCoords($value) + { + if(!is_array($value)) + return $this->error("Incorrect value for SetCoords [$value]"); + if(count($value)<3) + return $this->error("Incorrect values count for SetCoords [".count($value)."]"); + + $str_val = ""; + foreach($value as $val) + { + if(!is_numeric($val)) + return $this->error("Incorrect value for SetCoords [$val]"); + + $str_val .= $val.","; + } + $this->AddOption("coords",trim($str_val,',')); + } + function SetShape($value) + { + if(!is_string($value)) + return $this->error("Incorrect value for SetShape [$value]"); + + $this->AddOption("shape",$value); + } + function SetHref($value) + { + if(!is_string($value)) + return $this->error("Incorrect value for SetHref [$value]"); + + $this->AddOption("href",$value); + } + function SetAlt($value) + { + if(!is_string($value)) + return $this->error("Incorrect value for SetAlt [$value]"); + + $this->AddOption("alt",$value); + } + } +?> diff --git a/frontends/php/include/classes/cserverinfo.mod.php b/frontends/php/include/classes/cserverinfo.mod.php new file mode 100644 index 00000000..7aae9a3f --- /dev/null +++ b/frontends/php/include/classes/cserverinfo.mod.php @@ -0,0 +1,78 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2005 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 +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +?> +<?php + class CServerInfo extends CTable + { + function CServerInfo() + { + parent::CTable(NULL,"server_info"); + } + + function UpdateInfo() + { + global $USER_DETAILS; + global $_SERVER; + + $this->CleanItems(); + + $status = get_status(); + + if($status["zabbix_server"] == S_YES) + $server = new CSpan(S_RUNNING,"off"); + else + $server = new CSpan(S_NOT_RUNNING,"on"); + + $header = new CCol("ZABBIX ".S_SERVER_INFO,"header"); + $this->AddRow($header); + $this->AddRow("Updated: ".date("r",time())); + $this->AddRow(new CCol(array("Refreshed every: ".$USER_DETAILS["refresh"]." sec ", + "(",new CLink("refresh now","http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"],"action"),")"))); + $this->AddRow(S_NUMBER_OF_USERS_SHORT.": ".$status["users_count"]."(".$status["users_online"].")"); + $this->AddRow(new CCol(array("Logged in as ", new CLink($USER_DETAILS["alias"],"profile.php","action")))); + $this->AddRow(new CCol(array(new CLink("ZABBIX server","http://www.zabbix.com","action")," is ",$server)),"status"); + $this->AddRow(S_VALUES_STORED.": ".$status["history_count"]); + $this->AddRow(S_TRENDS_STORED.": ".$status["trends_count"]); + $this->AddRow(new CCol(array(S_NUMBER_OF_HOSTS_SHORT.": ".$status["hosts_count"]."(", + new CSpan($status["hosts_count_monitored"],"off"),"/", + new CSpan($status["hosts_count_not_monitored"],"on"),"/", + new CSpan($status["hosts_count_template"],"unknown"),"/", + $status["hosts_count_deleted"].")"))); + $this->AddRow(new CCol(array(S_NUMBER_OF_ITEMS_SHORT.": ".$status["items_count"]."(", + new CSpan($status["items_count_monitored"],"off"),"/", + new CSpan($status["items_count_disabled"],"on"),"/", + new CSpan($status["items_count_not_supported"],"unknown"), + ")[".$status["items_count_trapper"]."]"))); + $this->AddRow(new CCol(array(S_NUMBER_OF_TRIGGERS_SHORT.": ". $status["triggers_count"]. + "(".$status["triggers_count_enabled"]."/".$status["triggers_count_disabled"].")"."[", + new CSpan($status["triggers_count_on"],"on"),"/", + new CSpan($status["triggers_count_unknown"],"unknown"),"/", + new CSpan($status["triggers_count_off"],"off"),"]" + ))); + $this->AddRow(S_NUMBER_OF_ALARMS.": ".$status["alarms_count"]); + $this->AddRow(S_NUMBER_OF_ALERTS.": ".$status["alerts_count"]); + } + function Show() + { + $this->UpdateInfo(); + parent::Show(); + } + } +?> diff --git a/frontends/php/include/classes/ctable.inc.php b/frontends/php/include/classes/ctable.inc.php index eccdff4b..e82e5429 100644 --- a/frontends/php/include/classes/ctable.inc.php +++ b/frontends/php/include/classes/ctable.inc.php @@ -41,7 +41,6 @@ if(!is_int($value) && !is_numeric($value)) { return $this->error("Incorrect value for SetRowSpan [$value]"); - return 1; } return $this->AddOption("rowspan",strval($value)); } @@ -217,7 +216,7 @@ if(count($this->items)==0) { if(isset($this->message)) - $this->AddRow(new CCol($this->message,'table_message'),$this->evenRowClass); + $this->AddRow(new CCol($this->message,'message'),$this->evenRowClass); } parent::ShowTagBody(); diff --git a/frontends/php/include/classes/ctableinfo.inc.php b/frontends/php/include/classes/ctableinfo.inc.php index 36f58ee7..5819ddc9 100644 --- a/frontends/php/include/classes/ctableinfo.inc.php +++ b/frontends/php/include/classes/ctableinfo.inc.php @@ -22,20 +22,20 @@ class CTableInfo extends CTable { /* public */ - function CTableInfo($message='...',$class='tborder') + function CTableInfo($message='...',$class='tableinfo') { parent::CTable($message,$class); - $this->SetOddRowClass('table_odd_row'); - $this->SetEvenRowClass('table_even_row'); + $this->SetOddRowClass('odd_row'); + $this->SetEvenRowClass('even_row'); $this->SetCellSpacing(1); $this->SetCellPadding(3); $this->SetHeader(); } - function SetHeader($value=NULL,$class='table_header') + function SetHeader($value=NULL,$class='header') { parent::SetHeader($value,$class); } - function SetFooter($value=NULL,$class='table_header') + function SetFooter($value=NULL,$class='footer') { parent::SetFooter($value,$class); } diff --git a/frontends/php/include/classes/ctag.inc.php b/frontends/php/include/classes/ctag.inc.php index 83d44c7f..8a115bde 100644 --- a/frontends/php/include/classes/ctag.inc.php +++ b/frontends/php/include/classes/ctag.inc.php @@ -125,6 +125,10 @@ $this->options[$name] = htmlspecialchars(strval($value)); return 0; } + function CleanItems() + { + $this->items = array(); + } function AddItem($value) { if(is_null($value)) @@ -180,7 +184,7 @@ print ($this->tag_end); } } - function SetEnable($value='yes') + function SetEnabled($value='yes') { if(is_null($value)) return 0; @@ -192,7 +196,7 @@ ($value == 'no' || $value == 'disabled' || $value=='off') || $value=='0') || (is_int($value) && $value==0)) return $this->AddOption('disabled','disabled'); - return $this->error("Incorrect value for SetEnable [$value]"); + return $this->error("Incorrect value for SetEnabled [$value]"); } function error($value) { diff --git a/frontends/php/include/classes/ctextarea.inc.php b/frontends/php/include/classes/ctextarea.inc.php index 08277878..e9e75530 100644 --- a/frontends/php/include/classes/ctextarea.inc.php +++ b/frontends/php/include/classes/ctextarea.inc.php @@ -83,7 +83,7 @@ } function SetRows($value) { - if(!is_int($value)) + if(!is_numeric($value)) { return $this->error("Incorrect value for SetRows [$value]"); } @@ -92,7 +92,7 @@ } function SetCols($value) { - if(!is_int($value)) + if(!is_numeric($value)) { return $this->error("Incorrect value for SetCols [$value]"); } diff --git a/frontends/php/include/classes/ctriggerinfo.mod.php b/frontends/php/include/classes/ctriggerinfo.mod.php new file mode 100644 index 00000000..7c1f9d76 --- /dev/null +++ b/frontends/php/include/classes/ctriggerinfo.mod.php @@ -0,0 +1,98 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2005 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 +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +?> +<?php + class CTriggersInfo extends CTable + { + var $style; + function CTriggersInfo($style = STYLE_HORISONTAL) + { + parent::CTable(NULL,"triggers_info"); + $this->SetOrientation($style); + } + + function SetOrientation($value) + { + if($value != STYLE_HORISONTAL && $value != STYLE_VERTICAL) + return $this->error("Incorrect value for SetOrientation [$value]"); + + $this->style = $value; + } + + function UpdateInfo() + { + $this->CleanItems(); + + $uncn = $info = $warn = $avg = $high = $dis = 0; + + $db_priority = DBselect("select t.priority,count(*) as cnt from triggers t,hosts h,items i,functions f where t.value=1 and t.status=0 and f.itemid=i.itemid and h.hostid=i.hostid and h.status=".HOST_STATUS_MONITORED." and t.triggerid=f.triggerid and i.status=0 group by priority"); + + while($row=DBfetch($db_priority)) + { + switch($row["priority"]) + { + case 0: $uncn =$row["cnt"]; break; + case 1: $info =$row["cnt"]; break; + case 2: $warn =$row["cnt"]; break; + case 3: $avg =$row["cnt"]; break; + case 4: $high =$row["cnt"]; break; + case 5: $dis =$row["cnt"]; break; + } + } + + $db_ok_cnt = DBselect("select count(*) as cnt from triggers t,hosts h,items i,functions f where t.value=0 and t.status=0 and f.itemid=i.itemid and h.hostid=i.hostid and h.status=".HOST_STATUS_MONITORED." and t.triggerid=f.triggerid and i.status=0"); + $ok_cnt = DBfetch($db_ok_cnt); + + $header = new CCol(S_TRIGGERS_INFO,"header"); + if($this->style == STYLE_HORISONTAL) + $header->SetColspan(7); + $this->AddRow($header); + + $trok = new CCol($ok_cnt["cnt"]." ".S_OK, "trok"); + $uncn = new CCol($uncn." ".S_NOT_CLASSIFIED, "uncn"); + $info = new CCol($info." ".S_INFORMATION, "info"); + $warn = new CCol($warn." ".S_WARNING, "warn"); + $avg = new CCol($avg." ".S_AVERAGE, "avg"); + $high = new CCol($high." ".S_HIGH, "high"); + $dis = new CCol($dis." ".S_DISASTER, "dis"); + + + if($this->style == STYLE_HORISONTAL) + { + $this->AddRow(array($trok, $uncn, $info, $warn, $avg, $high, $dis)); + } + else + { + $this->AddRow($trok); + $this->AddRow($uncn); + $this->AddRow($info); + $this->AddRow($warn); + $this->AddRow($avg); + $this->AddRow($high); + $this->AddRow($dis); + } + } + function Show() + { + $this->UpdateInfo(); + parent::Show(); + } + } +?> diff --git a/frontends/php/include/classes/cvar.inc.php b/frontends/php/include/classes/cvar.inc.php index b089f181..fc823ce8 100644 --- a/frontends/php/include/classes/cvar.inc.php +++ b/frontends/php/include/classes/cvar.inc.php @@ -29,14 +29,6 @@ $this->SetName($name); $this->SetValue($value); } - function SetName($value) - { - if(!is_string($value)) - { - return $this->error("Incorrect value for SetName [$value]"); - } - return $this->AddOption("name",$value); - } function SetValue($value) { return $this->AddOption("value",$value); diff --git a/frontends/php/include/classes/table.inc.php b/frontends/php/include/classes/table.inc.php index c35802fd..b698e831 100644 --- a/frontends/php/include/classes/table.inc.php +++ b/frontends/php/include/classes/table.inc.php @@ -56,7 +56,7 @@ } // Private - function showHeader($class="tborder") + function showHeader($class="tableinfo") { echo "<table class=\"$class\" border=0 width=\"100%\" bgcolor='#AAAAAA' cellspacing=1 cellpadding=3>"; echo "\n"; diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php index 8d82fefe..e1f4ce3a 100644 --- a/frontends/php/include/config.inc.php +++ b/frontends/php/include/config.inc.php @@ -18,7 +18,7 @@ ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. **/ -function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! +function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!! ?> <?php @@ -42,6 +42,7 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! include_once "include/locales.inc.php"; include_once "include/audit.inc.php"; + include_once "include/acknow.inc.php"; include_once "include/autoregistration.inc.php"; include_once "include/escalations.inc.php"; include_once "include/hosts.inc.php"; @@ -80,6 +81,14 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! include_once("include/classes/clistbox.inc.php"); include_once("include/classes/cform.inc.php"); include_once("include/classes/cformtable.inc.php"); + include_once("include/classes/cmap.inc.php"); + include_once("include/classes/cflash.inc.php"); + +// Include Tactical Overview modules + include_once("include/classes/chostsinfo.mod.php"); + include_once("include/classes/ctriggerinfo.mod.php"); + include_once("include/classes/cserverinfo.mod.php"); + include_once("include/classes/cflashclock.mod.php"); function zbx_stripslashes($value){ if(is_array($value)){ @@ -1042,7 +1051,7 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo S_HTML_CHARSET; ?>"> -<meta name="Author" content="Alexei Vladishev"> +<meta name="Author" content="Alexei Vladishev, Eugene Grigorjev"> <link rel="stylesheet" href="css.css"> <?php // if($USER_DETAILS['alias']=='guest') @@ -1052,7 +1061,7 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! if(defined($title)) $title=constant($title); if($dorefresh && $USER_DETAILS["refresh"]) { - echo " <meta http-equiv=\"refresh\" content=\"".$USER_DETAILS["refresh"]."\"/>\n"; + echo " <meta http-equiv=\"refresh\" content=\"".$USER_DETAILS["refresh"]."\">\n"; echo " <title>$title [refreshed every ".$USER_DETAILS["refresh"]." sec]</title>\n"; } else @@ -1069,7 +1078,7 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! $menu=array( "view"=>array( "label"=>S_MONITORING, - "pages"=>array("overview.php","latest.php","tr_status.php","queue.php","events.php","actions.php","maps.php","charts.php","screens.php","srv_status.php","alarms.php","history.php","tr_comments.php","report3.php","profile.php"), + "pages"=>array("overview.php","latest.php","tr_status.php","queue.php","events.php","actions.php","maps.php","charts.php","screens.php","srv_status.php","alarms.php","history.php","tr_comments.php","report3.php","profile.php","acknow.php"), "level2"=>array( array("label"=>S_OVERVIEW,"url"=>"overview.php"), array("label"=>S_LATEST_DATA,"url"=>"latest.php"), @@ -1262,22 +1271,11 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! $result=DBselect($sql); $table = new CTableInfo(); - $table->SetHeader(array(S_TIMESTAMP,$item["description"])); -// table_begin(); -// table_header(array(S_TIMESTAMP,$item["description"])); -// $col=0; + $table->SetHeader(array(S_TIMESTAMP,item_description($item["description"],$item["key_"]))); while($row=DBfetch($result)) { - $table->AddRow(array( - date(S_DATE_FORMAT_YMDHMS,$row["clock"]), - $row["value"]) - ); -// table_row(array( -// date(S_DATE_FORMAT_YMDHMS,$row["clock"]), -// $row["value"], -// ),$col++); + $table->AddRow(array(date(S_DATE_FORMAT_YMDHMS,$row["clock"]), $row["value"])); } -// table_end(); return $table; } @@ -1483,14 +1481,18 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! return $exp; }*/ - function add_image($name,$imagetype,$files) + function add_image($name,$imagetype,$file) { - if(isset($files)) + if(!is_null($file)) { - if($files["image"]["error"]==0) - if($files["image"]["size"]<1024*1024) + if($file["error"] != 0 || $file["size"]==0) + { + error("Incorrect Image"); + return FALSE; + } + if($file["size"]<1024*1024) { - $image=fread(fopen($files["image"]["tmp_name"],"r"),filesize($files["image"]["tmp_name"])); + $image=fread(fopen($file["tmp_name"],"r"),filesize($file["tmp_name"])); $sql="insert into images (name,imagetype,image) values (".zbx_dbstr($name).",$imagetype,".zbx_dbstr($image).")"; return DBexecute($sql); } @@ -1507,14 +1509,18 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! } } - function update_image($imageid,$name,$imagetype,$files) + function update_image($imageid,$name,$imagetype,$file) { - if(isset($files)) + if(!is_null($file)) { - if($files["image"]["error"]==0) - if($files["image"]["size"]<1024*1024) + if($file["error"] != 0 || $file["size"]==0) + { + error("Incorrect Image"); + return FALSE; + } + if($file["size"]<1024*1024) { - $image=fread(fopen($files["image"]["tmp_name"],"r"),filesize($files["image"]["tmp_name"])); + $image=fread(fopen($file["tmp_name"],"r"),filesize($file["tmp_name"])); $sql="update images set name=".zbx_dbstr($name).",imagetype=".zbx_dbstr($imagetype).",image=".zbx_dbstr($image)." where imageid=$imageid"; return DBexecute($sql); } @@ -1526,8 +1532,8 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! } else { - error("Select image to download"); - return FALSE; + $sql="update images set name=".zbx_dbstr($name).",imagetype=".zbx_dbstr($imagetype)." where imageid=$imageid"; + return DBexecute($sql); } } @@ -1614,6 +1620,12 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! return DBexecute($sql); } + function get_alarm_by_alarmid($alarmid) + { + $db_alarms = DBselect("select * from alarms where alarmid=$alarmid"); + return DBfetch($db_alarms); + } + # Reset nextcheck for related items function reset_items_nextcheck($triggerid) @@ -2328,95 +2340,114 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! echo "</html>\n"; } - function get_stats() - { - global $DB_TYPE; - if ($DB_TYPE == "MYSQL") + function get_status() { - $result=DBselect("show table status like 'history'"); - $row=DBfetch($result); - $stat["history_count"]=$row["Rows"]; - - $result=DBselect("show table status like 'trends'"); - $row=DBfetch($result); - $stat["trends_count"]=$row["Rows"]; - } - else - { - $result=DBselect("select count(itemid) as cnt from history"); - $row=DBfetch($result); - $stat["history_count"]=$row["cnt"]; - - $result=DBselect("select count(itemid) as cnt from trends"); - $row=DBfetch($result); - $stat["trends_count"]=$row["cnt"]; - } - - $result=DBselect("select count(alarmid) as cnt from alarms"); - $row=DBfetch($result); - $stat["alarms_count"]=$row["cnt"]; - - $result=DBselect("select count(alertid) as cnt from alerts"); - $row=DBfetch($result); - $stat["alerts_count"]=$row["cnt"]; - - $result=DBselect("select count(triggerid) as cnt from triggers"); - $row=DBfetch($result); - $stat["triggers_count"]=$row["cnt"]; - - $result=DBselect("select count(triggerid) as cnt from triggers where status=0"); - $row=DBfetch($result); - $stat["triggers_count_enabled"]=$row["cnt"]; - - $result=DBselect("select count(triggerid) as cnt from triggers where status=1"); - $row=DBfetch($result); - $stat["triggers_count_disabled"]=$row["cnt"]; - - $result=DBselect("select count(itemid) as cnt from items"); - $row=DBfetch($result); - $stat["items_count"]=$row["cnt"]; - - $result=DBselect("select count(itemid) as cnt from items where status=0"); - $row=DBfetch($result); - $stat["items_count_active"]=$row["cnt"]; - - $result=DBselect("select count(itemid) as cnt from items where status=1"); - $row=DBfetch($result); - $stat["items_count_not_active"]=$row["cnt"]; - - $result=DBselect("select count(itemid) as cnt from items where status=3"); - $row=DBfetch($result); - $stat["items_count_not_supported"]=$row["cnt"]; - - $result=DBselect("select count(itemid) as cnt from items where type=2"); - $row=DBfetch($result); - $stat["items_count_trapper"]=$row["cnt"]; - - $result=DBselect("select count(hostid) as cnt from hosts"); - $row=DBfetch($result); - $stat["hosts_count"]=$row["cnt"]; - - $result=DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_MONITORED); - $row=DBfetch($result); - $stat["hosts_count_monitored"]=$row["cnt"]; - - $result=DBselect("select count(hostid) as cnt from hosts where status!=".HOST_STATUS_MONITORED); - $row=DBfetch($result); - $stat["hosts_count_not_monitored"]=$row["cnt"]; + global $DB_TYPE; + $status = array(); +// server + if( (exec("ps -ef|grep zabbix_server|grep -v grep|wc -l")>0) || (exec("ps -ax|grep zabbix_server|grep -v grep|wc -l")>0) ) + { + $status["zabbix_server"] = S_YES; + } + else + { + $status["zabbix_server"] = S_NO; + } - $result=DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_TEMPLATE); - $row=DBfetch($result); - $stat["hosts_count_template"]=$row["cnt"]; +// history & trends + if ($DB_TYPE == "MYSQL") + { + $row=DBfetch(DBselect("show table status like 'history'")); + $status["history_count"] = $row["Rows"]; + $row=DBfetch(DBselect("show table status like 'history_log'")); + $status["history_count"] += $row["Rows"]; + $row=DBfetch(DBselect("show table status like 'history_str'")); + $status["history_count"] += $row["Rows"]; + $row=DBfetch(DBselect("show table status like 'history_uint'")); + $status["history_count"] += $row["Rows"]; - $result=DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_DELETED); - $row=DBfetch($result); - $stat["hosts_count_deleted"]=$row["cnt"]; + $row=DBfetch(DBselect("show table status like 'trends'")); + $status["trends_count"] = $row["Rows"]; + } + else + { + $row=DBfetch(DBselect("select count(itemid) as cnt from history")); + $status["history_count"] = $row["cnt"]; + $row=DBfetch(DBselect("select count(itemid) as cnt from history_log")); + $status["history_count"] += $row["cnt"]; + $row=DBfetch(DBselect("select count(itemid) as cnt from history_str")); + $status["history_count"] += $row["cnt"]; + $row=DBfetch(DBselect("select count(itemid) as cnt from history_uint")); + $status["history_count"] += $row["cnt"]; - $result=DBselect("select count(userid) as cnt from users"); - $row=DBfetch($result); - $stat["users_count"]=$row["cnt"]; + $result=DBselect("select count(itemid) as cnt from trends"); + $row=DBfetch($result); + $status["trends_count"]=$row["cnt"]; + } +// alarms + $row=DBfetch(DBselect("select count(alarmid) as cnt from alarms")); + $status["alarms_count"]=$row["cnt"]; +// alerts + $row=DBfetch(DBselect("select count(alertid) as cnt from alerts")); + $status["alerts_count"]=$row["cnt"]; +// triggers + $sql = "select count(t.triggerid) as cnt from triggers t, functions f, items i, hosts h". + " where t.triggerid=f.triggerid and f.itemid=i.itemid and i.status=0 and i.hostid=h.hostid and h.status=".HOST_STATUS_MONITORED; + $row=DBfetch(DBselect($sql)); + $status["triggers_count"]=$row["cnt"]; + + $row=DBfetch(DBselect($sql." and t.status=0")); + $status["triggers_count_enabled"]=$row["cnt"]; + + $row=DBfetch(DBselect($sql." and t.status=1")); + $status["triggers_count_disabled"]=$row["cnt"]; + + $row=DBfetch(DBselect($sql." and t.status=0 and t.value=0")); + $status["triggers_count_off"]=$row["cnt"]; + + $row=DBfetch(DBselect($sql." and t.status=0 and t.value=1")); + $status["triggers_count_on"]=$row["cnt"]; + + $row=DBfetch(DBselect($sql." and t.status=0 and t.value=2")); + $status["triggers_count_unknown"]=$row["cnt"]; +// items + $sql = "select count(i.itemid) as cnt from items i, hosts h where i.hostid=h.hostid and h.status=".HOST_STATUS_MONITORED; + $row=DBfetch(DBselect($sql)); + $status["items_count"]=$row["cnt"]; + + $row=DBfetch(DBselect($sql." and i.status=0")); + $status["items_count_monitored"]=$row["cnt"]; + + $row=DBfetch(DBselect($sql." and i.status=1")); + $status["items_count_disabled"]=$row["cnt"]; + + $row=DBfetch(DBselect($sql." and i.status=3")); + $status["items_count_not_supported"]=$row["cnt"]; + + $row=DBfetch(DBselect($sql." and i.type=2")); + $status["items_count_trapper"]=$row["cnt"]; +// hosts + $row=DBfetch(DBselect("select count(hostid) as cnt from hosts")); + $status["hosts_count"]=$row["cnt"]; + + $row=DBfetch(DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_MONITORED)); + $status["hosts_count_monitored"]=$row["cnt"]; + + $row=DBfetch(DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_NOT_MONITORED)); + $status["hosts_count_not_monitored"]=$row["cnt"]; + + $row=DBfetch(DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_TEMPLATE)); + $status["hosts_count_template"]=$row["cnt"]; + + $row=DBfetch(DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_DELETED)); + $status["hosts_count_deleted"]=$row["cnt"]; +// users + $row=DBfetch(DBselect("select count(userid) as cnt from users")); + $status["users_count"]=$row["cnt"]; + + $status["users_online"]=DBnum_rows(DBselect("select distinct s.userid from sessions s, users u where u.userid=s.userid and (s.lastaccess+u.autologout)>".time())); - return $stat; + return $status; } // If $period_start=$period_end=0, then take maximum period @@ -2707,6 +2738,7 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! { echo " <script language=\"JavaScript\" type=\"text/javascript\"> +<!-- function Confirm(msg) { if(confirm(msg,'title')) @@ -2736,16 +2768,68 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! frmForm.elements[i].checked = value; } } +//--> </script> "; } + function insert_javascript_clock($form, $field) + { + echo " +<script language=\"JavaScript\" type=\"text/javascript\"> +<!-- + function show_clock() + { + var thetime=new Date(); + + var nhours=thetime.getHours(); + var nmins=thetime.getMinutes(); + var nsecn=thetime.getSeconds(); + var AorP=\" \"; + + var year = thetime.getFullYear(); + var nmonth = thetime.getMonth()+1; + var ndate = thetime.getDate(); + + if (nhours>=12) AorP=\"PM\"; + else AorP=\"AM\"; + + if (nhours>=13) nhours-=12; + if (nhours==0) nhours=12; + + if (nsecn<10) nsecn=\"0\"+nsecn; + if (nmins<10) nmins=\"0\"+nmins; + if (nmonth<10) nmonth=\"0\"+nmonth; + if (ndate<10) ndate=\"0\"+ndate; + + document.forms['$form'].elements['$field'].value=ndate+\"-\"+nmonth+\"-\"+year+\" \"+nhours+\":\"+nmins+\":\"+nsecn+\" \"+AorP; + + setTimeout('show_clock()',1000); + } +//--> +</script> +"; + } + + function start_javascript_clock() + { + echo " +<script language=\"JavaScript\" type=\"text/javascript\"> +<!-- + show_clock(); +//--> +</script> +"; + } function SetFocus($frm_name, $fld_name) { - echo - "<script language=\"JavaScript\" type=\"text/javascript\">\n". - " document.forms['$frm_name'].elements['$fld_name'].focus();\n". - "</script>"; + echo " +<script language=\"JavaScript\" type=\"text/javascript\"> +<!-- + document.forms['$frm_name'].elements['$fld_name'].focus(); +//--> +</script> +"; } /* Use ImageSetStyle+ImageLIne instead of bugged ImageDashedLine */ @@ -2983,8 +3067,12 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! function Alert($msg) { - echo "<script language=\"JavaScript\" type=\"text/javascript\">"; - echo "alert('$msg');"; - echo "</script>"; + echo " +<script language=\"JavaScript\" type=\"text/javascript\"> +<!-- + alert('$msg'); +//--> +</script> +"; } ?> diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php index 058a2a73..b32e5338 100644 --- a/frontends/php/include/db.inc.php +++ b/frontends/php/include/db.inc.php @@ -25,8 +25,8 @@ // $DB_TYPE ="POSTGRESQL"; $DB_TYPE ="MYSQL"; $DB_SERVER ="localhost"; - $DB_DATABASE ="zabbix"; -// $DB_DATABASE ="osmiy"; +// $DB_DATABASE ="zabbix"; + $DB_DATABASE ="osmiy"; $DB_USER ="root"; $DB_PASSWORD =""; // END OF DATABASE CONFIGURATION diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php index 69b3ba80..816d6b7d 100644 --- a/frontends/php/include/defines.inc.php +++ b/frontends/php/include/defines.inc.php @@ -95,9 +95,9 @@ define("GRAPH_YAXIS_SIDE_LEFT",0); define("GRAPH_YAXIS_SIDE_RIGHT",1); - define("MAP_LABEL_TYPE_HOSTLABEL",0); + define("MAP_LABEL_TYPE_LABEL",0); define("MAP_LABEL_TYPE_IP",1); - define("MAP_LABEL_TYPE_HOSTNAME",2); + define("MAP_LABEL_TYPE_NAME",2); define("MAP_LABEL_TYPE_STATUS",3); define("MAP_LABEL_TYPE_NOTHING",4); @@ -106,6 +106,10 @@ define("MAP_LABEL_LOC_RIGHT", 2); define("MAP_LABEL_LOC_TOP", 3); + define("SYSMAP_ELEMENT_TYPE_HOST", 0); + define("SYSMAP_ELEMENT_TYPE_MAP", 1); + define("SYSMAP_ELEMENT_TYPE_IMAGE", 2); + define("ITEM_TYPE_ZABBIX",0); define("ITEM_TYPE_SNMPV1",1); define("ITEM_TYPE_TRAPPER",2); @@ -155,6 +159,38 @@ define("LOGFILE_SEVERITY_AUDIT_SUCCESS",6); define("LOGFILE_SEVERITY_AUDIT_FAILURE",7); + define("SCREEN_RESOURCE_GRAPH", 0); + define("SCREEN_RESOURCE_SIMPLE_GRAPH", 1); + define("SCREEN_RESOURCE_MAP", 2); + define("SCREEN_RESOURCE_PLAIN_TEXT", 3); + define("SCREEN_RESOURCE_HOSTS_INFO", 4); + define("SCREEN_RESOURCE_TRIGGERS_INFO", 5); + define("SCREEN_RESOURCE_SERVER_INFO", 6); + define("SCREEN_RESOURCE_CLOCK", 7); + define("SCREEN_RESOURCE_SCREEN", 8); + define("SCREEN_RESOURCE_TRIGGERS_OVERVIEW", 9); + define("SCREEN_RESOURCE_DATA_OVERVIEW", 10); + define("SCREEN_RESOURCE_URL", 11); + +/* alignes */ + define("HALIGN_DEFAULT",0); + define("HALIGN_CENTER", 0); + define("HALIGN_LEFT", 1); + define("HALIGN_RIGHT", 2); + + define("VALIGN_DEFAULT",0); + define("VALIGN_MIDDLE", 0); + define("VALIGN_TOP", 1); + define("VALIGN_BOTTOM", 2); + +/* info module style */ + define("STYLE_HORISONTAL", 0); + define("STYLE_VERTICAL", 1); + +/* time module tipe */ + define("TIME_TYPE_LOCAL", 0); + define("TIME_TYPE_SERVER", 1); + /* Support for PHP5. PHP5 does not have $HTTP_..._VARS */ if (!function_exists('version_compare')) { diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php index 4e1d432c..e73db8d7 100644 --- a/frontends/php/include/forms.inc.php +++ b/frontends/php/include/forms.inc.php @@ -19,9 +19,40 @@ **/ ?> <?php +// TODO !!! Correcr the help links !!! TODO + include_once "include/defines.inc.php"; include_once "include/db.inc.php"; -// include_once "include/local_en.inc.php"; + + function insert_new_message_form() + { + global $USER_DETAILS; + global $_REQUEST; + + $db_acks = get_acknowledges_by_alarmid($_REQUEST["alarmid"]); + if(DBnum_rows($db_acks)==0) + { + $title = S_ACKNOWLEDGE_ALARM_BY; + $btn_txt = S_ACKNOWLEDGE; + } + else + { + $title = S_ADD_COMMENT_BY; + $btn_txt = S_SAVE; + } + + $frmMsg= new CFormTable($title." \"".$USER_DETAILS["alias"]."\""); + $frmMsg->SetHelp("manual.php"); + $frmMsg->AddVar("alarmid",get_request("alarmid",0)); + + $frmMsg->AddRow(S_MESSAGE, new CTextArea("message","",80,6)); + + $frmMsg->AddItemToBottomRow(new CButton("save",$btn_txt)); + + $frmMsg->Show(); + + SetFocus($frmMsg->GetName(),"message"); + } # Insert form for User function insert_user_form($userid,$profile=0) @@ -217,7 +248,7 @@ { global $_REQUEST; - $frmItem = new CFormTable(S_ITEM,"items.php#form"); + $frmItem = new CFormTable(S_ITEM,"items.php"); $frmItem->SetHelp("web.items.item.php"); if(isset($_REQUEST["groupid"])) @@ -1485,7 +1516,6 @@ { $frmImages = new CFormTable(S_IMAGE,"config.php","post","multipart/form-data"); $frmImages->SetHelp("web.config.images.php"); - $frmImages->AddVar("MAX_FILE_SIZE",(1024*1024)); $frmImages->AddVar("config",get_request("config",3)); if(isset($_REQUEST["imageid"])) @@ -1508,6 +1538,7 @@ { $name = get_request("name",""); $imagetype = get_request("imagetype",1); + $imageid = get_request("imageid",0); } $frmImages->AddRow(S_NAME,new CTextBox("name",$name,64)); @@ -1516,8 +1547,16 @@ $cmbImg->AddItem(1,S_ICON); $cmbImg->AddItem(2,S_BACKGROUND); $frmImages->AddRow(S_TYPE,$cmbImg); + $frmImages->AddRow(S_UPLOAD,new CFile("image")); + if($imageid > 0) + { + $frmImages->AddRow(S_IMAGE,new CLink( + new CImg("image.php?width=640&height=480&imageid=".$imageid,"no image",NULL), + "image.php?imageid=".$row["imageid"])); + } + $frmImages->AddItemToBottomRow(new CButton("save",S_SAVE)); if(isset($_REQUEST["imageid"])) { @@ -1581,7 +1620,7 @@ { global $_REQUEST; - $form = new CFormTable(S_SCREEN_CELL_CONFIGURATION,"screenedit.php"); + $form = new CFormTable(S_SCREEN_CELL_CONFIGURATION,"screenedit.php#form"); $form->SetHelp("web.screenedit.cell.php"); if(isset($_REQUEST["screenitemid"])) @@ -1606,7 +1645,9 @@ $colspan = $irow["colspan"]; $rowspan = $irow["rowspan"]; $elements = $irow["elements"]; - + $valign = $irow["valign"]; + $halign = $irow["halign"]; + $style = $irow["style"]; } else { @@ -1617,25 +1658,35 @@ $colspan = get_request("colspan", 0); $rowspan = get_request("rowspan", 0); $elements = get_request("elements", 25); + $valign = get_request("valign", VALIGN_DEFAULT); + $halign = get_request("halign", HALIGN_DEFAULT); + $style = get_request("style", 0); } $form->AddVar("screenid",$_REQUEST["screenid"]); $cmbRes = new CCombobox("resource",$resource,"submit()"); - $cmbRes->AddItem(0,S_GRAPH); - $cmbRes->AddItem(1,S_SIMPLE_GRAPH); - $cmbRes->AddItem(2,S_MAP); - $cmbRes->AddItem(3,S_PLAIN_TEXT); + $cmbRes->AddItem(SCREEN_RESOURCE_GRAPH, S_GRAPH); + $cmbRes->AddItem(SCREEN_RESOURCE_SIMPLE_GRAPH, S_SIMPLE_GRAPH); + $cmbRes->AddItem(SCREEN_RESOURCE_PLAIN_TEXT, S_PLAIN_TEXT); + $cmbRes->AddItem(SCREEN_RESOURCE_MAP, S_MAP); + $cmbRes->AddItem(SCREEN_RESOURCE_SCREEN, S_SCREEN); + $cmbRes->AddItem(SCREEN_RESOURCE_SERVER_INFO, S_SERVER_INFO); + $cmbRes->AddItem(SCREEN_RESOURCE_HOSTS_INFO, S_HOSTS_INFO); + $cmbRes->AddItem(SCREEN_RESOURCE_TRIGGERS_INFO, S_TRIGGERS_INFO); + $cmbRes->AddItem(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, S_TRIGGERS_OVERVIEW); + $cmbRes->AddItem(SCREEN_RESOURCE_DATA_OVERVIEW, S_DATA_OVERVIEW); + $cmbRes->AddItem(SCREEN_RESOURCE_CLOCK, S_CLOCK); +// $cmbRes->AddItem(SCREEN_RESOURCE_URL, S_URL); $form->AddRow(S_RESOURCE,$cmbRes); - if($resource == 0) + if($resource == SCREEN_RESOURCE_GRAPH) { // User-defined graph $result=DBselect("select graphid,name from graphs order by name"); $cmbGraphs = new CComboBox("resourceid",$resourceid); - $cmbGraphs->AddItem(0,"(none)"); while($row=DBfetch($result)) { $db_hosts = get_hosts_by_graphid($row["graphid"]); @@ -1653,7 +1704,7 @@ $form->AddRow(S_GRAPH_NAME,$cmbGraphs); } - elseif($resource == 1) + elseif($resource == SCREEN_RESOURCE_SIMPLE_GRAPH) { // Simple graph $result=DBselect("select h.host,i.description,i.itemid,i.key_". @@ -1663,7 +1714,6 @@ $cmbItems = new CCombobox("resourceid",$resourceid); - $cmbItems->AddItem(0,"(none)"); while($row=DBfetch($result)) { $description_=item_description($row["description"],$row["key_"]); @@ -1672,13 +1722,12 @@ } $form->AddRow(S_PARAMETER,$cmbItems); } - else if($resource == 2) + elseif($resource == SCREEN_RESOURCE_MAP) { // Map $result=DBselect("select sysmapid,name from sysmaps order by name"); $cmbMaps = new CComboBox("resourceid",$resourceid); - $cmbMaps->AddItem(0,"(none)"); while($row=DBfetch($result)) { $cmbMaps->AddItem($row["sysmapid"],$row["name"]); @@ -1686,7 +1735,7 @@ $form->AddRow(S_MAP,$cmbMaps); } - else if($resource == 3) + elseif($resource == SCREEN_RESOURCE_PLAIN_TEXT) { // Plain text $result=DBselect("select h.host,i.description,i.itemid,i.key_". @@ -1695,7 +1744,6 @@ " order by h.host,i.description"); $cmbHosts = new CComboBox("resourceid",$resourceid); - $cmbHosts->AddItem(0,"(none)"); while($row=DBfetch($result)) { $description_=item_description($row["description"],$row["key_"]); @@ -1706,22 +1754,103 @@ $form->AddRow(S_PARAMETER,$cmbHosts); $form->AddRow(S_SHOW_LINES, new CTextBox("elements",$elements,2)); } + elseif(in_array($resource,array(SCREEN_RESOURCE_TRIGGERS_OVERVIEW,SCREEN_RESOURCE_DATA_OVERVIEW))) + { + // Overiews + $cmbGroup = new CComboBox("resourceid",$resourceid); + + $cmbGroup->AddItem(0,S_ALL_SMALL); + $result=DBselect("select groupid,name from groups order by name"); + while($row=DBfetch($result)) + { + $cmbGroup = new CComboBox("resourceid",$resourceid); + + $cmbGroup->AddItem(0,S_ALL_SMALL); + $result=DBselect("select groupid,name from groups order by name"); + while($row=DBfetch($result)) + { + $result2=DBselect("select h.hostid,h.host from hosts h,items i,hosts_groups hg where". + " h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and hg.groupid=".$row["groupid"]. + " and hg.hostid=h.hostid group by h.hostid,h.host order by h.host"); + while($row2=DBfetch($result2)) + { + if(!check_right("Host","R",$row2["hostid"])) continue; + $cmbGroup->AddItem($row["groupid"],$row["name"]); + break; + } + } + } + $form->AddRow(S_GROUP,$cmbGroup); + + } + elseif($resource == SCREEN_RESOURCE_SCREEN) + { + $cmbScreens = new CComboBox("resourceid",$resourceid); + $result=DBselect("select screenid,name from screens"); + while($row=DBfetch($result)) + { + if(check_screen_recursion($_REQUEST["screenid"],$row["screenid"])) + continue; + $cmbScreens->AddItem($row["screenid"],$row["name"]); + + } + + $form->AddRow(S_SCREEN,$cmbScreens); + } + else // SCREEN_RESOURCE_HOSTS_INFO, SCREEN_RESOURCE_TRIGGERS_INFO, SCREEN_RESOURCE_CLOCK + { + $form->AddVar("resourceid",0); + } + + if(in_array($resource,array(SCREEN_RESOURCE_HOSTS_INFO,SCREEN_RESOURCE_TRIGGERS_INFO))) + { + $cmbStyle = new CComboBox("style", $style); + $cmbStyle->AddItem(STYLE_HORISONTAL, S_HORISONTAL); + $cmbStyle->AddItem(STYLE_VERTICAL, S_VERTICAL); + $form->AddRow(S_STYLE, $cmbStyle); + } + elseif($resource == SCREEN_RESOURCE_CLOCK) + { + $cmbStyle = new CComboBox("style", $style); + $cmbStyle->AddItem(TIME_TYPE_LOCAL, S_LOCAL_TIME); + $cmbStyle->AddItem(TIME_TYPE_SERVER, S_SERVER_TIME); + $form->AddRow(S_TIME_TYPE, $cmbStyle); + } else { - $form->AddVar("resouceid",$resourceid); + $form->AddVar("style", 0); } - if($resource!=3) + if(in_array($resource,array(SCREEN_RESOURCE_GRAPH,SCREEN_RESOURCE_SIMPLE_GRAPH,SCREEN_RESOURCE_CLOCK))) { $form->AddRow(S_WIDTH, new CTextBox("width",$width,5)); $form->AddRow(S_HEIGHT, new CTextBox("height",$height,5)); } else { - $form->AddVar("width", $width); - $form->AddVar("height", $height); + $form->AddVar("width", 0); + $form->AddVar("height", 0); } + if(in_array($resource,array(SCREEN_RESOURCE_GRAPH,SCREEN_RESOURCE_SIMPLE_GRAPH,SCREEN_RESOURCE_MAP,SCREEN_RESOURCE_CLOCK))) + { + $cmbHalign = new CComboBox("halign",$halign); + $cmbHalign->AddItem(HALIGN_CENTER, S_CENTER); + $cmbHalign->AddItem(HALIGN_LEFT, S_LEFT); + $cmbHalign->AddItem(HALIGN_RIGHT, S_RIGHT); + $form->AddRow(S_HORISONTAL_ALIGN, $cmbHalign); + } + else + { + $form->AddVar("halign", 0); + } + + $cmbValign = new CComboBox("valign",$valign); + $cmbValign->AddItem(VALIGN_MIDDLE, S_MIDDLE); + $cmbValign->AddItem(VALIGN_TOP, S_TOP); + $cmbValign->AddItem(VALIGN_BOTTOM, S_BOTTOM); + $form->AddRow(S_VERTICAL_ALIGN, $cmbValign); + $form->AddRow(S_COLUMN_SPAN, new CTextBox("colspan",$colspan,2)); $form->AddRow(S_ROW_SPAN, new CTextBox("rowspan",$rowspan,2)); @@ -2107,13 +2236,12 @@ $frmHostG->AddRow(S_GROUP_NAME,new CTextBox("gname",$name,30)); - $cmbHosts = new CListBox("hosts[]",10); + $cmbHosts = new CListBox("hosts[]",$hosts,10); $db_hosts=DBselect("select distinct hostid,host from hosts". " where status<>".HOST_STATUS_DELETED." order by host"); while($db_host=DBfetch($db_hosts)) { - $cmbHosts->AddItem($db_host["hostid"],$db_host["host"], - in_array($db_host["hostid"],$hosts) ? 'yes' : 'no'); + $cmbHosts->AddItem($db_host["hostid"],$db_host["host"]); } $frmHostG->AddRow(S_HOSTS,$cmbHosts); @@ -2225,9 +2353,9 @@ $frmMap->AddRow(S_BACKGROUND_IMAGE,$cmbImg); $cmbLabel = new CComboBox("label_type",$label_type); - $cmbLabel->AddItem(0,S_HOST_LABEL); + $cmbLabel->AddItem(0,S_LABEL); $cmbLabel->AddItem(1,S_IP_ADDRESS); - $cmbLabel->AddItem(2,S_HOST_NAME); + $cmbLabel->AddItem(2,S_ELEMENT_NAME); $cmbLabel->AddItem(3,S_STATUS_ONLY); $cmbLabel->AddItem(4,S_NOTHING); $frmMap->AddRow(S_ICON_LABEL_TYPE,$cmbLabel); @@ -2254,86 +2382,149 @@ } - function insert_map_host_form() + function insert_map_element_form() { - if(isset($_REQUEST["shostid"])) + $frmEl = new CFormTable("New map element","sysmap.php"); + $frmEl->SetHelp("web.sysmap.host.php"); + $frmEl->AddVar("sysmapid",$_REQUEST["sysmapid"]); + + if(isset($_REQUEST["selementid"])) { - $shost=get_sysmaps_hosts_by_shostid($_REQUEST["shostid"]); + $frmEl->AddVar("selementid",$_REQUEST["selementid"]); + + $element = get_sysmaps_element_by_selementid($_REQUEST["selementid"]); + $frmEl->SetTitle("Map element \"".$element["label"]."\""); + } - $hostid = $shost["hostid"]; - $label = $shost["label"]; - $x = $shost["x"]; - $y = $shost["y"]; - $icon = $shost["icon"]; - $url = $shost["url"]; - $icon_on= $shost["icon_on"]; + if(isset($_REQUEST["selementid"]) && !isset($_REQUEST["form_refresh"])) + { + $elementid = $element["elementid"]; + $elementtype = $element["elementtype"]; + $label = $element["label"]; + $x = $element["x"]; + $y = $element["y"]; + $icon = $element["icon"]; + $url = $element["url"]; + $icon_on = $element["icon_on"]; + $label_location = $element["label_location"]; + if(is_null($label_location)) $label_location = -1; } else { - $hostid = 0; - - $label = ""; - $x = 0; - $y = 0; - $icon = ""; - $url = ""; - $icon_on= ""; + $elementid = get_request("elementid", 0); + $elementtype = get_request("elementtype", SYSMAP_ELEMENT_TYPE_HOST); + $label = get_request("label", ""); + $x = get_request("x", 0); + $y = get_request("y", 0); + $icon = get_request("icon", ""); + $url = get_request("url", ""); + $icon_on = get_request("icon_on", ""); + $label_location = get_request("label_location", "-1"); } - if($hostid) + + $cmbType = new CComboBox("elementtype",$elementtype,"submit()"); + + $db_hosts = DBselect("select hostid from hosts"); + if(DBnum_rows($db_hosts)>0) + $cmbType->AddItem(SYSMAP_ELEMENT_TYPE_HOST, S_HOST); + + $db_maps = DBselect("select sysmapid from sysmaps where sysmapid!=".$_REQUEST["sysmapid"]); + if(DBnum_rows($db_maps)>0) + $cmbType->AddItem(SYSMAP_ELEMENT_TYPE_MAP, S_MAP); + + $cmbType->AddItem(SYSMAP_ELEMENT_TYPE_IMAGE, S_IMAGE); + + $frmEl->AddRow(S_TYPE,$cmbType); + + $frmEl->AddRow("Label", new CTextBox("label", $label, 32)); + + $cmbLocation = new CComboBox("label_location",$label_location); + $cmbLocation->AddItem(-1,'-'); + $cmbLocation->AddItem(0,S_BOTTOM); + $cmbLocation->AddItem(1,S_LEFT); + $cmbLocation->AddItem(2,S_RIGHT); + $cmbLocation->AddItem(3,S_TOP); + $frmEl->AddRow(S_LABEL_LOCATION,$cmbLocation); + + if($elementtype==SYSMAP_ELEMENT_TYPE_HOST) { - $host_info = get_host_by_hostid($hostid); - $host = $host_info["host"]; - } else { $host = ""; - } + $host_info = 0; + + $db_hosts = DBselect("select host from hosts where hostid=$elementid"); + $host_info = DBfetch($db_hosts); + if($host_info) + $host = $host_info["host"]; + else + $elementid=0; + + if($elementid==0) + { + $db_hosts = DBselect("select hostid,host from hosts limit 1"); + $db_host = DBfetch($db_hosts); + $host = $db_host["host"]; + $elementid = $db_host["hostid"]; + } - $frmHost = new CFormTable("New host to display","sysmap.php"); - $frmHost->SetHelp("web.sysmap.host.php"); - if(isset($_REQUEST["shostid"])) + $frmEl->AddVar("elementid",$elementid); + $frmEl->AddRow(S_HOST, array( + new CTextBox("host",$host,32,NULL,'yes'), + new CButton("btn1","Select","return PopUp('popup.php?form=".$frmEl->GetName(). + "&field1=elementid&field2=host','new_win',". + "'width=450,height=450,resizable=1,scrollbars=1');","T") + )); + } + elseif($elementtype==SYSMAP_ELEMENT_TYPE_MAP) { - $frmHost->AddVar("shostid",$_REQUEST["shostid"]); + $cmbMaps = new CComboBox("elementid",$elementid); + $db_maps = DBselect("select sysmapid,name from sysmaps"); + while($db_map = DBfetch($db_maps)) + { + $cmbMaps->AddItem($db_map["sysmapid"],$db_map["name"]); + } + $frmEl->AddRow(S_MAP, $cmbMaps); } - if(isset($_REQUEST["sysmapid"])) + elseif($elementtype==SYSMAP_ELEMENT_TYPE_IMAGE) { - $frmHost->AddVar("sysmapid",$_REQUEST["sysmapid"]); + $cmbTriggers= new CComboBox("elementid",$elementid); + $cmbTriggers->AddItem(0,"-"); + $db_triggers = DBselect("select triggerid from triggers"); + while($db_trigger = DBfetch($db_triggers)) + { + $cmbTriggers->AddItem( + $db_trigger["triggerid"], + expand_trigger_description($db_trigger["triggerid"])); + } + $frmEl->AddRow(S_TRIGGER, $cmbTriggers); } - $frmHost->AddVar("hostid",$hostid); - $frmHost->AddRow("Host",array( - new CTextBox("host",$host,32,NULL,'yes'), - new CButton("btn1","Select","return PopUp('popup.php?form=".$frmHost->GetName(). - "&field1=hostid&field2=host','new_win',". - "'width=450,height=450,resizable=1,scrollbars=1');","T") - )); - $cmbIcon = new CComboBox("icon",$icon); $result=DBselect("select name from images where imagetype=1 order by name"); while($row=DBfetch($result)) $cmbIcon->AddItem($row["name"],$row["name"]); - $frmHost->AddRow("Icon (OFF)",$cmbIcon); + $frmEl->AddRow("Icon (OFF)",$cmbIcon); $cmbIcon = new CComboBox("icon_on",$icon_on); $result=DBselect("select name from images where imagetype=1 order by name"); while($row=DBfetch($result)) $cmbIcon->AddItem($row["name"],$row["name"]); - $frmHost->AddRow("Icon (ON)",$cmbIcon); - - $frmHost->AddRow("Label", new CTextBox("label", $label, 32)); + $frmEl->AddRow("Icon (ON)",$cmbIcon); - $frmHost->AddRow("Coordinate X", new CTextBox("x", $x, 5)); - $frmHost->AddRow("Coordinate Y", new CTextBox("y", $y, 5)); - $frmHost->AddRow("URL", new CTextBox("url", $url, 64)); + $frmEl->AddRow("Coordinate X", new CTextBox("x", $x, 5)); + $frmEl->AddRow("Coordinate Y", new CTextBox("y", $y, 5)); + $frmEl->AddRow("URL", new CTextBox("url", $url, 64)); - $frmHost->AddItemToBottomRow(new CButton("register","add")); - if(isset($_REQUEST["shostid"])) + $frmEl->AddItemToBottomRow(new CButton("save",S_SAVE)); + if(isset($_REQUEST["selementid"])) { - $frmHost->AddItemToBottomRow(SPACE); - $frmHost->AddItemToBottomRow(new CButton("register","update")); + $frmEl->AddItemToBottomRow(SPACE); + $frmEl->AddItemToBottomRow(new CButtonDelete("Delete element?",url_param("form"). + url_param("selementid").url_param("sysmapid"))); } - $frmHost->AddItemToBottomRow(SPACE); - $frmHost->AddItemToBottomRow(new CButtonCancel(url_param("sysmapid"))); + $frmEl->AddItemToBottomRow(SPACE); + $frmEl->AddItemToBottomRow(new CButtonCancel(url_param("sysmapid"))); - $frmHost->Show(); + $frmEl->Show(); } function insert_map_link_form() @@ -2342,41 +2533,77 @@ $frmCnct->SetHelp("web.sysmap.connector.php"); $frmCnct->AddVar("sysmapid",$_REQUEST["sysmapid"]); - $cmbHosts = new CComboBox("shostid1"); - - $result=DBselect("select h.host,sh.shostid,sh.sysmapid,sh.hostid,sh.label,sh.x,". - "sh.y,sh.icon from sysmaps_hosts sh,hosts h". - " where sh.sysmapid=".$_REQUEST["sysmapid"]. - " and h.status not in (".HOST_STATUS_DELETED.") and h.hostid=sh.hostid". - " order by h.host"); + if(isset($_REQUEST["linkid"])) + { + $frmCnct->AddVar("linkid",$_REQUEST["linkid"]); + $db_links = DBselect("select * from sysmaps_links where linkid=".$_REQUEST["linkid"]); + $db_link = DBfetch($db_links); + } - while($row=DBfetch($result)) + if(isset($_REQUEST["linkid"]) && !isset($_REQUEST["form_refresh"])) { - $host=get_host_by_hostid($row["hostid"]); - $cmbHosts->AddItem($row["shostid"],$host["host"].": ".$row["label"]); + $selementid1 = $db_link["selementid1"]; + $selementid2 = $db_link["selementid2"]; + $triggerid = $db_link["triggerid"]; + $drawtype_off = $db_link["drawtype_off"]; + $drawtype_on = $db_link["drawtype_on"]; + $color_off = $db_link["color_off"]; + $color_on = $db_link["color_on"]; + } + else + { + $selementid1 = get_request("selementid1", 0); + $selementid2 = get_request("selementid2", 0); + $triggerid = get_request("triggerid", 0); + $drawtype_off = get_request("drawtype_off", 0); + $drawtype_on = get_request("drawtype_on", 0); + $color_off = get_request("color_off", 0); + $color_on = get_request("color_on", 0); } - $frmCnct->AddRow("Host 1",$cmbHosts); - $cmbHosts->SetName("shostid2"); - $frmCnct->AddRow("Host 2",$cmbHosts); +/* START comboboxes preparations */ + $cmbElements = new CComboBox("selementid1",$selementid1); + $db_selements = DBselect("select selementid,label,elementid,elementtype from sysmaps_elements". + " where sysmapid=".$_REQUEST["sysmapid"]); + while($db_selement = DBfetch($db_selements)) + { + $label = $db_selement["label"]; + if($db_selement["elementtype"] == SYSMAP_ELEMENT_TYPE_HOST) + { + $db_host = get_host_by_hostid($db_selement["elementid"]); + $label .= ":".$db_host["host"]; + } + elseif($db_selement["elementtype"] == SYSMAP_ELEMENT_TYPE_MAP) + { + $db_map = get_sysmap_by_sysmapid($db_selement["elementid"]); + $label .= ":".$db_map["host"]; + } + elseif($db_selement["elementtype"] == SYSMAP_ELEMENT_TYPE_IMAGE) + { + if($db_selement["elementid"]>0) + { + $label .= ":".expand_trigger_description($db_selement["elementid"]); + } + } + $cmbElements->AddItem($db_selement["selementid"],$label); + } - $cmbIndic = new CComboBox("triggerid"); + $cmbIndic = new CComboBox("triggerid",$triggerid); $cmbIndic->AddItem(0,"-"); $result=DBselect("select triggerid from triggers order by description"); while($row=DBfetch($result)) { $cmbIndic->AddItem($row["triggerid"],expand_trigger_description($row["triggerid"])); } - $frmCnct->AddRow("Link status indicator",$cmbIndic); - $cmbType = new CComboBox("drawtype_off"); + $cmbType = new CComboBox("drawtype_off",$drawtype_off); $cmbType->AddItem(0,get_drawtype_description(0)); $cmbType->AddItem(1,get_drawtype_description(1)); $cmbType->AddItem(2,get_drawtype_description(2)); $cmbType->AddItem(3,get_drawtype_description(3)); $cmbType->AddItem(4,get_drawtype_description(4)); - $cmbColor = new CComboBox("color_off"); + $cmbColor = new CComboBox("color_off",$color_off); $cmbColor->AddItem('Black',"Black"); $cmbColor->AddItem('Blue',"Blue"); $cmbColor->AddItem('Cyan',"Cyan"); @@ -2388,17 +2615,34 @@ $cmbColor->AddItem('Red',"Red"); $cmbColor->AddItem('White',"White"); $cmbColor->AddItem('Yellow',"Yellow"); +/* END preparation */ + + $frmCnct->AddRow("Element 1",$cmbElements); + + $cmbElements->SetName("selementid2"); // rename without recreation + $cmbElements->SetValue($selementid2); // rename without recreation + $frmCnct->AddRow("Element 2",$cmbElements); + + $frmCnct->AddRow("Link status indicator",$cmbIndic); $frmCnct->AddRow("Type (OFF)",$cmbType); $frmCnct->AddRow("Color (OFF)",$cmbColor); - $cmbType->SetName("drawtype_on"); - $cmbColor->SetName("color_on"); - + $cmbType->SetName("drawtype_on"); // rename without recreation + $cmbType->SetValue($drawtype_on); // rename without recreation $frmCnct->AddRow("Type (ON)",$cmbType); + + $cmbColor->SetName("color_on"); // rename without recreation + $cmbColor->SetValue($color_on); // rename without recreation $frmCnct->AddRow("Color (ON)",$cmbColor); - $frmCnct->AddItemToBottomRow(new CButton("register","add link")); + $frmCnct->AddItemToBottomRow(new CButton("save_link",S_SAVE)); + if(isset($_REQUEST["linkid"])) + { + $frmCnct->AddItemToBottomRow(SPACE); + $frmCnct->AddItemToBottomRow(new CButtonDelete("Delete link?", + url_param("linkid").url_param("sysmapid"))); + } $frmCnct->AddItemToBottomRow(SPACE); $frmCnct->AddItemToBottomRow(new CButtonCancel(url_param("sysmapid"))); diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php index 1763b364..4922d587 100644 --- a/frontends/php/include/hosts.inc.php +++ b/frontends/php/include/hosts.inc.php @@ -286,7 +286,7 @@ } // delete host from maps - delete_sysmaps_host_by_hostid($hostid); + delete_sysmaps_elements_with_hostid($hostid); // delete host from group DBexecute("delete from hosts_groups where hostid=$hostid"); diff --git a/frontends/php/include/html.inc.php b/frontends/php/include/html.inc.php index 2a67b47b..277668b7 100644 --- a/frontends/php/include/html.inc.php +++ b/frontends/php/include/html.inc.php @@ -23,6 +23,13 @@ define("SPACE"," "); define("RARR","⇒"); + function do_vertival_text($str) + { + for($i=0,$out = ""; $i<strlen($str); $i++) $out .= $str[$i].BR; + $str = $out; + return $str; + } + function bold($str) { if(is_array($str)){ @@ -38,7 +45,7 @@ function bfirst($str) // mark first symbol of string as bold { $res = bold($str[0]); - for($i=1; $i<strlen($str); $i++) $res .= $str[$i]; + for($i=1; $i<strlen($str); $i++) $res .= $str[$i]; $str = $res; return $str; } @@ -99,7 +106,7 @@ } } - function table_begin($class="tborder") + function table_begin($class="tableinfo") { echo "<table class=\"$class\" border=0 width=\"100%\" bgcolor='#AAAAAA' cellspacing=1 cellpadding=3>"; echo "\n"; diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php index 2d080f4c..23562cab 100644 --- a/frontends/php/include/items.inc.php +++ b/frontends/php/include/items.inc.php @@ -434,4 +434,68 @@ return get_host_by_itemid($itemid); } + + function get_items_data_overview($groupid) + { + $table = new CTableInfo(); + + if($groupid > 0) + { + $group_where = ",hosts_groups hg where hg.groupid=$groupid and hg.hostid=h.hostid and"; + } else { + $group_where = " where"; + } + + $header=array(new CCol(S_ITEMS,"center")); + + $hosts=array(); + $result=DBselect("select h.hostid,h.host from hosts h,items i $group_where". + " h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid". + " group by h.host,h.hostid order by h.host"); + while($row=DBfetch($result)) + { + $header=array_merge($header,array(do_vertival_text($row["host"]))); + $hosts=array_merge($hosts,array($row["hostid"])); + } + $table->SetHeader($header,"vertical_header"); + + + $db_items = DBselect("select distinct i.description from hosts h,items i $group_where". + " h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid order by 1"); + while($item = DBfetch($db_items)) + { + $table_row = array(nbsp($item["description"])); + foreach($hosts as $hostid) + { + $db_host_items = DBselect("select itemid,value_type,lastvalue,units from items where". + " hostid=$hostid and description=".zbx_dbstr($item["description"])); + if(DBnum_rows($db_host_items)!=1) + { + array_push($table_row,"-"); + continue; + } + $host_item = DBfetch($db_host_items); + if(!isset($host_item["lastvalue"])) + { + array_push($table_row,"-"); + continue; + } + $db_item_triggers = DBselect("select t.triggerid from triggers t, items i, functions f where". + " i.hostid=$hostid and i.itemid=".$host_item["itemid"]." and i.itemid=f.itemid". + " and t.priority>1 and t.triggerid=f.triggerid and t.value=".TRIGGER_VALUE_TRUE); + if(DBnum_rows($db_item_triggers) > 0) $style = "high"; + else $style = NULL; + + if($host_item["value_type"] == 0) + $value = convert_units($host_item["lastvalue"],$host_item["units"]); + else + $value = htmlspecialchars(substr($host_item["lastvalue"],0,20)." ..."); + + array_push($table_row,new CCol(nbsp($value),$style)); + } + + $table->AddRow($table_row); + } + return $table; + } ?> diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php index e429168a..fe7d6406 100644 --- a/frontends/php/include/locales/en_gb.inc.php +++ b/frontends/php/include/locales/en_gb.inc.php @@ -27,6 +27,15 @@ "S_DATE_FORMAT_YMD"=> "d M Y", "S_HTML_CHARSET"=> "iso-8859-1", +// acknow.php + "S_ACKNOWLEDGES"=> "Acknowledges", + "S_ACKNOWLEDGE"=> "Acknowledge", + "S_ACKNOWLEDGE_ALARM_BY"=> "Acknowledge alarm by", + "S_ADD_COMMENT_BY"=> "Add comment by", + "S_COMMENT_ADDED"=> "Comment added", + "S_CANNOT_ADD_COMMENT"=> "Cannot add coment", + "S_ALARM_ACKNOWLEDGES_BIG"=> "ALARM ACKNOWLEDGES", + // actionconf.php "S_FILTER_HOST_GROUP"=> "Filter: Host group", "S_FILTER_HOST"=> "Filter: Host", @@ -222,6 +231,7 @@ "S_IMAGES"=> "Images", "S_IMAGE"=> "Image", "S_IMAGES_BIG"=> "IMAGES", + "S_ICON"=> "Icon", "S_NO_IMAGES_DEFINED"=> "No images defined", "S_BACKGROUND"=> "Background", "S_UPLOAD"=> "Upload", @@ -317,6 +327,7 @@ // hosts.php "S_HOSTS"=> "Hosts", "S_ITEMS"=> "Items", + "S_ITEMS_BIG"=> "ITEMS", "S_TRIGGERS"=> "Triggers", "S_GRAPHS"=> "Graphs", "S_HOST_ADDED"=> "Host added", @@ -488,12 +499,14 @@ "S_LAST_VALUE"=> "Last value", // sysmap.php + "S_LINK"=> "Link", "S_LABEL"=> "Label", "S_X"=> "X", "S_Y"=> "Y", - "S_ICON"=> "Icon", - "S_HOST_1"=> "Host 1", - "S_HOST_2"=> "Host 2", + "S_ICON_ON"=> "Icon (on)", + "S_ICON_OFF"=> "Icon (off)", + "S_ELEMENT_1"=> "Element 1", + "S_ELEMENT_2"=> "Element 2", "S_LINK_STATUS_INDICATOR"=> "Link status indicator", "S_CONFIGURATION_OF_NETWORK_MAPS"=> "Configuration of network maps", @@ -518,8 +531,9 @@ "S_SELECT_MAP_DOT_DOT_DOT"=> "Select map...", "S_BACKGROUND_IMAGE"=> "Background image", "S_ICON_LABEL_TYPE"=> "Icon label type", - "S_HOST_LABEL"=> "Host label", - "S_HOST_NAME"=> "Host name", + "S_LABEL"=> "Label", + "S_LABEL_LOCATION"=> "Label location", + "S_ELEMENT_NAME"=> "Element name", "S_STATUS_ONLY"=> "Status only", "S_NOTHING"=> "Nothing", @@ -593,15 +607,23 @@ "S_VALUE"=> "Value", "S_ZABBIX_SERVER_IS_RUNNING"=> "ZABBIX server is running", "S_NUMBER_OF_VALUES_STORED"=> "Number of values stored", + "S_VALUES_STORED"=> "Values stored", "S_NUMBER_OF_TRENDS_STORED"=> "Number of trends stored", + "S_TRENDS_STORED"=> "Trends stored", "S_NUMBER_OF_ALARMS"=> "Number of alarms", "S_NUMBER_OF_ALERTS"=> "Number of alerts", - "S_NUMBER_OF_TRIGGERS_ENABLED_DISABLED"=>"Number of triggers (enabled/disabled)", - "S_NUMBER_OF_ITEMS_ACTIVE_TRAPPER"=> "Number of items (active/trapper/not active/not supported)", - "S_NUMBER_OF_USERS"=> "Number of users", - "S_NUMBER_OF_HOSTS_MONITORED"=> "Number of hosts (monitored/not monitored/templates/deleted)", + "S_NUMBER_OF_TRIGGERS"=> "Number of triggers (enabled/disabled)[true/unknown/false]", + "S_NUMBER_OF_TRIGGERS_SHORT"=> "Triggers (e/d)[t/u/f]", + "S_NUMBER_OF_ITEMS"=> "Number of items (monitored/disabled/not supported)[trapper]", + "S_NUMBER_OF_ITEMS_SHORT"=> "Items (m/d/n)[t]", + "S_NUMBER_OF_USERS"=> "Number of users (online)", + "S_NUMBER_OF_USERS_SHORT"=> "Users (online)", + "S_NUMBER_OF_HOSTS"=> "Number of hosts (monitored/not monitored/templates/deleted)", + "S_NUMBER_OF_HOSTS_SHORT"=> "Hosts (m/n/t/d)", "S_YES"=> "Yes", "S_NO"=> "No", + "S_RUNNING"=> "running", + "S_NOT_RUNNING"=> "not running", // report2.php "S_AVAILABILITY_REPORT"=> "Availability report", @@ -658,6 +680,30 @@ "S_COLUMN_SPAN"=> "Column span", "S_ROW_SPAN"=> "Row span", "S_SHOW_LINES"=> "Show lines", + "S_HOSTS_INFO"=> "Hosts info", + "S_TRIGGERS_INFO"=> "Triggers info", + "S_SERVER_INFO"=> "Server info", + "S_CLOCK"=> "Clock", + "S_TRIGGERS_OVERVIEW"=> "Triggers overview", + "S_DATA_OVERVIEW"=> "Data overview", + + "S_TIME_TYPE"=> "Time type", + "S_SERVER_TIME"=> "Server time", + "S_LOCAL_TIME"=> "Local time", + + "S_STYLE"=> "Style", + "S_VERTICAL"=> "Vertical", + "S_HORISONTAL"=> "Horisontal", + + "S_HORISONTAL_ALIGN"=> "Horisontal align", + "S_LEFT"=> "Left", + "S_CENTER"=> "Center", + "S_RIGHT"=> "Right", + + "S_VERTICAL_ALIGN"=> "Vertical align", + "S_TOP"=> "Top", + "S_MIDDLE"=> "Middle", + "S_BOTTOM"=> "Buttom", // screens.php "S_CUSTOM_SCREENS"=> "Custom screens", @@ -769,6 +815,7 @@ "S_LAST_CHANGE"=> "Last change", "S_COMMENTS"=> "Comments", "S_ACKNOWLEDGED"=> "Acknowledged", + "S_ACK"=> "Ack", // users.php "S_USERS"=> "Users", diff --git a/frontends/php/include/maps.inc.php b/frontends/php/include/maps.inc.php index c35bc044..1480af02 100644 --- a/frontends/php/include/maps.inc.php +++ b/frontends/php/include/maps.inc.php @@ -19,7 +19,7 @@ **/ ?> <?php - function get_map_by_sysmapid($sysmapid) + function get_sysmap_by_sysmapid($sysmapid) { $sql="select * from sysmaps where sysmapid=$sysmapid"; $result=DBselect($sql); @@ -34,9 +34,9 @@ return $result; } - function get_sysmaps_hosts_by_shostid($shostid) + function get_sysmaps_element_by_selementid($selementid) { - $sql="select * from sysmaps_hosts where shostid=$shostid"; + $sql="select * from sysmaps_elements where selementid=$selementid"; $result=DBselect($sql); if(DBnum_rows($result) == 1) { @@ -44,7 +44,7 @@ } else { - error("No sysmap host with shostid=[$shostid]"); + error("No sysmap element with selementid=[$selementid]"); } return $result; } @@ -53,20 +53,16 @@ function delete_sysmap( $sysmapid ) { - $sql="delete from sysmaps where sysmapid=$sysmapid"; - $result=DBexecute($sql); - if(!$result) - { - return $result; - } - $sql="delete from sysmaps_hosts where sysmapid=$sysmapid"; - $result=DBexecute($sql); - if(!$result) - { - return $result; - } - $sql="delete from sysmaps_links where sysmapid=$sysmapid"; - return DBexecute($sql); + $result = delete_sysmaps_elements_with_sysmapid($sysmapid); + if(!$result) return $result; + + $result = DBexecute("delete from sysmaps_links where sysmapid=$sysmapid"); + if(!$result) return $result; + + $result = DBexecute("delete from sysmaps_elements where sysmapid=$sysmapid"); + if(!$result) return $result; + + return DBexecute("delete from sysmaps where sysmapid=$sysmapid"); } # Update System Map @@ -79,8 +75,9 @@ return 0; } - $sql="update sysmaps set name=".zbx_dbstr($name).",width=$width,height=$height,background=".zbx_dbstr($background).",label_type=$label_type,label_location=$label_location where sysmapid=$sysmapid"; - return DBexecute($sql); + return DBexecute("update sysmaps set name=".zbx_dbstr($name).",width=$width,height=$height,". + "background=".zbx_dbstr($background).",label_type=$label_type,". + "label_location=$label_location where sysmapid=$sysmapid"); } # Add System Map @@ -93,115 +90,340 @@ return 0; } - $sql="insert into sysmaps (name,width,height,background,label_type,label_location) values (".zbx_dbstr($name).",$width,$height,".zbx_dbstr($background).",$label_type,$label_location)"; - return DBexecute($sql); + return DBexecute("insert into sysmaps (name,width,height,background,label_type,label_location)". + " values (".zbx_dbstr($name).",$width,$height,".zbx_dbstr($background).",$label_type, + $label_location)"); + } + + function add_link($sysmapid,$selementid1,$selementid2,$triggerid,$drawtype_off,$color_off,$drawtype_on,$color_on) + { + if($triggerid == 0) $triggerid = 'NULL'; + + return DBexecute("insert into sysmaps_links". + " (sysmapid,selementid1,selementid2,triggerid,drawtype_off,". + "color_off,drawtype_on,color_on)". + " values ($sysmapid,$selementid1,$selementid2,$triggerid,$drawtype_off,". + zbx_dbstr($color_off).",$drawtype_on,".zbx_dbstr($color_on).")"); + } + + function update_link($linkid,$sysmapid,$selementid1,$selementid2,$triggerid,$drawtype_off,$color_off,$drawtype_on,$color_on) + { + return DBexecute("update sysmaps_links set ". + "sysmapid=$sysmapid,selementid1=$selementid1,selementid2=$selementid2,". + "triggerid=$triggerid,drawtype_off=$drawtype_off,color_off=".zbx_dbstr($color_off).",". + "drawtype_on=$drawtype_on,color_on=".zbx_dbstr($color_on). + " where linkid=$linkid"); + } + + function delete_link($linkid) + { + return DBexecute("delete from sysmaps_links where linkid=$linkid"); } - function add_link($sysmapid,$shostid1,$shostid2,$triggerid,$drawtype_off,$color_off,$drawtype_on,$color_on) + function check_circle_elements_link($sysmapid,$elementid,$elementtype) { - if($triggerid == 0) + if($elementtype!=SYSMAP_ELEMENT_TYPE_MAP) return FALSE; + + if($sysmapid == $elementid) return TRUE; + + $db_elements = DBselect("select elementid, elementtype from sysmaps_elements". + " where sysmapid=$elementid"); + + while($element = DBfetch($db_elements)) { - $sql="insert into sysmaps_links (sysmapid,shostid1,shostid2,triggerid,drawtype_off,color_off,drawtype_on,color_on) values ($sysmapid,$shostid1,$shostid2,NULL,$drawtype_off,".zbx_dbstr($color_off).",$drawtype_on,".zbx_dbstr($color_on).")"; + if(check_circle_elements_link($sysmapid,$element["elementid"],$element["elementtype"])) + return TRUE; } - else + return FALSE; + } + + # Add Element to system map + + function add_element_to_sysmap($sysmapid,$elementid,$elementtype, + $label,$x,$y,$icon,$url,$icon_on,$label_location) + { + if($label_location<0) $label_location='null'; + if(check_circle_elements_link($sysmapid,$elementid,$elementtype)) { - $sql="insert into sysmaps_links (sysmapid,shostid1,shostid2,triggerid,drawtype_off,color_off,drawtype_on,color_on) values ($sysmapid,$shostid1,$shostid2,$triggerid,$drawtype_off,".zbx_dbstr($color_off).",$drawtype_on,".zbx_dbstr($color_on).")"; + error("Circle link can't be created"); + return FALSE; } - return DBexecute($sql); + + return DBexecute("insert into sysmaps_elements". + " (sysmapid,elementid,elementtype,label,x,y,icon,url,icon_on,label_location)". + " values ($sysmapid,$elementid,$elementtype,".zbx_dbstr($label).", + $x,$y,".zbx_dbstr($icon).",".zbx_dbstr($url).",".zbx_dbstr($icon_on).",". + "$label_location)"); } - function delete_link($linkid) + # Update Element from system map + + function update_sysmap_element($selementid,$sysmapid,$elementid,$elementtype, + $label,$x,$y,$icon,$url,$icon_on,$label_location) { - $sql="delete from sysmaps_links where linkid=$linkid"; - return DBexecute($sql); + if($label_location<0) $label_location='null'; + if(check_circle_elements_link($sysmapid,$elementid,$elementtype)) + { + error("Circle link can't be created"); + return FALSE; + } + + return DBexecute("update sysmaps_elements set elementid=$elementid,elementtype=$elementtype,". + "label=".zbx_dbstr($label).",x=$x,y=$y,icon=".zbx_dbstr($icon).",url=".zbx_dbstr($url). + ",icon_on=".zbx_dbstr($icon_on).",label_location=$label_location". + " where selementid=$selementid"); } - # Add Host to system map + # Delete Element from sysmap definition - function add_host_to_sysmap($sysmapid,$hostid,$label,$x,$y,$icon,$url,$icon_on) + function delete_sysmaps_element($selementid) { - $sql="insert into sysmaps_hosts (sysmapid,hostid,label,x,y,icon,url,icon_on) values ($sysmapid,$hostid,".zbx_dbstr($label).",$x,$y,".zbx_dbstr($icon).",".zbx_dbstr($url).",".zbx_dbstr($icon_on).")"; - return DBexecute($sql); + $result=DBexecute("delete from sysmaps_links". + " where selementid1=$selementid or selementid2=$selementid"); + + if(!$result) return $result; + + return DBexecute("delete from sysmaps_elements where selementid=$selementid"); } - function update_sysmap_host($shostid,$sysmapid,$hostid,$label,$x,$y,$icon,$url,$icon_on) + function delete_sysmaps_elements_with_hostid($hostid) { - $sql="update sysmaps_hosts set hostid=$hostid,label=".zbx_dbstr($label).",x=$x,y=$y,icon=".zbx_dbstr($icon).",url=".zbx_dbstr($url).",icon_on=".zbx_dbstr($icon_on)." where shostid=$shostid"; - return DBexecute($sql); + $db_elements = DBselect("select selementid from sysmaps_elements". + " where elementid=$hostid and elementtype=".SYSMAP_ELEMENT_TYPE_HOST); + while($db_element = DBfetch($db_elements)) + { + delete_sysmaps_element($db_element["selementid"]); + } + return TRUE; } - - function delete_sysmaps_host_by_hostid($hostid) + function delete_sysmaps_elements_with_sysmapid($sysmapid) { - $sql="select shostid from sysmaps_hosts where hostid=$hostid"; - $result=DBselect($sql); - while($row=DBfetch($result)) + $db_elements = DBselect("select selementid from sysmaps_elements". + " where elementid=$sysmapid and elementtype=".SYSMAP_ELEMENT_TYPE_MAP); + while($db_element = DBfetch($db_elements)) { - $sql="delete from sysmaps_links where shostid1=".$row["shostid"]." or shostid2=".$row["shostid"]; - DBexecute($sql); + delete_sysmaps_element($db_element["selementid"]); } - $sql="delete from sysmaps_hosts where hostid=$hostid"; - return DBexecute($sql); + return TRUE; } - - # Delete Host from sysmap definition - - function delete_sysmaps_host($shostid) + function delete_sysmaps_elements_with_triggerid($triggerid) { - $sql="delete from sysmaps_links where shostid1=$shostid or shostid2=$shostid"; - $result=DBexecute($sql); - if(!$result) + $db_elements = DBselect("select selementid from sysmaps_elements". + " where elementid=$triggerid and elementtype=".SYSMAP_ELEMENT_TYPE_IMAGE); + while($db_element = DBfetch($db_elements)) { - return $result; + delete_sysmaps_element($db_element["selementid"]); } - $sql="delete from sysmaps_hosts where shostid=$shostid"; - return DBexecute($sql); + return TRUE; } - function get_map_imagemap($sysmapid) + function get_png_by_selementid($selementid) { - $map="\n<map name=links$sysmapid>"; - $result=DBselect("select h.host,sh.shostid,sh.sysmapid,sh.hostid,sh.label,sh.x,sh.y,h.status,sh.icon,sh.url from sysmaps_hosts sh,hosts h where sh.sysmapid=$sysmapid and h.hostid=sh.hostid"); - while($row=DBfetch($result)) + $elements = DBselect("select * from sysmaps_elements where selementid=$selementid"); + if(!$elements) return FALSE; + + $element = DBfetch($elements); + if(!$element) return FALSE; + + $status = "off"; + if(get_info_by_selementid($element["selementid"],$info,$color)!="") + $status = "on"; + + if($status == "on") + $icon = $element["icon_on"]; + else + $icon = $element["icon"]; + + $images = DBselect("select image from images where imagetype=1 and name=".zbx_dbstr($icon)); + if(!$images) return FALSE; + + $image = DBfetch($images); + if(!$image) return FALSE; + + return imagecreatefromstring($image["image"]); + } + + function get_info_by_selementid($selementid, &$out_info, &$out_color) + { + global $colors; + + $info = ""; + $count = 0; + $color= $colors["Dark Green"]; + + $db_element = get_sysmaps_element_by_selementid($selementid); + if($db_element["elementtype"]==SYSMAP_ELEMENT_TYPE_HOST) { - $host=$row["host"]; - $shostid=$row["shostid"]; - $sysmapid=$row["sysmapid"]; - $hostid=$row["hostid"]; - $label=$row["label"]; - $x=$row["x"]; - $y=$row["y"]; - $status=$row["status"]; - $icon=$row["icon"]; - $url=$row["url"]; + $db_triggers = DBselect("select distinct t.triggerid, t.priority". + " from items i,functions f,triggers t,hosts h where h.hostid=i.hostid". + " and i.hostid=".$db_element["elementid"]." and i.itemid=f.itemid". + " and f.triggerid=t.triggerid and t.value=1 and t.status=0". + " and h.status=".HOST_STATUS_MONITORED." and i.status=0"); + $count = DBnum_rows($db_triggers); - if($status==HOST_STATUS_MONITORED) + if($count == 1) + { + $trigger = DBfetch($db_triggers); + if ($trigger["priority"] > 3) $color=$colors["Red"]; + else $color=$colors["Dark Yellow"]; + $info = expand_trigger_description_simple($trigger["triggerid"]); + } + elseif($count==0) { - $sql="select image from images where imagetype=1 and name=".zbx_dbstr($icon); - $result2=DBselect($sql); - if(DBnum_rows($result2)==1) + $host = get_host_by_hostid($db_element["elementid"]); + if($host["status"] == HOST_STATUS_TEMPLATE) { - $row2=DBfetch($result2); - $back=ImageCreateFromString($row2["image"]); - $sizex = imagesx($back); - $sizey = imagesy($back); - if($url=="") - { - $url="tr_status.php?hostid=$hostid&noactions=true&onlytrue=true&compact=true"; - } - $map=$map."\n<area shape=rect coords=$x,$y,".($x+$sizex).",".($y+$sizey)." href=\"$url\" alt=\"Host: $host Label: $label\">"; + $color = $colors["Gray"]; + $info = "template"; } - -/* if(function_exists("imagecreatetruecolor")&&@imagecreatetruecolor(1,1)) + else { - $map=$map."\n<area shape=rect coords=$x,$y,".($x+48).",".($y+48)." href=\"tr_status.php?hostid=$hostid&noactions=true&onlytrue=true&compact=true\" alt=\"$host\">"; + $info = S_OK_BIG; + $color = $colors["Dark Green"]; } - else + } + } + elseif($db_element["elementtype"]==SYSMAP_ELEMENT_TYPE_MAP) + { + $db_subelements = DBselect("select selementid from sysmaps_elements". + " where sysmapid=".$db_element["elementid"]); + while($db_subelement = DBfetch($db_subelements)) + {// recursion + $count += get_info_by_selementid($db_subelement["selementid"],$info,$color); + } + + if($count==0) + { + $out_info = S_OK_BIG; + $out_color = $colors["Dark Green"]; + } + } + elseif($db_element["elementtype"]==SYSMAP_ELEMENT_TYPE_IMAGE) + { + if($db_element["elementid"]>0){ + $trigger=get_trigger_by_triggerid($db_element["elementid"]); + if($trigger["value"] == TRIGGER_VALUE_TRUE) { - $map=$map."\n<area shape=rect coords=$x,$y,".($x+32).",".($y+32)." href=\"tr_status.php?hostid=$hostid&noactions=true&onlytrue=true&compact=true\" alt=\"$host\">"; - }*/ + $info=S_TRUE_BIG; + $color=$colors["Red"]; + $count = 1; + } + } + } + + if($count>1) + { + $out_info = $count." ".S_PROBLEMS_SMALL; + $out_color = $colors["Red"]; + } + else + { + $out_info = $info; + $out_color = $color; + } + + return $count; + } + + function get_action_map_by_sysmapid($sysmapid) + { + $action_map = new CMap("links$sysmapid"); + + $db_elements=DBselect("select * from sysmaps_elements where sysmapid=$sysmapid"); + while($db_element = DBfetch($db_elements)) + { + $url = $db_element["url"]; + $alt = "Label: ".$db_element["label"]; + + if($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_HOST) + { + $host = get_host_by_hostid($db_element["elementid"]); + if($host["status"] != HOST_STATUS_MONITORED) continue; + + + if($url=="") + $url="tr_status.php?hostid=".$db_element["elementid"]. + "&noactions=true&onlytrue=true&compact=true"; + + $alt = "Host: ".$host["host"]." ".$alt; } + elseif($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_MAP) + { + $map = get_sysmap_by_sysmapid($db_element["elementid"]); + + if($url=="") + $url="maps.php?sysmapid=".$db_element["elementid"]; + + $alt = "Host: ".$map["name"]." ".$alt; + } + elseif($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_IMAGE) + { + if($url=="" && $db_element["elementid"]!=0) + $url="alarms.php?triggerid=".$db_element["elementid"]; + } + + if($url=="") continue; + + $back = get_png_by_selementid($db_element["selementid"]); + if(!$back) continue; + + $x1_ = $db_element["x"]; + $y1_ = $db_element["y"]; + $x2_ = $db_element["x"] + imagesx($back); + $y2_ = $db_element["y"] + imagesy($back); + + $action_map->AddRectArea($x1_,$y1_,$x2_,$y2_, $url, $alt); + } + return $action_map; + } + + function get_icon_center_by_selementid($selementid) + { + $element = get_sysmaps_element_by_selementid($selementid); + $x = $element["x"]; + $y = $element["y"]; + + $image = get_png_by_selementid($selementid); + if($image) + { + $x += imagesx($image) / 2; + $y += imagesy($image) / 2; + } + + return array($x, $y); + } + + function MyDrawLine($image,$x1,$y1,$x2,$y2,$color,$drawtype) + { + if($drawtype == GRAPH_DRAW_TYPE_BOLDLINE) + { + ImageLine($image,$x1,$y1,$x2,$y2,$color); + if(($x1-$x2) < ($y1-$y2)) + { + $x1++; $x2++; + } + else + { + $y1++; $y2++; + } + ImageLine($image,$x1,$y1,$x2,$y2,$color); + } + else if($drawtype == GRAPH_DRAW_TYPE_DASHEDLINE) + { + if(function_exists("imagesetstyle")) + { /* Use ImageSetStyle+ImageLIne instead of bugged ImageDashedLine */ + $style = array($color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); + ImageSetStyle($image, $style); + ImageLine($image,$x1,$y1,$x2,$y2,IMG_COLOR_STYLED); + } + else + { + ImageDashedLine($image,$x1,$y1,$x2,$y2,$color); + } + } + else + { + ImageLine($image,$x1,$y1,$x2,$y2,$color); } - $map=$map."\n</map>"; - return $map; } ?> diff --git a/frontends/php/include/screens.inc.php b/frontends/php/include/screens.inc.php index a7cbd46d..8ade536d 100644 --- a/frontends/php/include/screens.inc.php +++ b/frontends/php/include/screens.inc.php @@ -45,27 +45,27 @@ function delete_screen($screenid) { - $sql="delete from screens_items where screenid=$screenid"; - $result=DBexecute($sql); - if(!$result) - { - return $result; - } - $sql="delete from screens where screenid=$screenid"; - return DBexecute($sql); + $result=DBexecute("delete from screens_items where screenid=$screenid"); + if(!$result) return $result; + + $result=DBexecute("delete from screens_items where resourceid=$screenid and resource=".SCREEN_RESOURCE_SCREEN); + if(!$result) return $result; + + return DBexecute("delete from screens where screenid=$screenid"); } - function add_screen_item($resource,$screenid,$x,$y,$resourceid,$width,$height,$colspan,$rowspan,$elements) + function add_screen_item($resource,$screenid,$x,$y,$resourceid,$width,$height,$colspan,$rowspan,$elements,$valign,$halign,$style) { $sql="delete from screens_items where screenid=$screenid and x=$x and y=$y"; DBexecute($sql); - $sql="insert into screens_items (resource,screenid,x,y,resourceid,width,height,colspan,rowspan,elements) values ($resource,$screenid,$x,$y,$resourceid,$width,$height,$colspan,$rowspan,$elements)"; + $sql="insert into screens_items (resource,screenid,x,y,resourceid,width,height,colspan,rowspan,elements,valign,halign,style)". + " values ($resource,$screenid,$x,$y,$resourceid,$width,$height,$colspan,$rowspan,$elements,$valign,$halign,$style)"; return DBexecute($sql); } - function update_screen_item($screenitemid,$resource,$resourceid,$width,$height,$colspan,$rowspan,$elements) + function update_screen_item($screenitemid,$resource,$resourceid,$width,$height,$colspan,$rowspan,$elements,$valign,$halign,$style) { - $sql="update screens_items set resource=$resource,resourceid=$resourceid,width=$width,height=$height,colspan=$colspan,rowspan=$rowspan,elements=$elements where screenitemid=$screenitemid"; + $sql="update screens_items set resource=$resource,resourceid=$resourceid,width=$width,height=$height,colspan=$colspan,rowspan=$rowspan,elements=$elements,valign=$valign,halign=$halign,style=$style where screenitemid=$screenitemid"; return DBexecute($sql); } @@ -85,8 +85,230 @@ } else { - error("No screen with screenid=[$screenid]"); + info("No screen with screenid=[$screenid]"); + return FALSE; } return $result; } + + function check_screen_recursion($mother_screenid, $child_screenid) + { + if($mother_screenid == $child_screenid) return TRUE; + + $db_scr_items = DBselect("select resourceid from screens_items where". + " screenid=$child_screenid and resource=".SCREEN_RESOURCE_SCREEN); + while($scr_item = DBfetch($db_scr_items)) + { + if(check_screen_recursion($mother_screenid,$scr_item["resourceid"])) + return TRUE; + } + return FALSE; + } + + + + // editmode: 0 - view with actions, 1 - edit mode, 2 - view without any actions + function get_screen($screenid, $editmode, $effectiveperiod=NULL) + { + if(is_null($effectiveperiod)) + $effectiveperiod = 3600; + + $result=DBselect("select name,cols,rows from screens where screenid=$screenid"); + if(DBnum_rows($result) == 0) return new CSpan("Screen missing".BR); + $row=DBfetch($result); + + for($r=0;$r<$row["rows"];$r++) + { + for($c=0;$c<$row["cols"];$c++) + { + if(isset($skip_field[$r][$c])) continue; + + $sql="select * from screens_items where screenid=$screenid and x=$c and y=$r"; + $iresult=DBSelect($sql); + if(DBnum_rows($iresult)>0) + { + $irow=DBfetch($iresult); + $colspan=$irow["colspan"]; + $rowspan=$irow["rowspan"]; + } else { + $colspan=0; + $rowspan=0; + } + for($i=0; $i < $rowspan || $i==0; $i++){ + for($j=0; $j < $colspan || $j==0; $j++){ + if($i!=0 || $j!=0) + $skip_field[$r+$i][$c+$j]=1; + } + } + } + } + $table = new CTable( + new CLink("No rows in screen ".$row["name"],"screenconf.php?form=update&screenid=".$screenid), + ($editmode == 0 || $editmode == 2) ? "screen_view" : "screen_edit"); + + for($r=0;$r<$row["rows"];$r++) + { + $new_cols = array(); + for($c=0;$c<$row["cols"];$c++) + { + $item = array(); + if(isset($skip_field[$r][$c])) continue; + + $iresult=DBSelect("select * from screens_items". + " where screenid=$screenid and x=$c and y=$r"); + + if(DBnum_rows($iresult)>0) + { + $irow = DBfetch($iresult); + $screenitemid = $irow["screenitemid"]; + $resource = $irow["resource"]; + $resourceid = $irow["resourceid"]; + $width = $irow["width"]; + $height = $irow["height"]; + $colspan = $irow["colspan"]; + $rowspan = $irow["rowspan"]; + $elements = $irow["elements"]; + $valign = $irow["valign"]; + $halign = $irow["halign"]; + $style = $irow["style"]; + } + else + { + $screenitemid = 0; + $screenitemid = 0; + $resource = 0; + $resourceid = 0; + $width = 0; + $height = 0; + $colspan = 0; + $rowspan = 0; + $elements = 0; + $valign = VALIGN_DEFAULT; + $halign = HALIGN_DEFAULT; + $style = 0; + } + + + if($editmode == 1 && $screenitemid!=0) + $url = "screenedit.php?form=update".url_param("screenid"). + "&screenitemid=$screenitemid#form"; + elseif ($editmode == 1 && $screenitemid==0) + $url = "screenedit.php?form=update".url_param("screenid")."&x=$c&y=$r#form"; + else + $url = NULL; + + if($editmode == 1 && isset($_REQUEST["form"]) && + isset($_REQUEST["x"]) && $_REQUEST["x"]==$c && + isset($_REQUEST["y"]) && $_REQUEST["y"]==$r) + { // click on empty field + $item = get_screen_item_form(); + } + elseif($editmode == 1 && isset($_REQUEST["form"]) && + isset($_REQUEST["screenitemid"]) && $_REQUEST["screenitemid"]==$screenitemid) + { // click on element + $item = get_screen_item_form(); + } + elseif( ($screenitemid!=0) && ($resource==SCREEN_RESOURCE_GRAPH) ) + { + if($editmode == 0) + $url = "charts.php?graphid=$resourceid".url_param("period"). + url_param("inc").url_param("dec"); + + $item = new CLink( + new CImg("chart2.php?graphid=$resourceid&width=$width&height=$height". + "&period=$effectiveperiod".url_param("stime").url_param("from")), + $url + ); + } + elseif( ($screenitemid!=0) && ($resource==SCREEN_RESOURCE_SIMPLE_GRAPH) ) + { + if($editmode == 0) + $url = "history.php?action=showhistory&itemid=$resourceid". + url_param("period").url_param("inc").url_param("dec"); + + $item = new CLink( + new CImg("chart.php?itemid=$resourceid&width=$width&height=$height". + "&period=$effectiveperiod".url_param("stime").url_param("from")), + $url + ); + } + elseif( ($screenitemid!=0) && ($resource==SCREEN_RESOURCE_MAP) ) + { + $image_map = new CImg("map.php?noedit=1&sysmapid=$resourceid". + "&width=$width&height=$height"); + if($editmode == 0) + { + $action_map = get_action_map_by_sysmapid($resourceid); + $image_map->SetMap($action_map->GetName()); + $item = array($action_map,$image_map); + } else { + $item = new CLink($image_map, $url); + } + } + elseif( ($screenitemid!=0) && ($resource==SCREEN_RESOURCE_PLAIN_TEXT) ) + { + $item = array(get_screen_plaintext($resourceid,$elements)); + if($editmode == 1) array_push($item,new CLink(S_CHANGE,$url)); + } + elseif( ($screenitemid!=0) && ($resource==SCREEN_RESOURCE_HOSTS_INFO) ) + { + $item = array(new CHostsInfo($style)); + if($editmode == 1) array_push($item,new CLink(S_CHANGE,$url)); + } + elseif( ($screenitemid!=0) && ($resource==SCREEN_RESOURCE_TRIGGERS_INFO) ) + { + $item = array(new CTriggersInfo($style)); + if($editmode == 1) array_push($item,new CLink(S_CHANGE,$url)); + } + elseif( ($screenitemid!=0) && ($resource==SCREEN_RESOURCE_SERVER_INFO) ) + { + $item = array(new CServerInfo()); + if($editmode == 1) array_push($item,new CLink(S_CHANGE,$url)); + } + elseif( ($screenitemid!=0) && ($resource==SCREEN_RESOURCE_CLOCK) ) + { + $item = new CFlashClock($width, $height, $style, $url); + } + elseif( ($screenitemid!=0) && ($resource==SCREEN_RESOURCE_SCREEN) ) + { + $item = array(get_screen($resourceid, 2, $effectiveperiod)); + if($editmode == 1) array_push($item,new CLink(S_CHANGE,$url)); + } + elseif( ($screenitemid!=0) && ($resource==SCREEN_RESOURCE_TRIGGERS_OVERVIEW) ) + { + $item = array(get_triggers_overview($resourceid)); + if($editmode == 1) array_push($item,new CLink(S_CHANGE,$url)); + } + elseif( ($screenitemid!=0) && ($resource==SCREEN_RESOURCE_DATA_OVERVIEW) ) + { + $item = array(get_items_data_overview($resourceid)); + if($editmode == 1) array_push($item,new CLink(S_CHANGE,$url)); + } + else + { + $item = array(SPACE); + if($editmode == 1) array_push($item,BR,new CLink(S_CHANGE,$url)); + } + + $str_halign = "def"; + if($halign == HALIGN_CENTER) $str_halign = "cntr"; + if($halign == HALIGN_LEFT) $str_halign = "left"; + if($halign == HALIGN_RIGHT) $str_halign = "right"; + + $str_valign = "def"; + if($valign == VALIGN_MIDDLE) $str_valign = "mdl"; + if($valign == VALIGN_TOP) $str_valign = "top"; + if($valign == VALIGN_BOTTOM) $str_valign = "bttm"; + + $new_col = new CCol($item,$str_halign."_".$str_valign); + + if($colspan) $new_col->SetColSpan($colspan); + if($rowspan) $new_col->SetRowSpan($rowspan); + + array_push($new_cols, $new_col); + } + $table->AddRow(new CRow($new_cols)); + } + return $table; + } ?> diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php index 690bd3bf..2da7658a 100644 --- a/frontends/php/include/triggers.inc.php +++ b/frontends/php/include/triggers.inc.php @@ -643,27 +643,21 @@ $trig_hosts = get_hosts_by_triggerid($triggerid); $result = delete_dependencies_by_triggerid($triggerid); - if(!$result) - { - return $result; - } + if(!$result) return $result; + DBexecute("delete from trigger_depends where triggerid_up=$triggerid"); $result=delete_function_by_triggerid($triggerid); - if(!$result) - { - return $result; - } + if(!$result) return $result; + $result=delete_alarms_by_triggerid($triggerid); - if(!$result) - { - return $result; - } + if(!$result) return $result; + $result=delete_services_by_triggerid($triggerid); - if(!$result) - { - return $result; - } + if(!$result) return $result; + + $result=delete_sysmaps_elements_with_triggerid($triggerid); + if(!$result) return $result; DBexecute("delete from alerts where triggerid=$triggerid"); @@ -951,4 +945,60 @@ copy_trigger_to_host($trigger["triggerid"], $hostid); } } + + function get_triggers_overview($groupid) + { + $table = new CTableInfo(); + + if($groupid > 0) + { + $group_where = ",hosts_groups hg where hg.groupid=$groupid and hg.hostid=h.hostid and"; + } else { + $group_where = " where"; + } + + $header=array(new CCol(S_TRIGGERS,"center")); + + $hosts=array(); + $result=DBselect("select h.hostid,h.host from hosts h,items i,triggers t, functions f $group_where". + " h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid". + " group by h.host,h.hostid order by h.host"); + while($row=DBfetch($result)) + { + $header=array_merge($header,array(do_vertival_text($row["host"]))); + $hosts=array_merge($hosts,array($row["hostid"])); + } + $table->SetHeader($header,"vertical_header"); + + + $db_triggers = DBselect("select distinct t.description from hosts h,items i,triggers t,functions f $group_where". + " h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid". + " group by 1"); + while($triggers = DBfetch($db_triggers)) + { + $table_row = array(nbsp($triggers["description"])); + foreach($hosts as $hostid) + { + $style = NULL; + $db_host_triggers = DBselect("select t.value,t.lastchange from triggers t,functions f,items i". + " where f.triggerid=t.triggerid and i.itemid=f.itemid and t.status=".TRIGGER_STATUS_ENABLED. + " and i.hostid=$hostid and t.description=".zbx_dbstr($triggers["description"])); + if(DBnum_rows($db_host_triggers)==1) + { + $host_trigger = DBfetch($db_host_triggers); + + if($host_trigger["value"] == TRIGGER_VALUE_FALSE) $style = "normal"; + elseif($host_trigger["value"] == TRIGGER_VALUE_UNKNOWN) $style = "unknown_trigger"; + else $style = "high"; + + if((time(NULL)-$host_trigger["lastchange"])<300) $style .= "_blink1"; + elseif((time(NULL)-$host_trigger["lastchange"])<900) $style .= "_blink3"; + } + array_push($table_row,new CCol(SPACE,$style)); + } + + $table->AddRow($table_row); + } + return $table; + } ?> diff --git a/frontends/php/include/validate.inc.php b/frontends/php/include/validate.inc.php index 39e9a66f..0e8ba889 100644 --- a/frontends/php/include/validate.inc.php +++ b/frontends/php/include/validate.inc.php @@ -19,7 +19,6 @@ **/ ?> <?php - function unset_request($key) { // SDI("unset: $key"); @@ -44,6 +43,10 @@ { return "in_array({".$var."},array(".$array."))&&"; } + function HEX($var=NULL) + { + return "ereg(\"^[a-zA-Z0-9]{1,}$\",{".$var."})"; + } define("NOT_EMPTY","({}!='')&&"); define("DB_ID","({}>=0&&{}<=4294967295)&&"); @@ -279,13 +282,22 @@ return ZBX_VALID_OK; } +// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION + $system_fields=array( + "sessionid"=> array(T_ZBX_STR, O_OPT, P_SYS, HEX(),NULL), + "triggers_hash"=> array(T_ZBX_STR, O_OPT, P_SYS, NOT_EMPTY,NULL) + ); + function check_fields(&$fields) { global $_REQUEST; + global $system_fields; $err = ZBX_VALID_OK; + $fields = array_merge($fields, $system_fields); + foreach($fields as $field => $checks) { $err |= check_field($fields, $field,$checks); |
