Exemplo n.º 1
0
 $tblActions->setHeader(array(new CCheckBox('all_items', null, "checkAll('" . $form->getName() . "','all_items','g_actionid');"), make_sorting_link(S_NAME, 'a.name'), S_CONDITIONS, S_OPERATIONS, make_sorting_link(S_STATUS, 'a.status')));
 $db_actions = DBselect('SELECT a.* ' . ' FROM actions a' . ' WHERE a.eventsource=' . $_REQUEST['eventsource'] . ' AND ' . DBin_node('actionid') . order_by('a.name,a.status', 'a.actionid'));
 while ($action_data = DBfetch($db_actions)) {
     if (!action_accessible($action_data['actionid'], PERM_READ_WRITE)) {
         continue;
     }
     $conditions = array();
     $db_conditions = DBselect('select * from conditions where actionid=' . $action_data['actionid'] . ' order by conditiontype,conditionid');
     while ($condition_data = DBfetch($db_conditions)) {
         array_push($conditions, array(get_condition_desc($condition_data['conditiontype'], $condition_data['operator'], $condition_data['value']), BR()));
     }
     unset($db_conditions, $condition_data);
     $operations = array();
     $db_operations = DBselect('select * from operations where actionid=' . $action_data['actionid'] . ' order by operationtype,operationid');
     while ($operation_data = DBfetch($db_operations)) {
         array_push($operations, array(get_operation_desc(SHORT_DESCRITION, $operation_data), BR()));
     }
     if ($action_data['status'] == ACTION_STATUS_DISABLED) {
         $status = new CLink(S_DISABLED, 'actionconf.php?group_enable=1&g_actionid%5B%5D=' . $action_data['actionid'] . url_param('eventsource'), 'disabled');
     } else {
         $status = new CLink(S_ENABLED, 'actionconf.php?group_disable=1&g_actionid%5B%5D=' . $action_data['actionid'] . url_param('eventsource'), 'enabled');
     }
     $tblActions->addRow(array(new CCheckBox('g_actionid[' . $action_data['actionid'] . ']', null, null, $action_data['actionid']), new CLink($action_data['name'], 'actionconf.php?form=update&actionid=' . $action_data['actionid']), $conditions, $operations, $status));
     $row_count++;
 }
 //----- GO ------
 $goBox = new CComboBox('go');
 $goBox->addItem('activate', S_ENABLE_SELECTED);
 $goBox->addItem('disable', S_DISABLE_SELECTED);
 $goBox->addItem('delete', S_DELETE_SELECTED);
 // goButton name is necessary!!!
