$caption[] = ' ('; foreach ($templates[$template['templateid']]['parentTemplates'] as $tpl) { $caption[] = new CLink(CHtml::encode($tpl['name']), 'templates.php?form=update&templateid=' . $tpl['templateid'], 'unknown'); $caption[] = ', '; } array_pop($caption); $caption[] = ')'; } $hostTemplates[] = $caption; $hostTemplates[] = ', '; } if ($hostTemplates) { array_pop($hostTemplates); } } $table->addRow(array(new CCheckBox('hosts[' . $host['hostid'] . ']', null, null, $host['hostid']), $displayNodes ? get_node_name_by_elid($host['hostid'], true) : null, $description, $applications, $items, $triggers, $graphs, $discoveries, $httpTests, $hostInterface, new CCol($hostTemplates, 'wraptext'), $status, getAvailabilityTable($host))); } $goBox = new CComboBox('go'); $goBox->addItem('export', _('Export selected')); $goBox->addItem('massupdate', _('Mass update')); $goOption = new CComboItem('activate', _('Enable selected')); $goOption->setAttribute('confirm', _('Enable selected hosts?')); $goBox->addItem($goOption); $goOption = new CComboItem('disable', _('Disable selected')); $goOption->setAttribute('confirm', _('Disable selected hosts?')); $goBox->addItem($goOption); $goOption = new CComboItem('delete', _('Delete selected')); $goOption->setAttribute('confirm', _('Delete selected hosts?')); $goBox->addItem($goOption); $goButton = new CSubmit('goButton', _('Go') . ' (0)'); $goButton->setAttribute('id', 'goButton');
/** * Create CDiv with host/template information and references to it's elements * * @param string $currentElement * @param int $hostid * @param int $discoveryid * * @return object */ function get_header_host_table($currentElement, $hostid, $discoveryid = null) { // LLD rule header if ($discoveryid) { $elements = array('items' => 'items', 'triggers' => 'triggers', 'graphs' => 'graphs', 'hosts' => 'hosts'); } else { $elements = array('items' => 'items', 'triggers' => 'triggers', 'graphs' => 'graphs', 'applications' => 'applications', 'screens' => 'screens', 'discoveries' => 'discoveries', 'web' => 'web'); } $options = array('hostids' => $hostid, 'output' => API_OUTPUT_EXTEND, 'templated_hosts' => true, 'selectHostDiscovery' => array('ts_delete')); if (isset($elements['items'])) { $options['selectItems'] = API_OUTPUT_COUNT; } if (isset($elements['triggers'])) { $options['selectTriggers'] = API_OUTPUT_COUNT; } if (isset($elements['graphs'])) { $options['selectGraphs'] = API_OUTPUT_COUNT; } if (isset($elements['applications'])) { $options['selectApplications'] = API_OUTPUT_COUNT; } if (isset($elements['discoveries'])) { $options['selectDiscoveries'] = API_OUTPUT_COUNT; } if (isset($elements['web'])) { $options['selectHttpTests'] = API_OUTPUT_COUNT; } if (isset($elements['hosts'])) { $options['selectHostPrototypes'] = API_OUTPUT_COUNT; } // get hosts $dbHost = API::Host()->get($options); $dbHost = reset($dbHost); if (!$dbHost) { return null; } // get discoveries if (!empty($discoveryid)) { $options['itemids'] = $discoveryid; $options['output'] = array('name'); unset($options['hostids'], $options['templated_hosts']); $dbDiscovery = API::DiscoveryRule()->get($options); $dbDiscovery = reset($dbDiscovery); } /* * Back */ $list = new CList(null, 'objectlist'); if ($dbHost['status'] == HOST_STATUS_TEMPLATE) { $list->addItem(array('« ', new CLink(_('Template list'), 'templates.php?templateid=' . $dbHost['hostid'] . url_param('groupid')))); $dbHost['screens'] = API::TemplateScreen()->get(array('editable' => true, 'countOutput' => true, 'groupCount' => true, 'templateids' => $dbHost['hostid'])); $dbHost['screens'] = isset($dbHost['screens'][0]['rowscount']) ? $dbHost['screens'][0]['rowscount'] : 0; } else { $list->addItem(array('« ', new CLink(_('Host list'), 'hosts.php?hostid=' . $dbHost['hostid'] . url_param('groupid')))); } /* * Name */ $proxyName = ''; if ($dbHost['proxy_hostid']) { $proxy = get_host_by_hostid($dbHost['proxy_hostid']); $proxyName = CHtml::encode($proxy['host']) . NAME_DELIMITER; } $name = get_node_name_by_elid($dbHost['hostid'], true, NAME_DELIMITER) . $proxyName . CHtml::encode($dbHost['name']); if ($dbHost['status'] == HOST_STATUS_TEMPLATE) { $list->addItem(array(bold(_('Template') . NAME_DELIMITER), new CLink($name, 'templates.php?form=update&templateid=' . $dbHost['hostid']))); } else { switch ($dbHost['status']) { case HOST_STATUS_MONITORED: if ($dbHost['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON) { $status = new CSpan(_('In maintenance'), 'orange'); } else { $status = new CSpan(_('Monitored'), 'enabled'); } break; case HOST_STATUS_NOT_MONITORED: $status = new CSpan(_('Not monitored'), 'on'); break; default: $status = _('Unknown'); break; } $list->addItem(array(bold(_('Host') . NAME_DELIMITER), new CLink($name, 'hosts.php?form=update&hostid=' . $dbHost['hostid']))); $list->addItem($status); $list->addItem(getAvailabilityTable($dbHost)); } if (!empty($dbDiscovery)) { $list->addItem(array('« ', new CLink(_('Discovery list'), 'host_discovery.php?hostid=' . $dbHost['hostid'] . url_param('groupid')))); $list->addItem(array(bold(_('Discovery') . NAME_DELIMITER), new CLink(CHtml::encode($dbDiscovery['name']), 'host_discovery.php?form=update&itemid=' . $dbDiscovery['itemid']))); } /* * Rowcount */ if (isset($elements['applications'])) { if ($currentElement == 'applications') { $list->addItem(_('Applications') . ' (' . $dbHost['applications'] . ')'); } else { $list->addItem(array(new CLink(_('Applications'), 'applications.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['applications'] . ')')); } } if (isset($elements['items'])) { if (!empty($dbDiscovery)) { if ($currentElement == 'items') { $list->addItem(_('Item prototypes') . ' (' . $dbDiscovery['items'] . ')'); } else { $list->addItem(array(new CLink(_('Item prototypes'), 'disc_prototypes.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['items'] . ')')); } } else { if ($currentElement == 'items') { $list->addItem(_('Items') . ' (' . $dbHost['items'] . ')'); } else { $list->addItem(array(new CLink(_('Items'), 'items.php?filter_set=1&hostid=' . $dbHost['hostid']), ' (' . $dbHost['items'] . ')')); } } } if (isset($elements['triggers'])) { if (!empty($dbDiscovery)) { if ($currentElement == 'triggers') { $list->addItem(_('Trigger prototypes') . ' (' . $dbDiscovery['triggers'] . ')'); } else { $list->addItem(array(new CLink(_('Trigger prototypes'), 'trigger_prototypes.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['triggers'] . ')')); } } else { if ($currentElement == 'triggers') { $list->addItem(_('Triggers') . ' (' . $dbHost['triggers'] . ')'); } else { $list->addItem(array(new CLink(_('Triggers'), 'triggers.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['triggers'] . ')')); } } } if (isset($elements['graphs'])) { if (!empty($dbDiscovery)) { if ($currentElement == 'graphs') { $list->addItem(_('Graph prototypes') . ' (' . $dbDiscovery['graphs'] . ')'); } else { $list->addItem(array(new CLink(_('Graph prototypes'), 'graphs.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['graphs'] . ')')); } } else { if ($currentElement == 'graphs') { $list->addItem(_('Graphs') . ' (' . $dbHost['graphs'] . ')'); } else { $list->addItem(array(new CLink(_('Graphs'), 'graphs.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['graphs'] . ')')); } } } if (isset($elements['hosts']) && $dbHost['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) { if ($currentElement == 'hosts') { $list->addItem(_('Host prototypes') . ' (' . $dbDiscovery['hostPrototypes'] . ')'); } else { $list->addItem(array(new CLink(_('Host prototypes'), 'host_prototypes.php?parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['hostPrototypes'] . ')')); } } if (isset($elements['screens']) && $dbHost['status'] == HOST_STATUS_TEMPLATE) { if ($currentElement == 'screens') { $list->addItem(_('Screens') . ' (' . $dbHost['screens'] . ')'); } else { $list->addItem(array(new CLink(_('Screens'), 'screenconf.php?templateid=' . $dbHost['hostid']), ' (' . $dbHost['screens'] . ')')); } } if (isset($elements['discoveries'])) { if ($currentElement == 'discoveries') { $list->addItem(_('Discovery rules') . ' (' . $dbHost['discoveries'] . ')'); } else { $list->addItem(array(new CLink(_('Discovery rules'), 'host_discovery.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['discoveries'] . ')')); } } if (isset($elements['web'])) { if ($currentElement == 'web') { $list->addItem(_('Web scenarios') . ' (' . $dbHost['httpTests'] . ')'); } else { $list->addItem(array(new CLink(_('Web scenarios'), 'httpconf.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['httpTests'] . ')')); } } return new CDiv($list, 'objectgroup top ui-widget-content ui-corner-all'); }
/** * Create CDiv with host/template information and references to it's elements * * @param string $currentElement * @param int $hostid * @param int $discoveryid * * @return object */ function get_header_host_table($currentElement, $hostid, $discoveryid = null) { $elements = array('items' => 'items', 'triggers' => 'triggers', 'graphs' => 'graphs', 'applications' => 'applications', 'screens' => 'screens', 'discoveries' => 'discoveries'); if (!empty($discoveryid)) { unset($elements['applications'], $elements['screens'], $elements['discoveries']); } $options = array('hostids' => $hostid, 'output' => API_OUTPUT_EXTEND, 'templated_hosts' => true); if (isset($elements['items'])) { $options['selectItems'] = API_OUTPUT_COUNT; } if (isset($elements['triggers'])) { $options['selectTriggers'] = API_OUTPUT_COUNT; } if (isset($elements['graphs'])) { $options['selectGraphs'] = API_OUTPUT_COUNT; } if (isset($elements['applications'])) { $options['selectApplications'] = API_OUTPUT_COUNT; } if (isset($elements['screens'])) { $options['selectScreens'] = API_OUTPUT_COUNT; } if (isset($elements['discoveries'])) { $options['selectDiscoveries'] = API_OUTPUT_COUNT; } // get hosts $dbHost = API::Host()->get($options); $dbHost = reset($dbHost); // get discoveries if (!empty($discoveryid)) { $options['itemids'] = $discoveryid; $options['output'] = array('name'); unset($options['hostids'], $options['templated_hosts']); $dbDiscovery = API::DiscoveryRule()->get($options); $dbDiscovery = reset($dbDiscovery); } /* * Back */ $list = new CList(null, 'objectlist'); if ($dbHost['status'] == HOST_STATUS_TEMPLATE) { $list->addItem(array('« ', new CLink(_('Template list'), 'templates.php?templateid=' . $dbHost['hostid'] . url_param('groupid')))); } else { $list->addItem(array('« ', new CLink(_('Host list'), 'hosts.php?hostid=' . $dbHost['hostid'] . url_param('groupid')))); } /* * Name */ $description = ''; if ($dbHost['proxy_hostid']) { $proxy = get_host_by_hostid($dbHost['proxy_hostid']); $description .= $proxy['host'] . ': '; } $description .= $dbHost['name']; if ($dbHost['status'] == HOST_STATUS_TEMPLATE) { $list->addItem(array(bold(_('Template') . ': '), new CLink($description, 'templates.php?form=update&templateid=' . $dbHost['hostid']))); } else { switch ($dbHost['status']) { case HOST_STATUS_MONITORED: $status = new CSpan(_('Monitored'), 'off'); break; case HOST_STATUS_NOT_MONITORED: $status = new CSpan(_('Not monitored'), 'on'); break; default: $status = _('Unknown'); break; } $list->addItem(array(bold(_('Host') . ': '), new CLink($description, 'hosts.php?form=update&hostid=' . $dbHost['hostid']))); $list->addItem($status); $list->addItem(getAvailabilityTable($dbHost)); } if (!empty($dbDiscovery)) { $list->addItem(array('« ', new CLink(_('Discovery list'), 'host_discovery.php?hostid=' . $dbHost['hostid'] . url_param('groupid')))); $list->addItem(array(bold(_('Discovery') . ': '), new CLink($dbDiscovery['name'], 'host_discovery.php?form=update&itemid=' . $dbDiscovery['itemid']))); } /* * Rowcount */ if (isset($elements['applications'])) { if ($currentElement == 'applications') { $list->addItem(_('Applications') . ' (' . $dbHost['applications'] . ')'); } else { $list->addItem(array(new CLink(_('Applications'), 'applications.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['applications'] . ')')); } } if (isset($elements['items'])) { if (!empty($dbDiscovery)) { if ($currentElement == 'items') { $list->addItem(_('Item prototypes') . ' (' . $dbDiscovery['items'] . ')'); } else { $list->addItem(array(new CLink(_('Item prototypes'), 'disc_prototypes.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['items'] . ')')); } } else { if ($currentElement == 'items') { $list->addItem(_('Items') . ' (' . $dbHost['items'] . ')'); } else { $list->addItem(array(new CLink(_('Items'), 'items.php?filter_set=1&hostid=' . $dbHost['hostid']), ' (' . $dbHost['items'] . ')')); } } } if (isset($elements['triggers'])) { if (!empty($dbDiscovery)) { if ($currentElement == 'triggers') { $list->addItem(_('Trigger prototypes') . ' (' . $dbDiscovery['triggers'] . ')'); } else { $list->addItem(array(new CLink(_('Trigger prototypes'), 'trigger_prototypes.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['triggers'] . ')')); } } else { if ($currentElement == 'triggers') { $list->addItem(_('Triggers') . ' (' . $dbHost['triggers'] . ')'); } else { $list->addItem(array(new CLink(_('Triggers'), 'triggers.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['triggers'] . ')')); } } } if (isset($elements['graphs'])) { if (!empty($dbDiscovery)) { if ($currentElement == 'graphs') { $list->addItem(_('Graph prototypes') . ' (' . $dbDiscovery['graphs'] . ')'); } else { $list->addItem(array(new CLink(_('Graph prototypes'), 'graphs.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['graphs'] . ')')); } } else { if ($currentElement == 'graphs') { $list->addItem(_('Graphs') . ' (' . $dbHost['graphs'] . ')'); } else { $list->addItem(array(new CLink(_('Graphs'), 'graphs.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['graphs'] . ')')); } } } if (isset($elements['screens']) && $dbHost['status'] == HOST_STATUS_TEMPLATE) { if ($currentElement == 'screens') { $list->addItem(_('Screens') . ' (' . $dbHost['screens'] . ')'); } else { $list->addItem(array(new CLink(_('Screens'), 'screenconf.php?templateid=' . $dbHost['hostid']), ' (' . $dbHost['screens'] . ')')); } } if (isset($elements['discoveries'])) { if ($currentElement == 'discoveries') { $list->addItem(_('Discovery rules') . ' (' . $dbHost['discoveries'] . ')'); } else { $list->addItem(array(new CLink(_('Discovery rules'), 'host_discovery.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['discoveries'] . ')')); } } return new CDiv($list, 'objectgroup top ui-widget-content ui-corner-all'); }
$caption[] = ' ('; foreach ($templates[$template['templateid']]['parentTemplates'] as $tpl) { $caption[] = new CLink($tpl['name'], 'templates.php?form=update&templateid=' . $tpl['templateid'], 'unknown'); $caption[] = ', '; } array_pop($caption); $caption[] = ')'; } $hostTemplates[] = $caption; $hostTemplates[] = ', '; } if (!empty($hostTemplates)) { array_pop($hostTemplates); } } $table->addRow(array(new CCheckBox('hosts[' . $host['hostid'] . ']', null, null, $host['hostid']), $description, $applications, $items, $triggers, $graphs, $discoveries, $hostIF, new CCol($hostTemplates, 'wraptext'), $status, getAvailabilityTable($host))); } $goBox = new CComboBox('go'); $goBox->addItem('export', _('Export selected')); $goBox->addItem('massupdate', _('Mass update')); $goOption = new CComboItem('activate', _('Enable selected')); $goOption->setAttribute('confirm', _('Enable selected hosts?')); $goBox->addItem($goOption); $goOption = new CComboItem('disable', _('Disable selected')); $goOption->setAttribute('confirm', _('Disable selected hosts?')); $goBox->addItem($goOption); $goOption = new CComboItem('delete', _('Delete selected')); $goOption->setAttribute('confirm', _('Delete selected hosts?')); $goBox->addItem($goOption); $goButton = new CSubmit('goButton', _('Go') . ' (0)'); $goButton->setAttribute('id', 'goButton');