diff options
Diffstat (limited to 'frontends/php/actionconf.php')
-rw-r--r-- | frontends/php/actionconf.php | 300 |
1 files changed, 159 insertions, 141 deletions
diff --git a/frontends/php/actionconf.php b/frontends/php/actionconf.php index 3d2758bc522..6c6dae3d19a 100644 --- a/frontends/php/actionconf.php +++ b/frontends/php/actionconf.php @@ -40,7 +40,9 @@ $fields = array( null ), 'evaltype' => array(T_ZBX_INT, O_OPT, null, - IN(array(CONDITION_EVAL_TYPE_AND_OR, CONDITION_EVAL_TYPE_AND, CONDITION_EVAL_TYPE_OR)), 'isset({save})'), + IN(array(CONDITION_EVAL_TYPE_AND_OR, CONDITION_EVAL_TYPE_AND, CONDITION_EVAL_TYPE_OR, CONDITION_EVAL_TYPE_EXPRESSION)), + 'isset({save})'), + 'formula' => array(T_ZBX_STR, O_OPT, null, null, 'isset({save})'), 'esc_period' => array(T_ZBX_INT, O_OPT, null, BETWEEN(60, 999999), null, _('Default operation step duration')), 'status' => array(T_ZBX_INT, O_OPT, null, IN(array(ACTION_STATUS_ENABLED, ACTION_STATUS_DISABLED)), null), 'def_shortdata' => array(T_ZBX_STR, O_OPT, null, null, 'isset({save})'), @@ -57,7 +59,10 @@ $fields = array( 'opconditions' => array(null, O_OPT, null, null, null), 'new_opcondition' => array(null, O_OPT, null, null, 'isset({add_opcondition})'), // 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('"action.massdelete","action.massdisable","action.massenable"'), + null + ), 'add_condition' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), 'cancel_new_condition' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), 'add_operation' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), @@ -65,11 +70,13 @@ $fields = array( 'add_opcondition' => array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null), 'cancel_new_opcondition' => 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), 'form' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), - 'form_refresh' => array(T_ZBX_INT, O_OPT, null, null, null) + 'form_refresh' => array(T_ZBX_INT, O_OPT, null, null, null), + // sort and sortorder + 'sort' => array(T_ZBX_STR, O_OPT, P_SYS, IN('"name","status"'), null), + 'sortorder' => array(T_ZBX_STR, O_OPT, P_SYS, IN('"'.ZBX_SORT_DOWN.'","'.ZBX_SORT_UP.'"'), null) ); $dataValid = check_fields($fields); @@ -78,10 +85,6 @@ if ($dataValid && hasRequest('eventsource') && !hasRequest('form')) { CProfile::update('web.actionconf.eventsource', getRequest('eventsource'), PROFILE_TYPE_INT); } -validate_sort_and_sortorder('name', ZBX_SORT_UP); - -$_REQUEST['go'] = getRequest('go', 'none'); - if (isset($_REQUEST['actionid'])) { $actionPermissions = API::Action()->get(array( 'output' => array('actionid'), @@ -96,11 +99,7 @@ if (isset($_REQUEST['actionid'])) { /* * Actions */ -if (isset($_REQUEST['clone']) && isset($_REQUEST['actionid'])) { - unset($_REQUEST['actionid']); - $_REQUEST['form'] = 'clone'; -} -elseif (isset($_REQUEST['cancel_new_operation'])) { +if (isset($_REQUEST['cancel_new_operation'])) { unset($_REQUEST['new_operation']); } elseif (isset($_REQUEST['cancel_new_opcondition'])) { @@ -108,17 +107,15 @@ elseif (isset($_REQUEST['cancel_new_opcondition'])) { } elseif (hasRequest('save')) { $action = array( - 'name' => get_request('name'), - 'evaltype' => get_request('evaltype', 0), - 'status' => get_request('status', ACTION_STATUS_DISABLED), - 'esc_period' => get_request('esc_period', 0), - 'def_shortdata' => get_request('def_shortdata', ''), - 'def_longdata' => get_request('def_longdata', ''), - 'recovery_msg' => get_request('recovery_msg', 0), - 'r_shortdata' => get_request('r_shortdata', ''), - 'r_longdata' => get_request('r_longdata', ''), - 'conditions' => get_request('conditions', array()), - 'operations' => get_request('operations', array()) + 'name' => getRequest('name'), + 'status' => getRequest('status', ACTION_STATUS_DISABLED), + 'esc_period' => getRequest('esc_period', 0), + 'def_shortdata' => getRequest('def_shortdata', ''), + 'def_longdata' => getRequest('def_longdata', ''), + 'recovery_msg' => getRequest('recovery_msg', 0), + 'r_shortdata' => getRequest('r_shortdata', ''), + 'r_longdata' => getRequest('r_longdata', ''), + 'operations' => getRequest('operations', array()) ); foreach ($action['operations'] as $num => $operation) { @@ -127,6 +124,23 @@ elseif (hasRequest('save')) { } } + $filter = array( + 'conditions' => getRequest('conditions', array()), + 'evaltype' => getRequest('evaltype') + ); + + if ($filter['evaltype'] == CONDITION_EVAL_TYPE_EXPRESSION) { + if (count($filter['conditions']) > 1) { + $filter['formula'] = getRequest('formula'); + } + else { + // if only one or no conditions are left, reset the evaltype to "and/or" and clear the formula + $filter['formula'] = ''; + $filter['evaltype'] = CONDITION_EVAL_TYPE_AND_OR; + } + } + $action['filter'] = $filter; + DBstart(); if (hasRequest('actionid')) { @@ -156,100 +170,91 @@ elseif (hasRequest('save')) { } $result = DBend($result); + + if ($result) { + uncheckTableRows(); + } show_messages($result, $messageSuccess, $messageFailed); - clearCookies($result); } elseif (isset($_REQUEST['delete']) && isset($_REQUEST['actionid'])) { $result = API::Action()->delete(array(getRequest('actionid'))); - show_messages($result, _('Action deleted'), _('Cannot delete action')); - if ($result) { unset($_REQUEST['form'], $_REQUEST['actionid']); - clearCookies($result); + uncheckTableRows(); } + show_messages($result, _('Action deleted'), _('Cannot delete action')); } elseif (isset($_REQUEST['add_condition']) && isset($_REQUEST['new_condition'])) { - try { - $newCondition = get_request('new_condition'); + $newCondition = getRequest('new_condition'); - if ($newCondition) { - $conditions = get_request('conditions', array()); + if ($newCondition) { + $conditions = getRequest('conditions', array()); - // when adding new maintenance, in order to check for an existing maintenance, it must have a not null value - if ($newCondition['conditiontype'] == CONDITION_TYPE_MAINTENANCE) { - $newCondition['value'] = ''; - } + // when adding new maintenance, in order to check for an existing maintenance, it must have a not null value + if ($newCondition['conditiontype'] == CONDITION_TYPE_MAINTENANCE) { + $newCondition['value'] = ''; + } - // check existing conditions and remove duplicate condition values - foreach ($conditions as $condition) { - if ($newCondition['conditiontype'] == $condition['conditiontype']) { - if (is_array($newCondition['value'])) { - foreach ($newCondition['value'] as $key => $newValue) { - if ($condition['value'] == $newValue) { - unset($newCondition['value'][$key]); - } + // check existing conditions and remove duplicate condition values + foreach ($conditions as $condition) { + if ($newCondition['conditiontype'] == $condition['conditiontype']) { + if (is_array($newCondition['value'])) { + foreach ($newCondition['value'] as $key => $newValue) { + if ($condition['value'] == $newValue) { + unset($newCondition['value'][$key]); } } - else { - if ($newCondition['value'] == $condition['value']) { - $newCondition['value'] = null; - } + } + else { + if ($newCondition['value'] == $condition['value']) { + $newCondition['value'] = null; } } } + } - $validateConditions = $conditions; + $usedFormulaIds = zbx_objectValues($conditions, 'formulaid'); - if (isset($newCondition['value'])) { - $newConditionValues = zbx_toArray($newCondition['value']); - foreach ($newConditionValues as $newValue) { - $condition = $newCondition; - $condition['value'] = $newValue; - $validateConditions[] = $condition; - } - } + $validateConditions = $conditions; - if ($validateConditions) { - CAction::validateConditions($validateConditions); + if (isset($newCondition['value'])) { + $newConditionValues = zbx_toArray($newCondition['value']); + foreach ($newConditionValues as $newValue) { + $condition = $newCondition; + $condition['value'] = $newValue; + $condition['formulaid'] = CConditionHelper::getNextFormulaId($usedFormulaIds); + $usedFormulaIds[] = $condition['formulaid']; + $validateConditions[] = $condition; } - - $_REQUEST['conditions'] = $validateConditions; } - } - catch (APIException $e) { - show_error_message(_('Cannot add action condition')); - error($e->getMessage()); - } -} -elseif (isset($_REQUEST['add_opcondition']) && isset($_REQUEST['new_opcondition'])) { - $new_opcondition = $_REQUEST['new_opcondition']; - try { - CAction::validateOperationConditions($new_opcondition); - $new_operation = get_request('new_operation', array()); + $conditionsValid = true; + if ($validateConditions) { + $filterConditionValidator = new CActionCondValidator(); + foreach ($validateConditions as $condition) { + if (!$filterConditionValidator->validate($condition)) { + $conditionsValid = false; + break; + } + } + } - if (!isset($new_operation['opconditions'])) { - $new_operation['opconditions'] = array(); + if ($conditionsValid) { + $_REQUEST['conditions'] = $validateConditions; } - if (!str_in_array($new_opcondition, $new_operation['opconditions'])) { - array_push($new_operation['opconditions'], $new_opcondition); + else { + error($filterConditionValidator->getError()); + show_error_message(_('Cannot add action condition')); } - - $_REQUEST['new_operation'] = $new_operation; - - unset($_REQUEST['new_opcondition']); - } - catch (APIException $e) { - error($e->getMessage()); } } elseif (isset($_REQUEST['add_operation']) && isset($_REQUEST['new_operation'])) { $new_operation = $_REQUEST['new_operation']; $result = true; - if (API::Action()->validateOperations($new_operation)) { - $_REQUEST['operations'] = get_request('operations', array()); + if (API::Action()->validateOperationsIntegrity($new_operation)) { + $_REQUEST['operations'] = getRequest('operations', array()); $uniqOperations = array( OPERATION_TYPE_HOST_ADD => 0, @@ -289,7 +294,7 @@ elseif (isset($_REQUEST['add_operation']) && isset($_REQUEST['new_operation'])) elseif (isset($_REQUEST['edit_operationid'])) { $_REQUEST['edit_operationid'] = array_keys($_REQUEST['edit_operationid']); $edit_operationid = $_REQUEST['edit_operationid'] = array_pop($_REQUEST['edit_operationid']); - $_REQUEST['operations'] = get_request('operations', array()); + $_REQUEST['operations'] = getRequest('operations', array()); if (isset($_REQUEST['operations'][$edit_operationid])) { $_REQUEST['new_operation'] = $_REQUEST['operations'][$edit_operationid]; @@ -297,9 +302,9 @@ elseif (isset($_REQUEST['edit_operationid'])) { $_REQUEST['new_operation']['action'] = 'update'; } } -elseif (str_in_array(getRequest('go'), array('activate', 'disable')) && hasRequest('g_actionid')) { +elseif (hasRequest('action') && str_in_array(getRequest('action'), array('action.massenable', 'action.massdisable')) && hasRequest('g_actionid')) { $result = true; - $enable = (getRequest('go') == 'activate'); + $enable = (getRequest('action') == 'action.massenable'); $status = $enable ? ACTION_STATUS_ENABLED : ACTION_STATUS_DISABLED; $statusName = $enable ? 'enabled' : 'disabled'; $actionIds = array(); @@ -310,7 +315,7 @@ elseif (str_in_array(getRequest('go'), array('activate', 'disable')) && hasReque $dbActions = DBselect( 'SELECT a.actionid'. ' FROM actions a'. - ' WHERE '.dbConditionInt('a.actionid', $_REQUEST['g_actionid']) + ' WHERE '.dbConditionInt('a.actionid', getRequest('g_actionid')) ); while ($row = DBfetch($dbActions)) { $result &= DBexecute( @@ -336,14 +341,19 @@ elseif (str_in_array(getRequest('go'), array('activate', 'disable')) && hasReque : _n('Cannot disable action', 'Cannot disable actions', $updated); $result = DBend($result); + + if ($result) { + uncheckTableRows(); + } show_messages($result, $messageSuccess, $messageFailed); - clearCookies($result); } -elseif ($_REQUEST['go'] == 'delete' && isset($_REQUEST['g_actionid'])) { - $goResult = API::Action()->delete($_REQUEST['g_actionid']); +elseif (hasRequest('action') && getRequest('action') == 'action.massdelete' && hasRequest('g_actionid')) { + $result = API::Action()->delete(getRequest('g_actionid')); - show_messages($goResult, _('Selected actions deleted'), _('Cannot delete selected actions')); - clearCookies($goResult); + if ($result) { + uncheckTableRows(); + } + show_messages($result, _('Selected actions deleted'), _('Cannot delete selected actions')); } /* @@ -353,10 +363,10 @@ show_messages(); if (hasRequest('form')) { $data = array( - 'form' => get_request('form'), - 'actionid' => get_request('actionid'), - 'new_condition' => get_request('new_condition', array()), - 'new_operation' => get_request('new_operation', null) + 'form' => getRequest('form'), + 'actionid' => getRequest('actionid'), + 'new_condition' => getRequest('new_condition', array()), + 'new_operation' => getRequest('new_operation') ); $action = null; @@ -364,18 +374,18 @@ if (hasRequest('form')) { $data['action'] = API::Action()->get(array( 'actionids' => $data['actionid'], 'selectOperations' => API_OUTPUT_EXTEND, - 'selectConditions' => API_OUTPUT_EXTEND, + 'selectFilter' => array('formula', 'conditions', 'evaltype'), 'output' => API_OUTPUT_EXTEND, 'editable' => true )); $data['action'] = reset($data['action']); + $data['eventsource'] = $data['action']['eventsource']; } else { $data['eventsource'] = getRequest('eventsource', CProfile::get('web.actionconf.eventsource', EVENT_SOURCE_TRIGGERS) ); - $data['evaltype'] = getRequest('evaltype'); $data['esc_period'] = getRequest('esc_period'); } @@ -383,55 +393,59 @@ if (hasRequest('form')) { sortOperations($data['eventsource'], $data['action']['operations']); } else { - $data['action']['name'] = get_request('name'); - $data['action']['evaltype'] = get_request('evaltype', 0); - $data['action']['esc_period'] = get_request('esc_period', SEC_PER_HOUR); - $data['action']['status'] = get_request('status', hasRequest('form_refresh') ? 1 : 0); - $data['action']['recovery_msg'] = get_request('recovery_msg', 0); - $data['action']['conditions'] = get_request('conditions', array()); - $data['action']['operations'] = get_request('operations', array()); + $data['action']['name'] = getRequest('name'); + $data['action']['esc_period'] = getRequest('esc_period', SEC_PER_HOUR); + $data['action']['status'] = getRequest('status', hasRequest('form_refresh') ? 1 : 0); + $data['action']['recovery_msg'] = getRequest('recovery_msg', 0); + $data['action']['operations'] = getRequest('operations', array()); + + $data['action']['filter']['evaltype'] = getRequest('evaltype'); + $data['action']['filter']['formula'] = getRequest('formula'); + $data['action']['filter']['conditions'] = getRequest('conditions', array()); sortOperations($data['eventsource'], $data['action']['operations']); if ($data['actionid'] && hasRequest('form_refresh')) { - $data['action']['def_shortdata'] = get_request('def_shortdata'); - $data['action']['def_longdata'] = get_request('def_longdata'); + $data['action']['def_shortdata'] = getRequest('def_shortdata'); + $data['action']['def_longdata'] = getRequest('def_longdata'); } else { if ($data['eventsource'] == EVENT_SOURCE_TRIGGERS) { - $data['action']['def_shortdata'] = get_request('def_shortdata', ACTION_DEFAULT_SUBJ_TRIGGER); - $data['action']['def_longdata'] = get_request('def_longdata', ACTION_DEFAULT_MSG_TRIGGER); - $data['action']['r_shortdata'] = get_request('r_shortdata', ACTION_DEFAULT_SUBJ_TRIGGER); - $data['action']['r_longdata'] = get_request('r_longdata', ACTION_DEFAULT_MSG_TRIGGER); + $data['action']['def_shortdata'] = getRequest('def_shortdata', ACTION_DEFAULT_SUBJ_TRIGGER); + $data['action']['def_longdata'] = getRequest('def_longdata', ACTION_DEFAULT_MSG_TRIGGER); + $data['action']['r_shortdata'] = getRequest('r_shortdata', ACTION_DEFAULT_SUBJ_TRIGGER); + $data['action']['r_longdata'] = getRequest('r_longdata', ACTION_DEFAULT_MSG_TRIGGER); } elseif ($data['eventsource'] == EVENT_SOURCE_DISCOVERY) { - $data['action']['def_shortdata'] = get_request('def_shortdata', ACTION_DEFAULT_SUBJ_DISCOVERY); - $data['action']['def_longdata'] = get_request('def_longdata', ACTION_DEFAULT_MSG_DISCOVERY); + $data['action']['def_shortdata'] = getRequest('def_shortdata', ACTION_DEFAULT_SUBJ_DISCOVERY); + $data['action']['def_longdata'] = getRequest('def_longdata', ACTION_DEFAULT_MSG_DISCOVERY); } elseif ($data['eventsource'] == EVENT_SOURCE_AUTO_REGISTRATION) { - $data['action']['def_shortdata'] = get_request('def_shortdata', ACTION_DEFAULT_SUBJ_AUTOREG); - $data['action']['def_longdata'] = get_request('def_longdata', ACTION_DEFAULT_MSG_AUTOREG); + $data['action']['def_shortdata'] = getRequest('def_shortdata', ACTION_DEFAULT_SUBJ_AUTOREG); + $data['action']['def_longdata'] = getRequest('def_longdata', ACTION_DEFAULT_MSG_AUTOREG); } else { - $data['action']['def_shortdata'] = get_request('def_shortdata'); - $data['action']['def_longdata'] = get_request('def_longdata'); - $data['action']['r_shortdata'] = get_request('r_shortdata'); - $data['action']['r_longdata'] = get_request('r_longdata'); + $data['action']['def_shortdata'] = getRequest('def_shortdata'); + $data['action']['def_longdata'] = getRequest('def_longdata'); + $data['action']['r_shortdata'] = getRequest('r_shortdata'); + $data['action']['r_longdata'] = getRequest('r_longdata'); } } } if (!$data['actionid'] && !hasRequest('form_refresh') && $data['eventsource'] == EVENT_SOURCE_TRIGGERS) { - $data['action']['conditions'] = array( - array( - 'conditiontype' => CONDITION_TYPE_TRIGGER_VALUE, - 'operator' => CONDITION_OPERATOR_EQUAL, - 'value' => TRIGGER_VALUE_TRUE - ), + $data['action']['filter']['conditions'] = array( array( + 'formulaid' => 'A', 'conditiontype' => CONDITION_TYPE_MAINTENANCE, 'operator' => CONDITION_OPERATOR_NOT_IN, 'value' => '' + ), + array( + 'formulaid' => 'B', + 'conditiontype' => CONDITION_TYPE_TRIGGER_VALUE, + 'operator' => CONDITION_OPERATOR_EQUAL, + 'value' => TRIGGER_VALUE_TRUE ) ); } @@ -439,13 +453,11 @@ if (hasRequest('form')) { $data['allowedConditions'] = get_conditions_by_eventsource($data['eventsource']); $data['allowedOperations'] = get_operations_by_eventsource($data['eventsource']); - // sort conditions - $sortFields = array( - array('field' => 'conditiontype', 'order' => ZBX_SORT_DOWN), - array('field' => 'operator', 'order' => ZBX_SORT_DOWN), - array('field' => 'value', 'order' => ZBX_SORT_DOWN) - ); - CArrayHelper::sort($data['action']['conditions'], $sortFields); + if (!hasRequest('add_condition')) { + $data['action']['filter']['conditions'] = CConditionHelper::sortConditionsByFormulaId( + $data['action']['filter']['conditions'] + ); + } // new condition $data['new_condition'] = array( @@ -478,25 +490,31 @@ if (hasRequest('form')) { $actionView->show(); } else { + $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( - 'eventsource' => getRequest('eventsource', CProfile::get('web.actionconf.eventsource', EVENT_SOURCE_TRIGGERS)) + 'eventsource' => getRequest('eventsource', CProfile::get('web.actionconf.eventsource', EVENT_SOURCE_TRIGGERS)), + 'sort' => $sortField, + 'sortorder' => $sortOrder ); - $sortfield = getPageSortField('name'); - $data['actions'] = API::Action()->get(array( 'output' => API_OUTPUT_EXTEND, 'filter' => array('eventsource' => array($data['eventsource'])), - 'selectConditions' => API_OUTPUT_EXTEND, + 'selectFilter' => array('formula', 'conditions', 'evaltype'), 'selectOperations' => API_OUTPUT_EXTEND, 'editable' => true, - 'sortfield' => $sortfield, + 'sortfield' => $sortField, 'limit' => $config['search_limit'] + 1 )); // sorting && paging - order_result($data['actions'], $sortfield, getPageSortOrder()); - $data['paging'] = getPagingLine($data['actions'], array('actionid')); + order_result($data['actions'], $sortField, $sortOrder); + $data['paging'] = getPagingLine($data['actions']); // render view $actionView = new CView('configuration.action.list', $data); |