diff options
author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-03-20 11:39:17 +0000 |
---|---|---|
committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-03-20 11:39:17 +0000 |
commit | a23c4de7f946b02f036315d319591ff5cfe08a93 (patch) | |
tree | f919d1e183903909f5d4220e9be574e2dd2b3351 /frontends/php/discoveryconf.php | |
parent | 80e1c36d1b3ae7593d368ca1e4d7bee2ff8f40f7 (diff) | |
download | zabbix-a23c4de7f946b02f036315d319591ff5cfe08a93.tar.gz zabbix-a23c4de7f946b02f036315d319591ff5cfe08a93.tar.xz zabbix-a23c4de7f946b02f036315d319591ff5cfe08a93.zip |
- developed configuration interface for discovery (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3900 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/discoveryconf.php')
-rw-r--r-- | frontends/php/discoveryconf.php | 266 |
1 files changed, 266 insertions, 0 deletions
diff --git a/frontends/php/discoveryconf.php b/frontends/php/discoveryconf.php new file mode 100644 index 00000000..9a67604c --- /dev/null +++ b/frontends/php/discoveryconf.php @@ -0,0 +1,266 @@ +<?php +/* +** ZABBIX +** Copyright (C) 2000-2005 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ +?> +<?php + require_once "include/config.inc.php"; + require_once "include/forms.inc.php"; + require_once "include/discovery.inc.php"; + + $page["title"] = "S_CONFIGURATION_OF_DISCOVERY"; + $page["file"] = "discoveryconf.php"; + +include_once "include/page_header.php"; + +?> +<?php +// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION + $fields=array( + "druleid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, '{form}=="update"'), + "name"=> array(T_ZBX_STR, O_OPT, null, NOT_EMPTY, 'isset({save})'), + "ipfirst"=> array(T_ZBX_IP, O_OPT, null, NOT_EMPTY, 'isset({save})'), + "iplast"=> array(T_ZBX_IP, O_OPT, null, NOT_EMPTY, 'isset({save})'), + "delay"=> array(T_ZBX_INT, O_OPT, null, null, 'isset({save})'), + "status"=> array(T_ZBX_INT, O_OPT, null, IN("0,1"), 'isset({save})'), + "upevent"=> array(T_ZBX_INT, O_OPT, null, null, 'isset({save})'), + "downevent"=> array(T_ZBX_INT, O_OPT, null, null, 'isset({save})'), + "svcupevent"=> array(T_ZBX_INT, O_OPT, null, null, 'isset({save})'), + "svcdownevent"=>array(T_ZBX_INT, O_OPT, null, null, 'isset({save})'), + + "g_druleid"=> array(T_ZBX_INT, O_OPT, null, DB_ID, null), + + "dchecks"=> array(null, O_OPT, null, null, null), + "selected_checks"=> array(T_ZBX_INT, O_OPT, null, null, null), + + "new_check_type"=> array(T_ZBX_INT, O_OPT, null, + IN(array(SVC_SSH, SVC_LDAP, SVC_SMTP, SVC_FTP, SVC_HTTP, SVC_POP, SVC_NNTP, SVC_IMAP, SVC_TCP)), + 'isset({add_check})'), + + "new_check_ports"=> array(T_ZBX_PORTS, O_OPT, null, NOT_EMPTY, 'isset({add_check})'), + +/* actions */ + "add_check"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), + "delete_ckecks"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), + "group_enable"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), + "group_disable"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), + "group_delete"=> 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), + "clone"=> 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), +/* other */ + "form"=> array(T_ZBX_STR, O_OPT, P_SYS, null, null), + "form_refresh"=> array(T_ZBX_INT, O_OPT, null, null, null) + ); + + check_fields($fields); + $_REQUEST['dchecks'] = get_request('dchecks', array()); + +?> +<?php + if(inarr_isset(array('add_check', 'new_check_type', 'new_check_ports'))) + { + $new_dcheck = array( + 'type' => $_REQUEST['new_check_type'], + 'ports'=> $_REQUEST['new_check_ports'] + ); + if( !in_array($new_dcheck, $_REQUEST['dchecks'])) + $_REQUEST['dchecks'][] = $new_dcheck; + } + else if(inarr_isset(array('delete_ckecks', 'selected_checks'))) + { + foreach($_REQUEST['selected_checks'] as $chk_id) + unset($_REQUEST['dchecks'][$chk_id]); + } + else if(inarr_isset('save')) + { + if(inarr_isset('druleid')) + { /* update */ + $msg_ok = S_DISCOVERY_RULE_UPDATED; + $msg_fail = S_CANNOT_UPDATE_DISCOVERY_RULE; + + $result = update_discovery_rule($_REQUEST["druleid"], $_REQUEST['name'], $_REQUEST['ipfirst'], $_REQUEST['iplast'], + $_REQUEST['delay'], $_REQUEST['status'], $_REQUEST['upevent'], $_REQUEST['downevent'], + $_REQUEST['svcupevent'], $_REQUEST['svcdownevent'], $_REQUEST['dchecks']); + + $druleid = $_REQUEST["druleid"]; + } + else + { /* add new */ + $msg_ok = S_DISCOVERY_RULE_ADDED; + $msg_fail = S_CANNOT_ADD_DISCOVERY_RULE; + + $druleid = add_discovery_rule($_REQUEST['name'], $_REQUEST['ipfirst'], $_REQUEST['iplast'], + $_REQUEST['delay'], $_REQUEST['status'], $_REQUEST['upevent'], $_REQUEST['downevent'], + $_REQUEST['svcupevent'], $_REQUEST['svcdownevent'], $_REQUEST['dchecks']); + + $result = $druleid; + } + + show_messages($result, $msg_ok, $msg_fail); + + if($result) // result - OK + { + add_audit(!isset($_REQUEST["druleid"]) ? AUDIT_ACTION_ADD : AUDIT_ACTION_UPDATE, + AUDIT_RESOURCE_DISCOVERY_RULE, '['.$druleid.'] '.$_REQUEST['name']); + + unset($_REQUEST["form"]); + } + } + else if(inarr_isset(array('clone','druleid'))) + { + unset($_REQUEST["druleid"]); + $_REQUEST["form"] = "clone"; + } + else if(inarr_isset(array('delete', 'druleid'))) + { + $result = delete_discovery_rule($_REQUEST['druleid']); + show_messages($result,S_DISCOVERY_RULE_DELETED,S_CANNOT_DELETE_DISCOVERY_RULE); + if($result) + { + add_audit(AUDIT_ACTION_DELETE,AUDIT_RESOURCE_DISCOVERY_RULE, + '['.$_REQUEST['druleid'].']'); + unset($_REQUEST['form']); + unset($_REQUEST['druleid']); + } + + } + else if(inarr_isset('g_druleid')) + { + if( inarr_isset('group_disable') || inarr_isset('group_enable') ) + { + $status = DRULE_STATUS_ACTIVE; + if(isset($_REQUEST['group_disable'])) $status = DRULE_STATUS_DISABLED; + + $result = false; + foreach($_REQUEST['g_druleid'] as $drid) + { + if(set_discovery_rule_status($drid,$status)) + { + $rule_data = get_discovery_rule_by_druleid($drid); + add_audit(AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_DISCOVERY_RULE, + '['.$drid.'] '.$rule_data['name']); + $result = true; + } + } + show_messages($result,S_DISCOVERY_RULES_UPDATED); + } + else if( inarr_isset('group_delete') ) + { + $result = false; + foreach($_REQUEST['g_druleid'] as $drid) + { + if(delete_discovery_rule($drid)) + { + add_audit(AUDIT_ACTION_DELETE,AUDIT_RESOURCE_DISCOVERY_RULE, + '['.$drid.']'); + $result = true; + } + } + show_messages($result,S_DISCOVERY_RULES_DELETED); + } + } +?> +<?php +/* header */ + $form = new CForm(); + $form->AddItem(new CButton('form', S_CREATE_RULE)); + show_table_header(S_CONFIGURATION_OF_DISCOVERY_BIG, $form); + echo BR; + + if(isset($_REQUEST["form"])) + { +/* form */ + insert_drule_form(); + } + else + { + show_table_header(S_DISCOVERY_BIG); +/* table */ + $form = new CForm(); + $form->SetName('frmdrules'); + + $tblDiscovery = new CTableInfo(S_NO_DISCOVERY_RULES_DEFINED); + $tblDiscovery->SetHeader(array( + array( new CCheckBox('all_drules',null,"CheckAll('".$form->GetName()."','all_drules');"), + S_NAME + ), + S_IP_FIRST, + S_IP_LAST, + S_DELAY, + S_INTERVALS.' (up/down)', + S_CHECKS, + S_STATUS)); + + $db_rules = DBselect('select * from drules where '.DBid2nodeid('druleid').'='.$ZBX_CURNODEID. + ' order by name, druleid'); + while($rule_data = DBfetch($db_rules)) + { + $cheks = array(); + $db_checks = DBselect("select * from dchecks where druleid=".$rule_data["druleid"]. + " order by type,druleid"); + while($check_data = DBfetch($db_checks)) + { + $cheks[] = discovery_check_type2str($check_data['type']); + } + + $intervals = '[host]('.($rule_data['upevent'] / (60*60)). + '/'.($rule_data['downevent'] / (60*60)). + ') [service]('.($rule_data['svcupevent'] / (60*60)). + '/'.($rule_data['svcdownevent'] / (60*60)).')'; + + $status = new CCol(new CLink(discovery_status2str($rule_data["status"]), + '?g_druleid%5B%5D='.$rule_data['druleid']. + ($rule_data["status"] == DRULE_STATUS_ACTIVE ? '&group_disable=1' : '&group_enable=1'), + discovery_status2style($rule_data["status"]))); + + $tblDiscovery->AddRow(array( + array( + new CCheckBox( + "g_druleid[]", /* name */ + null, /* checked */ + null, /* action */ + $rule_data["druleid"]), /* value */ + SPACE, + new CLink($rule_data['name'], + "?form=update&druleid=".$rule_data['druleid'],'action'), + ), + $rule_data['ipfirst'], + $rule_data['iplast'], + $rule_data['delay'], + $intervals, + implode(',', $cheks), + $status + )); + } + $tblDiscovery->SetFooter(new CCol(array( + new CButton('group_enable',S_ENABLE_SELECTED, "return Confirm('".S_ENABLE_SELECTED_RULES_Q."');"), SPACE, + new CButton('group_disable',S_DISABLE_SELECTED, "return Confirm('".S_DISABLE_SELECTED_RULES_Q."');"), SPACE, + new CButton('group_delete',S_DELETE_SELECTED, "return Confirm('".S_DELETE_SELECTED_RULES_Q."');"), + ))); + + $form->AddItem($tblDiscovery); + $form->Show(); + } +?> +<?php + + include_once "include/page_footer.php"; + +?> |