$guiAccess = (new CLink($guiAccess, 'usergrps.php?action=usergroup.set_gui_access&set_gui_access=' . $nextGuiAuth . '&usrgrpid=' . $userGroupId))->addClass($guiAccessStyle)->addSID();
        $usersStatus = $usrgrp['users_status'] == GROUP_STATUS_ENABLED ? (new CLink(_('Enabled'), 'usergrps.php?action=usergroup.massdisable&usrgrpid=' . $userGroupId))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(ZBX_STYLE_GREEN)->addSID() : (new CLink(_('Disabled'), 'usergrps.php?action=usergroup.massenable&usrgrpid=' . $userGroupId))->addClass(ZBX_STYLE_LINK_ACTION)->addClass(ZBX_STYLE_RED)->addSID();
    } else {
        $guiAccess = (new CSpan($guiAccess))->addClass($guiAccessStyle);
        $usersStatus = $usrgrp['users_status'] == GROUP_STATUS_ENABLED ? (new CSpan(_('Enabled')))->addClass(ZBX_STYLE_GREEN) : (new CSpan(_('Disabled')))->addClass(ZBX_STYLE_RED);
    }
    if (isset($usrgrp['users'])) {
        $userGroupUsers = $usrgrp['users'];
        order_result($userGroupUsers, 'alias');
        $users = [];
        $i = 0;
        foreach ($userGroupUsers as $user) {
            $i++;
            if ($i > $this->data['config']['max_in_table']) {
                $users[] = ' …';
                break;
            }
            if ($users) {
                $users[] = ', ';
            }
            $users[] = (new CLink(getUserFullname($user), 'users.php?form=update&userid=' . $user['userid']))->addClass(ZBX_STYLE_LINK_ALT)->addClass($user['gui_access'] == GROUP_GUI_ACCESS_DISABLED || $user['users_status'] == GROUP_STATUS_DISABLED ? ZBX_STYLE_RED : ZBX_STYLE_GREEN);
        }
    }
    $name = new CLink($usrgrp['name'], 'usergrps.php?form=update&usrgrpid=' . $userGroupId);
    $userGroupTable->addRow([new CCheckBox('group_groupid[' . $userGroupId . ']', $userGroupId), (new CCol($name))->addClass(ZBX_STYLE_NOWRAP), [new CLink(_('Users'), 'users.php?filter_usrgrpid=' . $userGroupId), CViewHelper::showNum(count($usrgrp['users']))], $users, $guiAccess, $debugMode, $usersStatus]);
}
// append table to form
$userGroupsForm->addItem([$userGroupTable, $this->data['paging'], new CActionButtonList('action', 'group_groupid', ['usergroup.massenable' => ['name' => _('Enable'), 'confirm' => _('Enable selected groups?')], 'usergroup.massdisable' => ['name' => _('Disable'), 'confirm' => _('Disable selected groups?')], 'usergroup.massenabledebug' => ['name' => _('Enable debug mode'), 'confirm' => _('Enable debug mode in selected groups?')], 'usergroup.massdisabledebug' => ['name' => _('Disable debug mode'), 'confirm' => _('Disable debug mode in selected groups?')], 'usergroup.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected groups?')]])]);
// append form to widget
$widget->addItem($userGroupsForm);
return $widget;
    $applicationsLink = new CLink(_('Applications'), 'applications.php?hostid=' . $data['host']['hostid'] . url_param('groupid'));
    $itemsLink = new CLink(_('Items'), 'items.php?filter_set=1&hostid=' . $data['host']['hostid'] . url_param('groupid'));
    $triggersLink = new CLink(_('Triggers'), 'triggers.php?hostid=' . $data['host']['hostid'] . url_param('groupid'));
    $graphsLink = new CLink(_('Graphs'), 'graphs.php?hostid=' . $data['host']['hostid'] . url_param('groupid'));
    $discoveryLink = new CLink(_('Discovery'), 'host_discovery.php?hostid=' . $data['host']['hostid'] . url_param('groupid'));
    $webLink = new CLink(_('Web'), 'httpconf.php?hostid=' . $data['host']['hostid'] . url_param('groupid'));
} else {
    $hostLink = _('Host');
    $applicationsLink = _('Application');
    $itemsLink = _('Items');
    $triggersLink = _('Triggers');
    $graphsLink = _('Graphs');
    $discoveryLink = _('Discovery');
    $webLink = _('Web');
}
$overviewFormList->addRow(_('Configuration'), new CHorList([$hostLink, new CSpan([$applicationsLink, CViewHelper::showNum($data['host']['applications'])]), new CSpan([$itemsLink, CViewHelper::showNum($data['host']['items'])]), new CSpan([$triggersLink, CViewHelper::showNum($data['host']['triggers'])]), new CSpan([$graphsLink, CViewHelper::showNum($data['host']['graphs'])]), new CSpan([$discoveryLink, CViewHelper::showNum($data['host']['discoveries'])]), new CSpan([$webLink, CViewHelper::showNum($data['host']['httpTests'])])]));
$hostInventoriesTab = (new CTabView(['remember' => true]))->setSelected(0)->addTab('overviewTab', _('Overview'), $overviewFormList);
/*
 * Details tab
 */
