diff options
author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-05-03 06:35:28 +0000 |
---|---|---|
committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-05-03 06:35:28 +0000 |
commit | cff3cc1ef8b6ac526e7968be6a10c09669461be1 (patch) | |
tree | cdb8c67a959922a86e98a01b6104f52c3828b786 /frontends | |
parent | 50cb63535597c91584f08f6d6f00cfcdbe0dd198 (diff) | |
download | zabbix-cff3cc1ef8b6ac526e7968be6a10c09669461be1.tar.gz zabbix-cff3cc1ef8b6ac526e7968be6a10c09669461be1.tar.xz zabbix-cff3cc1ef8b6ac526e7968be6a10c09669461be1.zip |
- 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')
21 files changed, 993 insertions, 93 deletions
diff --git a/frontends/php/history.php b/frontends/php/history.php index f65e8556..12f2da5c 100644 --- a/frontends/php/history.php +++ b/frontends/php/history.php @@ -457,9 +457,7 @@ $sql = "select h.clock,h.value,i.valuemapid from $h_table h, items i". " where h.itemid=i.itemid and i.itemid=".$_REQUEST["itemid"]. $cond_clock." order by clock desc".$cond_limit; - $result=DBselect($sql); - if(!isset($_REQUEST["plaintext"])) { $tbl_msg = DBnum_rows($result) > 1 ? NULL : "..."; @@ -477,6 +475,7 @@ $i=0; while($row=DBfetch($result)) { + $value = replace_value_by_map($row["value"], $row["valuemapid"]); $new_row = array(date("Y.M.d H:i:s",$row["clock"])); @@ -495,7 +494,7 @@ $table->evenRowClass : $table->oddRowClass ); - $crow->Show(); // to solve memory leak we call 'Show' method for each element + $crow->Show(); $i++; } else diff --git a/frontends/php/hosts.php b/frontends/php/hosts.php index a030232a..5f3a3a43 100644 --- a/frontends/php/hosts.php +++ b/frontends/php/hosts.php @@ -40,10 +40,13 @@ <?php // VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION $fields=array( - "config"=> array(T_ZBX_INT, O_OPT, P_SYS, IN("0,1,2,3"), NULL), + // 0 - hosts; 1 - groups; 2 - linkages; 3 - templates; 4 - applications + "config"=> array(T_ZBX_INT, O_OPT, P_SYS, IN("0,1,2,3,4"), NULL), +/* ARAYS */ "hosts"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), "groups"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), + "applications"=>array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), /* host */ "hostid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, '{config}==0&&{form}=="update"'), "host"=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, '{config}==0&&isset({save})'), @@ -71,6 +74,12 @@ "groupid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, '{config}==1&&{form}=="update"'), "gname"=> array(T_ZBX_STR, O_NO, NULL, NOT_EMPTY, '{config}==1&&isset({save})'), +/* application */ + "applicationid"=>array(T_ZBX_INT,O_OPT, P_SYS, DB_ID, '{config}==4&&{form}=="update"'), + "appname"=> array(T_ZBX_STR, O_NO, NULL, NOT_EMPTY, '{config}==4&&isset({save})'), + "apphostid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, '{config}==4&&isset({save})'), + "apptemplateid"=>array(T_ZBX_INT,O_OPT, NULL, DB_ID, NULL), + /* actions */ "activate"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), "disable"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), @@ -85,7 +94,10 @@ check_fields($fields); - validate_group("U"); + if($_REQUEST["config"]==4) + validate_group_with_host("U"); + elseif($_REQUEST["config"]==0 || $_REQUEST["config"]==3) + validate_group("U"); update_profile("web.hosts.config",$_REQUEST["config"]); update_profile("web.menu.config.last",$page["file"]); @@ -298,6 +310,64 @@ show_messages($result, S_HOST_STATUS_UPDATED, NULL); unset($_REQUEST["activate"]); } + + if($_REQUEST["config"]==4 && isset($_REQUEST["save"])) + { + if(isset($_REQUEST["applicationid"])) + { + $result = update_application($_REQUEST["applicationid"],$_REQUEST["appname"], $_REQUEST["apphostid"]); + $msg_ok = S_APPLICATION_UPDATED; + $msg_fail = S_CANNOT_UPDATE_APPLICATION; + $applicationid = $_REQUEST["applicationid"]; + } else { + $applicationid = add_application($_REQUEST["appname"], $_REQUEST["apphostid"]); + $msg_ok = S_APPLICATION_ADDED; + $msg_fail = S_CANNOT_ADD_APPLICATION; + $result = $applicationid; + } + show_messages($result, $msg_ok, $msg_fail); + if($result){ + unset($_REQUEST["form"]); + } + unset($_REQUEST["save"]); + } + elseif($_REQUEST["config"]==4 && isset($_REQUEST["delete"])) + { + if(isset($_REQUEST["applicationid"])){ + $app = get_application_by_applicationid($_REQUEST["applicationid"]); + $host=get_host_by_hostid($app["hostid"]); + $result=delete_application($_REQUEST["applicationid"]); + + show_messages($result, S_APPLICATION_DELETED, S_CANNOT_DELETE_APPLICATION); + if($result) + { +// TODO add_audit(AUDIT_ACTION_DELETE,AUDIT_RESOURCE_APPLICATION, +// TODO "Application [".$app["name"]."] from host [".$host["host"]."]"); + + unset($_REQUEST["form"]); + unset($_REQUEST["applicationid"]); + } + } else { +/* group operations */ + $result = 0; + $applications = get_request("applications",array()); + + $db_applications = DBselect("select applicationid from applications"); + while($db_app = DBfetch($db_applications)) + { + if(!in_array($db_app["applicationid"],$applications)) continue; + if(!delete_application($db_app["applicationid"])) continue; + $result = 1; + +// TODO add_audit(AUDIT_ACTION_DELETE,AUDIT_RESOURCE_APPLICATION, +// TODO "Application [".$app["name"]."] from host [".$host["host"]."]"); + } + show_messages($result, S_APPLICATION_DELETED, NULL); + } + unset($_REQUEST["delete"]); + } + + ?> <?php @@ -309,6 +379,9 @@ $cmbConf->AddItem(1,S_HOST_GROUPS); $cmbConf->AddItem(2,S_TEMPLATE_LINKAGE); + if(check_anyright("Application","U")) + $cmbConf->AddItem(4,S_APPLICATIONS); + switch($_REQUEST["config"]){ case 0: $btn = new CButton("form",S_CREATE_HOST); @@ -321,6 +394,10 @@ case 1: $btn = new CButton("form",S_CREATE_GROUP); break; + case 4: + $btn = new CButton("form",S_CREATE_APPLICATION); + $frmForm->AddVar("hostid",get_request("hostid",0)); + break; case 2: break; } @@ -614,6 +691,137 @@ $table->Show(); } + elseif($_REQUEST["config"]==4) + { + if(!check_anyright("Application","U")) + { + show_table_header("<font color=\"AA0000\">".S_NO_PERMISSIONS."</font>"); + show_page_footer(); + exit; + } + + if(isset($_REQUEST["form"])) + { + insert_application_form(); + } else { + // Table HEADER + $form = new CForm(); + + $_REQUEST["groupid"] = get_request("groupid",0); + $cmbGroup = new CComboBox("groupid",$_REQUEST["groupid"],"submit();"); + $cmbGroup->AddItem(0,S_ALL_SMALL); + $result=DBselect("select groupid,name from groups order by name"); + while($row=DBfetch($result)) + { + // Check if at least one host with read permission exists for this group + $result2=DBselect("select h.hostid,h.host from hosts h,hosts_groups hg". + " where hg.groupid=".$row["groupid"]." and hg.hostid=h.hostid and". + " h.status<>".HOST_STATUS_DELETED." group by h.hostid,h.host order by h.host"); + while($row2=DBfetch($result2)) + { + if(!check_right("Host","U",$row2["hostid"])) continue; + $cmbGroup->AddItem($row["groupid"],$row["name"]); + break; + } + } + $form->AddItem(S_GROUP.SPACE); + $form->AddItem($cmbGroup); + + if(isset($_REQUEST["groupid"]) && $_REQUEST["groupid"]>0) + { + $sql="select h.hostid,h.host from hosts h,hosts_groups hg". + " where hg.groupid=".$_REQUEST["groupid"]." and hg.hostid=h.hostid and". + " h.status<>".HOST_STATUS_DELETED." group by h.hostid,h.host order by h.host"; + } + else + { + $sql="select h.hostid,h.host from hosts h where h.status<>".HOST_STATUS_DELETED. + " group by h.hostid,h.host order by h.host"; + } + + $result=DBselect($sql); + + $_REQUEST["hostid"] = get_request("hostid",0); + $cmbHosts = new CComboBox("hostid",$_REQUEST["hostid"],"submit();"); + + $correct_hostid='no'; + $first_hostid = -1; + while($row=DBfetch($result)) + { + if(!check_right("Host","U",$row["hostid"])) continue; + $cmbHosts->AddItem($row["hostid"],$row["host"]); + + if($_REQUEST["hostid"]!=0){ + if($_REQUEST["hostid"]==$row["hostid"]) + $correct_hostid = 'ok'; + } + if($first_hostid <= 0) + $first_hostid = $row["hostid"]; + } + if($correct_hostid!='ok') + $_REQUEST["hostid"] = $first_hostid; + + $form->AddItem(SPACE.S_HOST.SPACE); + $form->AddItem($cmbHosts); + + show_header2(S_APPLICATIONS_BIG, $form); + + + $form = new CForm(); + $form->SetName('applications'); + + $table = new CTableInfo(); + $table->SetHeader(array( + array(new CCheckBox("all_applications",NULL,NULL, + "CheckAll('".$form->GetName()."','all_applications');"), + SPACE, + S_ID), + S_APPLICATION, + S_SHOW + )); + + $db_applications = DBselect("select * from applications where hostid=".$_REQUEST["hostid"]); + while($db_app = DBfetch($db_applications)) + { + if($db_app["templateid"]==0) + { + $name = new CLink( + $db_app["name"], + "hosts.php?form=update&applicationid=".$db_app["applicationid"]. + url_param("config"),'action'); + } else { + $template_host = get_realhost_by_applicationid($db_app["templateid"]); + $name = array( + new CLink($template_host["host"], + "hosts.php?hostid=".$template_host["hostid"].url_param("config"), + 'action'), + ":", + $db_app["name"] + ); + } + $table->AddRow(array( + array(new CCheckBox("applications[]",NULL,NULL,NULL,$db_app["applicationid"]), + SPACE, + $db_app["applicationid"]), + $name, + array(new CLink(S_ITEMS,"items.php?hostid=".$db_app["hostid"],"action"), + SPACE."(".DBnum_rows(get_items_by_applicationid($db_app["applicationid"])).")") + )); + } + $footerButtons = array(); + array_push($footerButtons, new CButton('activate','Activate Items', + "return Confirm('".S_ACTIVATE_ITEMS_FROM_SELECTED_APPLICATIONS_Q."');")); + array_push($footerButtons, SPACE); + array_push($footerButtons, new CButton('disable','Disable Items', + "return Confirm('".S_DISABLE_ITEMS_FROM_SELECTED_APPLICATIONS_Q."');")); + array_push($footerButtons, SPACE); + array_push($footerButtons, new CButton('delete','Delete selected', + "return Confirm('".S_DELETE_SELECTED_APPLICATIONS_Q."');")); + $table->SetFooter(new CCol($footerButtons)); + $form->AddItem($table); + $form->Show(); + } + } ?> <?php show_page_footer(); diff --git a/frontends/php/images/general/closed.gif b/frontends/php/images/general/closed.gif Binary files differnew file mode 100644 index 00000000..a4c4c248 --- /dev/null +++ b/frontends/php/images/general/closed.gif diff --git a/frontends/php/images/general/opened.gif b/frontends/php/images/general/opened.gif Binary files differnew file mode 100644 index 00000000..19a4cc43 --- /dev/null +++ b/frontends/php/images/general/opened.gif diff --git a/frontends/php/images/general/sortdown.gif b/frontends/php/images/general/sortdown.gif Binary files differnew file mode 100644 index 00000000..44fd1bbb --- /dev/null +++ b/frontends/php/images/general/sortdown.gif diff --git a/frontends/php/images/general/sortdown_off.gif b/frontends/php/images/general/sortdown_off.gif Binary files differnew file mode 100644 index 00000000..add54866 --- /dev/null +++ b/frontends/php/images/general/sortdown_off.gif diff --git a/frontends/php/images/general/sortup.gif b/frontends/php/images/general/sortup.gif Binary files differnew file mode 100644 index 00000000..6a836674 --- /dev/null +++ b/frontends/php/images/general/sortup.gif diff --git a/frontends/php/images/general/sortup_off.gif b/frontends/php/images/general/sortup_off.gif Binary files differnew file mode 100644 index 00000000..e52c2a8a --- /dev/null +++ b/frontends/php/images/general/sortup_off.gif 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", diff --git a/frontends/php/items.php b/frontends/php/items.php index 972dfc07..73735bc8 100644 --- a/frontends/php/items.php +++ b/frontends/php/items.php @@ -76,7 +76,8 @@ "formula"=> array(T_ZBX_DBL, O_OPT, NULL, NULL,'isset({save})&&{multiplier}==1'), "logtimefmt"=> array(T_ZBX_STR, O_OPT, NULL, NULL,'isset({save})&&{value_type}==2'), - "group_itemid"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID, NULL), + "group_itemid"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID, NULL), + "applications"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID, NULL), "del_history"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), @@ -111,6 +112,7 @@ } else if(isset($_REQUEST["save"])) { + $applications = get_request("applications",array()); if(isset($_REQUEST["itemid"])) { $result=update_item($_REQUEST["itemid"], @@ -121,7 +123,7 @@ $_REQUEST["multiplier"],$_REQUEST["delta"],$_REQUEST["snmpv3_securityname"], $_REQUEST["snmpv3_securitylevel"],$_REQUEST["snmpv3_authpassphrase"], $_REQUEST["snmpv3_privpassphrase"],$_REQUEST["formula"],$_REQUEST["trends"], - $_REQUEST["logtimefmt"],$_REQUEST["valuemapid"]); + $_REQUEST["logtimefmt"],$_REQUEST["valuemapid"],$applications); show_messages($result, S_ITEM_UPDATED, S_CANNOT_UPDATE_ITEM); } @@ -135,7 +137,7 @@ $_REQUEST["multiplier"],$_REQUEST["delta"],$_REQUEST["snmpv3_securityname"], $_REQUEST["snmpv3_securitylevel"],$_REQUEST["snmpv3_authpassphrase"], $_REQUEST["snmpv3_privpassphrase"],$_REQUEST["formula"],$_REQUEST["trends"], - $_REQUEST["logtimefmt"],$_REQUEST["valuemapid"]); + $_REQUEST["logtimefmt"],$_REQUEST["valuemapid"],$applications); $result = $itemid; show_messages($result, S_ITEM_ADDED, S_CANNOT_ADD_ITEM); @@ -162,6 +164,7 @@ { if($_REQUEST["action"]=="add to group") { + $applications = get_request("applications",array()); $itemid=add_item_to_group( $_REQUEST["add_groupid"],$_REQUEST["description"],$_REQUEST["key"], $_REQUEST["hostid"],$_REQUEST["delay"],$_REQUEST["history"], @@ -171,7 +174,8 @@ $_REQUEST["delta"],$_REQUEST["snmpv3_securityname"], $_REQUEST["snmpv3_securitylevel"],$_REQUEST["snmpv3_authpassphrase"], $_REQUEST["snmpv3_privpassphrase"],$_REQUEST["formula"], - $_REQUEST["trends"],$_REQUEST["logtimefmt"],$_REQUEST["valuemapid"]); + $_REQUEST["trends"],$_REQUEST["logtimefmt"],$_REQUEST["valuemapid"], + $applications); show_messages($itemid, S_ITEM_ADDED, S_CANNOT_ADD_ITEM); if($itemid){ unset($_REQUEST["form"]); @@ -181,6 +185,7 @@ } if($_REQUEST["action"]=="update in group") { + $applications = get_request("applications",array()); $result=update_item_in_group($_REQUEST["add_groupid"], $_REQUEST["itemid"],$_REQUEST["description"],$_REQUEST["key"], $_REQUEST["hostid"],$_REQUEST["delay"],$_REQUEST["history"], @@ -190,7 +195,8 @@ $_REQUEST["delta"],$_REQUEST["snmpv3_securityname"], $_REQUEST["snmpv3_securitylevel"],$_REQUEST["snmpv3_authpassphrase"], $_REQUEST["snmpv3_privpassphrase"],$_REQUEST["formula"], - $_REQUEST["trends"],$_REQUEST["logtimefmt"],$_REQUEST["valuemapid"]); + $_REQUEST["trends"],$_REQUEST["logtimefmt"],$_REQUEST["valuemapid"], + $applications); show_messages($result, S_ITEM_UPDATED, S_CANNOT_UPDATE_ITEM); if($result){ unset($_REQUEST["form"]); @@ -368,19 +374,23 @@ $form->SetName('items'); $form->AddVar('hostid',$_REQUEST["hostid"]); + $show_applications = 1; + $table = new CTableInfo(); $table->setHeader(array( array( new CCheckBox("all_items",NULL,NULL, "CheckAll('".$form->GetName()."','all_items');"), S_ID), S_DESCRIPTION,S_KEY,nbsp(S_UPDATE_INTERVAL), - S_HISTORY,S_TRENDS,S_TYPE,S_STATUS,S_ERROR)); + S_HISTORY,S_TRENDS,S_TYPE,S_STATUS, + $show_applications == 1 ? S_APPLICATIONS : NULL, + S_ERROR)); $db_items = DBselect("select i.* from hosts h,items i where h.hostid=i.hostid and". " h.hostid=".$_REQUEST["hostid"]." order by i.description, i.key_"); while($db_item = DBfetch($db_items)) { - if(!check_right("Item","R",$db_item["itemid"])) + if(!check_right("Item","U",$db_item["itemid"])) { continue; } @@ -447,6 +457,14 @@ { $error=new CCol($db_item["error"],"on"); } + + $applications = ""; + $db_applications = get_applications_by_itemid($db_item["itemid"]); + while($db_app = DBfetch($db_applications)) + { + $applications .= $db_app["name"].", "; + } + $table->AddRow(array( array( new CCheckBox("group_itemid[]",NULL,NULL,NULL,$db_item["itemid"]), @@ -459,6 +477,7 @@ $db_item["trends"], $type, $status, + $show_applications == 1 ? trim($applications,", ") : NULL, $error )); } diff --git a/frontends/php/latest.php b/frontends/php/latest.php index 0a00bf38..68e01142 100644 --- a/frontends/php/latest.php +++ b/frontends/php/latest.php @@ -37,12 +37,20 @@ <?php // VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION $fields=array( + "applications"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID, NULL), + "applicationid"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID, NULL), + "close"=> array(T_ZBX_INT, O_OPT, NULL, IN("1"), NULL), + "open"=> array(T_ZBX_INT, O_OPT, NULL, IN("1"), NULL), + "groupbyapp"=> array(T_ZBX_INT, O_OPT, NULL, IN("1"), NULL), + "groupid"=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0,65535), NULL), "hostid"=> array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0,65535), NULL), - "select"=> array(T_ZBX_STR, O_OPT, NULL, NULL, NULL) + "select"=> array(T_ZBX_STR, O_OPT, NULL, NULL, NULL), + + "show"=> array(T_ZBX_STR, O_OPT, NULL, NULL, NULL) ); -// check_fields($fields); + check_fields($fields); validate_group_with_host("R",array("allow_all_hosts","always_select_first_host","monitored_hosts","with_monitored_items")); ?> @@ -54,12 +62,33 @@ show_page_footer(); exit; } + update_profile("web.menu.view.last",$page["file"]); ?> <?php $_REQUEST["select"] = get_request("select",""); - update_profile("web.menu.view.last",$page["file"]); + $_REQUEST["groupbyapp"] = get_request("groupbyapp",get_profile("web.latest.groupbyapp",1)); + update_profile("web.latest.groupbyapp",$_REQUEST["groupbyapp"]); + + $_REQUEST["applications"] = get_request("applications",get_profile("web.latest.applications",array()),PROFILE_TYPE_ARRAY); + + if(isset($_REQUEST["open"]) && isset($_REQUEST["applicationid"])) + { + if(!in_array($_REQUEST["applicationid"],$_REQUEST["applications"])) + { + array_push($_REQUEST["applications"],$_REQUEST["applicationid"]); + } + + } elseif(isset($_REQUEST["close"]) && isset($_REQUEST["applicationid"])) + { + if(($i=array_search($_REQUEST["applicationid"], $_REQUEST["applications"])) !== FALSE) + { + unset($_REQUEST["applications"][$i]); + } + } + + update_profile("web.latest.applications",$_REQUEST["applications"],PROFILE_TYPE_ARRAY); ?> <?php @@ -112,7 +141,7 @@ if($first_hostid == -1) $first_hostid = $row["hostid"]; - if($_REQUEST["hostid"]!=0){ + if($_REQUEST["hostid"] > 0){ if($_REQUEST["hostid"] == $row["hostid"]) $correct_hostid = 'ok'; } @@ -146,61 +175,202 @@ else $compare_description = ""; - if($_REQUEST["hostid"] != 0) + if($_REQUEST["hostid"] > 0) $compare_host = " and h.hostid=".$_REQUEST["hostid"]; else $compare_host = ""; - $sql="select h.host,i.*,h.hostid from items i,hosts h". - " where h.hostid=i.hostid and h.status=".HOST_STATUS_MONITORED. - " and i.status=".ITEM_STATUS_ACTIVE.$compare_description.$compare_host. - " order by i.description"; + $db_applications = DBselect("select h.host,h.hostid,a.* from applications a,hosts h where a.hostid=h.hostid".$compare_host. + " order by a.name,a.applicationid,h.host"); + while($db_app = DBfetch($db_applications)) + { + if(!check_right("Application","R",$db_app["applicationid"])) continue; - $result=DBselect($sql); - while($row=DBfetch($result)) + $sql = "select i.* from items i,hosts h,items_applications ia". + " where h.hostid=i.hostid and ia.applicationid=".$db_app["applicationid"]." and i.itemid=ia.itemid". + " and h.status=".HOST_STATUS_MONITORED." and i.status=".ITEM_STATUS_ACTIVE. + $compare_description.$compare_host. + " order by i.description"; + + $db_items = DBselect($sql); + + $currAppID = -1; + while($db_item = DBfetch($db_items)) + { + if(!check_right("Item","R",$db_item["itemid"])) + { + continue; + } + if(!check_right("Host","R",$db_item["hostid"])) + { + continue; + } + + if($currAppID != $db_app["applicationid"]) + { + $currAppID = $db_app["applicationid"]; + + if(in_array($db_app["applicationid"],$_REQUEST["applications"])) + $link = new CLink(new CImg("images/general/opened.gif"), + "latest.php?close=1&applicationid=".$db_app["applicationid"]. + url_param("groupid").url_param("hostid").url_param("applications"). + url_param("select")); + else + $link = new CLink(new CImg("images/general/closed.gif"), + "latest.php?open=1&applicationid=".$db_app["applicationid"]. + url_param("groupid").url_param("hostid").url_param("applications"). + url_param("select")); + + $col = new CCol(array($link,SPACE,bold($db_app["name"]), + SPACE."(".DBnum_rows($db_items).SPACE.S_ITEMS.")")); + $col->SetColSpan(5); + + $table->AddRow(array($_REQUEST["hostid"] > 0 ? NULL : $db_app["host"], $col)); + + if(!in_array($db_app["applicationid"],$_REQUEST["applications"])) break; + } + + if(isset($db_item["lastclock"])) + $lastclock=date(S_DATE_FORMAT_YMDHMS,$db_item["lastclock"]); + else + $lastclock="-"; + + if(isset($db_item["lastvalue"])) + { + if(($db_item["value_type"] == ITEM_VALUE_TYPE_FLOAT) || + ($db_item["value_type"] == ITEM_VALUE_TYPE_UINT64)) + { + $lastvalue=convert_units($db_item["lastvalue"],$db_item["units"]); + } + else + { + $lastvalue=nbsp(htmlspecialchars(substr($db_item["lastvalue"],0,20)." ...")); + } + $lastvalue = replace_value_by_map($lastvalue, $db_item["valuemapid"]); + } + else + { + $lastvalue=new CCol("-","center"); + } + if( isset($db_item["lastvalue"]) && isset($db_item["prevvalue"]) && + ($db_item["value_type"] == 0) && ($db_item["lastvalue"]-$db_item["prevvalue"] != 0) ) + { + if($db_item["lastvalue"]-$db_item["prevvalue"]<0) + { + $change=convert_units($db_item["lastvalue"]-$db_item["prevvalue"],$db_item["units"]); + $change=nbsp($change); + } + else + { + $change="+".convert_units($db_item["lastvalue"]-$db_item["prevvalue"],$db_item["units"]); + $change=nbsp($change); + } + } + else + { + $change=new CCol("-","center"); + } + if(($db_item["value_type"]==ITEM_VALUE_TYPE_FLOAT) ||($db_item["value_type"]==ITEM_VALUE_TYPE_UINT64)) + { + $actions=new CLink(S_GRAPH,"history.php?action=showgraph&itemid=".$db_item["itemid"],"action"); + } + else + { + $actions=new CLink(S_HISTORY,"history.php?action=showvalues&period=3600&itemid=".$db_item["itemid"],"action"); + } + + $table->AddRow(array( + $_REQUEST["hostid"] > 0 ? NULL : SPACE, + str_repeat(SPACE,6).item_description($db_item["description"],$db_item["key_"]), + $lastclock, + $lastvalue, + $change, + $actions + )); + } + + } + + $show_group_other = $table->GetNumRows() > 0 ? TRUE : FALSE; + $space = ""; + + $sql="select h.host,h.hostid,i.* from hosts h, items i LEFT JOIN items_applications ia ON ia.itemid=i.itemid". + " where ia.itemid is NULL and h.hostid=i.hostid and h.status=".HOST_STATUS_MONITORED." and i.status=".ITEM_STATUS_ACTIVE. + $compare_description.$compare_host. + " order by i.description,h.host"; + + $db_items = DBselect($sql); + + $currAppID = -1; + $appID = 0; + while($db_item = DBfetch($db_items)) { - if(!check_right("Item","R",$row["itemid"])) + if(!check_right("Host","R",$db_item["hostid"])) { continue; } - if(!check_right("Host","R",$row["hostid"])) + if(!check_right("Item","R",$db_item["itemid"])) { continue; } + if($currAppID != $appID && $show_group_other) + { + $currAppID = $appID; + + if(in_array($appID,$_REQUEST["applications"])) + $link = new CLink(new CImg("images/general/opened.gif"), + "latest.php?close=1&applicationid=".$appID. + url_param("groupid").url_param("hostid").url_param("applications"). + url_param("select")); + else + $link = new CLink(new CImg("images/general/closed.gif"), + "latest.php?open=1&applicationid=".$appID. + url_param("groupid").url_param("hostid").url_param("applications"). + url_param("select")); + + $col = new CCol(array($link,SPACE,bold(S_MINUS_OTHER_MINUS), + SPACE."(".DBnum_rows($db_items).SPACE.S_ITEMS.")")); + $col->SetColSpan(5); + + $table->AddRow(array($_REQUEST["hostid"] > 0 ? NULL : SPACE, $col)); + + if(!in_array($appID,$_REQUEST["applications"])) break; + $space = str_repeat(SPACE,6); + } - if(isset($row["lastclock"])) - $lastclock=date(S_DATE_FORMAT_YMDHMS,$row["lastclock"]); + if(isset($db_item["lastclock"])) + $lastclock=date(S_DATE_FORMAT_YMDHMS,$db_item["lastclock"]); else $lastclock="-"; - if(isset($row["lastvalue"])) + if(isset($db_item["lastvalue"])) { - if(($row["value_type"] == ITEM_VALUE_TYPE_FLOAT) || - ($row["value_type"] == ITEM_VALUE_TYPE_UINT64)) + if(($db_item["value_type"] == ITEM_VALUE_TYPE_FLOAT) || + ($db_item["value_type"] == ITEM_VALUE_TYPE_UINT64)) { - $lastvalue=convert_units($row["lastvalue"],$row["units"]); + $lastvalue=convert_units($db_item["lastvalue"],$db_item["units"]); } else { - $lastvalue=nbsp(htmlspecialchars(substr($row["lastvalue"],0,20)." ...")); + $lastvalue=nbsp(htmlspecialchars(substr($db_item["lastvalue"],0,20)." ...")); } - $lastvalue = replace_value_by_map($lastvalue, $row["valuemapid"]); + $lastvalue = replace_value_by_map($lastvalue, $db_item["valuemapid"]); } else { $lastvalue=new CCol("-","center"); } - if( isset($row["lastvalue"]) && isset($row["prevvalue"]) && - ($row["value_type"] == 0) && ($row["lastvalue"]-$row["prevvalue"] != 0) ) + if( isset($db_item["lastvalue"]) && isset($db_item["prevvalue"]) && + ($db_item["value_type"] == 0) && ($db_item["lastvalue"]-$db_item["prevvalue"] != 0) ) { - if($row["lastvalue"]-$row["prevvalue"]<0) + if($db_item["lastvalue"]-$db_item["prevvalue"]<0) { - $change=convert_units($row["lastvalue"]-$row["prevvalue"],$row["units"]); + $change=convert_units($db_item["lastvalue"]-$db_item["prevvalue"],$db_item["units"]); $change=nbsp($change); } else { - $change="+".convert_units($row["lastvalue"]-$row["prevvalue"],$row["units"]); + $change="+".convert_units($db_item["lastvalue"]-$db_item["prevvalue"],$db_item["units"]); $change=nbsp($change); } } @@ -208,23 +378,23 @@ { $change=new CCol("-","center"); } - if(($row["value_type"]==ITEM_VALUE_TYPE_FLOAT) ||($row["value_type"]==ITEM_VALUE_TYPE_UINT64)) + if(($db_item["value_type"]==ITEM_VALUE_TYPE_FLOAT) ||($db_item["value_type"]==ITEM_VALUE_TYPE_UINT64)) { - $actions=new CLink(S_GRAPH,"history.php?action=showgraph&itemid=".$row["itemid"],"action"); + $actions=new CLink(S_GRAPH,"history.php?action=showgraph&itemid=".$db_item["itemid"],"action"); } else { - $actions=new CLink(S_HISTORY,"history.php?action=showvalues&period=3600&itemid=".$row["itemid"],"action"); + $actions=new CLink(S_HISTORY,"history.php?action=showvalues&period=3600&itemid=".$db_item["itemid"],"action"); } - $table->addRow(array( - $_REQUEST["hostid"] ==0 ? $row["host"] : NULL, - item_description($row["description"],$row["key_"]), + $table->AddRow(array( + $_REQUEST["hostid"] > 0 ? NULL : $db_item["host"], + $space.item_description($db_item["description"],$db_item["key_"]), $lastclock, $lastvalue, $change, $actions - )); + )); } $table->show(); ?> |