if ($host['tls_connect'] == HOST_ENCRYPTION_NONE) {
            $in_encryption = (new CSpan(_('None')))->addClass(ZBX_STYLE_STATUS_GREEN);
        } elseif ($host['tls_connect'] == HOST_ENCRYPTION_PSK) {
            $in_encryption = (new CSpan(_('PSK')))->addClass(ZBX_STYLE_STATUS_GREEN);
        } else {
            $in_encryption = (new CSpan(_('CERT')))->addClass(ZBX_STYLE_STATUS_GREEN);
        }
        // Outgoing encryption.
        $out_encryption = [];
        if (($host['tls_accept'] & HOST_ENCRYPTION_NONE) == HOST_ENCRYPTION_NONE) {
            $out_encryption[] = (new CSpan(_('None')))->addClass(ZBX_STYLE_STATUS_GREEN);
        } else {
            $out_encryption[] = (new CSpan(_('None')))->addClass(ZBX_STYLE_STATUS_GREY);
        }
        if (($host['tls_accept'] & HOST_ENCRYPTION_PSK) == HOST_ENCRYPTION_PSK) {
            $out_encryption[] = (new CSpan(_('PSK')))->addClass(ZBX_STYLE_STATUS_GREEN);
        } else {
            $out_encryption[] = (new CSpan(_('PSK')))->addClass(ZBX_STYLE_STATUS_GREY);
        }
        if (($host['tls_accept'] & HOST_ENCRYPTION_CERTIFICATE) == HOST_ENCRYPTION_CERTIFICATE) {
            $out_encryption[] = (new CSpan(_('CERT')))->addClass(ZBX_STYLE_STATUS_GREEN);
        } else {
            $out_encryption[] = (new CSpan(_('CERT')))->addClass(ZBX_STYLE_STATUS_GREY);
        }
        $encryption = (new CDiv([$in_encryption, ' ', $out_encryption]))->addClass(ZBX_STYLE_STATUS_CONTAINER);
    }
    $table->addRow([new CCheckBox('hosts[' . $host['hostid'] . ']', $host['hostid']), (new CCol($description))->addClass(ZBX_STYLE_NOWRAP), [new CLink(_('Applications'), 'applications.php?groupid=' . $data['groupId'] . '&hostid=' . $host['hostid']), CViewHelper::showNum($host['applications'])], [new CLink(_('Items'), 'items.php?filter_set=1&hostid=' . $host['hostid']), CViewHelper::showNum($host['items'])], [new CLink(_('Triggers'), 'triggers.php?groupid=' . $data['groupId'] . '&hostid=' . $host['hostid']), CViewHelper::showNum($host['triggers'])], [new CLink(_('Graphs'), 'graphs.php?groupid=' . $data['groupId'] . '&hostid=' . $host['hostid']), CViewHelper::showNum($host['graphs'])], [new CLink(_('Discovery'), 'host_discovery.php?&hostid=' . $host['hostid']), CViewHelper::showNum($host['discoveries'])], [new CLink(_('Web'), 'httpconf.php?&hostid=' . $host['hostid']), CViewHelper::showNum($host['httpTests'])], $hostInterface, $hostTemplates, $status, getHostAvailabilityTable($host), $encryption, $lifetime_indicator]);
}
$form->addItem([$table, $data['paging'], new CActionButtonList('action', 'hosts', ['host.massenable' => ['name' => _('Enable'), 'confirm' => _('Enable selected hosts?')], 'host.massdisable' => ['name' => _('Disable'), 'confirm' => _('Disable selected hosts?')], 'host.export' => ['name' => _('Export')], 'host.massupdateform' => ['name' => _('Mass update')], 'host.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected hosts?')]])]);
$widget->addItem($form);
return $widget;
Exemple #2
0
/**
 * Create CDiv with host/template information and references to it's elements
 *
 * @param string $currentElement
 * @param int $hostid
 * @param int $lld_ruleid
 *
 * @return object
 */