Exemplo n.º 2
0
function get_act_operations_form($action = null)
{
    $tblOper = new CTableInfo(S_NO_OPERATIONS_DEFINED);
    $tblOper->addOption('style', 'background-color: #CCC;');
    if (isset($_REQUEST['actionid']) && empty($action)) {
        $action = get_action_by_actionid($_REQUEST['actionid']);
    }
    $operations = get_request('operations', array());
    if (isset($_REQUEST['actionid']) && !isset($_REQUEST['form_refresh'])) {
        $eventsource = $action['eventsource'];
        $evaltype = $action['evaltype'];
        $esc_period = $action['esc_period'];
        /* prepate operations */
        $db_operations = DBselect('SELECT * ' . ' FROM operations' . ' WHERE actionid=' . $_REQUEST['actionid'] . ' ORDER BY esc_step_from,operationtype,object,operationid');
        while ($operation_data = DBfetch($db_operations)) {
            $operation_data = array('operationtype' => $operation_data['operationtype'], 'operationid' => $operation_data['operationid'], 'object' => $operation_data['object'], 'objectid' => $operation_data['objectid'], 'shortdata' => $operation_data['shortdata'], 'longdata' => $operation_data['longdata'], 'esc_period' => $operation_data['esc_period'], 'esc_step_from' => $operation_data['esc_step_from'], 'esc_step_to' => $operation_data['esc_step_to'], 'default_msg' => $operation_data['default_msg'], 'evaltype' => $operation_data['evaltype']);
            $operation_data['opconditions'] = array();
            $sql = 'SELECT * FROM opconditions WHERE operationid=' . $operation_data['operationid'];
            $db_opconds = DBselect($sql);
            while ($db_opcond = DBfetch($db_opconds)) {
                $operation_data['opconditions'][] = $db_opcond;
            }
            if (str_in_array($operation_data, $operations)) {
                continue;
            }
            array_push($operations, $operation_data);
        }
        unset($db_operations, $operation_data);
    } else {
        $eventsource = get_request('eventsource');
        $evaltype = get_request('evaltype');
        $esc_period = get_request('esc_period');
    }
    $esc_step_from = array();
    foreach ($operations as $key => $operation) {
        $esc_step_from[$key] = $operation['esc_step_from'];
    }
    array_multisort($esc_step_from, SORT_ASC, $operations);
    $tblOper->SetHeader(array(new CCheckBox('all_operations', null, 'CheckAll("' . S_ACTION . '","all_operations","g_operationid");'), isset($_REQUEST['escalation']) ? S_STEPS : null, S_DETAILS, isset($_REQUEST['escalation']) ? S_PERIOD . ' (' . S_SEC_SMALL . ')' : null, isset($_REQUEST['escalation']) ? S_DELAY : null, S_ACTION));
    $allowed_operations = get_operations_by_eventsource($eventsource);
    zbx_rksort($operations);
    $delay = count_operations_delay($operations, $esc_period);
    foreach ($operations as $id => $val) {
        if (!str_in_array($val['operationtype'], $allowed_operations)) {
            continue;
        }
        if (!isset($val['default_msg'])) {
            $val['default_msg'] = 0;
        }
        if (!isset($val['opconditions'])) {
            $val['opconditions'] = array();
        }
        $oper_details = new CSpan(get_operation_desc(SHORT_DESCRITION, $val));
        $oper_details->SetHint(nl2br(get_operation_desc(LONG_DESCRITION, $val)));
        $esc_steps_txt = null;
        $esc_period_txt = null;
        $esc_delay_txt = null;
        if ($val['esc_step_from'] < 1) {
            $val['esc_step_from'] = 1;
        }
        if (isset($_REQUEST['escalation'])) {
            $esc_steps_txt = $val['esc_step_from'] . ' - ' . $val['esc_step_to'];
            $esc_period_txt = $val['esc_period'] ? $val['esc_period'] : S_DEFAULT;
            $esc_delay_txt = $delay[$val['esc_step_from']] ? convert_units($delay[$val['esc_step_from']], 'uptime') : S_AT_MOMENT;
        }
        $tblOper->addRow(array(new CCheckBox("g_operationid[]", 'no', null, $id), $esc_steps_txt, $oper_details, $esc_period_txt, $esc_delay_txt, new CButton('edit_operationid[' . $id . ']', S_EDIT)));
        $tblOper->addItem(new CVar('operations[' . $id . '][operationtype]', $val['operationtype']));
        $tblOper->addItem(new CVar('operations[' . $id . '][object]', $val['object']));
        $tblOper->addItem(new CVar('operations[' . $id . '][objectid]', $val['objectid']));
        $tblOper->addItem(new CVar('operations[' . $id . '][shortdata]', $val['shortdata']));
        $tblOper->addItem(new CVar('operations[' . $id . '][longdata]', $val['longdata']));
        $tblOper->addItem(new CVar('operations[' . $id . '][esc_period]', $val['esc_period']));
        $tblOper->addItem(new CVar('operations[' . $id . '][esc_step_from]', $val['esc_step_from']));
        $tblOper->addItem(new CVar('operations[' . $id . '][esc_step_to]', $val['esc_step_to']));
        $tblOper->addItem(new CVar('operations[' . $id . '][default_msg]', $val['default_msg']));
        $tblOper->addItem(new CVar('operations[' . $id . '][evaltype]', $val['evaltype']));
        foreach ($val['opconditions'] as $opcondid => $opcond) {
            foreach ($opcond as $field => $value) {
                $tblOper->addItem(new CVar('operations[' . $id . '][opconditions][' . $opcondid . '][' . $field . ']', $value));
            }
        }
    }
    unset($operations);
    $tblOperFooter = new CTableInfo(null);
    $oper_buttons = array();
    if (!isset($_REQUEST['new_operation'])) {
        $oper_buttons[] = new CButton('new_operation', S_NEW);
    }
    if ($tblOper->ItemsCount() > 0) {
        $oper_buttons[] = new CButton('del_operation', S_DELETE_SELECTED);
    }
    $td = new CCol($oper_buttons);
    $td->addOption('colspan', isset($_REQUEST['escalation']) ? 6 : 3);
    $td->addOption('style', 'text-align: right;');
    $tblOperFooter->SetFooter($td);
    // end of condition list preparation
    return array($tblOper, $tblOperFooter);
}
// create form
$actionForm = new CForm('get');
$actionForm->setName('actionForm');
// create table
$actionTable = new CTableInfo(_('No actions defined.'));
$actionTable->setHeader(array(new CCheckBox('all_items', null, "checkAll('" . $actionForm->getName() . "', 'all_items', 'g_actionid');"), make_sorting_header(_('Name'), 'name'), _('Conditions'), _('Operations'), make_sorting_header(_('Status'), 'status')));
foreach ($this->data['actions'] as $action) {
    $conditions = array();
    order_result($action['conditions'], 'conditiontype', ZBX_SORT_DOWN);
    foreach ($action['conditions'] as $condition) {
        $conditions[] = array(get_condition_desc($condition['conditiontype'], $condition['operator'], $condition['value']), BR());
    }
    sortOperations($action['eventsource'], $action['operations']);
    $operations = array();
    foreach ($action['operations'] as $operation) {
        $operations[] = get_operation_desc(SHORT_DESCRIPTION, $operation);
    }
    if ($action['status'] == ACTION_STATUS_DISABLED) {
        $status = new CLink(_('Disabled'), 'actionconf.php?go=activate&g_actionid' . SQUAREBRACKETS . '=' . $action['actionid'] . url_param('eventsource'), 'disabled');
    } else {
        $status = new CLink(_('Enabled'), 'actionconf.php?go=disable&g_actionid' . SQUAREBRACKETS . '=' . $action['actionid'] . url_param('eventsource'), 'enabled');
    }
    $actionTable->addRow(array(new CCheckBox('g_actionid[' . $action['actionid'] . ']', null, null, $action['actionid']), new CLink($action['name'], 'actionconf.php?form=update&actionid=' . $action['actionid']), $conditions, new CCol($operations, 'wraptext'), $status));
}
// create go buttons
$goComboBox = new CComboBox('go');
$goOption = new CComboItem('activate', _('Enable selected'));
$goOption->setAttribute('confirm', _('Enable selected actions?'));
$goComboBox->addItem($goOption);
$goOption = new CComboItem('disable', _('Disable selected'));
$goOption->setAttribute('confirm', _('Disable selected actions?'));
    $delay = count_operations_delay($this->data['action']['operations'], $this->data['action']['esc_period']);
} else {
    $operationsTable->setHeader(array(_('Details'), _('Action')));
}
foreach ($this->data['action']['operations'] as $operationid => $operation) {
    if (!str_in_array($operation['operationtype'], $this->data['allowedOperations'])) {
        continue;
    }
    if (!isset($operation['opconditions'])) {
        $operation['opconditions'] = array();
    }
    if (!isset($operation['mediatypeid'])) {
        $operation['mediatypeid'] = 0;
    }
    $details = new CSpan(get_operation_desc(SHORT_DESCRIPTION, $operation));
    $details->setHint(get_operation_desc(LONG_DESCRIPTION, $operation));
    if ($this->data['eventsource'] == EVENT_SOURCE_TRIGGERS) {
        $esc_steps_txt = null;
        $esc_period_txt = null;
        $esc_delay_txt = null;
        if ($operation['esc_step_from'] < 1) {
            $operation['esc_step_from'] = 1;
        }
        $esc_steps_txt = $operation['esc_step_from'] . ' - ' . $operation['esc_step_to'];
        // display N-N as N
        $esc_steps_txt = $operation['esc_step_from'] == $operation['esc_step_to'] ? $operation['esc_step_from'] : $operation['esc_step_from'] . ' - ' . $operation['esc_step_to'];
        $esc_period_txt = $operation['esc_period'] ? $operation['esc_period'] : _('Default');
        $esc_delay_txt = $delay[$operation['esc_step_from']] ? convert_units($delay[$operation['esc_step_from']], 'uptime') : _('Immediately');
        $operationRow = array($esc_steps_txt, $details, $esc_delay_txt, $esc_period_txt, array(new CSubmit('edit_operationid[' . $operationid . ']', _('Edit'), null, 'link_menu'), SPACE, SPACE, SPACE, array(new CButton('remove', _('Remove'), 'javascript: removeOperation(' . $operationid . ');', 'link_menu'), new CVar('operations[' . $operationid . ']', $operation))));
    } else {
        $operationRow = array($details, array(new CSubmit('edit_operationid[' . $operationid . ']', _('Edit'), null, 'link_menu'), SPACE, SPACE, SPACE, array(new CButton('remove', _('Remove'), 'javascript: removeOperation(' . $operationid . ');', 'link_menu'), new CVar('operations[' . $operationid . ']', $operation))));
Exemplo n.º 5
0
 $options = array('output' => API_OUTPUT_EXTEND, 'filter' => array('eventsource' => array($_REQUEST['eventsource'])), 'select_conditions' => API_OUTPUT_EXTEND, 'select_operations' => API_OUTPUT_EXTEND, 'editable' => 1, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'limit' => $config['search_limit'] + 1);
 $actions = CAction::get($options);
 // sorting && paging
 order_result($actions, $sortfield, $sortorder);
 $paging = getPagingLine($actions);
 //-------
 foreach ($actions as $anum => $action) {
     $conditions = array();
     order_result($action['conditions'], 'conditiontype', ZBX_SORT_DOWN);
     foreach ($action['conditions'] as $cnum => $condition) {
         $conditions[] = array(get_condition_desc($condition['conditiontype'], $condition['operator'], $condition['value']), BR());
     }
     $operations = array();
     order_result($action['operations'], 'operationtype', ZBX_SORT_DOWN);
     foreach ($action['operations'] as $onum => $operation) {
         $operations[] = array(get_operation_desc(SHORT_DESCRITION, $operation), BR());
     }
     if ($action['status'] == ACTION_STATUS_DISABLED) {
         $status = new CLink(S_DISABLED, 'actionconf.php?go=activate&g_actionid%5B%5D=' . $action['actionid'] . url_param('eventsource'), 'disabled');
     } else {
         $status = new CLink(S_ENABLED, 'actionconf.php?go=disable&g_actionid%5B%5D=' . $action['actionid'] . url_param('eventsource'), 'enabled');
     }
     $tblActions->addRow(array(new CCheckBox('g_actionid[' . $action['actionid'] . ']', null, null, $action['actionid']), new CLink($action['name'], 'actionconf.php?form=update&actionid=' . $action['actionid']), $conditions, $operations, $status));
 }
 //----- GO ------
 $goBox = new CComboBox('go');
 $goOption = new CComboItem('activate', S_ENABLE_SELECTED);
 $goOption->setAttribute('confirm', S_ENABLE . ' ' . S_SELECTED_ACTIONS);
 $goBox->addItem($goOption);
 $goOption = new CComboItem('disable', S_DISABLE_SELECTED);
 $goOption->setAttribute('confirm', S_DISABLE . ' ' . S_SELECTED_ACTIONS);