summaryrefslogtreecommitdiffstats
path: root/frontends/php/hosts.php
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-02-10 12:53:34 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-02-10 12:53:34 +0000
commitf54860dfdd8d24de1dc26a530d95a23343756dc2 (patch)
tree76234c5a861862aee2170b41cf7a517e82633e93 /frontends/php/hosts.php
parent455a64dfe19d7700fa1fe10edecb1ea82fa5dcce (diff)
- improved Templates logic (Eugene)
- speed improvement for proc.num of Tru64 (Eugene) git-svn-id: svn://svn.zabbix.com/trunk@2631 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/hosts.php')
-rw-r--r--frontends/php/hosts.php403
1 files changed, 101 insertions, 302 deletions
diff --git a/frontends/php/hosts.php b/frontends/php/hosts.php
index 7e5b64ff..09c5bd4a 100644
--- a/frontends/php/hosts.php
+++ b/frontends/php/hosts.php
@@ -42,7 +42,7 @@
<?php
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$fields=array(
- "config"=> array(T_ZBX_INT, O_OPT, NULL, IN("0,1,2"), NULL),
+ "config"=> array(T_ZBX_INT, O_OPT, NULL, IN("0,1"), NULL),
"hosts"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL),
"groups"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL),
@@ -50,12 +50,12 @@
"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})'),
"useip"=> array(T_ZBX_STR, O_OPT, NULL, NULL, NULL),
- "ip"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useip})'),
+ "ip"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useip})'),
"port"=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,65535),'{config}==0&&isset({save})'),
"status"=> array(T_ZBX_INT, O_OPT, NULL, IN("0,1,3"), '{config}==0&&isset({save})'),
"newgroup"=> array(T_ZBX_STR, O_OPT, NULL, NULL, NULL),
- "host_templateid"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID, NULL),
+ "templateid"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID, NULL),
"useprofile"=> array(T_ZBX_STR, O_OPT, NULL, NULL, NULL),
"devicetype"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'),
@@ -72,18 +72,11 @@
/* group */
"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})'),
-/* linkages */
- "hosttemplateid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, '{config}==3&&{form}=="update"'),
- "templateid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL),
- "items"=> array(T_ZBX_INT, O_OPT, P_SYS, IN("1,2,4"), NULL),
- "triggers"=> array(T_ZBX_INT, O_OPT, P_SYS, IN("1,2,4"), NULL),
- "graphs"=> array(T_ZBX_INT, O_OPT, P_SYS, IN("1,2,4"), 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),
-// "register"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
"save"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
"delete"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
"cancel"=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL),
@@ -106,59 +99,36 @@
if(isset($_REQUEST["hostid"]))
{
- $result=update_host(
- $_REQUEST["hostid"],$_REQUEST["host"],$_REQUEST["port"],$_REQUEST["status"],
- $useip,$_REQUEST["ip"],$_REQUEST["newgroup"],$groups);
+ $result = update_host($_REQUEST["hostid"],
+ $_REQUEST["host"],$_REQUEST["port"],$_REQUEST["status"],$useip,
+ $_REQUEST["ip"],$_REQUEST["templateid"],$_REQUEST["newgroup"],$groups);
$msg_ok = S_HOST_UPDATED;
$msg_fail = S_CANNOT_UPDATE_HOST;
$audit_action = AUDIT_ACTION_UPDATE;
- $hostid=$_REQUEST["hostid"];
+ $hostid = $_REQUEST["hostid"];
} else {
- $result=add_host(
+ $hostid = add_host(
$_REQUEST["host"],$_REQUEST["port"],$_REQUEST["status"],$useip,
- $_REQUEST["ip"],$_REQUEST["host_templateid"],$_REQUEST["newgroup"],$groups);
+ $_REQUEST["ip"],$_REQUEST["templateid"],$_REQUEST["newgroup"],$groups);
$msg_ok = S_HOST_ADDED;
$msg_fail = S_CANNOT_ADD_HOST;
$audit_action = AUDIT_ACTION_ADD;
- $db_hosts=DBexecute("select hostid from hosts where host='".$_REQUEST["host"]."'");
- if(DBnum_rows($db_hosts)==0){
- $result=FALSE;
- $hostid=0;
- } else {
- $db_host = DBfetch($db_hosts);
- $hostid=$db_host["hostid"];
- }
+ $result = $hostid;
}
if($result){
- $useprofile = get_request("useprofile","no");
- $db_profiles = DBselect("select * from hosts_profiles where hostid=".$hostid);
- if($useprofile=="yes"){
- if(DBnum_rows($db_profiles)==0)
- {
- $result=add_host_profile($hostid,
- $_REQUEST["devicetype"],$_REQUEST["name"],$_REQUEST["os"],
- $_REQUEST["serialno"],$_REQUEST["tag"],$_REQUEST["macaddress"],
- $_REQUEST["hardware"],$_REQUEST["software"],$_REQUEST["contact"],
- $_REQUEST["location"],$_REQUEST["notes"]);
-
-// show_messages($result, S_PROFILE_ADDED, S_CANNOT_ADD_PROFILE);
- } else {
- $result=update_host_profile($hostid,
- $_REQUEST["devicetype"],$_REQUEST["name"],$_REQUEST["os"],
- $_REQUEST["serialno"],$_REQUEST["tag"],$_REQUEST["macaddress"],
- $_REQUEST["hardware"],$_REQUEST["software"],$_REQUEST["contact"],
- $_REQUEST["location"],$_REQUEST["notes"]);
-
-// show_messages($result, S_PROFILE_UPDATED, S_CANNOT_UPDATE_PROFILE);
- }
- } elseif (DBnum_rows($db_profiles)>0){
- $result=delete_host_profile($hostid);
-// show_messages($result, S_PROFILE_DELETED, S_CANNOT_DELETE_PROFILE);
+ delete_host_profile($hostid);
+
+ if(get_request("useprofile","no") == "yes"){
+ $result = add_host_profile($hostid,
+ $_REQUEST["devicetype"],$_REQUEST["name"],$_REQUEST["os"],
+ $_REQUEST["serialno"],$_REQUEST["tag"],$_REQUEST["macaddress"],
+ $_REQUEST["hardware"],$_REQUEST["software"],$_REQUEST["contact"],
+ $_REQUEST["location"],$_REQUEST["notes"]);
}
}
@@ -252,10 +222,12 @@
$result = update_host_group($_REQUEST["groupid"], $_REQUEST["gname"], $hosts);
$msg_ok = S_GROUP_UPDATED;
$msg_fail = S_CANNOT_UPDATE_GROUP;
+ $groupid = $_REQUEST["groupid"];
} else {
- $result = add_host_group($_REQUEST["gname"], $hosts);
+ $groupid = add_host_group($_REQUEST["gname"], $hosts);
$msg_ok = S_GROUP_ADDED;
$msg_fail = S_CANNOT_ADD_GROUP;
+ $result = $groupid;
}
show_messages($result, $msg_ok, $msg_fail);
if($result){
@@ -318,66 +290,6 @@
show_messages($result, S_HOST_STATUS_UPDATED, NULL);
unset($_REQUEST["activate"]);
}
-/****** ACTIONS FOR LINKS **********/
- elseif($_REQUEST["config"]==2&&isset($_REQUEST["save"]))
- {
- $items = 0;
- $arr_items = get_request("items",array());
- foreach($arr_items as $el) $items |= $el;
-
- $triggers=0;
- $arr_triggers= get_request("triggers",array());
- foreach($arr_triggers as $el) $triggers |= $el;
-
- $graphs=0;
- $arr_graphs = get_request("graphs",array());
- foreach($arr_graphs as $el) $graphs |= $el;
-
- if(isset($_REQUEST["hosttemplateid"]))
- {
- $result=update_template_linkage($_REQUEST["hosttemplateid"],
- $_REQUEST["hostid"],$_REQUEST["templateid"],$items,$triggers,$graphs);
- show_messages($result, S_TEMPLATE_LINKAGE_UPDATED, S_CANNOT_UPDATE_TEMPLATE_LINKAGE);
- }
- else
- {
- $result=add_template_linkage(
- $_REQUEST["hostid"],$_REQUEST["templateid"],$items,$triggers,$graphs);
-
- show_messages($result, S_TEMPLATE_LINKAGE_ADDED, S_CANNOT_ADD_TEMPLATE_LINKAGE);
- }
- if($result){
- unset($_REQUEST["form"]);
- }
- }
- elseif($_REQUEST["config"]==2&&isset($_REQUEST["delete"])&&isset($_REQUEST["hosttemplateid"]))
- {
- $result=delete_template_linkage($_REQUEST["hosttemplateid"]);
- show_messages($result, S_TEMPLATE_LINKAGE_DELETED, S_CANNOT_DELETE_TEMPLATE_LINKAGE);
- unset($_REQUEST["hosttemplateid"]);
- if($result){
- unset($_REQUEST["form"]);
- }
- }
-
-/************* OLD ACTIONS ***************/
-/*
- elseif(isset($_REQUEST["register"]))
- {
- if($_REQUEST["register"]=="add items from template")
- {
- if(isset($_REQUEST["host_templateid"])&&($_REQUEST["host_templateid"]!=0))
- {
- $result=sync_items_with_template_host($_REQUEST["hostid"],$_REQUEST["host_templateid"]);
- show_messages(TRUE,S_ITEMS_ADDED,S_CANNOT_ADD_ITEMS);
- }
- else
- {
- show_messages(FALSE,"",S_SELECT_HOST_TEMPLATE_FIRST);
- }
- }
- }
-*/
?>
<?php
@@ -386,21 +298,15 @@
$cmbConf = new CComboBox("config",$_REQUEST["config"],"submit()");
$cmbConf->AddItem(0,S_HOSTS);
$cmbConf->AddItem(1,S_HOST_GROUPS);
- $cmbConf->AddItem(2,S_HOSTS_TEMPLATES_LINKAGE);
switch($_REQUEST["config"]){
case 0:
- $frmForm->AddVar("groupid",get_request("groupid",0));
$btn = new CButton("form",S_CREATE_HOST);
+ $frmForm->AddVar("groupid",get_request("groupid",0));
break;
case 1:
$btn = new CButton("form",S_CREATE_GROUP);
break;
- case 2:
- $frmForm->AddVar("groupid",get_request("groupid",0));
- $frmForm->AddVar("hostid",get_request("hostid",0));
- $btn = new CButton("form",S_CREATE_LINKAGE);
- break;
}
$frmForm->AddItem($cmbConf);
@@ -412,185 +318,6 @@
echo BR;
?>
-
-<?php
- if($_REQUEST["config"]==2)
- {
- if(isset($_REQUEST["groupid"])&&($_REQUEST["groupid"]==0))
- {
- unset($_REQUEST["groupid"]);
- }
- if(isset($_REQUEST["hostid"])&&($_REQUEST["hostid"]==0))
- {
- unset($_REQUEST["hostid"]);
- }
-
-/* filter panel */
- $form = new CForm();
- $form->AddVar("config",$_REQUEST["config"]);
-
- $_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_CONFIGURATION_OF_ITEMS_BIG, $form);
-
-/* table */
- echo BR;
- if(isset($_REQUEST["form"]))
- {
- insert_template_form();
- } else {
- $table = new CTableInfo(S_NO_LINKAGES_DEFINED);
- $table->setHeader(array(S_HOST,S_TEMPLATE,S_ITEMS,S_TRIGGERS,S_GRAPHS));
-
- $result=DBselect("select * from hosts_templates where hostid=".$_REQUEST["hostid"]);
- while($row=DBfetch($result))
- {
- $host=get_host_by_hostid($row["hostid"]);
- $template=get_host_by_hostid($row["templateid"]);
-
- $table->addRow(array(
- new CLink(
- $host["host"],
- "hosts.php?form=update".url_param("config").
- "&hostid=".$row["hostid"].
- "&hosttemplateid=".$row["hosttemplateid"],
- 'action'),
- new CLink(
- $template["host"],
- "hosts.php?form=update".url_param("config").
- "&hostid=".$row["hostid"].
- "&hosttemplateid=".$row["hosttemplateid"],
- 'action'),
- get_template_permission_str($row["items"]),
- get_template_permission_str($row["triggers"]),
- get_template_permission_str($row["graphs"])
- ));
- }
- $table->show();
- }
- }
-?>
-<?php
- if($_REQUEST["config"]==1)
- {
- if(isset($_REQUEST["form"]))
- {
- insert_hostgroups_form(get_request("groupid",NULL));
- } else {
- show_table_header(S_HOST_GROUPS_BIG);
-
- $form = new CForm('hosts.php');
- $form->SetName('groups');
- $form->AddVar("config",get_request("config",0));
-
- $table = new CTableInfo(S_NO_HOST_GROUPS_DEFINED);
-
- $table->setHeader(array(
- array( new CCheckBox("all_groups",NULL,NULL,
- "CheckAll('".$form->GetName()."','all_groups');"),
- S_NAME),
- S_MEMBERS));
-
- $db_groups=DBselect("select groupid,name from groups order by name");
- while($db_group=DBfetch($db_groups))
- {
- $db_hosts = DBselect("select distinct h.host, h.status".
- " from hosts h, hosts_groups hg".
- " where h.hostid=hg.hostid and hg.groupid=".$db_group["groupid"].
- " and h.status not in (".HOST_STATUS_DELETED.") order by host");
-
- $hosts = array("");
- if($db_host=DBfetch($db_hosts)){
- $style = $db_host["status"]==HOST_STATUS_MONITORED ? NULL: "on";
- array_push($hosts,new CSpan($db_host["host"],$style));
- }
- while($db_host=DBfetch($db_hosts)){
- $style = $db_host["status"]==HOST_STATUS_MONITORED ? NULL: "on";
- array_push($hosts,", ",new CSpan($db_host["host"],$style));
- }
-
- $table->AddRow(array(
- array(
- new CCheckBox("groups[]",NULL,NULL,NULL,$db_group["groupid"]),
- new CLink(
- $db_group["name"],
- "hosts.php?form=update&groupid=".$db_group["groupid"].
- url_param("config"),'action')
- ),
- $hosts
- ));
- }
- $footerButtons = array();
- array_push($footerButtons, new CButton('activate','Activate selected',
- "return Confirm('".S_ACTIVATE_SELECTED_HOSTS_Q."');"));
- array_push($footerButtons, SPACE);
- array_push($footerButtons, new CButton('disable','Disable selected',
- "return Confirm('".S_DISABLE_SELECTED_HOSTS_Q."');"));
- array_push($footerButtons, SPACE);
- array_push($footerButtons, new CButton('delete','Delete selected',
- "return Confirm('".S_DELETE_SELECTED_GROUPS_Q."');"));
- $table->SetFooter(new CCol($footerButtons),'table_footer');
-
- $form->AddItem($table);
- $form->Show();
- }
- }
-?>
<?php
if($_REQUEST["config"]==0)
{
@@ -604,19 +331,17 @@
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,items i,hosts_groups hg".
- " where h.hostid=i.hostid and hg.groupid=".$row["groupid"].
+ $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 not in (".HOST_STATUS_DELETED.")".
" group by h.hostid,h.host order by h.host");
- $right='no';
while($row2=DBfetch($result2))
{
if(!check_right("Host","R",$row2["hostid"])) continue;
- $right='yes'; break;
+ $cmbGroups->AddItem($row["groupid"],$row["name"]);
+ break;
}
- if($right=='no') continue;
- $cmbGroups->AddItem($row["groupid"],$row["name"]);
}
$frmForm = new CForm("hosts.php");
$frmForm->AddVar("config",$_REQUEST["config"]);
@@ -654,8 +379,12 @@
continue;
}
+ $template = get_template_path($row["hostid"]);
+ if($template == "/") $template = NULL;
+
$host=new CCol(array(
new CCheckBox("hosts[]",NULL,NULL,NULL,$row["hostid"]),
+ $template,
new CLink($row["host"],"hosts.php?form=update&hostid=".
$row["hostid"].url_param("groupid").url_param("config"), 'action')
));
@@ -694,7 +423,7 @@
else if($row["available"] == HOST_AVAILABLE_UNKNOWN)
$available=new CCol(S_UNKNOWN,"unknown");
- if($row["error"] == "") $error=new CCol("&nbsp;","off");
+ if($row["error"] == "") $error=new CCol(SPACE,"off");
else $error=new CCol($row["error"],"on");
if(check_right("Host","U",$row["hostid"])) {
@@ -729,6 +458,76 @@
}
}
+ elseif($_REQUEST["config"]==1)
+ {
+ if(isset($_REQUEST["form"]))
+ {
+ insert_hostgroups_form(get_request("groupid",NULL));
+ } else {
+ show_table_header(S_HOST_GROUPS_BIG);
+
+ $form = new CForm('hosts.php');
+ $form->SetName('groups');
+ $form->AddVar("config",get_request("config",0));
+
+ $table = new CTableInfo(S_NO_HOST_GROUPS_DEFINED);
+
+ $table->setHeader(array(
+ array( new CCheckBox("all_groups",NULL,NULL,
+ "CheckAll('".$form->GetName()."','all_groups');"),
+ S_NAME),
+ S_MEMBERS));
+
+ $db_groups=DBselect("select groupid,name from groups order by name");
+ while($db_group=DBfetch($db_groups))
+ {
+ $db_hosts = DBselect("select distinct h.host, h.status".
+ " from hosts h, hosts_groups hg".
+ " where h.hostid=hg.hostid and hg.groupid=".$db_group["groupid"].
+ " and h.status not in (".HOST_STATUS_DELETED.") order by host");
+
+ $hosts = array("");
+ if($db_host=DBfetch($db_hosts)){
+ $style =
+ $db_host["status"]==HOST_STATUS_MONITORED ? NULL: (
+ $db_host["status"]==HOST_STATUS_TEMPLATE ? "unknown" :
+ "on");
+ array_push($hosts,new CSpan($db_host["host"],$style));
+ }
+ while($db_host=DBfetch($db_hosts)){
+ $style =
+ $db_host["status"]==HOST_STATUS_MONITORED ? NULL: (
+ $db_host["status"]==HOST_STATUS_TEMPLATE ? "unknown" :
+ "on");
+ array_push($hosts,", ",new CSpan($db_host["host"],$style));
+ }
+
+ $table->AddRow(array(
+ array(
+ new CCheckBox("groups[]",NULL,NULL,NULL,$db_group["groupid"]),
+ new CLink(
+ $db_group["name"],
+ "hosts.php?form=update&groupid=".$db_group["groupid"].
+ url_param("config"),'action')
+ ),
+ $hosts
+ ));
+ }
+ $footerButtons = array();
+ array_push($footerButtons, new CButton('activate','Activate selected',
+ "return Confirm('".S_ACTIVATE_SELECTED_HOSTS_Q."');"));
+ array_push($footerButtons, SPACE);
+ array_push($footerButtons, new CButton('disable','Disable selected',
+ "return Confirm('".S_DISABLE_SELECTED_HOSTS_Q."');"));
+ array_push($footerButtons, SPACE);
+ array_push($footerButtons, new CButton('delete','Delete selected',
+ "return Confirm('".S_DELETE_SELECTED_GROUPS_Q."');"));
+ $table->SetFooter(new CCol($footerButtons),'table_footer');
+
+ $form->AddItem($table);
+ $form->Show();
+ }
+ }
?>
<?php
show_page_footer();