$itemForm = (new CForm())->setName('items')->addVar('hostid', $this->data['hostid'])->addVar('parent_discoveryid', $this->data['parent_discoveryid']);
// create table
$itemTable = (new CTableInfo())->setHeader([(new CColHeader((new CCheckBox('all_items'))->onClick("checkAll('" . $itemForm->getName() . "', 'all_items', 'group_itemid');")))->addClass(ZBX_STYLE_CELL_WIDTH), make_sorting_header(_('Name'), 'name', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Key'), 'key_', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Interval'), 'delay', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('History'), 'history', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Trends'), 'trends', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Type'), 'type', $this->data['sort'], $this->data['sortorder']), _('Applications'), make_sorting_header(_('Status'), 'status', $this->data['sort'], $this->data['sortorder'])]);
foreach ($this->data['items'] as $item) {
    $description = [];
    if (!empty($item['templateid'])) {
        $template_host = get_realhost_by_itemid($item['templateid']);
        $templateDiscoveryRuleId = get_realrule_by_itemid_and_hostid($this->data['parent_discoveryid'], $template_host['hostid']);
        $description[] = (new CLink($template_host['name'], '?parent_discoveryid=' . $templateDiscoveryRuleId))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_GREY);
        $description[] = NAME_DELIMITER;
    }
    $description[] = new CLink($item['name_expanded'], '?form=update&itemid=' . $item['itemid'] . '&parent_discoveryid=' . $this->data['parent_discoveryid']);
    $status = (new CLink(itemIndicator($item['status']), '?group_itemid=' . $item['itemid'] . '&parent_discoveryid=' . $this->data['parent_discoveryid'] . '&action=' . ($item['status'] == ITEM_STATUS_DISABLED ? 'itemprototype.massenable' : 'itemprototype.massdisable')))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(itemIndicatorStyle($item['status']))->addSID();
    if (!empty($item['applications'])) {
        order_result($item['applications'], 'name');
        $applications = zbx_objectValues($item['applications'], 'name');
        $applications = implode(', ', $applications);
        if (empty($applications)) {
            $applications = '';
        }
    } else {
        $applications = '';
    }
    $itemTable->addRow([new CCheckBox('group_itemid[' . $item['itemid'] . ']', $item['itemid']), $description, $item['key_'], $item['delay'] !== '' ? convertUnitsS($item['delay']) : '', $item['history'] . _x('d', 'day short'), $item['trends'] !== '' ? $item['trends'] . _x('d', 'day short') : '', item_type2str($item['type']), $applications, $status]);
}
zbx_add_post_js('cookie.prefix = "' . $this->data['parent_discoveryid'] . '";');
// append table to form
$itemForm->addItem([$itemTable, $this->data['paging'], new CActionButtonList('action', 'group_itemid', ['itemprototype.massenable' => ['name' => _('Enable'), 'confirm' => _('Enable selected item prototypes?')], 'itemprototype.massdisable' => ['name' => _('Disable'), 'confirm' => _('Disable selected item prototypes?')], 'itemprototype.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected item prototypes?')]], $this->data['parent_discoveryid'])]);
// append form to widget
$widget->addItem($itemForm);
return $widget;
    $hintTable->addRow(array(getSeverityCell($i), _('PROBLEM')));
}
$config = select_config();
if ($this->data['type'] == SHOW_TRIGGERS) {
    // blinking preview in help popup (only if blinking is enabled)
    if ($config['blink_period'] > 0) {
        $row = new CRow(null);
        $row->addItem(new CCol(SPACE, 'normal'));
        for ($i = 0; $i < TRIGGER_SEVERITY_COUNT; $i++) {
            $row->addItem(new CCol(SPACE, getSeverityStyle($i)));
        }
        $col = new CTable('', 'blink overview-mon-severities');
        $col->addRow($row);
        // double div necassary for FireFox
        $col = new CCol(new CDiv(new CDiv($col), 'overview-mon-severities-container'));
        $hintTable->addRow(array($col, _s('Age less than %s', convertUnitsS($config['blink_period']))));
    }
    $hintTable->addRow(array(new CCol(SPACE), _('No trigger')));
} else {
    $hintTable->addRow(array(new CCol(SPACE), _('OK or no trigger')));
}
$help = new CHelp('web.view.php', 'right');
$help->setHint($hintTable, '', '', true, false);
// header right
$overviewWidget->addPageHeader(_('OVERVIEW'), array(get_icon('fullscreen', array('fullscreen' => $this->data['fullscreen'])), SPACE, $help));
// header left
$styleComboBox = new CComboBox('view_style', $this->data['view_style'], 'submit()');
$styleComboBox->addItem(STYLE_TOP, _('Top'));
$styleComboBox->addItem(STYLE_LEFT, _('Left'));
$hostLocationForm = new CForm('get');
$hostLocationForm->addVar('groupid', $this->data['groupid']);
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/
zbx_add_post_js('jqBlink.blink();');
// hint table
$help_hint = (new CList())->addClass(ZBX_STYLE_NOTIF_BODY)->addStyle('min-width: ' . ZBX_OVERVIEW_HELP_MIN_WIDTH . 'px')->addItem([(new CDiv())->addClass(ZBX_STYLE_NOTIF_INDIC)->addClass(getSeverityStyle(null, false)), new CTag('h4', true, _('OK')), (new CTag('p', true, ''))->addClass(ZBX_STYLE_GREY)]);
for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) {
    $help_hint->addItem([(new CDiv())->addClass(ZBX_STYLE_NOTIF_INDIC)->addClass(getSeverityStyle($severity)), new CTag('h4', true, getSeverityName($severity, $data['config'])), (new CTag('p', true, _('PROBLEM')))->addClass(ZBX_STYLE_GREY)]);
}
// blinking preview in help popup (only if blinking is enabled)
if ($data['config']['blink_period'] > 0) {
    $indic_container = (new CDiv())->addClass(ZBX_STYLE_NOTIF_INDIC_CONTAINER)->addItem((new CDiv())->addClass(ZBX_STYLE_NOTIF_INDIC)->addClass(getSeverityStyle(null, false))->addClass('blink'));
    for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) {
        $indic_container->addItem((new CDiv())->addClass(ZBX_STYLE_NOTIF_INDIC)->addClass(getSeverityStyle($severity))->addClass('blink'));
    }
    $indic_container->addItem((new CTag('p', true, _s('Age less than %s', convertUnitsS($data['config']['blink_period']))))->addClass(ZBX_STYLE_GREY));
    $help_hint->addItem($indic_container);
}
// header right
$help = get_icon('overviewhelp');
$help->setHint($help_hint);
$widget = (new CWidget())->setTitle(_('Overview'))->setControls((new CForm('get'))->cleanItems()->addItem((new CList())->addItem([_('Group'), SPACE, $this->data['pageFilter']->getGroupsCB()])->addItem([_('Type'), SPACE, new CComboBox('type', $this->data['type'], 'submit()', [SHOW_TRIGGERS => _('Triggers'), SHOW_DATA => _('Data')])])->addItem([_('Hosts location'), SPACE, new CComboBox('view_style', $this->data['view_style'], 'submit()', [STYLE_TOP => _('Top'), STYLE_LEFT => _('Left')])])->addItem(get_icon('fullscreen', ['fullscreen' => $this->data['fullscreen']]))->addItem($help)));
// filter
$filter = $this->data['filter'];
$filterFormView = new CView('common.filter.trigger', ['overview' => true, 'filter' => ['filterid' => 'web.overview.filter.state', 'showTriggers' => $filter['showTriggers'], 'ackStatus' => $filter['ackStatus'], 'showSeverity' => $filter['showSeverity'], 'statusChange' => $filter['statusChange'], 'statusChangeDays' => $filter['statusChangeDays'], 'txtSelect' => $filter['txtSelect'], 'application' => $filter['application'], 'inventory' => $filter['inventory'], 'showMaintenance' => $filter['showMaintenance'], 'hostId' => $this->data['hostid'], 'groupId' => $this->data['groupid'], 'fullScreen' => $this->data['fullscreen']], 'config' => $data['config']]);
$filterForm = $filterFormView->render();
$widget->addItem($filterForm);
// data table
if ($data['pageFilter']->groupsSelected) {
    global $page;
    $dataTable = getTriggersOverview($this->data['hosts'], $this->data['triggers'], $page['file'], $this->data['view_style']);
Beispiel #4
0
/**
 * Converts value to actual value.
 * Example:
 * 	6442450944 B convert to 6 GB
 *
 * @param array  $options
 * @param string $options['value']
 * @param string $options['units']
 * @param string $options['convert']
 * @param string $options['byteStep']
 * @param string $options['pow']
 * @param bool   $options['ignoreMillisec']
 * @param string $options['length']
 *
 * @return string
 */
function convert_units($options = array())
{
    $defOptions = array('value' => null, 'units' => null, 'convert' => ITEM_CONVERT_WITH_UNITS, 'byteStep' => false, 'pow' => false, 'ignoreMillisec' => false, 'length' => false);
    $options = zbx_array_merge($defOptions, $options);
    // special processing for unix timestamps
    if ($options['units'] == 'unixtime') {
        return zbx_date2str(DATE_TIME_FORMAT_SECONDS, $options['value']);
    }
    // special processing of uptime
    if ($options['units'] == 'uptime') {
        return convertUnitsUptime($options['value']);
    }
    // special processing for seconds
    if ($options['units'] == 's') {
        return convertUnitsS($options['value'], $options['ignoreMillisec']);
    }
    // any other unit
    // black list of units that should have no multiplier prefix (K, M, G etc) applied
    $blackList = array('%', 'ms', 'rpm', 'RPM');
    if (in_array($options['units'], $blackList) || zbx_empty($options['units']) && $options['convert'] == ITEM_CONVERT_WITH_UNITS) {
        if (abs($options['value']) >= ZBX_UNITS_ROUNDOFF_THRESHOLD) {
            $options['value'] = round($options['value'], ZBX_UNITS_ROUNDOFF_UPPER_LIMIT);
        }
        $options['value'] = sprintf('%.' . ZBX_UNITS_ROUNDOFF_LOWER_LIMIT . 'f', $options['value']);
        $options['value'] = preg_replace('/^([\\-0-9]+)(\\.)([0-9]*)[0]+$/U', '$1$2$3', $options['value']);
        $options['value'] = rtrim($options['value'], '.');
        return trim($options['value'] . ' ' . $options['units']);
    }
    // if one or more items is B or Bps, then Y-scale use base 8 and calculated in bytes
    if ($options['byteStep']) {
        $step = 1024;
    } else {
        switch ($options['units']) {
            case 'Bps':
            case 'B':
                $step = 1024;
                $options['convert'] = $options['convert'] ? $options['convert'] : ITEM_CONVERT_NO_UNITS;
                break;
            case 'b':
            case 'bps':
                $options['convert'] = $options['convert'] ? $options['convert'] : ITEM_CONVERT_NO_UNITS;
            default:
                $step = 1000;
        }
    }
    if ($options['value'] < 0) {
        $abs = bcmul($options['value'], '-1');
    } else {
        $abs = $options['value'];
    }
    if (bccomp($abs, 1) == -1) {
        $options['value'] = round($options['value'], ZBX_UNITS_ROUNDOFF_MIDDLE_LIMIT);
        $options['value'] = $options['length'] && $options['value'] != 0 ? sprintf('%.' . $options['length'] . 'f', $options['value']) : $options['value'];
        return trim($options['value'] . ' ' . $options['units']);
    }
    // init intervals
    static $digitUnits;
    if (is_null($digitUnits)) {
        $digitUnits = array();
    }
    if (!isset($digitUnits[$step])) {
        $digitUnits[$step] = array(array('pow' => 0, 'short' => '', 'long' => ''), array('pow' => 1, 'short' => _x('K', 'Kilo short'), 'long' => _('Kilo')), array('pow' => 2, 'short' => _x('M', 'Mega short'), 'long' => _('Mega')), array('pow' => 3, 'short' => _x('G', 'Giga short'), 'long' => _('Giga')), array('pow' => 4, 'short' => _x('T', 'Tera short'), 'long' => _('Tera')), array('pow' => 5, 'short' => _x('P', 'Peta short'), 'long' => _('Peta')), array('pow' => 6, 'short' => _x('E', 'Exa short'), 'long' => _('Exa')), array('pow' => 7, 'short' => _x('Z', 'Zetta short'), 'long' => _('Zetta')), array('pow' => 8, 'short' => _x('Y', 'Yotta short'), 'long' => _('Yotta')));
        foreach ($digitUnits[$step] as $dunit => $data) {
            // skip milli & micro for values without units
            $digitUnits[$step][$dunit]['value'] = bcpow($step, $data['pow'], 9);
        }
    }
    $valUnit = array('pow' => 0, 'short' => '', 'long' => '', 'value' => $options['value']);
    if ($options['pow'] === false || $options['value'] == 0) {
        foreach ($digitUnits[$step] as $dnum => $data) {
            if (bccomp($abs, $data['value']) > -1) {
                $valUnit = $data;
            } else {
                break;
            }
        }
    } else {
        foreach ($digitUnits[$step] as $data) {
            if ($options['pow'] == $data['pow']) {
                $valUnit = $data;
                break;
            }
        }
    }
    if (round($valUnit['value'], ZBX_UNITS_ROUNDOFF_MIDDLE_LIMIT) > 0) {
        $valUnit['value'] = bcdiv(sprintf('%.10f', $options['value']), sprintf('%.10f', $valUnit['value']), ZBX_PRECISION_10);
    } else {
        $valUnit['value'] = 0;
    }
    switch ($options['convert']) {
        case 0:
            $options['units'] = trim($options['units']);
        case 1:
            $desc = $valUnit['short'];
            break;
        case 2:
            $desc = $valUnit['long'];
            break;
    }
    $options['value'] = preg_replace('/^([\\-0-9]+)(\\.)([0-9]*)[0]+$/U', '$1$2$3', round($valUnit['value'], ZBX_UNITS_ROUNDOFF_UPPER_LIMIT));
    $options['value'] = rtrim($options['value'], '.');
    // fix negative zero
    if (bccomp($options['value'], 0) == 0) {
        $options['value'] = 0;
    }
    return trim(sprintf('%s %s%s', $options['length'] ? sprintf('%.' . $options['length'] . 'f', $options['value']) : $options['value'], $desc, $options['units']));
}
function convert_units($value, $units, $convert = ITEM_CONVERT_WITH_UNITS)
{
    // special processing for unix timestamps
    if ($units == 'unixtime') {
        return zbx_date2str(_('Y.m.d H:i:s'), $value);
    }
    // special processing of uptime
    if ($units == 'uptime') {
        return convertUnitsUptime($value);
    }
    // special processing for seconds
    if ($units == 's') {
        return convertUnitsS($value);
    }
    // any other unit
    // black list wich do not require units metrics..
    $blackList = array('%', 'ms', 'rpm', 'RPM');
    if (in_array($units, $blackList) || zbx_empty($units) && ($convert == ITEM_CONVERT_WITH_UNITS || $value < 1)) {
        if (abs($value) >= ZBX_UNITS_ROUNDOFF_THRESHOLD) {
            $value = round($value, ZBX_UNITS_ROUNDOFF_UPPER_LIMIT);
        }
        $value = sprintf('%.' . ZBX_UNITS_ROUNDOFF_LOWER_LIMIT . 'f', $value);
        $value = preg_replace('/^([\\-0-9]+)(\\.)([0-9]*)[0]+$/U', '$1$2$3', $value);
        $value = rtrim($value, '.');
        if (zbx_empty($units)) {
            return $value;
        } else {
            return $value . ' ' . $units;
        }
    }
    switch ($units) {
        case 'Bps':
        case 'B':
            $step = 1024;
            $convert = $convert ? $convert : ITEM_CONVERT_NO_UNITS;
            break;
        case 'b':
        case 'bps':
            $convert = $convert ? $convert : ITEM_CONVERT_NO_UNITS;
        default:
            $step = 1000;
    }
    // init intervals
    static $digitUnits;
    if (is_null($digitUnits)) {
        $digitUnits = array();
    }
    if (!isset($digitUnits[$step])) {
        $digitUnits[$step] = array(array('pow' => -2, 'short' => _x('µ', 'Micro short'), 'long' => _('Micro')), array('pow' => -1, 'short' => _x('m', 'Milli short'), 'long' => _('Milli')), array('pow' => 0, 'short' => '', 'long' => ''), array('pow' => 1, 'short' => _x('K', 'Kilo short'), 'long' => _('Kilo')), array('pow' => 2, 'short' => _x('M', 'Mega short'), 'long' => _('Mega')), array('pow' => 3, 'short' => _x('G', 'Giga short'), 'long' => _('Giga')), array('pow' => 4, 'short' => _x('T', 'Tera short'), 'long' => _('Tera')), array('pow' => 5, 'short' => _x('P', 'Peta short'), 'long' => _('Peta')), array('pow' => 6, 'short' => _x('E', 'Exa short'), 'long' => _('Exa')), array('pow' => 7, 'short' => _x('Z', 'Zetta short'), 'long' => _('Zetta')), array('pow' => 8, 'short' => _x('Y', 'Yotta short'), 'long' => _('Yotta')));
        foreach ($digitUnits[$step] as $dunit => $data) {
            // skip mili & micro for values without units
            $digitUnits[$step][$dunit]['value'] = bcpow($step, $data['pow'], 9);
        }
    }
    if ($value < 0) {
        $abs = bcmul($value, '-1');
    } else {
        $abs = $value;
    }
    $valUnit = array('pow' => 0, 'short' => '', 'long' => '', 'value' => $value);
    if ($abs > 999 || $abs < 0.001) {
        foreach ($digitUnits[$step] as $dnum => $data) {
            if (bccomp($abs, $data['value']) > -1) {
                $valUnit = $data;
            } else {
                break;
            }
        }
        if (round($valUnit['value'], 6) > 0) {
            $valUnit['value'] = bcdiv(sprintf('%.6f', $value), sprintf('%.6f', $valUnit['value']), 6);
        } else {
            $valUnit['value'] = 0;
        }
    }
    switch ($convert) {
        case 0:
            $units = trim($units);
        case 1:
            $desc = $valUnit['short'];
            break;
        case 2:
            $desc = $valUnit['long'];
            break;
    }
    $value = preg_replace('/^([\\-0-9]+)(\\.)([0-9]*)[0]+$/U', '$1$2$3', round($valUnit['value'], ZBX_UNITS_ROUNDOFF_UPPER_LIMIT));
    $value = rtrim($value, '.');
    return rtrim(sprintf('%s %s%s', $value, $desc, $units));
}
**
** 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/
$widget = (new CWidget())->setTitle(_('Slide shows'));
$controls = (new CList())->addItem(new CComboBox('config', 'slides.php', 'redirect(this.options[this.selectedIndex].value);', ['screens.php' => _('Screens'), 'slides.php' => _('Slide shows')]))->addItem(new CSubmit('form', _('Create slide show')));
$createForm = (new CForm('get'))->cleanItems()->addItem($controls);
$widget->setControls($createForm);
// filter
$widget->addItem((new CFilter('web.slideconf.filter.state'))->addColumn((new CFormList())->addRow(_('Name like'), (new CTextBox('filter_name', $data['filter']['name']))->setWidth(ZBX_TEXTAREA_FILTER_STANDARD_WIDTH))));
// Create form.
$form = (new CForm())->setName('slideForm');
// create table
$slidesTable = (new CTableInfo())->setHeader([(new CColHeader((new CCheckBox('all_shows'))->onClick("checkAll('" . $form->getName() . "', 'all_shows', 'shows');")))->addClass(ZBX_STYLE_CELL_WIDTH), make_sorting_header(_('Name'), 'name', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Delay'), 'delay', $this->data['sort'], $this->data['sortorder']), make_sorting_header(_('Number of slides'), 'cnt', $this->data['sort'], $this->data['sortorder']), _('Actions')]);
foreach ($this->data['slides'] as $slide) {
    $user_type = CWebUser::getType();
    if ($user_type == USER_TYPE_SUPER_ADMIN || $user_type == USER_TYPE_ZABBIX_ADMIN || $slide['editable']) {
        $checkbox = new CCheckBox('shows[' . $slide['slideshowid'] . ']', $slide['slideshowid']);
        $properties = (new CLink(_('Properties'), '?form=update&slideshowid=' . $slide['slideshowid']))->addClass('action');
    } else {
        $checkbox = (new CCheckBox('shows[' . $slide['slideshowid'] . ']', $slide['slideshowid']))->setAttribute('disabled', 'disabled');
        $properties = '';
    }
    $slidesTable->addRow([$checkbox, (new CLink($slide['name'], 'slides.php?elementid=' . $slide['slideshowid']))->addClass('action'), convertUnitsS($slide['delay']), $slide['cnt'], $properties]);
}
// append table to form
$form->addItem([$slidesTable, $this->data['paging'], new CActionButtonList('action', 'shows', ['slideshow.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected slide shows?')]])]);
// append form to widget
$widget->addItem($form);
return $widget;
    if ($discovery['templateid']) {
        $dbTemplate = get_realhost_by_itemid($discovery['templateid']);
        $description[] = (new CLink($dbTemplate['name'], '?hostid=' . $dbTemplate['hostid']))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_GREY);
        $description[] = NAME_DELIMITER;
    }
    $description[] = new CLink($discovery['name_expanded'], '?form=update&itemid=' . $discovery['itemid']);
    // status
    $status = (new CLink(itemIndicator($discovery['status'], $discovery['state']), '?hostid=' . $_REQUEST['hostid'] . '&g_hostdruleid=' . $discovery['itemid'] . '&action=' . ($discovery['status'] == ITEM_STATUS_DISABLED ? 'discoveryrule.massenable' : 'discoveryrule.massdisable')))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(itemIndicatorStyle($discovery['status'], $discovery['state']))->addSID();
    // info
    if ($data['showInfoColumn']) {
        if ($discovery['status'] == ITEM_STATUS_ACTIVE && !zbx_empty($discovery['error'])) {
            $info = makeErrorIcon($discovery['error']);
        } else {
            $info = '';
        }
    } else {
        $info = null;
    }
    // host prototype link
    $hostPrototypeLink = null;
    if ($data['host']['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) {
        $hostPrototypeLink = [new CLink(_('Host prototypes'), 'host_prototypes.php?parent_discoveryid=' . $discovery['itemid']), CViewHelper::showNum($discovery['hostPrototypes'])];
    }
    $discoveryTable->addRow([new CCheckBox('g_hostdruleid[' . $discovery['itemid'] . ']', $discovery['itemid']), $description, [new CLink(_('Item prototypes'), 'disc_prototypes.php?parent_discoveryid=' . $discovery['itemid']), CViewHelper::showNum($discovery['items'])], [new CLink(_('Trigger prototypes'), 'trigger_prototypes.php?parent_discoveryid=' . $discovery['itemid']), CViewHelper::showNum($discovery['triggers'])], [new CLink(_('Graph prototypes'), 'graphs.php?parent_discoveryid=' . $discovery['itemid']), CViewHelper::showNum($discovery['graphs'])], $hostPrototypeLink, $discovery['key_'], $discovery['delay'] === '' ? '' : convertUnitsS($discovery['delay']), item_type2str($discovery['type']), $status, $info]);
}
zbx_add_post_js('cookie.prefix = "' . $this->data['hostid'] . '";');
// append table to form
$discoveryForm->addItem([$discoveryTable, $this->data['paging'], new CActionButtonList('action', 'g_hostdruleid', ['discoveryrule.massenable' => ['name' => _('Enable'), 'confirm' => _('Enable selected discovery rules?')], 'discoveryrule.massdisable' => ['name' => _('Disable'), 'confirm' => _('Disable selected discovery rules?')], 'discoveryrule.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected discovery rules?')]], $this->data['hostid'])]);
// append form to widget
$widget->addItem($discoveryForm);
return $widget;
$httpTable = (new CTableInfo())->setHeader([(new CColHeader((new CCheckBox('all_httptests'))->onClick("checkAll('" . $httpForm->getName() . "', 'all_httptests', 'group_httptestid');")))->addClass(ZBX_STYLE_CELL_WIDTH), $this->data['hostid'] == 0 ? make_sorting_header(_('Host'), 'hostname', $this->data['sort'], $this->data['sortorder']) : null, make_sorting_header(_('Name'), 'name', $this->data['sort'], $this->data['sortorder']), _('Number of steps'), _('Update interval'), _('Attempts'), _('Authentication'), _('HTTP proxy'), _('Application'), make_sorting_header(_('Status'), 'status', $this->data['sort'], $this->data['sortorder']), $this->data['showInfoColumn'] ? _('Info') : null]);
$httpTestsLastData = $this->data['httpTestsLastData'];
$httpTests = $this->data['httpTests'];
foreach ($httpTests as $httpTestId => $httpTest) {
    $name = [];
    if (isset($this->data['parentTemplates'][$httpTestId])) {
        $template = $this->data['parentTemplates'][$httpTestId];
        $name[] = (new CLink($template['name'], '?groupid=0&hostid=' . $template['id']))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_GREY);
        $name[] = NAME_DELIMITER;
    }
    $name[] = new CLink($httpTest['name'], '?form=update' . '&httptestid=' . $httpTestId . '&hostid=' . $httpTest['hostid']);
    if ($this->data['showInfoColumn']) {
        if ($httpTest['status'] == HTTPTEST_STATUS_ACTIVE && isset($httpTestsLastData[$httpTestId]) && $httpTestsLastData[$httpTestId]['lastfailedstep']) {
            $lastData = $httpTestsLastData[$httpTestId];
            $failedStep = $lastData['failedstep'];
            $errorMessage = $failedStep ? _s('Step "%1$s" [%2$s of %3$s] failed: %4$s', $failedStep['name'], $failedStep['no'], $httpTest['stepscnt'], $lastData['error'] === null ? _('Unknown error') : $lastData['error']) : _s('Unknown step failed: %1$s', $lastData['error']);
            $infoIcon = makeErrorIcon($errorMessage);
        } else {
            $infoIcon = '';
        }
    } else {
        $infoIcon = null;
    }
    $httpTable->addRow([new CCheckBox('group_httptestid[' . $httpTest['httptestid'] . ']', $httpTest['httptestid']), $this->data['hostid'] > 0 ? null : $httpTest['hostname'], $name, $httpTest['stepscnt'], convertUnitsS($httpTest['delay']), $httpTest['retries'], httptest_authentications($httpTest['authentication']), $httpTest['http_proxy'] !== '' ? _('Yes') : _('No'), $httpTest['applicationid'] != 0 ? $httpTest['application_name'] : '', (new CLink(httptest_status2str($httpTest['status']), '?group_httptestid[]=' . $httpTest['httptestid'] . '&hostid=' . $httpTest['hostid'] . '&action=' . ($httpTest['status'] == HTTPTEST_STATUS_DISABLED ? 'httptest.massenable' : 'httptest.massdisable')))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(httptest_status2style($httpTest['status']))->addSID(), $infoIcon]);
}
zbx_add_post_js('cookie.prefix = "' . $this->data['hostid'] . '";');
// append table to form
$httpForm->addItem([$httpTable, $this->data['paging'], new CActionButtonList('action', 'group_httptestid', ['httptest.massenable' => ['name' => _('Enable'), 'confirm' => _('Enable selected web scenarios?')], 'httptest.massdisable' => ['name' => _('Disable'), 'confirm' => _('Disable selected web scenarios?')], 'httptest.massclearhistory' => ['name' => _('Clear history'), 'confirm' => _('Delete history of selected web scenarios?')], 'httptest.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected web scenarios?')]], $this->data['hostid'])]);
// append form to widget
$widget->addItem($httpForm);
return $widget;
** Copyright (C) 2001-2016 Zabbix SIA
**
** 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/
$widget = (new CWidget())->setTitle(_('Discovery rules'))->setControls((new CForm('get'))->cleanItems()->addItem((new CList())->addItem(new CSubmit('form', _('Create discovery rule')))));
// create form
$discoveryForm = (new CForm())->setName('druleForm');
// create table
$discoveryTable = (new CTableInfo())->setHeader([(new CColHeader((new CCheckBox('all_drules'))->onClick("checkAll('" . $discoveryForm->getName() . "', 'all_drules', 'g_druleid');")))->addClass(ZBX_STYLE_CELL_WIDTH), make_sorting_header(_('Name'), 'name', $this->data['sort'], $this->data['sortorder']), _('IP range'), _('Delay'), _('Checks'), _('Status')]);
foreach ($data['drules'] as $drule) {
    array_push($drule['description'], new CLink($drule['name'], '?form=update&druleid=' . $drule['druleid']));
    $status = new CCol((new CLink(discovery_status2str($drule['status']), '?g_druleid[]=' . $drule['druleid'] . '&action=' . ($drule['status'] == DRULE_STATUS_ACTIVE ? 'drule.massdisable' : 'drule.massenable')))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(discovery_status2style($drule['status']))->addSID());
    $discoveryTable->addRow([new CCheckBox('g_druleid[' . $drule['druleid'] . ']', $drule['druleid']), $drule['description'], $drule['iprange'], convertUnitsS($drule['delay']), !empty($drule['checks']) ? implode(', ', $drule['checks']) : '', $status]);
}
// append table to form
$discoveryForm->addItem([$discoveryTable, $this->data['paging'], new CActionButtonList('action', 'g_druleid', ['drule.massenable' => ['name' => _('Enable'), 'confirm' => _('Enable selected discovery rules?')], 'drule.massdisable' => ['name' => _('Disable'), 'confirm' => _('Disable selected discovery rules?')], 'drule.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected discovery rules?')]])]);
// append form to widget
$widget->addItem($discoveryForm);
return $widget;