function get_header_host_table($current_element, $hostid, $lld_ruleid = 0)
{
    $options = ['output' => ['hostid', 'status', 'proxy_hostid', 'name', 'maintenance_status', 'flags', 'available', 'snmp_available', 'jmx_available', 'ipmi_available', 'error', 'snmp_error', 'jmx_error', 'ipmi_error'], 'selectHostDiscovery' => ['ts_delete'], 'hostids' => [$hostid], 'editable' => true];
    if ($lld_ruleid == 0) {
        $options['selectApplications'] = API_OUTPUT_COUNT;
        $options['selectItems'] = API_OUTPUT_COUNT;
        $options['selectTriggers'] = API_OUTPUT_COUNT;
        $options['selectGraphs'] = API_OUTPUT_COUNT;
        $options['selectDiscoveries'] = API_OUTPUT_COUNT;
        $options['selectHttpTests'] = API_OUTPUT_COUNT;
    }
    // get hosts
    $db_host = API::Host()->get($options);
    if (!$db_host) {
        $options = ['output' => ['templateid', 'name', 'flags'], 'templateids' => [$hostid], 'editable' => true];
        if ($lld_ruleid == 0) {
            $options['selectApplications'] = API_OUTPUT_COUNT;
            $options['selectItems'] = API_OUTPUT_COUNT;
            $options['selectTriggers'] = API_OUTPUT_COUNT;
            $options['selectGraphs'] = API_OUTPUT_COUNT;
            $options['selectScreens'] = API_OUTPUT_COUNT;
            $options['selectDiscoveries'] = API_OUTPUT_COUNT;
            $options['selectHttpTests'] = API_OUTPUT_COUNT;
        }
        // get templates
        $db_host = API::Template()->get($options);
        $is_template = true;
    } else {
        $is_template = false;
    }
    if (!$db_host) {
        return null;
    }
    $db_host = reset($db_host);
    // get lld-rules
    if ($lld_ruleid != 0) {
        $db_discovery_rule = API::DiscoveryRule()->get(['output' => ['name'], 'selectItems' => API_OUTPUT_COUNT, 'selectTriggers' => API_OUTPUT_COUNT, 'selectGraphs' => API_OUTPUT_COUNT, 'selectHostPrototypes' => API_OUTPUT_COUNT, 'itemids' => [$lld_ruleid], 'editable' => true]);
        $db_discovery_rule = reset($db_discovery_rule);
    }
    /*
     * list and host (template) name
     */
    $list = (new CList())->addClass(ZBX_STYLE_OBJECT_GROUP);
    if ($is_template) {
        $template = new CSpan(new CLink($db_host['name'], 'templates.php?form=update&templateid=' . $db_host['templateid']));
        if ($current_element === '') {
            $template->addClass(ZBX_STYLE_SELECTED);
        }
        $list->addItem([new CSpan(new CLink(_('All templates'), 'templates.php?templateid=' . $db_host['templateid'] . url_param('groupid'))), '/', $template]);
        $db_host['hostid'] = $db_host['templateid'];
    } else {
        $proxy_name = '';
        if ($db_host['proxy_hostid'] != 0) {
            $db_proxies = API::Proxy()->get(['output' => ['host'], 'proxyids' => [$db_host['proxy_hostid']]]);
            $proxy_name = CHtml::encode($db_proxies[0]['host']) . NAME_DELIMITER;
        }
        $name = $proxy_name . CHtml::encode($db_host['name']);
        switch ($db_host['status']) {
            case HOST_STATUS_MONITORED:
                if ($db_host['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON) {
                    $status = (new CSpan(_('In maintenance')))->addClass(ZBX_STYLE_ORANGE);
                } else {
                    $status = (new CSpan(_('Enabled')))->addClass(ZBX_STYLE_GREEN);
                }
                break;
            case HOST_STATUS_NOT_MONITORED:
                $status = (new CSpan(_('Disabled')))->addClass(ZBX_STYLE_RED);
                break;
            default:
                $status = _('Unknown');
                break;
        }
        $host = new CSpan(new CLink($name, 'hosts.php?form=update&hostid=' . $db_host['hostid']));
        if ($current_element === '') {
            $host->addClass(ZBX_STYLE_SELECTED);
        }
        $list->addItem([new CSpan(new CLink(_('All hosts'), 'hosts.php?hostid=' . $db_host['hostid'] . url_param('groupid'))), '/', $host]);
        $list->addItem($status);
        $list->addItem(getHostAvailabilityTable($db_host));
        if ($db_host['flags'] == ZBX_FLAG_DISCOVERY_CREATED && $db_host['hostDiscovery']['ts_delete'] != 0) {
            $lifetime_indicator = getHostLifetimeIndicator(time(), $db_host['hostDiscovery']['ts_delete']);
            $list->addItem((new CDiv($lifetime_indicator))->addClass(ZBX_STYLE_STATUS_CONTAINER));
        }
    }
    /*
     * the count of rows
     */
    if ($lld_ruleid == 0) {
        // applications
        $applications = new CSpan([new CLink(_('Applications'), 'applications.php?hostid=' . $db_host['hostid']), CViewHelper::showNum($db_host['applications'])]);
        if ($current_element == 'applications') {
            $applications->addClass(ZBX_STYLE_SELECTED);
        }
        $list->addItem($applications);
        // items
        $items = new CSpan([new CLink(_('Items'), 'items.php?filter_set=1&hostid=' . $db_host['hostid']), CViewHelper::showNum($db_host['items'])]);
        if ($current_element == 'items') {
            $items->addClass(ZBX_STYLE_SELECTED);
        }
        $list->addItem($items);
        // triggers
        $triggers = new CSpan([new CLink(_('Triggers'), 'triggers.php?hostid=' . $db_host['hostid']), CViewHelper::showNum($db_host['triggers'])]);
        if ($current_element == 'triggers') {
            $triggers->addClass(ZBX_STYLE_SELECTED);
        }
        $list->addItem($triggers);
        // graphs
        $graphs = new CSpan([new CLink(_('Graphs'), 'graphs.php?hostid=' . $db_host['hostid']), CViewHelper::showNum($db_host['graphs'])]);
        if ($current_element == 'graphs') {
            $graphs->addClass(ZBX_STYLE_SELECTED);
        }
        $list->addItem($graphs);
        // screens
        if ($is_template) {
            $screens = new CSpan([new CLink(_('Screens'), 'screenconf.php?templateid=' . $db_host['hostid']), CViewHelper::showNum($db_host['screens'])]);
            if ($current_element == 'screens') {
                $screens->addClass(ZBX_STYLE_SELECTED);
            }
            $list->addItem($screens);
        }
        // discovery rules
        $lld_rules = new CSpan([new CLink(_('Discovery rules'), 'host_discovery.php?hostid=' . $db_host['hostid']), CViewHelper::showNum($db_host['discoveries'])]);
        if ($current_element == 'discoveries') {
            $lld_rules->addClass(ZBX_STYLE_SELECTED);
        }
        $list->addItem($lld_rules);
        // web scenarios
        $http_tests = new CSpan([new CLink(_('Web scenarios'), 'httpconf.php?hostid=' . $db_host['hostid']), CViewHelper::showNum($db_host['httpTests'])]);
        if ($current_element == 'web') {
            $http_tests->addClass(ZBX_STYLE_SELECTED);
        }
        $list->addItem($http_tests);
    } else {
        $discovery_rule = (new CSpan())->addItem(new CLink(CHtml::encode($db_discovery_rule['name']), 'host_discovery.php?form=update&itemid=' . $db_discovery_rule['itemid']));
        if ($current_element == 'discoveries') {
            $discovery_rule->addClass(ZBX_STYLE_SELECTED);
        }
        $list->addItem([(new CSpan())->addItem(new CLink(_('Discovery list'), 'host_discovery.php?hostid=' . $db_host['hostid'] . url_param('groupid'))), '/', $discovery_rule]);
        // item prototypes
        $item_prototypes = new CSpan([new CLink(_('Item prototypes'), 'disc_prototypes.php?parent_discoveryid=' . $db_discovery_rule['itemid']), CViewHelper::showNum($db_discovery_rule['items'])]);
        if ($current_element == 'items') {
            $item_prototypes->addClass(ZBX_STYLE_SELECTED);
        }
        $list->addItem($item_prototypes);
        // trigger prototypes
        $trigger_prototypes = new CSpan([new CLink(_('Trigger prototypes'), 'trigger_prototypes.php?parent_discoveryid=' . $db_discovery_rule['itemid']), CViewHelper::showNum($db_discovery_rule['triggers'])]);
        if ($current_element == 'triggers') {
            $trigger_prototypes->addClass(ZBX_STYLE_SELECTED);
        }
        $list->addItem($trigger_prototypes);
        // graph prototypes
        $graph_prototypes = new CSpan([new CLink(_('Graph prototypes'), 'graphs.php?parent_discoveryid=' . $db_discovery_rule['itemid']), CViewHelper::showNum($db_discovery_rule['graphs'])]);
        if ($current_element == 'graphs') {
            $graph_prototypes->addClass(ZBX_STYLE_SELECTED);
        }
        $list->addItem($graph_prototypes);
        // host prototypes
        if ($db_host['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) {
            $host_prototypes = new CSpan([new CLink(_('Host prototypes'), 'host_prototypes.php?parent_discoveryid=' . $db_discovery_rule['itemid']), CViewHelper::showNum($db_discovery_rule['hostPrototypes'])]);
            if ($current_element == 'hosts') {
                $host_prototypes->addClass(ZBX_STYLE_SELECTED);
            }
            $list->addItem($host_prototypes);
        }
    }
    return $list;
}