order_result($parentTemplates, 'name'); $caption[] = ' ('; foreach ($parentTemplates as $parentTemplate) { $caption[] = (new CLink(CHtml::encode($parentTemplate['name']), 'templates.php?form=update&templateid=' . $parentTemplate['templateid']))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_GREY); $caption[] = ', '; } array_pop($caption); $caption[] = ')'; } if ($hostTemplates) { $hostTemplates[] = ', '; } $hostTemplates[] = $caption; } if ($host['flags'] == ZBX_FLAG_DISCOVERY_CREATED && $host['hostDiscovery']['ts_delete'] != 0) { $lifetime_indicator = getHostLifetimeIndicator($current_time, $host['hostDiscovery']['ts_delete']); } else { $lifetime_indicator = ''; } if ($host['tls_connect'] == HOST_ENCRYPTION_NONE && ($host['tls_accept'] & HOST_ENCRYPTION_NONE) == HOST_ENCRYPTION_NONE && ($host['tls_accept'] & HOST_ENCRYPTION_PSK) != HOST_ENCRYPTION_PSK && ($host['tls_accept'] & HOST_ENCRYPTION_CERTIFICATE) != HOST_ENCRYPTION_CERTIFICATE) { $encryption = (new CDiv((new CSpan(_('None')))->addClass(ZBX_STYLE_STATUS_GREEN)))->addClass(ZBX_STYLE_STATUS_CONTAINER); } else { // Incoming encryption. 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.
/** * 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; }