$detailsFormList = new CFormList();
$inventoryValues = false;
foreach ($data['host']['inventory'] as $key => $value) {
    if ($value !== '') {
        $detailsFormList->addRow($data['tableTitles'][$key]['title'], (new CDiv(zbx_str2links($value)))->setWidth(ZBX_TEXTAREA_BIG_WIDTH));
        $inventoryValues = true;
    }
}
if (!$inventoryValues) {
    $hostInventoriesTab->setDisabled([1]);
}
Example #3
0
 foreach ($templates as $tnum => $template) {
     $templateid = $template['templateid'];
     $group = reset($template['groups']);
     $link = 'groupid=' . $group['groupid'] . '&hostid=' . $templateid;
     // highlight visible name
     $templateVisibleName = make_decoration($template['name'], $search);
     if (isset($rw_templates[$templateid])) {
         // template
         $templateCell = [new CLink($templateVisibleName, 'templates.php?form=update&' . '&templateid=' . $templateid)];
         $applications_link = [new CLink(_('Applications'), 'applications.php?' . $link), CViewHelper::showNum($template['applications'])];
         $items_link = [new CLink(_('Items'), 'items.php?filter_set=1&' . $link), CViewHelper::showNum($template['items'])];
         $triggers_link = [new CLink(_('Triggers'), 'triggers.php?' . $link), CViewHelper::showNum($template['triggers'])];
         $graphs_link = [new CLink(_('Graphs'), 'graphs.php?' . $link), CViewHelper::showNum($template['graphs'])];
         $screensLink = [new CLink(_('Screens'), 'screenconf.php?templateid=' . $templateid), CViewHelper::showNum($template['screens'])];
         $discoveryLink = [new CLink(_('Discovery'), 'host_discovery.php?' . $link), CViewHelper::showNum($template['discoveries'])];
         $httpTestsLink = [new CLink(_('Web'), 'httpconf.php?' . $link), CViewHelper::showNum($template['httpTests'])];
     } else {
         // host
         $templateCell = [new CSpan($templateVisibleName)];
         $applications_link = _('Applications') . ' (' . $template['applications'] . ')';
         $items_link = _('Items') . ' (' . $template['items'] . ')';
         $triggers_link = _('Triggers') . ' (' . $template['triggers'] . ')';
         $graphs_link = _('Graphs') . ' (' . $template['graphs'] . ')';
         $screensLink = _('Screens') . ' (' . $template['screens'] . ')';
         $discoveryLink = _('Discovery') . ' (' . $template['discoveries'] . ')';
         $httpTestsLink = _('Web') . ' (' . $template['httpTests'] . ')';
     }
     // display the template host name only if it matches the search string and is different from the visible name
     if ($template['host'] !== $template['name'] && stripos($template['host'], $search) !== false) {
         $templateCell[] = BR();
         $templateCell[] = '(';
            $hostsOutput[] = ' …';
            break;
        }
        if ($n > 1) {
            $hostsOutput[] = ', ';
        }
        $url = 'hosts.php?form=update&hostid=' . $host['hostid'] . '&groupid=' . $group['groupid'];
        $hostsOutput[] = (new CLink($host['name'], $url))->addClass(ZBX_STYLE_LINK_ALT)->addClass($host['status'] == HOST_STATUS_MONITORED ? ZBX_STYLE_GREEN : ZBX_STYLE_RED);
    }
    $hostCount = $this->data['groupCounts'][$group['groupid']]['hosts'];
    $templateCount = $this->data['groupCounts'][$group['groupid']]['templates'];
    // name
    $name = [];
    if ($group['discoveryRule']) {
        $name[] = (new CLink($group['discoveryRule']['name'], 'host_prototypes.php?parent_discoveryid=' . $group['discoveryRule']['itemid']))->addClass(ZBX_STYLE_ORANGE);
        $name[] = NAME_DELIMITER;
    }
    $name[] = new CLink($group['name'], 'hostgroups.php?form=update&groupid=' . $group['groupid']);
    // info, discovered item lifetime indicator
    if ($group['flags'] == ZBX_FLAG_DISCOVERY_CREATED && $group['groupDiscovery']['ts_delete'] != 0) {
        $info = getHostGroupLifetimeIndicator($current_time, $group['groupDiscovery']['ts_delete']);
    } else {
        $info = '';
    }
    $hostGroupTable->addRow([new CCheckBox('groups[' . $group['groupid'] . ']', $group['groupid']), (new CCol($name))->addClass(ZBX_STYLE_NOWRAP), [new CLink(_('Hosts'), 'hosts.php?groupid=' . $group['groupid']), CViewHelper::showNum($hostCount)], [new CLink(_('Templates'), 'templates.php?groupid=' . $group['groupid']), CViewHelper::showNum($templateCount)], empty($hostsOutput) ? '' : $hostsOutput, $info]);
}
// append table to form
$hostGroupForm->addItem([$hostGroupTable, $this->data['paging'], new CActionButtonList('action', 'groups', ['hostgroup.massenable' => ['name' => _('Enable hosts'), 'confirm' => _('Enable selected hosts?')], 'hostgroup.massdisable' => ['name' => _('Disable hosts'), 'confirm' => _('Disable hosts in the selected host groups?')], 'hostgroup.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected host groups?')]])]);
// append form to widget
$widget->addItem($hostGroupForm);
return $widget;
Example #5
0
        order_result($linkedToObjects, 'name');
        foreach ($linkedToObjects as $linkedToObject) {
            $i++;
            if ($i > $config['max_in_table']) {
                $linkedToOutput[] = ' …';
                break;
            }
            if ($linkedToOutput) {
                $linkedToOutput[] = ', ';
            }
            if ($linkedToObject['status'] == HOST_STATUS_TEMPLATE) {
                $url = 'templates.php?form=update&templateid=' . $linkedToObject['templateid'] . url_param('groupid');
            } else {
                $url = 'hosts.php?form=update&hostid=' . $linkedToObject['hostid'] . url_param('groupid');
            }
            $link = (new CLink($linkedToObject['name'], $url))->addClass(ZBX_STYLE_LINK_ALT);
            if ($linkedToObject['status'] == HOST_STATUS_TEMPLATE) {
                $link->addClass(ZBX_STYLE_GREY);
            } else {
                $link->addClass($linkedToObject['status'] == HOST_STATUS_MONITORED ? ZBX_STYLE_GREEN : ZBX_STYLE_RED);
            }
            $linkedToOutput[] = $link;
        }
        $table->addRow([new CCheckBox('templates[' . $template['templateid'] . ']', $template['templateid']), (new CCol($templatesOutput))->addClass(ZBX_STYLE_NOWRAP), [new CLink(_('Applications'), 'applications.php?hostid=' . $template['templateid'] . url_param('groupid')), CViewHelper::showNum($template['applications'])], [new CLink(_('Items'), 'items.php?filter_set=1&hostid=' . $template['templateid'] . url_param('groupid')), CViewHelper::showNum($template['items'])], [new CLink(_('Triggers'), 'triggers.php?hostid=' . $template['templateid'] . url_param('groupid')), CViewHelper::showNum($template['triggers'])], [new CLink(_('Graphs'), 'graphs.php?hostid=' . $template['templateid'] . url_param('groupid')), CViewHelper::showNum($template['graphs'])], [new CLink(_('Screens'), 'screenconf.php?templateid=' . $template['templateid']), CViewHelper::showNum($template['screens'])], [new CLink(_('Discovery'), 'host_discovery.php?hostid=' . $template['templateid']), CViewHelper::showNum($template['discoveries'])], [new CLink(_('Web'), 'httpconf.php?hostid=' . $template['templateid'] . url_param('groupid')), CViewHelper::showNum($template['httpTests'])], $linkedTemplatesOutput, $linkedToOutput]);
    }
    $footer = new CActionButtonList('action', 'templates', ['template.export' => ['name' => _('Export')], 'template.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected templates?')], 'template.massdeleteclear' => ['name' => _('Delete and clear'), 'confirm' => _('Delete and clear selected templates? (Warning: all linked hosts will be cleared!)')]]);
    $form->addItem([$table, $paging, $footer]);
    $templateWidget->addItem($form);
}
$templateWidget->show();
require_once dirname(__FILE__) . '/include/page_footer.php';
Example #6
0
/**
 * Create element with event acknowledges info.
 * If $event has subarray 'acknowledges', returned link will have hint with acknowledges.
 *
 * @param array			$event   event data
 * @param int			$event['acknowledged']
 * @param int			$event['eventid']
 * @param int			$event['objectid']
 * @param mixed			$event['acknowledges']
 * @param string		$backurl  add url param to link with current page file name
 *
 * @return CLink
 */
