diff options
Diffstat (limited to 'frontends/php/discoveryconf.php')
-rw-r--r-- | frontends/php/discoveryconf.php | 129 |
1 files changed, 77 insertions, 52 deletions
diff --git a/frontends/php/discoveryconf.php b/frontends/php/discoveryconf.php index fdd9b8a9e18..04bda6cb9e9 100644 --- a/frontends/php/discoveryconf.php +++ b/frontends/php/discoveryconf.php @@ -42,31 +42,39 @@ $fields = array( 'g_druleid' => array(T_ZBX_INT, O_OPT, null, DB_ID, null), 'dchecks' => array(null, O_OPT, null, null, null), // actions - 'go' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), + 'action' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, + IN('"drule.massdelete","drule.massdisable","drule.massenable"'), + 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), 'form' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'form_refresh' => array(T_ZBX_INT, O_OPT, null, null, null), 'output' => array(T_ZBX_STR, O_OPT, P_ACT, null, null), 'ajaxaction' => array(T_ZBX_STR, O_OPT, P_ACT, null, null), - 'ajaxdata' => array(T_ZBX_STR, O_OPT, P_ACT, null, null) + 'ajaxdata' => array(T_ZBX_STR, O_OPT, P_ACT, null, null), + // sort and sortorder + 'sort' => array(T_ZBX_STR, O_OPT, P_SYS, IN('"name"'), null), + 'sortorder' => array(T_ZBX_STR, O_OPT, P_SYS, IN('"'.ZBX_SORT_DOWN.'","'.ZBX_SORT_UP.'"'), null) ); check_fields($fields); -validate_sort_and_sortorder('name', ZBX_SORT_UP); $_REQUEST['status'] = isset($_REQUEST['status']) ? DRULE_STATUS_ACTIVE : DRULE_STATUS_DISABLED; -$_REQUEST['dchecks'] = get_request('dchecks', array()); +$_REQUEST['dchecks'] = getRequest('dchecks', array()); /* * Permissions */ if (isset($_REQUEST['druleid'])) { $dbDRule = API::DRule()->get(array( - 'druleids' => get_request('druleid'), - 'output' => API_OUTPUT_EXTEND, - 'selectDChecks' => API_OUTPUT_EXTEND, + 'druleids' => getRequest('druleid'), + 'output' => array('name', 'proxy_hostid', 'iprange', 'delay', 'status'), + 'selectDChecks' => array( + 'type', 'key_', 'snmp_community', 'ports', 'snmpv3_securityname', 'snmpv3_securitylevel', + 'snmpv3_authpassphrase', 'snmpv3_privpassphrase', 'uniq', 'snmpv3_authprotocol', 'snmpv3_privprotocol', + 'snmpv3_contextname' + ), 'editable' => true )); if (empty($dbDRule)) { @@ -74,14 +82,12 @@ if (isset($_REQUEST['druleid'])) { } } -$_REQUEST['go'] = get_request('go', 'none'); - // ajax if (isset($_REQUEST['output']) && $_REQUEST['output'] == 'ajax') { - $ajaxResponse = new AjaxResponse; + $ajaxResponse = new CAjaxResponse; if (isset($_REQUEST['ajaxaction']) && $_REQUEST['ajaxaction'] == 'validate') { - $ajaxData = get_request('ajaxdata', array()); + $ajaxData = getRequest('ajaxdata', array()); foreach ($ajaxData as $check) { switch ($check['field']) { @@ -111,26 +117,30 @@ if (isset($_REQUEST['output']) && $_REQUEST['output'] == 'ajax') { * Action */ if (isset($_REQUEST['save'])) { - $dChecks = get_request('dchecks', array()); - $uniq = get_request('uniqueness_criteria', 0); + $dChecks = getRequest('dchecks', array()); + $uniq = getRequest('uniqueness_criteria', 0); foreach ($dChecks as $dcnum => $check) { + if (substr($check['dcheckid'], 0, 3) === 'new') { + unset($dChecks[$dcnum]['dcheckid']); + } + $dChecks[$dcnum]['uniq'] = ($uniq == $dcnum) ? 1 : 0; } $discoveryRule = array( - 'name' => get_request('name'), - 'proxy_hostid' => get_request('proxy_hostid'), - 'iprange' => get_request('iprange'), - 'delay' => get_request('delay'), - 'status' => get_request('status'), + 'name' => getRequest('name'), + 'proxy_hostid' => getRequest('proxy_hostid'), + 'iprange' => getRequest('iprange'), + 'delay' => getRequest('delay'), + 'status' => getRequest('status'), 'dchecks' => $dChecks ); DBStart(); if (isset($_REQUEST['druleid'])) { - $discoveryRule['druleid'] = get_request('druleid'); + $discoveryRule['druleid'] = getRequest('druleid'); $result = API::DRule()->update($discoveryRule); $messageSuccess = _('Discovery rule updated'); @@ -152,22 +162,24 @@ if (isset($_REQUEST['save'])) { } $result = DBend($result); + + if ($result) { + uncheckTableRows(); + } show_messages($result, $messageSuccess, $messageFailed); - clearCookies($result); } elseif (isset($_REQUEST['delete']) && isset($_REQUEST['druleid'])) { $result = API::DRule()->delete(array($_REQUEST['druleid'])); - show_messages($result, _('Discovery rule deleted'), _('Cannot delete discovery rule')); - if ($result) { unset($_REQUEST['form'], $_REQUEST['druleid']); - clearCookies($result); + uncheckTableRows(); } + show_messages($result, _('Discovery rule deleted'), _('Cannot delete discovery rule')); } -elseif (str_in_array(getRequest('go'), array('activate', 'disable')) && hasRequest('g_druleid')) { +elseif (hasRequest('action') && str_in_array(getRequest('action'), array('drule.massenable', 'drule.massdisable')) && hasRequest('g_druleid')) { $result = true; - $enable = (getRequest('go') == 'activate'); + $enable = (getRequest('action') == 'drule.massenable'); $status = $enable ? DRULE_STATUS_ACTIVE : DRULE_STATUS_DISABLED; $auditAction = $enable ? AUDIT_ACTION_ENABLE : AUDIT_ACTION_DISABLE; $updated = 0; @@ -175,7 +187,7 @@ elseif (str_in_array(getRequest('go'), array('activate', 'disable')) && hasReque DBStart(); foreach (getRequest('g_druleid') as $druleId) { - $result &= DBexecute('UPDATE drules SET status='.$status.' WHERE druleid='.zbx_dbstr($druleId)); + $result &= DBexecute('UPDATE drules SET status='.zbx_dbstr($status).' WHERE druleid='.zbx_dbstr($druleId)); if ($result) { $druleData = get_discovery_rule_by_druleid($druleId); @@ -193,14 +205,19 @@ elseif (str_in_array(getRequest('go'), array('activate', 'disable')) && hasReque : _n('Cannot disable discovery rule', 'Cannot disable discovery rules', $updated); $result = DBend($result); + + if ($result) { + uncheckTableRows(); + } show_messages($result, $messageSuccess, $messageFailed); - clearCookies($result); } -elseif ($_REQUEST['go'] == 'delete' && isset($_REQUEST['g_druleid'])) { - $result = API::DRule()->delete($_REQUEST['g_druleid']); +elseif (hasRequest('action') && getRequest('action') == 'drule.massdelete' && hasRequest('g_druleid')) { + $result = API::DRule()->delete(getRequest('g_druleid')); + if ($result) { + uncheckTableRows(); + } show_messages($result, _('Discovery rules deleted'), _('Cannot delete discovery rules')); - clearCookies($result); } /* @@ -208,10 +225,10 @@ elseif ($_REQUEST['go'] == 'delete' && isset($_REQUEST['g_druleid'])) { */ if (isset($_REQUEST['form'])) { $data = array( - 'druleid' => get_request('druleid'), + 'druleid' => getRequest('druleid'), 'drule' => array(), - 'form' => get_request('form'), - 'form_refresh' => get_request('form_refresh', 0) + 'form' => getRequest('form'), + 'form_refresh' => getRequest('form_refresh', 0) ); // get drule @@ -228,14 +245,14 @@ if (isset($_REQUEST['form'])) { } } else { - $data['drule']['proxy_hostid'] = get_request('proxy_hostid', 0); - $data['drule']['name'] = get_request('name', ''); - $data['drule']['iprange'] = get_request('iprange', '192.168.0.1-254'); - $data['drule']['delay'] = get_request('delay', SEC_PER_HOUR); - $data['drule']['status'] = get_request('status', DRULE_STATUS_ACTIVE); - $data['drule']['dchecks'] = get_request('dchecks', array()); - $data['drule']['nextcheck'] = get_request('nextcheck', 0); - $data['drule']['uniqueness_criteria'] = get_request('uniqueness_criteria', -1); + $data['drule']['proxy_hostid'] = getRequest('proxy_hostid', 0); + $data['drule']['name'] = getRequest('name', ''); + $data['drule']['iprange'] = getRequest('iprange', '192.168.0.1-254'); + $data['drule']['delay'] = getRequest('delay', SEC_PER_HOUR); + $data['drule']['status'] = getRequest('status', DRULE_STATUS_ACTIVE); + $data['drule']['dchecks'] = getRequest('dchecks', array()); + $data['drule']['nextcheck'] = getRequest('nextcheck', 0); + $data['drule']['uniqueness_criteria'] = getRequest('uniqueness_criteria', -1); } if (!empty($data['drule']['dchecks'])) { @@ -262,18 +279,26 @@ if (isset($_REQUEST['form'])) { $discoveryView->show(); } else { - $data = array(); + $sortField = getRequest('sort', CProfile::get('web.'.$page['file'].'.sort', 'name')); + $sortOrder = getRequest('sortorder', CProfile::get('web.'.$page['file'].'.sortorder', ZBX_SORT_UP)); + + CProfile::update('web.'.$page['file'].'.sort', $sortField, PROFILE_TYPE_STR); + CProfile::update('web.'.$page['file'].'.sortorder', $sortOrder, PROFILE_TYPE_STR); + + $data = array( + 'sort' => $sortField, + 'sortorder' => $sortOrder + ); // get drules $data['drules'] = API::DRule()->get(array( - 'output' => API_OUTPUT_EXTEND, - 'sortfield' => getPageSortField('name'), - 'selectDChecks' => API_OUTPUT_EXTEND, + 'output' => array('proxy_hostid', 'name', 'status', 'iprange', 'delay'), + 'selectDChecks' => array('type'), 'editable' => true )); if ($data['drules']) { - foreach ($data['drules'] as $druleId => $drule) { + foreach ($data['drules'] as $key => $drule) { // checks $checks = array(); @@ -283,23 +308,23 @@ else { order_result($checks); - $data['drules'][$druleId]['checks'] = $checks; + $data['drules'][$key]['checks'] = $checks; // description - $data['drules'][$druleId]['description'] = array(); + $data['drules'][$key]['description'] = array(); if ($drule['proxy_hostid']) { $proxy = get_host_by_hostid($drule['proxy_hostid']); - array_push($data['drules'][$druleId]['description'], $proxy['host'].NAME_DELIMITER); + array_push($data['drules'][$key]['description'], $proxy['host'].NAME_DELIMITER); } } - order_result($data['drules'], getPageSortField('name'), getPageSortOrder()); + order_result($data['drules'], $sortField, $sortOrder); } // get paging - $data['paging'] = getPagingLine($data['drules'], array('druleid')); + $data['paging'] = getPagingLine($data['drules']); // render view $discoveryView = new CView('configuration.discovery.list', $data); |