summaryrefslogtreecommitdiffstats
path: root/frontends/php/include
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-05-03 06:35:28 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-05-03 06:35:28 +0000
commitcff3cc1ef8b6ac526e7968be6a10c09669461be1 (patch)
treecdb8c67a959922a86e98a01b6104f52c3828b786 /frontends/php/include
parent50cb63535597c91584f08f6d6f00cfcdbe0dd198 (diff)
- improved 'Latest data' sreen, items grouped by applications (Eugene)
- added applications for hosts (Eugene) git-svn-id: svn://svn.zabbix.com/trunk@2794 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
-rw-r--r--frontends/php/include/classes/ctable.inc.php15
-rw-r--r--frontends/php/include/classes/ctableinfo.inc.php43
-rw-r--r--frontends/php/include/classes/ctag.inc.php17
-rw-r--r--frontends/php/include/config.inc.php92
-rw-r--r--frontends/php/include/db.inc.php2
-rw-r--r--frontends/php/include/defines.inc.php5
-rw-r--r--frontends/php/include/forms.inc.php98
-rw-r--r--frontends/php/include/hosts.inc.php191
-rw-r--r--frontends/php/include/html.inc.php16
-rw-r--r--frontends/php/include/items.inc.php104
-rw-r--r--frontends/php/include/locales/en_gb.inc.php17
11 files changed, 552 insertions, 48 deletions
diff --git a/frontends/php/include/classes/ctable.inc.php b/frontends/php/include/classes/ctable.inc.php
index b0d5485a..46a18fff 100644
--- a/frontends/php/include/classes/ctable.inc.php
+++ b/frontends/php/include/classes/ctable.inc.php
@@ -127,6 +127,7 @@
}else{
$this->header = new CRow($value,$class);
}
+ return true;
}
function SetFooter($value=NULL,$class=NULL)
{
@@ -208,10 +209,20 @@
}
}
/* protected */
- function ShowTagBody()
+ function ShowHeader()
{
- if(is_a($this->header,'crow'))
+ if(isset($this->header))
$this->header->Show();
+ }
+
+ function GetNumRows()
+ {
+ return $this->GetItemsCount();
+ }
+
+ function ShowTagBody()
+ {
+ $this->ShowHeader();
if(count($this->items)==0)
{
diff --git a/frontends/php/include/classes/ctableinfo.inc.php b/frontends/php/include/classes/ctableinfo.inc.php
index 5819ddc9..cbf43365 100644
--- a/frontends/php/include/classes/ctableinfo.inc.php
+++ b/frontends/php/include/classes/ctableinfo.inc.php
@@ -22,6 +22,8 @@
class CTableInfo extends CTable
{
/* public */
+ var $sortby;
+
function CTableInfo($message='...',$class='tableinfo')
{
parent::CTable($message,$class);
@@ -30,6 +32,7 @@
$this->SetCellSpacing(1);
$this->SetCellPadding(3);
$this->SetHeader();
+ $this->SortBy();
}
function SetHeader($value=NULL,$class='header')
{
@@ -39,5 +42,45 @@
{
parent::SetFooter($value,$class);
}
+ function SortBy($value = NULL)
+ {
+ if(!is_numeric($value) && !is_null($value))
+ {
+ return $this->error("Incorrect value for SortBy [$value]");
+ }
+ $this->sortby = $value;
+ }
+ function ShowHeader()
+ {
+ if(isset($this->header))
+ {
+ // create a copy of real header
+ $header = $this->header;
+
+ if(!is_null($this->sortby))
+ {
+ $i = 1;
+ foreach($header->items as $id => $col)
+ {
+ $sort = new CSpan();
+ $down = "_off";
+ $up = "_off";
+
+ if(($i-$this->sortby) == 0) $down = "";
+ if(($i+$this->sortby) == 0) $up = "";
+
+ $sort->AddItem(array(
+ new CImg("images/general/sortup$up.gif"),
+ new CImg("images/general/sortdown$down.gif"),
+ SPACE));
+ $sort->AddOption("style","float:left");
+
+ $header->items[$id]->AddItem($sort);
+ $i++;
+ }
+ }
+ $header->Show();
+ }
+ }
}
?>
diff --git a/frontends/php/include/classes/ctag.inc.php b/frontends/php/include/classes/ctag.inc.php
index bdeb3099..4d58626f 100644
--- a/frontends/php/include/classes/ctag.inc.php
+++ b/frontends/php/include/classes/ctag.inc.php
@@ -19,6 +19,14 @@
**/
?>
<?php
+ function fnc($c)
+ {
+ $ret = '<tr>';
+ foreach($c as $cc)
+ $ret .= '<td>'.$cc.'</td>';
+ $ret .= '</tr>';
+ return $ret;
+ }
class CTag
{
/* private */
@@ -34,6 +42,15 @@
var $tag_start;
var $tag_end;
+ function fnc($c)
+ {
+ $ret = '<tr>';
+ foreach($c as $cc)
+ $ret .= '<td>'.$cc.'</td>';
+ $ret .= '</tr>';
+ return $ret;
+ }
+
/* public */
function CTag($name=NULL, $paired='no', $body=NULL)
{
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index d4b1d540..2817675f 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -26,10 +26,10 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
include_once("include/copt.lib.php");
// GLOBALS
- $USER_DETAILS ="";
- $USER_RIGHTS ="";
- $ERROR_MSG ="";
- $INFO_MSG ="";
+ $USER_DETAILS = array();
+ $USER_RIGHTS = array();
+ $ERROR_MSG = array();
+ $INFO_MSG = array();
// END OF GLOBALS
// if magic quotes on then get rid of them
@@ -557,7 +557,6 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
}
*/
-
// The hash has form <md5sum of triggerid>,<sum of priorities>
function calc_trigger_hash()
{
@@ -2327,34 +2326,64 @@ COpt::profiling_start("page");
$res="All maps";
}
}
+ else if($permission=="Application")
+ {
+ if(isset($id)&&($id!=0))
+ {
+ $app = get_application_by_applicationid($id);
+ $res = $app["name"];
+ }
+ else
+ {
+ $res="All applications";
+ }
+ }
return $res;
}
- function get_profile($idx,$default_value)
+ function not_empty($var)
+ {
+ return ($var == "" ? 0 : 1);
+ }
+
+ function get_profile($idx,$default_value,$type=PROFILE_TYPE_UNCNOWN)
{
global $USER_DETAILS;
- if($USER_DETAILS["alias"]=="guest")
+ $result = $default_value;
+ if($USER_DETAILS["alias"]!="guest")
{
- return $default_value;
- }
+ $db_profiles = DBselect("select * from profiles where userid=".$USER_DETAILS["userid"]." and idx=".zbx_dbstr($idx));
- $sql="select value from profiles where userid=".$USER_DETAILS["userid"]." and idx=".zbx_dbstr($idx);
- $result=DBselect($sql);
+ if(DBnum_rows($db_profiles)==1)
+ {
+ $profile = DBfetch($db_profiles);
- if(DBnum_rows($result)==0)
+ if($type==PROFILE_TYPE_UNCNOWN)
+ $type = $profile["valuetype"];
+
+ $result = $profile["value"];
+ }
+ }
+ switch($type)
{
- return $default_value;
+ case PROFILE_TYPE_ARRAY: $result = explode(";", $result); break;
+ case PROFILE_TYPE_INT: $result = intval($result); break;
+ case PROFILE_TYPE_STR: $result = strval($result); break;
}
- else
+
+ if(is_array($result))
{
- $row=DBfetch($result);
- return $row["value"];
+ $result = array_filter($result, "not_empty");
}
+// SDI("Get profile:".$idx." = ".$result);
+ return $result;
}
- function update_profile($idx,$value)
+ function update_profile($idx,$value,$type=PROFILE_TYPE_UNCNOWN)
{
+// SDI("Save profile:".$idx." = ".$value);
+
global $USER_DETAILS;
if($USER_DETAILS["alias"]=="guest")
@@ -2362,18 +2391,30 @@ COpt::profiling_start("page");
return;
}
+ if($type==PROFILE_TYPE_UNCNOWN && is_array($value)) $type = PROFILE_TYPE_ARRAY;
+ if($type==PROFILE_TYPE_ARRAY && !is_array($value)) $value = array($value);
+
+ switch($type)
+ {
+ case PROFILE_TYPE_ARRAY: $value = implode(";", $value); break;
+ default: $value = strval($value);
+ }
+
+
$sql="select value from profiles where userid=".$USER_DETAILS["userid"]." and idx=".zbx_dbstr($idx);
$result=DBselect($sql);
if(DBnum_rows($result)==0)
{
- $sql="insert into profiles (userid,idx,value) values (".$USER_DETAILS["userid"].",".zbx_dbstr($idx).",".zbx_dbstr($value).")";
+ $sql="insert into profiles (userid,idx,value,valuetype)".
+ " values (".$USER_DETAILS["userid"].",".zbx_dbstr($idx).",".zbx_dbstr($value).",".$type.")";
DBexecute($sql);
}
else
{
$row=DBfetch($result);
- $sql="update profiles set value=".zbx_dbstr($value)." where userid=".$USER_DETAILS["userid"]." and idx=".zbx_dbstr($idx);
+ $sql="update profiles set value=".zbx_dbstr($value).",valuetype=".$type.
+ " where userid=".$USER_DETAILS["userid"]." and idx=".zbx_dbstr($idx);
DBexecute($sql);
}
}
@@ -2737,4 +2778,17 @@ COpt::profiling_start("page");
";
}
+ function natksort(&$array) {
+ $keys = array_keys($array);
+ natcasesort($keys);
+
+ $new_array = array();
+
+ foreach ($keys as $k) {
+ $new_array[$k] = $array[$k];
+ }
+
+ $array = $new_array;
+ return true;
+ }
?>
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php
index d1c1cf42..df6d7b98 100644
--- a/frontends/php/include/db.inc.php
+++ b/frontends/php/include/db.inc.php
@@ -151,6 +151,8 @@
{
global $DB_TYPE;
+ if(!$result) return 0;
+
if($DB_TYPE == "MYSQL")
{
return mysql_num_rows($result);
diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php
index e25b2761..8e371dee 100644
--- a/frontends/php/include/defines.inc.php
+++ b/frontends/php/include/defines.inc.php
@@ -206,6 +206,11 @@
define("MARK_COLOR_GREEN", 2);
define("MARK_COLOR_BLUE", 3);
+ define("PROFILE_TYPE_UNCNOWN", 0);
+ define("PROFILE_TYPE_ARRAY", 1);
+ define("PROFILE_TYPE_INT", 2);
+ define("PROFILE_TYPE_STR", 3);
+
/* 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 5eee69b5..aa631b00 100644
--- a/frontends/php/include/forms.inc.php
+++ b/frontends/php/include/forms.inc.php
@@ -162,6 +162,7 @@
$cmbRes->AddItem("Network map","Network map");
$cmbRes->AddItem("Trigger comment","Trigger comment");
$cmbRes->AddItem("User","User");
+ $cmbRes->AddItem("Application","Application");
$frmPerm->AddRow(S_RESOURCE,$cmbRes);
$cmbPerm = new CComboBox("permission");
@@ -274,6 +275,7 @@
$multiplier = get_request("multiplier" ,0);
$delta = get_request("delta" ,0);
$trends = get_request("trends" ,365);
+ $applications = get_request("applications" ,array());
$snmpv3_securityname = get_request("snmpv3_securityname" ,"");
$snmpv3_securitylevel = get_request("snmpv3_securitylevel" ,0);
@@ -329,7 +331,17 @@
$formula = $row["formula"];
$logtimefmt = $row["logtimefmt"];
+
+ $db_applications = get_applications_by_itemid($_REQUEST["itemid"]);
+ while($db_app = DBfetch($db_applications))
+ {
+ if(in_array($db_app["applicationid"],$applications)) continue;
+ array_push($applications,$db_app["applicationid"]);
+ }
+
}
+ if(count($applications)==0) array_push($applications,0);
+
if(isset($_REQUEST["itemid"])) {
$frmItem->SetTitle(S_ITEM." '$host:".$row["description"]."'");
} else {
@@ -483,7 +495,10 @@
$db_valuemaps = DBselect("select * from valuemaps");
while($db_valuemap = DBfetch($db_valuemaps))
$cmbMap->AddItem($db_valuemap["valuemapid"],$db_valuemap["name"]);
- $frmItem->AddRow(S_SHOW_VALUE,$cmbMap);
+
+ $link = new CLink("throw map","config.php?config=6","action");
+ $link->AddOption("target","_blank");
+ $frmItem->AddRow(array(S_SHOW_VALUE.SPACE,$link),$cmbMap);
}
else
@@ -500,6 +515,16 @@
$frmItem->AddVar("trapper_hosts",$trapper_hosts);
}
+ $cmbApps = new CListBox("applications[]",$applications,6);
+ $cmbApps->AddItem(0,"-".S_NONE."-");
+ $db_applications = DBselect("select distinct applicationid,name from applications".
+ " where hostid=".$_REQUEST["hostid"]." order by name");
+ while($db_app = DBfetch($db_applications))
+ {
+ $cmbApps->AddItem($db_app["applicationid"],$db_app["name"]);
+ }
+ $frmItem->AddRow(S_APPLICATIONS,$cmbApps);
+
$frmRow = array(new CButton("save",S_SAVE));
if(isset($_REQUEST["itemid"]))
{
@@ -2234,6 +2259,77 @@
$frmHostP->Show();
}
+ function insert_application_form()
+ {
+ global $_REQUEST;
+
+ $frm_title = "New Application";
+
+ if(isset($_REQUEST["applicationid"]))
+ {
+ $result=DBselect("select * from applications where applicationid=".$_REQUEST["applicationid"]);
+ $row=DBfetch($result);
+ $frm_title = "Application: \"".$row["name"]."\"";
+ }
+ if(isset($_REQUEST["applicationid"]) && !isset($_REQUEST["form_refresh"]))
+ {
+ $appname = $row["name"];
+ $apphostid = $row["hostid"];
+ }
+ else
+ {
+ $appname = get_request("appname","");
+ $apphostid = get_request("apphostid",get_request("hostid",0));
+ }
+
+ $db_host = get_host_by_hostid($apphostid,1 /* no error message */);
+ if($db_host)
+ {
+ $apphost = $db_host["host"];
+ }
+ else
+ {
+ $apphost = "";
+ $apphostid = 0;
+ }
+
+ $frmApp = new CFormTable($frm_title);
+ $frmApp->SetHelp("web.applications.php");
+
+ if(isset($_REQUEST["applicationid"]))
+ $frmApp->AddVar("applicationid",$_REQUEST["applicationid"]);
+
+ $frmApp->AddRow(S_NAME,new CTextBox("appname",$appname,32));
+
+ $frmApp->AddVar("apphostid",$apphostid);
+
+ if(!isset($_REQUEST["applicationid"]))
+ { // anly new application can select host
+ $frmApp->AddRow(S_HOST,array(
+ new CTextBox("apphost",$apphost,32,NULL,'yes'),
+ new CButton("btn1",S_SELECT,
+ "return PopUp('popup.php?dstfrm=".$frmApp->GetName().
+ "&dstfld1=apphostid&dstfld2=apphost&srctbl=hosts&srcfld1=hostid&srcfld2=host','new_win',".
+ "'width=450,height=450,resizable=1,scrollbars=1');",
+ 'T')
+ ));
+ }
+
+ $frmApp->AddItemToBottomRow(new CButton("save",S_SAVE));
+ if(isset($_REQUEST["applicationid"]))
+ {
+ $frmApp->AddItemToBottomRow(SPACE);
+ $frmApp->AddItemToBottomRow(new CButtonDelete("Delete this application?",
+ url_param("config").url_param("hostid").url_param("groupid").
+ url_param("form").url_param("applicationid")));
+ }
+ $frmApp->AddItemToBottomRow(SPACE);
+ $frmApp->AddItemToBottomRow(new CButtonCancel(url_param("config").url_param("hostid").url_param("groupid")));
+
+ $frmApp->Show();
+
+ }
+
function insert_map_form()
{
global $_REQUEST;
diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php
index 569d9793..2f31cb34 100644
--- a/frontends/php/include/hosts.inc.php
+++ b/frontends/php/include/hosts.inc.php
@@ -244,6 +244,7 @@
if($host["templateid"] > 0)
{
// start host syncing
+ sync_applications_with_template($hostid);
sync_items_with_template($hostid);
sync_triggers_with_template($hostid);
sync_graphs_with_templates($hostid);
@@ -337,7 +338,7 @@
return FALSE;
}
- function get_host_by_hostid($hostid)
+ function get_host_by_hostid($hostid,$no_error_message=0)
{
$sql="select * from hosts where hostid=$hostid";
$result=DBselect($sql);
@@ -345,7 +346,8 @@
{
return DBfetch($result);
}
- error("No host with hostid=[$hostid]");
+ if($no_error_message == 0)
+ error("No host with hostid=[$hostid]");
return FALSE;
}
@@ -491,7 +493,7 @@
$hostid = 0;
}
- if(($hostid < 0) || ($hostid == 0 && !($allow_all_hosts ==1 && $groupid==0)))
+ if(($hostid < 0) || ($hostid == 0 && !($allow_all_hosts ==1 && $groupid==0)))
{
$hostid = $first_hostig_in_group;
}
@@ -515,7 +517,7 @@
function validate_group_with_host($right, $options = array(),$group_var=NULL,$host_var=NULL)
{
if(is_null($group_var)) $group_var = "web.latest.groupid";
- if(is_null($host_var)) $host_var = "web.latest.hostid";
+ if(is_null($host_var)) $host_var = "web.latest.hostid";
$_REQUEST["groupid"] = get_request("groupid",get_profile($group_var,0));
$_REQUEST["hostid"] = get_request("hostid",get_profile($host_var,
@@ -542,4 +544,185 @@
update_profile($group_var,$_REQUEST["groupid"]);
}
+
+/* APPLICATIONS */
+
+ function db_save_application($name,$hostid,$applicationid=NULL,$templateid=0)
+ {
+ if(!is_string($name)){
+ error("incorrect parameters for 'db_save_application'");
+ return FALSE;
+ }
+
+ if($applicationid==NULL)
+ $result = DBexecute("select * from applications where name=".zbx_dbstr($name)." and hostid=".$hostid);
+ else
+ $result = DBexecute("select * from applications where name=".zbx_dbstr($name)." and hostid=".$hostid.
+ " and applicationid<>$applicationid");
+
+ $match_cnt = DBnum_rows($result);
+ if($match_cnt > 0)
+ {
+ $db_app = DBfetch($result);;
+ }
+ if($match_cnt > 0 && $templateid==0)
+ {
+ error("Application '$name' already exists");
+ return FALSE;
+ }
+ if($match_cnt > 0 && $applicationid!=NULL)
+ { // delete old item with same name
+ delete_application($db_app["applicationid"]);
+ }
+
+ if($match_cnt > 0 && $applicationid==NULL)
+ { // if found application with same name update them, adding not needed
+ $applicationid = $db_app["applicationid"];
+ }
+
+ $host = get_host_by_hostid($hostid);
+
+ if($applicationid==NULL)
+ {
+ if($result = DBexecute("insert into applications (name,hostid,templateid)".
+ " values (".zbx_dbstr($name).",$hostid,$templateid)"))
+ info("Added new application ".$host["host"].":$name");
+ }
+ else
+ {
+ $old_app = get_application_by_applicationid($applicationid);
+ if($result = DBexecute("update applications set name=".zbx_dbstr($name).",hostid=$hostid,templateid=$templateid".
+ " where applicationid=$applicationid"))
+ info("Updated application ".$host["host"].":".$old_app["name"]);
+ }
+
+ if(!$result) return $result;
+
+ if($applicationid==NULL)
+ {
+ $applicationid = DBinsert_id($result,"applications","applicationid");
+
+ $db_childs = get_hosts_by_templateid($hostid);
+ while($db_child = DBfetch($db_childs))
+ {// recursion
+ $result = add_application($name,$db_child["hostid"],$applicationid);
+ if(!$result) break;
+ }
+ }
+ else
+ {
+ $db_applications = get_applications_by_templateid($applicationid);
+ while($db_app = DBfetch($db_applications))
+ {// recursion
+ $result = update_application($db_app["applicationid"],$name,$db_app["hostid"],$applicationid);
+ if(!$result) break;
+ }
+ }
+
+ if($result)
+ return $applicationid;
+
+ if($templateid == 0){
+ delete_application($itemid);
+ }
+
+ }
+ function add_application($name,$hostid,$templateid=0)
+ {
+ return db_save_application($name,$hostid,NULL,$templateid);
+ }
+
+ function update_application($applicationid,$name,$hostid,$templateid=0)
+ {
+ return db_save_application($name,$hostid,$applicationid,$templateid);
+ }
+
+ function delete_application($applicationid)
+ {
+ $app = get_application_by_applicationid($applicationid);
+ $host = get_host_by_hostid($app["hostid"]);
+
+ // first delete child applications
+ $db_applications = DBselect("select applicationid from applications where templateid=$applicationid");
+ while($db_app = DBfetch($db_applications))
+ {// recursion
+ $result = delete_application($db_app["applicationid"]);
+ if(!$result) return $result;
+ }
+
+ $result = DBexecute("delete from items_applications where applicationid=$applicationid");
+
+ $result = DBexecute("delete from applications where applicationid=$applicationid");
+ if($result)
+ {
+ info("Application '".$host["host"].":".$app["name"]."' deleted");
+ }
+ return $result;
+ }
+
+ function get_application_by_applicationid($applicationid,$no_error_message=0)
+ {
+ $result = DBselect("select * from applications where applicationid=".$applicationid);
+ if(DBnum_rows($result) == 1)
+ {
+ return DBfetch($result);
+ }
+ if($no_error_message == 0)
+ error("No application with id=[$applicationid]");
+ return FALSE;
+
+ }
+
+ function get_applications_by_templateid($applicationid)
+ {
+ return DBselect("select * from applications where templateid=".$applicationid);
+ }
+
+ function get_realhost_by_applicationid($applicationid)
+ {
+ $application = get_application_by_applicationid($applicationid);
+ if($application["templateid"] > 0)
+ return get_realhost_by_applicationid($application["templateid"]);
+
+ return get_host_by_applicationid($applicationid);
+ }
+
+ function get_host_by_applicationid($applicationid)
+ {
+ $sql="select h.* from hosts h, applications a where a.hostid=h.hostid and a.applicationid=$applicationid";
+ $result=DBselect($sql);
+ if(DBnum_rows($result) == 1)
+ {
+ return DBfetch($result);
+ }
+ error("No host with applicationid=[$applicationid]");
+ return FALSE;
+ }
+
+ function get_items_by_applicationid($applicationid)
+ {
+ return DBselect("select i.* from items i,items_applications ia where i.itemid=ia.itemid and ia.applicationid=$applicationid");
+ }
+
+ function get_applications_by_hostid($hostid)
+ {
+ return DBselect("select * from applications where hostid=$hostid");
+ }
+
+ function sync_applications_with_template($hostid)
+ {
+ $host = get_host_by_hostid($hostid);
+
+//SDI("sync host: ".$host['host']);
+
+ $db_tmp_applications = get_applications_by_hostid($host["templateid"]);
+
+ while($db_tmp_app = DBfetch($db_tmp_applications))
+ {
+ add_application(
+ $db_tmp_app["name"],
+ $hostid,
+ $db_tmp_app["applicationid"]);
+ }
+ }
?>
diff --git a/frontends/php/include/html.inc.php b/frontends/php/include/html.inc.php
index 61ec6dca..9a4f593a 100644
--- a/frontends/php/include/html.inc.php
+++ b/frontends/php/include/html.inc.php
@@ -89,14 +89,20 @@
{
global $_REQUEST;
+ $result = "";
if(isset($_REQUEST[$parameter]))
{
- return "&$parameter=".$_REQUEST[$parameter];
- }
- else
- {
- return "";
+ if(is_array($_REQUEST[$parameter]))
+ {
+ foreach($_REQUEST[$parameter] as $par)
+ $result .= "&".$parameter."[]=".$par;
+ }
+ else
+ {
+ $result = "&".$parameter."=".$_REQUEST[$parameter];
+ }
}
+ return $result;
}
function table_begin($class="tableinfo")
diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php
index 29fbf33f..bd9a2dda 100644
--- a/frontends/php/include/items.inc.php
+++ b/frontends/php/include/items.inc.php
@@ -21,13 +21,13 @@
<?php
# Update Item definition for selected group
- function update_item_in_group($groupid,$itemid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid)
+ function update_item_in_group($groupid,$itemid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid,$applications)
{
$sql="select i.itemid,i.hostid from hosts_groups hg,items i where hg.groupid=$groupid and i.key_=".zbx_dbstr($key)." and hg.hostid=i.hostid";
$result=DBexecute($sql);
while($row=DBfetch($result))
{
- update_item($row["itemid"],$description,$key,$row["hostid"],$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid);
+ update_item($row["itemid"],$description,$key,$row["hostid"],$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid,$applications);
}
return 1;
}
@@ -60,13 +60,13 @@
# Add Item definition to selected group
- function add_item_to_group($groupid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid)
+ function add_item_to_group($groupid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid,$applications)
{
$sql="select hostid from hosts_groups where groupid=$groupid";
$result=DBexecute($sql);
while($row=DBfetch($result))
{
- add_item($description,$key,$row["hostid"],$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid);
+ add_item($description,$key,$row["hostid"],$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid,$applications);
}
return 1;
}
@@ -77,7 +77,7 @@
$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,
$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,
$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,
- $valuemapid,$templateid=0)
+ $valuemapid,$applications,$templateid=0)
{
$host=get_host_by_hostid($hostid);
@@ -87,6 +87,9 @@
return FALSE;
}
+ if(($i = array_search(0,$applications)) !== FALSE)
+ unset($applications[$i]);
+
if($delay<1)
{
error("Delay cannot be less than 1 second");
@@ -157,7 +160,9 @@
$value_type, $trapper_hosts, $snmp_port, $units, $multiplier,
$delta, $snmpv3_securityname, $snmpv3_securitylevel,
$snmpv3_authpassphrase, $snmpv3_privpassphrase, $formula,
- $trends, $logtimefmt, $valuemapid, $templateid);
+ $trends, $logtimefmt, $valuemapid,
+ get_same_applications_for_host($applications, $db_item["hostid"]),
+ $templateid);
return $result;
}
@@ -180,6 +185,12 @@
return $result;
$itemid = DBinsert_id($result,"items","itemid");
+
+ foreach($applications as $appid)
+ {
+ DBexecute("insert into items_applications (itemid,applicationid) values(".$itemid.",".$appid.")");
+ }
+
info("Added new item ".$host["host"].":$key");
// add items to child hosts
@@ -193,7 +204,9 @@
$value_type, $trapper_hosts, $snmp_port, $units, $multiplier,
$delta, $snmpv3_securityname, $snmpv3_securitylevel,
$snmpv3_authpassphrase, $snmpv3_privpassphrase, $formula,
- $trends, $logtimefmt, $valuemapid, $itemid);
+ $trends, $logtimefmt, $valuemapid,
+ get_same_applications_for_host($applications, $db_host["hostid"]),
+ $itemid);
if(!$result)
break;
}
@@ -231,7 +244,7 @@
function update_item($itemid,$description,$key,$hostid,$delay,$history,$status,$type,
$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,
$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,
- $formula,$trends,$logtimefmt,$valuemapid,$templateid=0)
+ $formula,$trends,$logtimefmt,$valuemapid,$applications,$templateid=0)
{
$host = get_host_by_hostid($hostid);
@@ -241,6 +254,9 @@
return FALSE;
}
+ if(($i = array_search(0,$applications)) !== FALSE)
+ unset($applications[$i]);
+
if($delay<1)
{
error("Delay cannot be less than 1 second");
@@ -258,7 +274,7 @@
$delta=0;
}
- $db_items = DBexecute("select itemid as cnt from items".
+ $db_items = DBexecute("select itemid from items".
" where hostid=$hostid and itemid<>$itemid and key_=".zbx_dbstr($key));
if(DBnum_rows($db_items) > 0 && $templateid == 0)
{
@@ -278,7 +294,10 @@
$value_type, $trapper_hosts, $snmp_port, $units, $multiplier,
$delta, $snmpv3_securityname, $snmpv3_securitylevel,
$snmpv3_authpassphrase, $snmpv3_privpassphrase, $formula,
- $trends, $logtimefmt, $valuemapid, $itemid);
+ $trends, $logtimefmt, $valuemapid,
+ get_same_applications_for_host($applications, $db_tmp_item["hostid"]),
+ $itemid);
+
if(!$result)
return $result;
@@ -286,13 +305,12 @@
if(DBnum_rows($db_items) > 0 && $templateid != 0)
{
- $result = delete_item($itemid);
+ $db_item = DBfetch($db_items);
+ $result = delete_item($db_item["itemid"]);
if(!$result) {
error("Can't update item '".$host["host"].":$key'");
return FALSE;
}
- $db_item = DBfetch($db_items);
- $itemid = $db_item("itemid");
}
DBexecute("update items set lastlogsize=0 where itemid=$itemid and key_<>".zbx_dbstr($key));
@@ -301,6 +319,10 @@
update_item_status($itemid, $status);
}
+ $result = DBexecute("delete from items_applications where itemid=$itemid");
+ foreach($applications as $appid)
+ DBexecute("insert into items_applications (itemid,applicationid) values(".$itemid.",".$appid.")");
+
$result=DBexecute(
"update items set description=".zbx_dbstr($description).",key_=".zbx_dbstr($key).",".
"hostid=$hostid,delay=$delay,history=$history,nextcheck=0,type=$type,".
@@ -341,6 +363,13 @@
while($db_tmp_item = DBfetch($db_tmp_items))
{
+ $parrent_applications = array();
+ $db_applications = get_applications_by_itemid($db_tmp_item["itemid"]);
+ while($db_application = DBfetch($db_applications))
+ array_push($parrent_applications,$db_application["applicationid"]);
+
+ $applications = get_same_applications_for_host($parrent_applications,$hostid);
+
add_item(
$db_tmp_item["description"],
$db_tmp_item["key_"],
@@ -365,6 +394,7 @@
$db_tmp_item["trends"],
$db_tmp_item["logtimefmt"],
$db_tmp_item["valuemapid"],
+ $applications,
$db_tmp_item["itemid"]);
}
}
@@ -446,6 +476,9 @@
if(!$result) return $result;
+ $result = DBexecute("delete from items_applications where itemid=$itemid");
+ if(!$result) return $result;
+
$result = DBexecute("delete from items where itemid=$itemid");
if($result)
{
@@ -524,11 +557,11 @@
while($item = DBfetch($db_items))
{
$table_row = array(nbsp($item["description"]));
- $host_added = 0;
+ $hosts_added = 0;
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"]));
+ " hostid=$hostid and status=".ITEM_STATUS_ACTIVE." and description=".zbx_dbstr($item["description"]));
if(DBnum_rows($db_host_items)!=1)
{
array_push($table_row,"-");
@@ -538,7 +571,23 @@
if(!check_right("Item","R",$host_item["itemid"])) continue;
- ++$host_added; // added corect host item;
+ $access = 0;
+ $db_applications = get_applications_by_itemid($host_item["itemid"]);
+ while($db_app = DBfetch($db_applications))
+ {
+ if(!check_right("Application","R",$db_app["applicationid"]))
+ $access |= 1;
+ else
+ $access |= 2;
+ }
+ if($access == 1)
+ {
+ array_push($table_row,"-");
+ continue;
+ }
+
+ $hosts_added++; // exist item in host
+
if(!isset($host_item["lastvalue"]))
{
array_push($table_row,"-");
@@ -558,8 +607,29 @@
array_push($table_row,new CCol(nbsp($value),$style));
}
- if($host_added > 0) $table->AddRow($table_row);
+ if($hosts_added > 0) $table->AddRow($table_row);
}
return $table;
}
+
+ function get_same_applications_for_host($applications, $hostid)
+ {
+ $child_applications = array();
+
+ foreach($applications as $appid)
+ {
+ $db_apps = DBselect("select a1.applicationid from applications a1, applications a2".
+ " where a1.name=a2.name and a1.hostid=".$hostid." and a2.applicationid=".$appid);
+ $db_app = DBfetch($db_apps);
+ if(!$db_app) continue;
+ array_push($child_applications,$db_app["applicationid"]);
+ }
+ return $child_applications;
+ }
+
+ function get_applications_by_itemid($itemid)
+ {
+ return DBselect("select distinct app.* from applications app, items_applications ia".
+ " where app.applicationid=ia.applicationid and ia.itemid=".$itemid);
+ }
?>
diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php
index 7cac9097..4d03473c 100644
--- a/frontends/php/include/locales/en_gb.inc.php
+++ b/frontends/php/include/locales/en_gb.inc.php
@@ -270,6 +270,9 @@
"S_NO_PERMISSIONS"=> "No permissions !",
"S_LATEST_DATA_BIG"=> "LATEST DATA",
"S_ALL_SMALL"=> "all",
+ "S_ALL"=> "All",
+ "S_MINUS_ALL_MINUS"=> "- all -",
+ "S_MINUS_OTHER_MINUS"=> "- other -",
"S_DESCRIPTION_LARGE"=> "DESCRIPTION",
"S_DESCRIPTION_SMALL"=> "Description",
"S_GRAPH"=> "Graph",
@@ -342,6 +345,20 @@
"S_AS_BLUE"=> "as Blue",
// hosts.php
+ "S_APPLICATION"=> "Application",
+ "S_APPLICATIONS"=> "Applications",
+ "S_APPLICATIONS_BIG"=> "APPLICATIONS",
+ "S_CREATE_APPLICATION"=> "Create application",
+ "S_DELETE_SELECTED_APPLICATIONS_Q"=> "Delete selected applications?",
+ "S_DISABLE_ITEMS_FROM_SELECTED_APPLICATIONS_Q"=>"Disable items from selected applications?",
+ "S_ACTIVATE_ITEMS_FROM_SELECTED_APPLICATIONS_Q"=>"Activate items from selected applications?",
+ "S_APPLICATION_UPDATED"=> "Application updated",
+ "S_CANNOT_UPDATE_APPLICATION"=> "Cannot update application",
+ "S_APPLICATION_ADDED"=> "Application added",
+ "S_CANNOT_ADD_APPLICATION"=> "Cannot add application",
+ "S_APPLICATION_DELETED"=> "Application deleted",
+ "S_CANNOT_DELETE_APPLICATION"=> "Cannot delete application",
+
"S_HOSTS"=> "Hosts",
"S_ITEMS"=> "Items",
"S_ITEMS_BIG"=> "ITEMS",