function getEventAckState($event, $backurl)
{
    if ($event['acknowledged'] == EVENT_ACKNOWLEDGED) {
        $acknowledges_num = is_array($event['acknowledges']) ? count($event['acknowledges']) : $event['acknowledges'];
    }
    $link = 'zabbix.php?action=acknowledge.edit&eventids[]=' . $event['eventid'] . '&backurl=' . urlencode($backurl);
    if ($event['acknowledged'] == EVENT_ACKNOWLEDGED) {
        $ack = (new CLink(_('Yes'), $link))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_GREEN);
        if (is_array($event['acknowledges'])) {
            $ack->setHint(makeAckTab(array_slice($event['acknowledges'], 0, ZBX_WIDGET_ROWS)), '', false);
        }
        $ack = [$ack, CViewHelper::showNum($acknowledges_num)];
    } else {
        $ack = (new CLink(_('No'), $link))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_RED);
    }
    return $ack;
}
    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;
        CArrayHelper::sort($application['sourceTemplates'], ['name']);
        foreach ($application['sourceTemplates'] as $template) {
            $name[] = (new CLink($template['name'], 'applications.php?hostid=' . $template['hostid']))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_GREY);
            $name[] = ', ';
        }
        array_pop($name);
        $name[] = NAME_DELIMITER;
        $name[] = $application['name'];
        $info_icons[] = '';
    } elseif ($application['flags'] == ZBX_FLAG_DISCOVERY_CREATED && $application['discoveryRule']) {
        $name = [(new CLink(CHtml::encode($application['discoveryRule']['name']), 'disc_prototypes.php?parent_discoveryid=' . $application['discoveryRule']['itemid']))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_ORANGE)];
        $name[] = NAME_DELIMITER . $application['name'];
        if ($application['applicationDiscovery']['ts_delete'] != 0) {
            $info_icons[] = getApplicationLifetimeIndicator($current_time, $application['applicationDiscovery']['ts_delete']);
        } else {
            $info_icons[] = '';
        }
    } else {
        $name = new CLink($application['name'], 'applications.php?form=update&applicationid=' . $application['applicationid'] . '&hostid=' . $application['hostid']);
        $info_icons[] = '';
    }
    $checkBox = new CCheckBox('applications[' . $application['applicationid'] . ']', $application['applicationid']);
    $checkBox->setEnabled(!$application['discoveryRule']);
    $applicationTable->addRow([$checkBox, $this->data['hostid'] > 0 ? null : $application['host']['name'], (new CCol($name))->addClass(ZBX_STYLE_NOWRAP), [new CLink(_('Items'), 'items.php?' . 'hostid=' . $application['hostid'] . '&filter_set=1' . '&filter_application=' . urlencode($application['name'])), CViewHelper::showNum(count($application['items']))], $data['showInfoColumn'] ? $info_icons : null]);
}
zbx_add_post_js('cookie.prefix = "' . $this->data['hostid'] . '";');
// append table to form
$form->addItem([$applicationTable, $this->data['paging'], new CActionButtonList('action', 'applications', ['application.massenable' => ['name' => _('Enable'), 'confirm' => _('Enable selected applications?')], 'application.massdisable' => ['name' => _('Disable'), 'confirm' => _('Disable selected applications?')], 'application.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected applications?')]], $this->data['hostid'])]);
// append form to widget
$widget->addItem($form);
return $widget;
        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;
