Ejemplo n.º 1
0
 $i = 0;
 foreach ($this->data['new_operation']['opconditions'] as $opcondition) {
     if (!isset($opcondition['conditiontype'])) {
         $opcondition['conditiontype'] = 0;
     }
     if (!isset($opcondition['operator'])) {
         $opcondition['operator'] = 0;
     }
     if (!isset($opcondition['value'])) {
         $opcondition['value'] = 0;
     }
     if (!str_in_array($opcondition['conditiontype'], $allowed_opconditions)) {
         continue;
     }
     $label = num2letter($i);
     $operationConditionsTable->addRow(array('(' . $label . ')', get_condition_desc($opcondition['conditiontype'], $opcondition['operator'], $opcondition['value']), array(new CButton('remove', _('Remove'), 'javascript: removeOperationCondition(' . $i . ');', 'link_menu'), new CVar('new_operation[opconditions][' . $i . '][conditiontype]', $opcondition['conditiontype']), new CVar('new_operation[opconditions][' . $i . '][operator]', $opcondition['operator']), new CVar('new_operation[opconditions][' . $i . '][value]', $opcondition['value']))), null, 'opconditions_' . $i);
     $grouped_opconditions[$opcondition['conditiontype']][] = $label;
     $i++;
 }
 if ($operationConditionsTable->itemsCount() > 1) {
     switch ($this->data['new_operation']['evaltype']) {
         case ACTION_EVAL_TYPE_AND:
             $group_op = $glog_op = _('and');
             break;
         case ACTION_EVAL_TYPE_OR:
             $group_op = $glog_op = _('or');
             break;
         default:
             $group_op = _('or');
             $glog_op = _('and');
             break;
$sourceComboBox->addItem(EVENT_SOURCE_INTERNAL, _x('Internal', 'event source'));
$filterForm = new CForm('get');
$filterForm->addItem(array(_('Event source'), SPACE, $sourceComboBox));
$actionWidget->addHeader(_('Actions'), $filterForm);
$actionWidget->addHeaderRowNumber();
// create form
$actionForm = new CForm();
$actionForm->setName('actionForm');
// create table
$actionTable = new CTableInfo(_('No actions found.'));
$actionTable->setHeader(array(new CCheckBox('all_items', null, "checkAll('" . $actionForm->getName() . "', 'all_items', 'g_actionid');"), make_sorting_header(_('Name'), 'name', $this->data['sort'], $this->data['sortorder']), _('Conditions'), _('Operations'), make_sorting_header(_('Status'), 'status', $this->data['sort'], $this->data['sortorder'])));
foreach ($this->data['actions'] as $action) {
    $conditions = array();
    order_result($action['filter']['conditions'], 'conditiontype', ZBX_SORT_DOWN);
    foreach ($action['filter']['conditions'] as $condition) {
        $conditions[] = get_condition_desc($condition['conditiontype'], $condition['operator'], $condition['value']);
        $conditions[] = BR();
    }
    sortOperations($this->data['eventsource'], $action['operations']);
    $operations = array();
    foreach ($action['operations'] as $operation) {
        $operations[] = get_operation_descr(SHORT_DESCRIPTION, $operation);
    }
    if ($action['status'] == ACTION_STATUS_DISABLED) {
        $status = new CLink(_('Disabled'), 'actionconf.php?action=action.massenable&g_actionid[]=' . $action['actionid'] . url_param('eventsource'), 'disabled');
    } else {
        $status = new CLink(_('Enabled'), 'actionconf.php?action=action.massdisable&g_actionid[]=' . $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
Ejemplo n.º 3
0
function get_act_new_oper_form($action = null)
{
    $tblOper = new CTableInfo();
    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'];
    } else {
        $eventsource = get_request('eventsource');
    }
    $allowed_operations = get_operations_by_eventsource($eventsource);
    /* init new_operation variable */
    $new_operation = get_request('new_operation', array());
    if (!is_array($new_operation)) {
        $new_operation = array();
        $new_operation['default_msg'] = 1;
    }
    if (!isset($new_operation['operationtype'])) {
        $new_operation['operationtype'] = OPERATION_TYPE_MESSAGE;
    }
    if (!isset($new_operation['object'])) {
        $new_operation['object'] = OPERATION_OBJECT_GROUP;
    }
    if (!isset($new_operation['objectid'])) {
        $new_operation['objectid'] = 0;
    }
    if (!isset($new_operation['shortdata'])) {
        $new_operation['shortdata'] = '{TRIGGER.NAME}: {STATUS}';
    }
    if (!isset($new_operation['longdata'])) {
        $new_operation['longdata'] = '{TRIGGER.NAME}: {STATUS}';
    }
    if (!isset($new_operation['esc_step_from'])) {
        $new_operation['esc_step_from'] = 1;
    }
    if (!isset($new_operation['esc_step_to'])) {
        $new_operation['esc_step_to'] = 1;
    }
    if (!isset($new_operation['esc_period'])) {
        $new_operation['esc_period'] = 0;
    }
    if (!isset($new_operation['evaltype'])) {
        $new_operation['evaltype'] = 0;
    }
    if (!isset($new_operation['opconditions'])) {
        $new_operation['opconditions'] = array();
    }
    if (!isset($new_operation['default_msg'])) {
        $new_operation['default_msg'] = 0;
    }
    unset($update_mode);
    $evaltype = $new_operation['evaltype'];
    if (isset($new_operation['id'])) {
        $tblOper->addItem(new CVar('new_operation[id]', $new_operation['id']));
        $update_mode = true;
    }
    $tblNewOperation = new CTable(null, 'nowrap');
    if (isset($_REQUEST['escalation'])) {
        $tblStep = new CTable(null, 'nowrap');
        $step_from = new CNumericBox('new_operation[esc_step_from]', $new_operation['esc_step_from'], 4);
        $step_from->addAction('onchange', 'javascript:' . $step_from->GetOption('onchange') . ' if(this.value == 0) this.value=1;');
        $tblStep->addRow(array(S_FROM, $step_from));
        $tblStep->addRow(array(S_TO, new CCol(array(new CNumericBox('new_operation[esc_step_to]', $new_operation['esc_step_to'], 4), ' [0-' . S_INFINITY . ']'))));
        $tblStep->addRow(array(S_PERIOD, new CCol(array(new CNumericBox('new_operation[esc_period]', $new_operation['esc_period'], 5), ' [0-' . S_DEFAULT . ']'))));
        $tblNewOperation->addRow(array(S_STEP, $tblStep));
    } else {
        $tblOper->addItem(new CVar('new_operation[esc_period]', $new_operation['esc_period']));
        $tblOper->addItem(new CVar('new_operation[esc_step_from]', $new_operation['esc_step_from']));
        $tblOper->addItem(new CVar('new_operation[esc_step_to]', $new_operation['esc_step_to']));
        $tblOper->addItem(new CVar('new_operation[evaltype]', $new_operation['evaltype']));
    }
    $cmbOpType = new CComboBox('new_operation[operationtype]', $new_operation['operationtype'], 'submit()');
    foreach ($allowed_operations as $oper) {
        $cmbOpType->addItem($oper, operation_type2str($oper));
    }
    $tblNewOperation->addRow(array(S_OPERATION_TYPE, $cmbOpType));
    switch ($new_operation['operationtype']) {
        case OPERATION_TYPE_MESSAGE:
            if ($new_operation['object'] == OPERATION_OBJECT_GROUP) {
                $object_srctbl = 'usrgrp';
                $object_srcfld1 = 'usrgrpid';
                $object_name = get_group_by_usrgrpid($new_operation['objectid']);
                $display_name = 'name';
            } else {
                $object_srctbl = 'users';
                $object_srcfld1 = 'userid';
                $object_name = get_user_by_userid($new_operation['objectid']);
                $display_name = 'alias';
            }
            $tblOper->addItem(new CVar('new_operation[objectid]', $new_operation['objectid']));
            if ($object_name) {
                $object_name = $object_name[$display_name];
            }
            $cmbObject = new CComboBox('new_operation[object]', $new_operation['object'], 'submit()');
            $cmbObject->addItem(OPERATION_OBJECT_USER, S_SINGLE_USER);
            $cmbObject->addItem(OPERATION_OBJECT_GROUP, S_USER_GROUP);
            $tblNewOperation->addRow(array(S_SEND_MESSAGE_TO, array($cmbObject, new CTextBox('object_name', $object_name, 40, 'yes'), new CButton('select_object', S_SELECT, 'return PopUp("popup.php?dstfrm=' . S_ACTION . '&dstfld1=new_operation%5Bobjectid%5D&dstfld2=object_name' . '&srctbl=' . $object_srctbl . '&srcfld1=' . $object_srcfld1 . '&srcfld2=' . $display_name . '",450,450)', 'T'))));
            $tblNewOperation->addRow(array(S_DEFAULT_MESSAGE, new CCheckBox('new_operation[default_msg]', $new_operation['default_msg'], 'javascript: submit();', 1)));
            if (!$new_operation['default_msg']) {
                $tblNewOperation->addRow(array(S_SUBJECT, new CTextBox('new_operation[shortdata]', $new_operation['shortdata'], 77)));
                $tblNewOperation->addRow(array(S_MESSAGE, new CTextArea('new_operation[longdata]', $new_operation['longdata'], 77, 7)));
            } else {
                $tblOper->addItem(new CVar('new_operation[shortdata]', $new_operation['shortdata']));
                $tblOper->addItem(new CVar('new_operation[longdata]', $new_operation['longdata']));
            }
            break;
        case OPERATION_TYPE_COMMAND:
            $tblOper->addItem(new CVar('new_operation[object]', 0));
            $tblOper->addItem(new CVar('new_operation[objectid]', 0));
            $tblOper->addItem(new CVar('new_operation[shortdata]', ''));
            $tblNewOperation->addRow(array(S_REMOTE_COMMAND, new CTextArea('new_operation[longdata]', $new_operation['longdata'], 77, 7)));
            break;
        case OPERATION_TYPE_HOST_ADD:
            $tblOper->addItem(new CVar('new_operation[object]', 0));
            $tblOper->addItem(new CVar('new_operation[objectid]', 0));
            $tblOper->addItem(new CVar('new_operation[shortdata]', ''));
            $tblOper->addItem(new CVar('new_operation[longdata]', ''));
            break;
        case OPERATION_TYPE_HOST_REMOVE:
            $tblOper->addItem(new CVar('new_operation[object]', 0));
            $tblOper->addItem(new CVar('new_operation[objectid]', 0));
            $tblOper->addItem(new CVar('new_operation[shortdata]', ''));
            $tblOper->addItem(new CVar('new_operation[longdata]', ''));
            break;
        case OPERATION_TYPE_GROUP_ADD:
            $tblOper->addItem(new CVar('new_operation[object]', 0));
            $tblOper->addItem(new CVar('new_operation[objectid]', $new_operation['objectid']));
            $tblOper->addItem(new CVar('new_operation[shortdata]', ''));
            $tblOper->addItem(new CVar('new_operation[longdata]', ''));
            if ($object_name = DBfetch(DBselect('select name FROM groups WHERE groupid=' . $new_operation['objectid']))) {
                $object_name = $object_name['name'];
            }
            $tblNewOperation->addRow(array(S_GROUP, array(new CTextBox('object_name', $object_name, 40, 'yes'), new CButton('select_object', S_SELECT, 'return PopUp("popup.php?dstfrm=' . S_ACTION . '&dstfld1=new_operation%5Bobjectid%5D&dstfld2=object_name' . '&srctbl=host_group&srcfld1=groupid&srcfld2=name' . '",450,450)', 'T'))));
            break;
        case OPERATION_TYPE_GROUP_REMOVE:
            $tblOper->addItem(new CVar('new_operation[object]', 0));
            $tblOper->addItem(new CVar('new_operation[objectid]', $new_operation['objectid']));
            $tblOper->addItem(new CVar('new_operation[shortdata]', ''));
            $tblOper->addItem(new CVar('new_operation[longdata]', ''));
            if ($object_name = DBfetch(DBselect('select name FROM groups WHERE groupid=' . $new_operation['objectid']))) {
                $object_name = $object_name['name'];
            }
            $tblNewOperation->addRow(array(S_GROUP, array(new CTextBox('object_name', $object_name, 40, 'yes'), new CButton('select_object', S_SELECT, 'return PopUp("popup.php?dstfrm=' . S_ACTION . '&dstfld1=new_operation%5Bobjectid%5D&dstfld2=object_name' . '&srctbl=host_group&srcfld1=groupid&srcfld2=name' . '",450,450)', 'T'))));
            break;
        case OPERATION_TYPE_TEMPLATE_ADD:
            $tblOper->addItem(new CVar('new_operation[object]', 0));
            $tblOper->addItem(new CVar('new_operation[objectid]', $new_operation['objectid']));
            $tblOper->addItem(new CVar('new_operation[shortdata]', ''));
            $tblOper->addItem(new CVar('new_operation[longdata]', ''));
            if ($object_name = DBfetch(DBselect('SELECT host FROM hosts ' . ' WHERE status=' . HOST_STATUS_TEMPLATE . ' AND hostid=' . $new_operation['objectid']))) {
                $object_name = $object_name['host'];
            }
            $tblNewOperation->addRow(array(S_TEMPLATE, array(new CTextBox('object_name', $object_name, 40, 'yes'), new CButton('select_object', S_SELECT, 'return PopUp("popup.php?dstfrm=' . S_ACTION . '&dstfld1=new_operation%5Bobjectid%5D&dstfld2=object_name' . '&srctbl=host_templates&srcfld1=hostid&srcfld2=host' . '",450,450)', 'T'))));
            break;
        case OPERATION_TYPE_TEMPLATE_REMOVE:
            $tblOper->addItem(new CVar('new_operation[object]', 0));
            $tblOper->addItem(new CVar('new_operation[objectid]', $new_operation['objectid']));
            $tblOper->addItem(new CVar('new_operation[shortdata]', ''));
            $tblOper->addItem(new CVar('new_operation[longdata]', ''));
            if ($object_name = DBfetch(DBselect('SELECT host FROM hosts ' . ' WHERE status=' . HOST_STATUS_TEMPLATE . ' AND hostid=' . $new_operation['objectid']))) {
                $object_name = $object_name['host'];
            }
            $tblNewOperation->addRow(array(S_TEMPLATE, array(new CTextBox('object_name', $object_name, 40, 'yes'), new CButton('select_object', S_SELECT, 'return PopUp("popup.php?dstfrm=' . S_ACTION . '&dstfld1=new_operation%5Bobjectid%5D&dstfld2=object_name' . '&srctbl=host_templates&srcfld1=hostid&srcfld2=host' . '",450,450)', 'T'))));
            break;
    }
    // new Operation conditions
    if (isset($_REQUEST['escalation'])) {
        $tblCond = new CTable();
        $opconditions = $new_operation['opconditions'];
        $allowed_opconditions = get_opconditions_by_eventsource($eventsource);
        // show opcondition LIST
        zbx_rksort($opconditions);
        /* group opconditions by type */
        $grouped_opconditions = array();
        $cond_el = new CTable(S_NO_CONDITIONS_DEFINED);
        $i = 0;
        foreach ($opconditions as $val) {
            if (!isset($val['conditiontype'])) {
                $val['conditiontype'] = 0;
            }
            if (!isset($val['operator'])) {
                $val['operator'] = 0;
            }
            if (!isset($val['value'])) {
                $val['value'] = 0;
            }
            if (!str_in_array($val["conditiontype"], $allowed_opconditions)) {
                continue;
            }
            $label = chr(ord('A') + $i);
            $cond_el->addRow(array('(' . $label . ')', array(new CCheckBox("g_opconditionid[]", 'no', null, $i), get_condition_desc($val["conditiontype"], $val["operator"], $val["value"]))));
            $tblCond->addItem(new CVar("new_operation[opconditions][{$i}][conditiontype]", $val["conditiontype"]));
            $tblCond->addItem(new CVar("new_operation[opconditions][{$i}][operator]", $val["operator"]));
            $tblCond->addItem(new CVar("new_operation[opconditions][{$i}][value]", $val["value"]));
            $grouped_opconditions[$val["conditiontype"]][] = $label;
            $i++;
        }
        unset($opconditions);
        $cond_buttons = array();
        if (!isset($_REQUEST['new_opcondition'])) {
            $cond_buttons[] = new CButton('new_opcondition', S_NEW);
        }
        if ($cond_el->ItemsCount() > 0) {
            if ($cond_el->ItemsCount() > 1) {
                /* prepare opcondition calcuation type selector */
                switch ($evaltype) {
                    case ACTION_EVAL_TYPE_AND:
                        $group_op = $glog_op = S_AND;
                        break;
                    case ACTION_EVAL_TYPE_OR:
                        $group_op = $glog_op = S_OR;
                        break;
                    default:
                        $group_op = S_OR;
                        $glog_op = S_AND;
                        break;
                }
                foreach ($grouped_opconditions as $id => $val) {
                    $grouped_opconditions[$id] = '(' . implode(' ' . $group_op . ' ', $val) . ')';
                }
                $grouped_opconditions = implode(' ' . $glog_op . ' ', $grouped_opconditions);
                $cmb_calc_type = new CComboBox('new_operation[evaltype]', $evaltype, 'submit()');
                $cmb_calc_type->addItem(ACTION_EVAL_TYPE_AND_OR, S_AND_OR_BIG);
                $cmb_calc_type->addItem(ACTION_EVAL_TYPE_AND, S_AND_BIG);
                $cmb_calc_type->addItem(ACTION_EVAL_TYPE_OR, S_OR_BIG);
                $tblNewOperation->addRow(array(S_TYPE_OF_CALCULATION, new CCol(array($cmb_calc_type, new CTextBox('preview', $grouped_opconditions, 60, 'yes')))));
                unset($cmb_calc_type, $group_op, $glog_op);
                /* end of calcuation type selector */
            } else {
                $tblCond->addItem(new CVar('new_operation[evaltype]', ACTION_EVAL_TYPE_AND_OR));
            }
            $cond_buttons[] = new CButton('del_opcondition', S_DELETE_SELECTED);
        } else {
            $tblCond->addItem(new CVar('new_operation[evaltype]', ACTION_EVAL_TYPE_AND_OR));
        }
        $tblCond->addRow($cond_el);
        $tblCond->addRow(new CCol($cond_buttons));
        // end of opcondition LIST
        $tblNewOperation->addRow(array(S_CONDITIONS, $tblCond));
        unset($grouped_opconditions, $cond_el, $cond_buttons, $tblCond);
    }
    $tblOper->addRow($tblNewOperation);
    $td = new CCol(array(new CButton('add_operation', isset($update_mode) ? S_SAVE : S_ADD), SPACE, new CButton('cancel_new_operation', S_CANCEL)));
    $td->addOption('colspan', '3');
    $td->addOption('style', 'text-align: right;');
    $tblOper->SetFooter($td);
    return $tblOper;
}
Ejemplo n.º 4
0
 show_table_header($header, $form);
 unset($form, $cmbSource);
 /* table */
 $form = new CForm();
 $form->setName('actions');
 $tblActions = new CTableInfo(S_NO_ACTIONS_DEFINED);
 $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++;
 }
$sourceComboBox->addItem(EVENT_SOURCE_AUTO_REGISTRATION, _('Auto registration'));
$filterForm = new CForm('get');
$filterForm->addItem(array(_('Event source'), SPACE, $sourceComboBox));
$actionWidget->addHeader(_('Actions'), $filterForm);
$actionWidget->addHeaderRowNumber();
// 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');