diff options
author | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-04-18 09:52:54 +0000 |
---|---|---|
committer | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-04-18 09:52:54 +0000 |
commit | 5ee0e65e708340172b938d324ca316b0204b7dc5 (patch) | |
tree | 6356bab6e7f933290cf5b1964d77b1cfe2ccdddf /frontends/php | |
parent | b024b6875f0b6c1575cb8317970afb5faa52df65 (diff) | |
download | zabbix-5ee0e65e708340172b938d324ca316b0204b7dc5.tar.gz zabbix-5ee0e65e708340172b938d324ca316b0204b7dc5.tar.xz zabbix-5ee0e65e708340172b938d324ca316b0204b7dc5.zip |
- [ZBX-362] merged rev. 5630:5634 of branches/1.4 (Artem) [added mass template linkage to hosts, mod by sergio.cricca]
git-svn-id: svn://svn.zabbix.com/trunk@5635 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php')
-rw-r--r-- | frontends/php/hosts.php | 176 | ||||
-rw-r--r-- | frontends/php/include/forms.inc.php | 58 | ||||
-rw-r--r-- | frontends/php/include/hosts.inc.php | 15 | ||||
-rw-r--r-- | frontends/php/include/locales/en_gb.inc.php | 6 | ||||
-rw-r--r-- | frontends/php/overview.php | 2 |
5 files changed, 203 insertions, 54 deletions
diff --git a/frontends/php/hosts.php b/frontends/php/hosts.php index 6d60f191..5339a530 100644 --- a/frontends/php/hosts.php +++ b/frontends/php/hosts.php @@ -57,7 +57,7 @@ include_once "include/page_header.php"; "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, 'isset({config})&&({config}==0||{config}==5)&&isset({form})&&({form}=="update")'), + "hostid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({config})&&({config}==0||{config}==5||{config}==2)&&isset({form})&&({form}=="update")'), "host"=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, 'isset({config})&&({config}==0||{config}==3||{config}==5)&&isset({save})'), 'proxy_hostid'=>array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({config})&&({config}==0)&&isset({save})'), "dns"=> array(T_ZBX_STR, O_OPT, NULL, NULL, '(isset({config})&&({config}==0))&&isset({save})'), @@ -81,7 +81,7 @@ include_once "include/page_header.php"; "software"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'), "contact"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'), "location"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'), - "notes"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'), + "notes"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})'), /* group */ "groupid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, '(isset({config})&&({config}==1))&&(isset({form})&&({form}=="update"))'), "gname"=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, '(isset({config})&&({config}==1))&&isset({save})'), @@ -91,6 +91,9 @@ include_once "include/page_header.php"; "appname"=> array(T_ZBX_STR, O_NO, NULL, NOT_EMPTY, '(isset({config})&&({config}==4))&&isset({save})'), "apphostid"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID.'{}>0', '(isset({config})&&({config}==4))&&isset({save})'), "apptemplateid"=>array(T_ZBX_INT,O_OPT, NULL, DB_ID, NULL), + +/* host linkage form */ + "tname"=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, 'isset({config})&&({config}==2)&&isset({save})'), /* actions */ "activate"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), @@ -126,8 +129,87 @@ include_once "include/page_header.php"; <?php /************ ACTIONS FOR HOSTS ****************/ +// Original mod by scricca@vipsnet.net +// Modified by Aly +/* this code menages operations to unlink 1 template from multiple hosts */ + if ($_REQUEST["config"]==2 && (isset($_REQUEST["unlink"]))){ + $hosts = get_request("hosts",array()); + if(isset($_REQUEST["hostid"])){ + $templateid=$_REQUEST["hostid"]; + $result = false; +// Permission check + $tmp_hosts = array_diff($hosts,$available_hosts); + $hosts = array_diff($hosts,$tmp_hosts); + unset($tmp_hosts); +//-- + DBstart(); + foreach($hosts as $id => $hostid){ + $result=unlink_template($hostid,$templateid); + } + $result = DBend(); + + show_messages($result, S_UNLINK_FROM_TEMPLATE, S_CANNOT_UNLINK_FROM_TEMPLATE); + if($result){ + $host=get_host_by_hostid($templateid); + add_audit(AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_HOST, + 'Host ['.$host['host'].'] '. + 'Mass Linkage '. + 'Status ['.$host['status'].']'); + } + + unset($_REQUEST["unlink"]); + unset($_REQUEST["hostid"]); + unset($_REQUEST["form"]); + } + } +/* this code menages operations to link 1 template to multiple hosts */ + if($_REQUEST["config"]==2 && (isset($_REQUEST["save"]))){ + if(isset($_REQUEST['hostid'])){ + $hosts = get_request('hosts',array()); + $templateid=$_REQUEST['hostid']; + $result = false; +// Permission check + $tmp_hosts = array_diff($hosts,$available_hosts); + $hosts = array_diff($hosts,$tmp_hosts); + unset($tmp_hosts); +//-- + + $template_name=DBfetch(DBselect('SELECT host FROM hosts WHERE hostid='.$templateid)); + DBstart(); + foreach($hosts as $id => $hostid){ + + $host_groups=array(); + $db_hosts_groups = DBselect('SELECT groupid FROM hosts_groups WHERE hostid='.$hostid); + while($hg = DBfetch($db_hosts_groups)) $host_groups[] = $hg['groupid']; + + $host=get_host_by_hostid($hostid); + + $templates_tmp=get_templates_by_hostid($hostid); + $templates_tmp[$templateid]=$template_name["host"]; + + $result=update_host($hostid, + $host["host"],$host["port"],$host["status"],$host["useip"],$host["dns"], + $host["ip"],$host['proxy_hostid'],$templates_tmp,null,$host_groups); + } + $result = DBend(); + + show_messages($result, S_LINK_TO_TEMPLATE, S_CANNOT_LINK_TO_TEMPLATE); + if($result){ + $host=get_host_by_hostid($templateid); + add_audit(AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_HOST, + 'Host ['.$host['host'].'] '. + 'Mass Linkage '. + 'Status ['.$host['status'].']'); + } + + unset($_REQUEST["save"]); + unset($_REQUEST["hostid"]); + unset($_REQUEST["form"]); + } + } +//--------- END MOD ------------ /* UNLINK HOST */ - if(($_REQUEST["config"]==0 || $_REQUEST["config"]==3) && (isset($_REQUEST["unlink"]) || isset($_REQUEST["unlink_and_clear"]))){ + else if(($_REQUEST["config"]==0 || $_REQUEST["config"]==3) && (isset($_REQUEST["unlink"]) || isset($_REQUEST["unlink_and_clear"]))){ $_REQUEST['clear_templates'] = get_request('clear_templates', array()); if(isset($_REQUEST["unlink"])){ $unlink_templates = array_keys($_REQUEST["unlink"]); @@ -686,22 +768,20 @@ include_once "include/page_header.php"; show_table_header(S_CONFIGURATION_OF_HOSTS_GROUPS_AND_TEMPLATES, $frmForm); echo SBR; ?> - <?php - if($_REQUEST["config"]==0 || $_REQUEST["config"]==3) - { + if($_REQUEST["config"]==0 || $_REQUEST["config"]==3){ $show_only_tmp = 0; if($_REQUEST["config"]==3) $show_only_tmp = 1; if(isset($_REQUEST["form"])){ insert_host_form($show_only_tmp); - } + } else { if($show_only_tmp==1) - $status_filter = " and h.status in (".HOST_STATUS_TEMPLATE.") "; + $status_filter = ' AND h.status IN ('.HOST_STATUS_TEMPLATE.') '; else - $status_filter = " and h.status in (".HOST_STATUS_MONITORED.",".HOST_STATUS_NOT_MONITORED.") "; + $status_filter = ' AND h.status IN ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.') '; $cmbGroups = new CComboBox("groupid",get_request("groupid",0),"submit()"); $cmbGroups->AddItem(0,S_ALL_SMALL); @@ -955,8 +1035,7 @@ include_once "include/page_header.php"; ' FROM groups g'. ' WHERE g.groupid in ('.$available_groups.')'. order_by('g.name')); - while($db_group=DBfetch($db_groups)) - { + 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 '. @@ -1002,42 +1081,51 @@ include_once "include/page_header.php"; $form->Show(); } } +// Original mod by scricca@vipsnet.net +// Modified by Aly +/* this code adds links to Template Names in Template_Linkage page and link them to the form in forms.inc.php */ else if($_REQUEST["config"]==2){ - show_table_header(S_TEMPLATE_LINKAGE_BIG); - - $table = new CTableInfo(S_NO_LINKAGES); - $table->SetHeader(array( - make_sorting_link(S_TEMPLATES,'h.host'), - S_HOSTS)); - - $templates = DBSelect('SELECT h.* '. - ' FROM hosts h'. - ' WHERE h.status='.HOST_STATUS_TEMPLATE. - ' AND '.DBcondition('h.hostid',$available_hosts). - order_by('h.host')); - - while($template = DBfetch($templates)){ - $hosts = DBSelect('SELECT h.* '. - ' FROM hosts h, hosts_templates ht '. - ' WHERE ht.templateid='.$template['hostid']. - ' AND ht.hostid=h.hostid '. - ' AND h.status in ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.') '. - ' AND '.DBcondition('h.hostid',$available_hosts). - ' ORDER BY host'); - $host_list = array(); - while($host = DBfetch($hosts)) - { - $style = $host["status"] == HOST_STATUS_MONITORED ? NULL : 'on'; - - array_push($host_list, empty($host_list) ? '' : ', ', new CSpan($host["host"], $style)); - } - $table->AddRow(array( - new CSpan($template["host"],"unknown"), - empty($host_list)?'-':$host_list + + if(isset($_REQUEST["form"])){ + insert_template_form(get_request("hostid",NULL)); + } + else{ + + show_table_header(S_TEMPLATE_LINKAGE_BIG); + + $table = new CTableInfo(S_NO_LINKAGES); + $table->SetHeader(array(S_TEMPLATES,S_HOSTS)); + + $templates = DBSelect('SELECT h.* FROM hosts h'. + ' WHERE h.status='.HOST_STATUS_TEMPLATE. + ' AND '.DBcondition('h.hostid',$available_hosts). + ' ORDER BY h.host'); + while($template = DBfetch($templates)){ + + $hosts = DBSelect('SELECT h.* '. + ' FROM hosts h, hosts_templates ht '. + ' WHERE ht.templateid='.$template['hostid']. + ' AND ht.hostid=h.hostid '. + ' AND h.status IN ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.') '. + ' AND '.DBcondition('h.hostid',$available_hosts). + ' ORDER BY host'); + $host_list = array(); + while($host = DBfetch($hosts)){ + $style = ($host["status"] == HOST_STATUS_MONITORED)?NULL:'on'; + array_push($host_list, empty($host_list) ? '' : ', ', new CSpan($host["host"], $style)); + } + $table->AddRow(array( + new CCol(array( + new CLink($template['host'],'hosts.php?form=update&hostid='. + $template['hostid'].url_param('hostid').url_param('config'), 'action') + ),'unknown'), + empty($host_list)?'-':$host_list )); + } + + $table->Show(); } - - $table->Show(); +//----- END MODE ----- } else if($_REQUEST["config"]==4){ if(isset($_REQUEST["form"])){ diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php index efb3273a..b6cce472 100644 --- a/frontends/php/include/forms.inc.php +++ b/frontends/php/include/forms.inc.php @@ -4637,6 +4637,64 @@ include_once 'include/discovery.inc.php'; $frmHostP->AddItemToBottomRow(new CButtonCancel(url_param("groupid"))); $frmHostP->Show(); } + +// Original mod by scricca@vipsnet.net +// Modified by Aly +/* this code creates a form to link/unlink 1 template to/from multiple hosts */ + function insert_template_form(){ + global $USER_DETAILS; + $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_WRITE, PERM_RES_IDS_ARRAY); + + $frm_title = S_TEMPLATE; + + if(isset($_REQUEST["hostid"])){ + $template = get_host_by_hostid($_REQUEST["hostid"]); + $frm_title = S_TEMPLATE.' ['.$template['host'].']'; + } + + if(isset($_REQUEST['hostid']) && !isset($_REQUEST["form_refresh"])){ + $name=$template['host']; + } + else{ + $name=get_request("tname",''); + } + + $frmHostT = new CFormTable($frm_title,"hosts.php"); + $frmHostT->SetHelp("web.hosts.group.php"); + $frmHostT->AddVar("config",get_request("config",2)); + if(isset($_REQUEST["hostid"])){ + $frmHostT->AddVar("hostid",$_REQUEST["hostid"]); + } + + $frmHostT->AddRow(S_TEMPLATE,new CTextBox("tname",$name,60)); + + $cmbHosts = new CListBox('hosts[]',null,10); + + $sql = 'SELECT DISTINCT h.hostid,h.host '. + ' FROM hosts h'. + ' WHERE ( h.status='.HOST_STATUS_MONITORED.' OR h.status='.HOST_STATUS_NOT_MONITORED.' ) '. + ' AND '.DBcondition('h.hostid',$available_hosts). + ' ORDER BY h.host'; + + $db_hosts=DBselect($sql); + + while($db_host=DBfetch($db_hosts)){ + $cmbHosts->AddItem( + $db_host["hostid"], + get_node_name_by_elid($db_host["hostid"]).$db_host["host"] + ); + } + + $frmHostT->AddRow(S_HOSTS,$cmbHosts); + $frmHostT->AddItemToBottomRow(new CButton('save',S_LINK_TO_TEMPLATE)); + $frmHostT->AddItemToBottomRow(SPACE); + $frmHostT->AddItemToBottomRow(new CButton('unlink',S_UNLINK_FROM_TEMPLATE)); + $frmHostT->AddItemToBottomRow(SPACE); + $frmHostT->AddItemToBottomRow(new CButtonCancel(url_param("config"))); + $frmHostT->Show(); + } +//--- end mod --- + function insert_application_form() { diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php index 920adde5..9e3caf9b 100644 --- a/frontends/php/include/hosts.inc.php +++ b/frontends/php/include/hosts.inc.php @@ -327,12 +327,13 @@ require_once "include/items.inc.php"; * Comments: !!! Don't forget sync code with C !!! * */ - function unlink_template($hostid, $templateid, $unlink_mode = true) - { - if( !is_numeric($templateid) ) fatal_error('Not supported type for [templateid] in [unlink_template] - ['.$templateid.']'); + function unlink_template($hostid, $templateid, $unlink_mode = true){ + if(!is_numeric($templateid)) + fatal_error('Not supported type for [templateid] in [unlink_template] - ['.$templateid.']'); - delete_template_elements($hostid, $templateid, $unlink_mode); - DBexecute("delete from hosts_templates where hostid=".$hostid.' and templateid='.$templateid); + $result = delete_template_elements($hostid, $templateid, $unlink_mode); + $result&= DBexecute("delete from hosts_templates where hostid=".$hostid.' and templateid='.$templateid); + return $result; } /* @@ -353,6 +354,7 @@ require_once "include/items.inc.php"; delete_template_triggers($hostid, $templateid, $unlink_mode); delete_template_items($hostid, $templateid, $unlink_mode); delete_template_applications($hostid, $templateid, $unlink_mode); + return true; } /* @@ -1130,8 +1132,7 @@ require_once "include/items.inc.php"; function delete_template_applications($hostid, $templateid = null, $unlink_mode = false) { $db_apps = get_applications_by_hostid($hostid); - while($db_app = DBfetch($db_apps)) - { + while($db_app = DBfetch($db_apps)){ if($db_app["templateid"] == 0) continue; diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php index 082dc0e2..b17190cc 100644 --- a/frontends/php/include/locales/en_gb.inc.php +++ b/frontends/php/include/locales/en_gb.inc.php @@ -246,8 +246,10 @@ 'S_NEW'=> 'New', 'S_ADD_HOST'=> 'Add host', 'S_REMOVE_HOST'=> 'Remove host', - 'S_LINK_TO_TEMPLATE'=> 'Link to template', - 'S_UNLINK_FROM_TEMPLATE'=> 'Unlink from template', + 'S_LINK_TO_TEMPLATE'=> 'Link to template', + 'S_CANNOT_LINK_TO_TEMPLATE'=> 'CAnnot link to template', + 'S_UNLINK_FROM_TEMPLATE'=> 'Unlink from template', + 'S_CANNOT_UNLINK_FROM_TEMPLATE'=> 'Cannot unlink from template', 'S_INCORRECT_TRIGGER'=> 'Incorrect trigger', 'S_INCORRECT_HOST'=> 'Incorrect host', diff --git a/frontends/php/overview.php b/frontends/php/overview.php index 20d86410..10355cc1 100644 --- a/frontends/php/overview.php +++ b/frontends/php/overview.php @@ -70,7 +70,7 @@ if(isset($_REQUEST["select"])&&($_REQUEST["select"]!="")) $cmbGroup->AddItem(0,S_ALL_SMALL); if($_REQUEST["type"] == SHOW_TRIGGERS){ - $from = ', functions f, triggers t'; + $from = ', functions f, triggers t '; $where = ' and i.itemid=f.itemid '. ' and f.triggerid=t.triggerid '. ' and t.status='.TRIGGER_STATUS_ENABLED; |