Example #10
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;
}
Example #11
0
     }
     $hostList[] = $host_name;
     $hostList[] = ', ';
 }
 array_pop($hostList);
 // status
 $statusSpan = new CSpan(trigger_value2str($trigger['value']));
 // add colors and blinking to span depending on configuration and trigger parameters
 addTriggerValueStyle($statusSpan, $trigger['value'], $trigger['lastchange'], $config['event_ack_enable'] ? $trigger['event_count'] == 0 : false);
 // open or close
 // acknowledge
 if ($config['event_ack_enable']) {
     if ($trigger['hasEvents']) {
         $ack_checkbox = new CCheckBox('eventids[' . $trigger['lastEvent']['eventid'] . ']', $trigger['lastEvent']['eventid']);
         if ($trigger['event_count']) {
             $ackColumn = [(new CLink(_('No'), 'zabbix.php?action=acknowledge.edit' . '&acknowledge_type=' . ZBX_ACKNOWLEDGE_PROBLEM . '&eventids[]=' . $trigger['lastEvent']['eventid'] . '&backurl=' . $page['file']))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_RED), CViewHelper::showNum($trigger['event_count'])];
         } else {
             $ackColumn = (new CLink(_('Yes'), 'zabbix.php?action=acknowledge.edit' . '&acknowledge_type=' . ZBX_ACKNOWLEDGE_PROBLEM . '&eventids[]=' . $trigger['lastEvent']['eventid'] . '&backurl=' . $page['file']))->addClass(ZBX_STYLE_LINK_ALT)->addClass(ZBX_STYLE_GREEN);
         }
     } else {
         $ack_checkbox = '';
         $ackColumn = (new CCol(_('No events')))->addClass(ZBX_STYLE_GREY);
     }
 } else {
     $ack_checkbox = null;
     $ackColumn = null;
 }
 if ($showEvents == EVENTS_OPTION_ALL || $showEvents == EVENTS_OPTION_NOT_ACK) {
     $openOrCloseDiv = $trigger['events'] ? (new CDiv())->addClass(ZBX_STYLE_TREEVIEW)->setAttribute('data-switcherid', $trigger['triggerid'])->addItem((new CSpan())->addClass(ZBX_STYLE_ARROW_RIGHT)) : '';
 } else {
     $openOrCloseDiv = null;