本文整理汇总了PHP中CMacrosResolverHelper::resolveTriggerNames方法的典型用法代码示例。如果您正苦于以下问题:PHP CMacrosResolverHelper::resolveTriggerNames方法的具体用法?PHP CMacrosResolverHelper::resolveTriggerNames怎么用?PHP CMacrosResolverHelper::resolveTriggerNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMacrosResolverHelper
的用法示例。
在下文中一共展示了CMacrosResolverHelper::resolveTriggerNames方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mktime
break;
case 'year':
$period_start = mktime(0, 0, 0, 1, 1, date('Y'));
break;
case 24:
case 24 * 7:
case 24 * 30:
case 24 * DAY_IN_YEAR:
$period_start = $period_end - $period * 3600;
break;
}
// fetch services
$services = API::Service()->get(array('output' => array('name', 'serviceid', 'showsla', 'goodsla', 'algorithm'), 'selectParent' => array('serviceid'), 'selectDependencies' => array('servicedownid', 'soft', 'linkid'), 'selectTrigger' => array('description', 'triggerid', 'expression'), 'preservekeys' => true, 'sortfield' => 'sortorder', 'sortorder' => ZBX_SORT_UP));
// expand trigger descriptions
$triggers = zbx_objectValues($services, 'trigger');
$triggers = CMacrosResolverHelper::resolveTriggerNames($triggers);
foreach ($services as &$service) {
if ($service['trigger']) {
$service['trigger'] = $triggers[$service['trigger']['triggerid']];
}
}
unset($service);
// fetch sla
$slaData = API::Service()->getSla(array('intervals' => array(array('from' => $period_start, 'to' => $period_end))));
// expand problem trigger descriptions
foreach ($slaData as &$serviceSla) {
foreach ($serviceSla['problems'] as &$problemTrigger) {
$problemTrigger['description'] = $triggers[$problemTrigger['triggerid']]['description'];
}
unset($problemTrigger);
}
示例2: get
//.........这里部分代码省略.........
if (is_array($options['filter'])) {
if (!array_key_exists('flags', $options['filter'])) {
$options['filter']['flags'] = [ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED];
}
$this->dbFilter('triggers t', $options, $sqlParts);
if (isset($options['filter']['host']) && !is_null($options['filter']['host'])) {
zbx_value2array($options['filter']['host']);
$sqlParts['from']['functions'] = 'functions f';
$sqlParts['from']['items'] = 'items i';
$sqlParts['where']['ft'] = 'f.triggerid=t.triggerid';
$sqlParts['where']['fi'] = 'f.itemid=i.itemid';
$sqlParts['from']['hosts'] = 'hosts h';
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
$sqlParts['where']['host'] = dbConditionString('h.host', $options['filter']['host']);
}
if (isset($options['filter']['hostid']) && !is_null($options['filter']['hostid'])) {
zbx_value2array($options['filter']['hostid']);
$sqlParts['from']['functions'] = 'functions f';
$sqlParts['from']['items'] = 'items i';
$sqlParts['where']['ft'] = 'f.triggerid=t.triggerid';
$sqlParts['where']['fi'] = 'f.itemid=i.itemid';
$sqlParts['where']['hostid'] = dbConditionInt('i.hostid', $options['filter']['hostid']);
}
}
// group
if (!is_null($options['group'])) {
$sqlParts['from']['functions'] = 'functions f';
$sqlParts['from']['items'] = 'items i';
$sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
$sqlParts['from']['groups'] = 'groups g';
$sqlParts['where']['ft'] = 'f.triggerid=t.triggerid';
$sqlParts['where']['fi'] = 'f.itemid=i.itemid';
$sqlParts['where']['hgi'] = 'hg.hostid=i.hostid';
$sqlParts['where']['ghg'] = 'g.groupid = hg.groupid';
$sqlParts['where']['group'] = ' g.name=' . zbx_dbstr($options['group']);
}
// host
if (!is_null($options['host'])) {
$sqlParts['from']['functions'] = 'functions f';
$sqlParts['from']['items'] = 'items i';
$sqlParts['from']['hosts'] = 'hosts h';
$sqlParts['where']['ft'] = 'f.triggerid=t.triggerid';
$sqlParts['where']['fi'] = 'f.itemid=i.itemid';
$sqlParts['where']['hi'] = 'h.hostid=i.hostid';
$sqlParts['where']['host'] = ' h.host=' . zbx_dbstr($options['host']);
}
// only_true
if (!is_null($options['only_true'])) {
$config = select_config();
$sqlParts['where']['ot'] = '((t.value=' . TRIGGER_VALUE_TRUE . ')' . ' OR ' . '((t.value=' . TRIGGER_VALUE_FALSE . ') AND (t.lastchange>' . (time() - $config['ok_period']) . ')))';
}
// min_severity
if (!is_null($options['min_severity'])) {
$sqlParts['where'][] = 't.priority>=' . zbx_dbstr($options['min_severity']);
}
// limit
if (!zbx_ctype_digit($options['limit']) || !$options['limit']) {
$options['limit'] = null;
}
$sqlParts = $this->applyQueryOutputOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
$sqlParts = $this->applyQuerySortOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
// return count or grouped counts via direct SQL count
if (!is_null($options['countOutput']) && !$this->requiresPostSqlFiltering($options)) {
$dbRes = DBselect($this->createSelectQueryFromParts($sqlParts), $options['limit']);
while ($trigger = DBfetch($dbRes)) {
if (!is_null($options['groupCount'])) {
$result[] = $trigger;
} else {
$result = $trigger['rowscount'];
}
}
return $result;
}
$result = zbx_toHash($this->customFetch($this->createSelectQueryFromParts($sqlParts), $options), 'triggerid');
// return count for post SQL filtered result sets
if (!is_null($options['countOutput'])) {
return count($result);
}
if ($result) {
$result = $this->addRelatedObjects($options, $result);
}
// expandDescription
if (!is_null($options['expandDescription']) && $result && array_key_exists('description', reset($result))) {
$result = CMacrosResolverHelper::resolveTriggerNames($result);
}
// expandComment
if (!is_null($options['expandComment']) && $result && array_key_exists('comments', reset($result))) {
$result = CMacrosResolverHelper::resolveTriggerDescriptions($result);
}
// expand expression
if ($options['expandExpression'] !== null && $result && array_key_exists('expression', reset($result))) {
$result = CMacrosResolverHelper::resolveTriggerExpressions($result, ['resolve_usermacros' => true, 'resolve_macros' => true]);
}
// removing keys (hash -> array)
if (is_null($options['preservekeys'])) {
$result = zbx_cleanHashes($result);
}
$result = $this->unsetExtraFields($result, ['state', 'expression'], $options['output']);
return $result;
}
示例3: makeTriggersPopup
/**
* Generate table for dashboard triggers popup.
*
* @see make_system_status
*
* @param array $triggers
* @param array $ackParams
* @param array $actions
* @param array $config
*
* @return CTableInfo
*/
function makeTriggersPopup(array $triggers, array $ackParams, array $actions, array $config)
{
$popupTable = new CTableInfo();
$popupTable->setAttribute('style', 'width: 400px;');
$popupTable->setHeader(array(_('Host'), _('Issue'), _('Age'), _('Info'), $config['event_ack_enable'] ? _('Ack') : null, _('Actions')));
CArrayHelper::sort($triggers, array(array('field' => 'lastchange', 'order' => ZBX_SORT_DOWN)));
$triggers = CMacrosResolverHelper::resolveTriggerNames($triggers);
foreach ($triggers as $trigger) {
// unknown triggers
$unknown = SPACE;
if ($trigger['state'] == TRIGGER_STATE_UNKNOWN) {
$unknown = new CDiv(SPACE, 'status_icon iconunknown');
$unknown->setHint($trigger['error'], 'on');
}
// ack
if ($config['event_ack_enable']) {
$ack = isset($trigger['event']['eventid']) ? getEventAckState($trigger['event'], true, true, $ackParams) : _('No events');
} else {
$ack = null;
}
// action
$action = isset($trigger['event']['eventid']) && isset($actions[$trigger['event']['eventid']]) ? $actions[$trigger['event']['eventid']] : _('-');
$popupTable->addRow(array($trigger['hosts'][0]['name'], getSeverityCell($trigger['priority'], $trigger['description']), zbx_date2age($trigger['lastchange']), $unknown, $ack, $action));
}
return $popupTable;
}
示例4: CLink
$trigger['hostname'] = $host['name'];
$description = new CLink($trigger['description'], 'javascript:void(0);');
$trigger['description'] = $trigger['hostname'] . NAME_DELIMITER . $trigger['description'];
if ($multiselect) {
$js_action = 'addValue(' . zbx_jsvalue($reference) . ', ' . zbx_jsvalue($trigger['triggerid']) . ', ' . $parentId . ');';
} else {
$values = [$dstfld1 => $trigger[$srcfld1], $dstfld2 => $trigger[$srcfld2]];
if (isset($srcfld3)) {
$values[$dstfld3] = $trigger[$srcfld3];
}
$js_action = 'addValues(' . zbx_jsvalue($dstfrm) . ', ' . zbx_jsvalue($values) . '); return false;';
}
$description->onClick($js_action . ' jQuery(this).removeAttr("onclick");');
if ($trigger['dependencies']) {
$description = [$description, BR(), bold(_('Depends on')), BR()];
$dependencies = CMacrosResolverHelper::resolveTriggerNames(zbx_toHash($trigger['dependencies'], 'triggerid'));
foreach ($dependencies as $dependency) {
$description[] = $dependency['description'];
$description[] = BR();
}
array_pop($description);
}
$table->addRow([$multiselect ? new CCheckBox('triggers[' . zbx_jsValue($trigger[$srcfld1]) . ']', $trigger['triggerid']) : null, $description, getSeverityCell($trigger['priority'], $config), (new CSpan(triggerIndicator($trigger['status'], $trigger['state'])))->addClass(triggerIndicatorStyle($trigger['status'], $trigger['state']))]);
// made to save memory usage
if ($multiselect) {
$jsTriggers[$trigger['triggerid']] = ['id' => $trigger['triggerid'], 'name' => $trigger['description'], 'triggerid' => $trigger['triggerid'], 'description' => $trigger['description'], 'expression' => $trigger['expression'], 'priority' => $trigger['priority'], 'status' => $trigger['status'], 'host' => $trigger['hostname']];
}
}
if ($multiselect) {
$table->setFooter(new CCol((new CButton('select', _('Select')))->onClick("addSelectedValues('triggers', " . zbx_jsvalue($reference) . ', ' . $parentId . ');')));
insert_js('var popupReference = ' . zbx_jsValue($jsTriggers, true) . ';');
示例5: getTriggersOverview
/**
* Creates and returns the trigger overview table for the given hosts.
*
* @param array $hosts an array of hosts with host IDs as keys
* @param string $hosts[hostid][name]
* @param string $hosts[hostid][hostid]
* @param array $triggers
* @param string $triggers[][triggerid]
* @param string $triggers[][description]
* @param string $triggers[][expression]
* @param int $triggers[][value]
* @param int $triggers[][lastchange]
* @param int $triggers[][flags]
* @param array $triggers[][url]
* @param int $triggers[][priority]
* @param array $triggers[][hosts]
* @param string $triggers[][hosts][][hostid]
* @param string $triggers[][hosts][][name]
* @param string $pageFile the page where the element is displayed
* @param int $viewMode table display style: either hosts on top, or host on the left side
* @param string $screenId the ID of the screen, that contains the trigger overview table
*
* @return CTableInfo
*/
function getTriggersOverview(array $hosts, array $triggers, $pageFile, $viewMode = null, $screenId = null)
{
$data = [];
$hostNames = [];
$trcounter = [];
$triggers = CMacrosResolverHelper::resolveTriggerNames($triggers, true);
foreach ($triggers as $trigger) {
$trigger_name = $trigger['description'];
foreach ($trigger['hosts'] as $host) {
// triggers may belong to hosts that are filtered out and shouldn't be displayed, skip them
if (!isset($hosts[$host['hostid']])) {
continue;
}
$hostNames[$host['hostid']] = $host['name'];
if (!array_key_exists($host['name'], $trcounter)) {
$trcounter[$host['name']] = [];
}
if (!array_key_exists($trigger_name, $trcounter[$host['name']])) {
$trcounter[$host['name']][$trigger_name] = 0;
}
$data[$trigger_name][$trcounter[$host['name']][$trigger_name]][$host['name']] = ['groupid' => $trigger['groupid'], 'hostid' => $host['hostid'], 'triggerid' => $trigger['triggerid'], 'value' => $trigger['value'], 'lastchange' => $trigger['lastchange'], 'priority' => $trigger['priority'], 'flags' => $trigger['flags'], 'url' => $trigger['url'], 'hosts' => $trigger['hosts'], 'items' => $trigger['items']];
$trcounter[$host['name']][$trigger_name]++;
}
}
$triggerTable = new CTableInfo();
if (empty($hostNames)) {
return $triggerTable;
}
$triggerTable->makeVerticalRotation();
order_result($hostNames);
if ($viewMode == STYLE_TOP) {
// header
$header = [_('Triggers')];
foreach ($hostNames as $hostName) {
$header[] = (new CColHeader($hostName))->addClass('vertical_rotation');
}
$triggerTable->setHeader($header);
// data
foreach ($data as $trigger_name => $trigger_data) {
foreach ($trigger_data as $trigger_hosts) {
$columns = [nbsp($trigger_name)];
foreach ($hostNames as $hostName) {
$columns[] = getTriggerOverviewCells(isset($trigger_hosts[$hostName]) ? $trigger_hosts[$hostName] : null, $pageFile, $screenId);
}
$triggerTable->addRow($columns);
}
}
} else {
// header
$header = [_('Host')];
foreach ($data as $trigger_name => $trigger_data) {
foreach ($trigger_data as $trigger_hosts) {
$header[] = (new CColHeader($trigger_name))->addClass('vertical_rotation');
}
}
$triggerTable->setHeader($header);
// data
$scripts = API::Script()->getScriptsByHosts(zbx_objectValues($hosts, 'hostid'));
foreach ($hostNames as $hostId => $hostName) {
$name = (new CSpan($hostName))->addClass(ZBX_STYLE_LINK_ACTION);
$name->setMenuPopup(CMenuPopupHelper::getHost($hosts[$hostId], $scripts[$hostId]));
$columns = [(new CCol($name))->addClass(ZBX_STYLE_NOWRAP)];
foreach ($data as $trigger_data) {
foreach ($trigger_data as $trigger_hosts) {
$columns[] = getTriggerOverviewCells(isset($trigger_hosts[$hostName]) ? $trigger_hosts[$hostName] : null, $pageFile, $screenId);
}
}
$triggerTable->addRow($columns);
}
}
return $triggerTable;
}
示例6: CView
$data['trigger'] = $host['name'] . NAME_DELIMITER . $trigger['description'];
} else {
$data['trigger'] = '';
}
// render view
$servicesView = new CView('configuration.services.edit', $data);
$servicesView->render();
$servicesView->show();
} else {
// services
$services = API::Service()->get(['output' => ['name', 'serviceid', 'algorithm'], 'selectParent' => ['serviceid'], 'selectDependencies' => ['servicedownid', 'soft', 'linkid'], 'selectTrigger' => ['description', 'triggerid', 'expression'], 'preservekeys' => true, 'sortfield' => 'sortorder', 'sortorder' => ZBX_SORT_UP]);
// triggers
$triggers = zbx_objectValues(array_filter($services, function ($service) {
return (bool) $service['trigger'];
}), 'trigger');
$triggers = CMacrosResolverHelper::resolveTriggerNames(zbx_toHash($triggers, 'triggerid'));
foreach ($services as &$service) {
if ($service['trigger']) {
$service['trigger'] = $triggers[$service['trigger']['triggerid']];
}
}
unset($service);
$treeData = [];
createServiceConfigurationTree($services, $treeData);
$tree = new CServiceTree('service_conf_tree', $treeData, ['caption' => _('Service'), 'action' => _('Action'), 'algorithm' => _('Status calculation'), 'description' => _('Trigger')]);
if (empty($tree)) {
error(_('Cannot format tree.'));
}
$data = ['tree' => $tree];
// render view
$servicesView = new CView('configuration.services.list', $data);