本文整理汇总了PHP中API::Host方法的典型用法代码示例。如果您正苦于以下问题:PHP API::Host方法的具体用法?PHP API::Host怎么用?PHP API::Host使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API
的用法示例。
在下文中一共展示了API::Host方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bodyToString
public function bodyToString()
{
$this->cleanItems();
$total = 0;
// fetch accessible host ids
$hosts = API::Host()->get(array('nodeids' => get_current_nodeid(true), 'output' => array('hostid'), 'preservekeys' => true));
$hostIds = array_keys($hosts);
if (remove_nodes_from_id($this->groupid) > 0) {
$cond_from = ',hosts_groups hg';
$cond_where = ' AND hg.hostid=h.hostid AND hg.groupid=' . zbx_dbstr($this->groupid);
} else {
$cond_from = '';
$cond_where = andDbNode('h.hostid', $this->nodeid);
}
$db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_TRUE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostIds) . $cond_where);
$host_cnt = DBfetch($db_host_cnt);
$avail = $host_cnt['cnt'];
$total += $host_cnt['cnt'];
$db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_FALSE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostIds) . $cond_where);
$host_cnt = DBfetch($db_host_cnt);
$notav = $host_cnt['cnt'];
$total += $host_cnt['cnt'];
$db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_UNKNOWN . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostIds) . $cond_where);
$host_cnt = DBfetch($db_host_cnt);
$uncn = $host_cnt['cnt'];
$total += $host_cnt['cnt'];
$node = get_node_by_nodeid($this->nodeid);
$header_str = _('Hosts info') . SPACE;
if ($node > 0) {
$header_str .= '(' . $node['name'] . ')' . SPACE;
}
if (remove_nodes_from_id($this->groupid) > 0) {
$group = get_hostgroup_by_groupid($this->groupid);
$header_str .= _('Group') . SPACE . '"' . $group['name'] . '"';
} else {
$header_str .= _('All groups');
}
$header = new CCol($header_str, 'header');
if ($this->style == STYLE_HORISONTAL) {
$header->setColspan(4);
}
$this->addRow($header);
$avail = new CCol($avail . ' ' . _('Available'), 'avail');
$notav = new CCol($notav . ' ' . _('Not available'), 'notav');
$uncn = new CCol($uncn . ' ' . _('Unknown'), 'uncn');
$total = new CCol($total . ' ' . _('Total'), 'total');
if ($this->style == STYLE_HORISONTAL) {
$this->addRow(array($avail, $notav, $uncn, $total));
} else {
$this->addRow($avail);
$this->addRow($notav);
$this->addRow($uncn);
$this->addRow($total);
}
return parent::bodyToString();
}
示例2: doAction
protected function doAction()
{
$proxy = [];
$this->getInputs($proxy, ['host', 'status', 'description', 'tls_connect', 'tls_accept', 'tls_issuer', 'tls_subject', 'tls_psk_identity', 'tls_psk']);
if ($this->getInput('status', HOST_STATUS_PROXY_ACTIVE) == HOST_STATUS_PROXY_PASSIVE) {
$proxy['interface'] = [];
$this->getInputs($proxy['interface'], ['dns', 'ip', 'useip', 'port']);
}
DBstart();
if ($this->hasInput('proxy_hostids')) {
// skip discovered hosts
$proxy['hosts'] = API::Host()->get(['output' => ['hostid'], 'hostids' => $this->getInput('proxy_hostids'), 'filter' => ['flags' => ZBX_FLAG_DISCOVERY_NORMAL]]);
}
$result = API::Proxy()->create([$proxy]);
if ($result) {
add_audit(AUDIT_ACTION_ADD, AUDIT_RESOURCE_PROXY, '[' . $this->getInput('host', '') . '] [' . reset($result['proxyids']) . ']');
}
$result = DBend($result);
if ($result) {
$response = new CControllerResponseRedirect('zabbix.php?action=proxy.list&uncheck=1');
$response->setMessageOk(_('Proxy added'));
} else {
$response = new CControllerResponseRedirect('zabbix.php?action=proxy.edit');
$response->setFormData($this->getInputAll());
$response->setMessageError(_('Cannot add proxy'));
}
$this->setResponse($response);
}
示例3: get
/**
* Process screen.
*
* @return CDiv (screen inside container)
*/
public function get()
{
// fetch hosts
$hosts = API::Host()->get(['output' => ['hostid', 'status'], 'selectGraphs' => $this->screenitem['style'] == STYLE_LEFT ? API_OUTPUT_COUNT : null, 'selectScreens' => $this->screenitem['style'] == STYLE_LEFT ? API_OUTPUT_COUNT : null, 'groupids' => $this->screenitem['resourceid'], 'preservekeys' => true]);
$hostids = array_keys($hosts);
$options = ['output' => ['triggerid', 'expression', 'description', 'url', 'value', 'priority', 'lastchange', 'flags'], 'selectHosts' => ['hostid', 'name', 'status'], 'selectItems' => ['itemid', 'hostid', 'name', 'key_', 'value_type'], 'hostids' => $hostids, 'monitored' => true, 'skipDependent' => true, 'sortfield' => 'description', 'preservekeys' => true];
// application filter
if ($this->screenitem['application'] !== '') {
$applications = API::Application()->get(['output' => [], 'hostids' => $hostids, 'search' => ['name' => $this->screenitem['application']], 'preservekeys' => true]);
$options['applicationids'] = array_keys($applications);
}
$triggers = API::Trigger()->get($options);
$triggers = CMacrosResolverHelper::resolveTriggerUrls($triggers);
/*
* Each screen cell with "Triggers overview" depends on one specific group which in this case is 'resourceid'.
* Pass it as 'groupid' to menu pop-up "Events" link.
*/
foreach ($triggers as &$trigger) {
$trigger['groupid'] = $this->screenitem['resourceid'];
}
unset($trigger);
$groups = API::HostGroup()->get(['output' => ['name'], 'groupids' => [$this->screenitem['resourceid']]]);
$header = (new CDiv([new CTag('h4', true, _('Triggers overview')), (new CList())->addItem([_('Group'), ':', SPACE, $groups[0]['name']])]))->addClass(ZBX_STYLE_DASHBRD_WIDGET_HEAD);
$table = getTriggersOverview($hosts, $triggers, $this->pageFile, $this->screenitem['style'], $this->screenid);
$footer = (new CList())->addItem(_s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)))->addClass(ZBX_STYLE_DASHBRD_WIDGET_FOOT);
return $this->getOutput(new CUiWidget(uniqid(), [$header, $table, $footer]));
}
示例4: rightsForLink
function rightsForLink($idl)
{
$glinks = DBfetchArray(DBselect('SELECT host1, host2
FROM hosts_links WHERE hosts_links.id = ' . $idl));
if (API::Host()->isWritable(array(1 * $glinks[0]['host1'])) and API::Host()->isWritable(array(1 * $glinks[0]['host2']))) {
return true;
}
return false;
}
示例5: validate
/**
* Checks is any of the given hosts are discovered.
*
* @param $hostIds
*
* @return bool
*/
public function validate($hostIds)
{
$hosts = API::Host()->get(['output' => ['host'], 'hostids' => $hostIds, 'filter' => ['flags' => ZBX_FLAG_DISCOVERY_CREATED], 'limit' => 1]);
if ($hosts) {
$host = reset($hosts);
$this->error($this->message, $host['host']);
return false;
}
return true;
}
示例6: get
/**
* Process screen.
*
* @return CDiv (screen inside container)
*/
public function get()
{
// fetch hosts
$hosts = API::Host()->get(array('output' => array('hostid', 'status'), 'selectGraphs' => $this->screenitem['style'] == STYLE_LEFT ? API_OUTPUT_COUNT : null, 'selectScreens' => $this->screenitem['style'] == STYLE_LEFT ? API_OUTPUT_COUNT : null, 'groupids' => $this->screenitem['resourceid'], 'preservekeys' => true));
$hostIds = array_keys($hosts);
$options = array('output' => array('description', 'expression', 'priority', 'url', 'value', 'triggerid', 'lastchange', 'flags'), 'selectHosts' => array('hostid', 'name', 'status'), 'hostids' => $hostIds, 'monitored' => true, 'skipDependent' => true, 'sortfield' => 'description');
// application filter
if ($this->screenitem['application'] !== '') {
$applications = API::Application()->get(array('output' => array('applicationid'), 'hostids' => $hostIds, 'search' => array('name' => $this->screenitem['application'])));
$options['applicationids'] = zbx_objectValues($applications, 'applicationid');
}
$triggers = API::Trigger()->get($options);
return $this->getOutput(getTriggersOverview($hosts, $triggers, $this->pageFile, $this->screenitem['style'], $this->screenid));
}
示例7: get
/**
* Process screen.
*
* @return CDiv (screen inside container)
*/
public function get()
{
$total = 0;
// fetch accessible host ids
$hosts = API::Host()->get(['output' => ['hostid'], 'preservekeys' => true]);
$hostids = array_keys($hosts);
if ($this->screenitem['resourceid'] != 0) {
$cond_from = ',hosts_groups hg';
$cond_where = ' AND hg.hostid=h.hostid AND hg.groupid=' . zbx_dbstr($this->screenitem['resourceid']);
} else {
$cond_from = '';
$cond_where = '';
}
$db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_TRUE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostids) . $cond_where);
$host_cnt = DBfetch($db_host_cnt);
$avail = $host_cnt['cnt'];
$total += $host_cnt['cnt'];
$db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_FALSE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostids) . $cond_where);
$host_cnt = DBfetch($db_host_cnt);
$notav = $host_cnt['cnt'];
$total += $host_cnt['cnt'];
$db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_UNKNOWN . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostids) . $cond_where);
$host_cnt = DBfetch($db_host_cnt);
$uncn = $host_cnt['cnt'];
$total += $host_cnt['cnt'];
$avail = (new CCol($avail . ' ' . _('Available')))->addClass(ZBX_STYLE_GREEN);
$notav = (new CCol($notav . ' ' . _('Not available')))->addClass(ZBX_STYLE_RED);
$uncn = (new CCol($uncn . ' ' . _('Unknown')))->addClass(ZBX_STYLE_GREY);
$total = new CCol($total . ' ' . _('Total'));
$header = (new CDiv([new CTag('h4', true, _('Hosts info'))]))->addClass(ZBX_STYLE_DASHBRD_WIDGET_HEAD);
if ($this->screenitem['resourceid'] != 0) {
$groups = API::HostGroup()->get(['output' => ['name'], 'groupids' => [$this->screenitem['resourceid']]]);
$header->addItem((new CList())->addItem([_('Group'), ':', SPACE, $groups[0]['name']]));
}
$table = new CTableInfo();
if ($this->screenitem['style'] == STYLE_HORIZONTAL) {
$table->addRow([$avail, $notav, $uncn, $total]);
} else {
$table->addRow($avail);
$table->addRow($notav);
$table->addRow($uncn);
$table->addRow($total);
}
$footer = (new CList())->addItem(_s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)))->addClass(ZBX_STYLE_DASHBRD_WIDGET_FOOT);
return $this->getOutput(new CUiWidget(uniqid(), [$header, $table, $footer]));
}
示例8: doAction
protected function doAction()
{
$hosts = API::Host()->get(['output' => ['hostid'], 'filter' => ['proxy_hostid' => $this->getInput('proxyids'), 'status' => HOST_STATUS_NOT_MONITORED]]);
foreach ($hosts as &$host) {
$host['status'] = HOST_STATUS_MONITORED;
}
unset($host);
$result = API::Host()->update($hosts);
$updated = count($hosts);
$response = new CControllerResponseRedirect('zabbix.php?action=proxy.list&uncheck=1');
if ($result) {
$response->setMessageOk(_n('Host enabled', 'Hosts enabled', $updated));
} else {
$response->setMessageError(_n('Cannot enable host', 'Cannot enable hosts', $updated));
}
$this->setResponse($response);
}
示例9: doAction
protected function doAction()
{
$filter = ['groupids' => null, 'maintenance' => null, 'severity' => null, 'trigger_name' => '', 'extAck' => 0];
if (CProfile::get('web.dashconf.filter.enable', 0) == 1) {
// groups
if (CProfile::get('web.dashconf.groups.grpswitch', 0) == 0) {
// null mean all groups
$filter['groupids'] = null;
} else {
$filter['groupids'] = zbx_objectValues(CFavorite::get('web.dashconf.groups.groupids'), 'value');
$hideHostGroupIds = zbx_objectValues(CFavorite::get('web.dashconf.groups.hide.groupids'), 'value');
if ($hideHostGroupIds) {
// get all groups if no selected groups defined
if (!$filter['groupids']) {
$dbHostGroups = API::HostGroup()->get(['output' => ['groupid']]);
$filter['groupids'] = zbx_objectValues($dbHostGroups, 'groupid');
}
$filter['groupids'] = array_diff($filter['groupids'], $hideHostGroupIds);
// get available hosts
$dbAvailableHosts = API::Host()->get(['groupids' => $filter['groupids'], 'output' => ['hostid']]);
$availableHostIds = zbx_objectValues($dbAvailableHosts, 'hostid');
$dbDisabledHosts = API::Host()->get(['groupids' => $hideHostGroupIds, 'output' => ['hostid']]);
$disabledHostIds = zbx_objectValues($dbDisabledHosts, 'hostid');
$filter['hostids'] = array_diff($availableHostIds, $disabledHostIds);
} else {
if (!$filter['groupids']) {
// null mean all groups
$filter['groupids'] = null;
}
}
}
// hosts
$maintenance = CProfile::get('web.dashconf.hosts.maintenance', 1);
$filter['maintenance'] = $maintenance == 0 ? 0 : null;
// triggers
$severity = CProfile::get('web.dashconf.triggers.severity', null);
$filter['severity'] = zbx_empty($severity) ? null : explode(';', $severity);
$filter['severity'] = zbx_toHash($filter['severity']);
$filter['trigger_name'] = CProfile::get('web.dashconf.triggers.name', '');
$config = select_config();
$filter['extAck'] = $config['event_ack_enable'] ? CProfile::get('web.dashconf.events.extAck', 0) : 0;
}
$this->setResponse(new CControllerResponseData(['filter' => $filter, 'user' => ['debug_mode' => $this->getDebugMode()]]));
}
示例10: checkPermissions
protected function checkPermissions()
{
if ($this->getUserType() < USER_TYPE_ZABBIX_USER) {
return false;
}
if ($this->hasInput('groupid') && $this->getInput('groupid') != 0) {
$groups = API::HostGroup()->get(['output' => [], 'groupids' => [$this->getInput('groupid')]]);
if (!$groups) {
return false;
}
}
if ($this->hasInput('hostid') && $this->getInput('hostid') != 0) {
$hosts = API::Host()->get(['output' => [], 'hostids' => [$this->getInput('hostid')]]);
if (!$hosts) {
return false;
}
}
return true;
}
示例11: get
/**
* Process screen.
*
* @return CDiv (screen inside container)
*/
public function get()
{
// fetch hosts
$hosts = API::Host()->get(array('output' => array('hostid', 'status'), 'selectGraphs' => $this->screenitem['style'] == STYLE_LEFT ? API_OUTPUT_COUNT : null, 'selectScreens' => $this->screenitem['style'] == STYLE_LEFT ? API_OUTPUT_COUNT : null, 'groupids' => $this->screenitem['resourceid'], 'preservekeys' => true));
$hostIds = array_keys($hosts);
$options = array('output' => array('description', 'expression', 'priority', 'url', 'value', 'triggerid', 'lastchange', 'flags'), 'selectHosts' => array('hostid', 'name', 'status'), 'selectItems' => array('itemid', 'hostid', 'name', 'key_', 'value_type'), 'hostids' => $hostIds, 'monitored' => true, 'skipDependent' => true, 'sortfield' => 'description');
// application filter
if ($this->screenitem['application'] !== '') {
$applications = API::Application()->get(array('output' => array('applicationid'), 'hostids' => $hostIds, 'search' => array('name' => $this->screenitem['application'])));
$options['applicationids'] = zbx_objectValues($applications, 'applicationid');
}
$triggers = API::Trigger()->get($options);
/*
* Each screen cell with "Triggers overview" depends on one specific group which in this case is 'resourceid'.
* Pass it as 'groupid' to menu pop-up "Events" link.
*/
foreach ($triggers as &$trigger) {
$trigger['groupid'] = $this->screenitem['resourceid'];
}
unset($trigger);
return $this->getOutput(getTriggersOverview($hosts, $triggers, $this->pageFile, $this->screenitem['style'], $this->screenid));
}
示例12: doAction
protected function doAction()
{
$filter = ['groupids' => null, 'maintenance' => null];
if (CProfile::get('web.dashconf.filter.enable', 0) == 1) {
// groups
if (CProfile::get('web.dashconf.groups.grpswitch', 0) == 0) {
// null mean all groups
$filter['groupids'] = null;
} else {
$filter['groupids'] = zbx_objectValues(CFavorite::get('web.dashconf.groups.groupids'), 'value');
$hideHostGroupIds = zbx_objectValues(CFavorite::get('web.dashconf.groups.hide.groupids'), 'value');
if ($hideHostGroupIds) {
// get all groups if no selected groups defined
if (!$filter['groupids']) {
$dbHostGroups = API::HostGroup()->get(['output' => ['groupid']]);
$filter['groupids'] = zbx_objectValues($dbHostGroups, 'groupid');
}
$filter['groupids'] = array_diff($filter['groupids'], $hideHostGroupIds);
// get available hosts
$dbAvailableHosts = API::Host()->get(['groupids' => $filter['groupids'], 'output' => ['hostid']]);
$availableHostIds = zbx_objectValues($dbAvailableHosts, 'hostid');
$dbDisabledHosts = API::Host()->get(['groupids' => $hideHostGroupIds, 'output' => ['hostid']]);
$disabledHostIds = zbx_objectValues($dbDisabledHosts, 'hostid');
$filter['hostids'] = array_diff($availableHostIds, $disabledHostIds);
} else {
if (!$filter['groupids']) {
// null mean all groups
$filter['groupids'] = null;
}
}
}
// hosts
$maintenance = CProfile::get('web.dashconf.hosts.maintenance', 1);
$filter['maintenance'] = $maintenance == 0 ? 0 : null;
}
$this->setResponse(new CControllerResponseData(['filter' => $filter, 'user' => ['debug_mode' => $this->getDebugMode()]]));
}
示例13: inherit
protected function inherit($graph, $hostids = null)
{
$graphTemplates = API::Template()->get(array('itemids' => zbx_objectValues($graph['gitems'], 'itemid'), 'output' => array('templateid'), 'nopermissions' => true));
if (empty($graphTemplates)) {
return true;
}
$graphTemplate = reset($graphTemplates);
$chdHosts = API::Host()->get(array('templateids' => $graphTemplate['templateid'], 'output' => array('hostid', 'host'), 'preservekeys' => true, 'hostids' => $hostids, 'nopermissions' => true, 'templated_hosts' => true));
$graph = $this->get(array('graphids' => $graph['graphid'], 'nopermissions' => true, 'filter' => array('flags' => null), 'selectGraphItems' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND));
$graph = reset($graph);
foreach ($chdHosts as $chdHost) {
$tmpGraph = $graph;
$tmpGraph['templateid'] = $graph['graphid'];
$tmpGraph['gitems'] = getSameGraphItemsForHost($tmpGraph['gitems'], $chdHost['hostid']);
if (!$tmpGraph['gitems']) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" cannot inherit. No required items on "%2$s".', $tmpGraph['name'], $chdHost['host']));
}
if ($tmpGraph['ymax_itemid'] > 0) {
$ymaxItemid = getSameGraphItemsForHost(array(array('itemid' => $tmpGraph['ymax_itemid'])), $chdHost['hostid']);
if (!$ymaxItemid) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" cannot inherit. No required items on "%2$s" (Ymax value item).', $tmpGraph['name'], $chdHost['host']));
}
$ymaxItemid = reset($ymaxItemid);
$tmpGraph['ymax_itemid'] = $ymaxItemid['itemid'];
}
if ($tmpGraph['ymin_itemid'] > 0) {
$yminItemid = getSameGraphItemsForHost(array(array('itemid' => $tmpGraph['ymin_itemid'])), $chdHost['hostid']);
if (!$yminItemid) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" cannot inherit. No required items on "%2$s" (Ymin value item).', $tmpGraph['name'], $chdHost['host']));
}
$yminItemid = reset($yminItemid);
$tmpGraph['ymin_itemid'] = $yminItemid['itemid'];
}
// check if templated graph exists
$chdGraphs = $this->get(array('filter' => array('templateid' => $tmpGraph['graphid'], 'flags' => array(ZBX_FLAG_DISCOVERY_PROTOTYPE, ZBX_FLAG_DISCOVERY_NORMAL)), 'output' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'hostids' => $chdHost['hostid']));
if ($chdGraph = reset($chdGraphs)) {
if ($tmpGraph['name'] !== $chdGraph['name']) {
$graphExists = $this->get(array('output' => array('graphid'), 'hostids' => $chdHost['hostid'], 'filter' => array('name' => $tmpGraph['name'], 'flags' => null), 'nopermissions' => true, 'limit' => 1));
if ($graphExists) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" already exists on "%2$s".', $tmpGraph['name'], $chdHost['host']));
}
} elseif ($chdGraph['flags'] != $tmpGraph['flags']) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Graph with same name but other type exist.'));
}
$tmpGraph['graphid'] = $chdGraph['graphid'];
$this->updateReal($tmpGraph, $chdGraph);
} else {
$chdGraph = $this->get(array('filter' => array('name' => $tmpGraph['name'], 'flags' => null), 'output' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'nopermissions' => true, 'hostids' => $chdHost['hostid']));
if ($chdGraph = reset($chdGraph)) {
if ($chdGraph['templateid'] != 0) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" already exists on "%2$s" (inherited from another template).', $tmpGraph['name'], $chdHost['host']));
} elseif ($chdGraph['flags'] != $tmpGraph['flags']) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Graph with same name but other type exist.'));
}
$chdGraphItemItems = array();
foreach (array(API::Item(), API::ItemPrototype()) as $api) {
$chdGraphItemItems += $api->get(array('output' => array('key_', 'hostid', 'itemid'), 'itemids' => zbx_objectValues($chdGraph['gitems'], 'itemid'), 'preservekeys' => true));
}
if (count($chdGraph['gitems']) == count($tmpGraph['gitems'])) {
foreach ($tmpGraph['gitems'] as $gitem) {
foreach ($chdGraph['gitems'] as $chdGraphItem) {
$chdGraphItemItem = $chdGraphItemItems[$chdGraphItem['itemid']];
if ($gitem['key_'] == $chdGraphItemItem['key_'] && bccomp($chdHost['hostid'], $chdGraphItemItem['hostid']) == 0) {
continue 2;
}
}
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" already exists on "%2$s" (items are not identical).', $tmpGraph['name'], $chdHost['host']));
}
$tmpGraph['graphid'] = $chdGraph['graphid'];
$this->updateReal($tmpGraph, $chdGraph);
} else {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" already exists on "%2$s" (items are not identical).', $tmpGraph['name'], $chdHost['host']));
}
} else {
$graphid = $this->createReal($tmpGraph);
$tmpGraph['graphid'] = $graphid;
}
}
$this->inherit($tmpGraph);
}
}
示例14: dirname
//PAGE_TYPE_IMAGE;
require_once dirname(__FILE__) . '/include/page_header.php';
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$fields = array('graphid' => array(T_ZBX_INT, O_MAND, P_SYS, DB_ID, null), 'period' => array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(ZBX_MIN_PERIOD, ZBX_MAX_PERIOD), null), 'stime' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'profileIdx' => array(T_ZBX_STR, O_OPT, null, null, null), 'profileIdx2' => array(T_ZBX_STR, O_OPT, null, null, null), 'updateProfile' => array(T_ZBX_STR, O_OPT, null, null, null), 'border' => array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), 'width' => array(T_ZBX_INT, O_OPT, P_NZERO, '{}>0', null), 'height' => array(T_ZBX_INT, O_OPT, P_NZERO, '{}>0', null));
check_fields($fields);
/*
* Permissions
*/
$dbGraph = API::Graph()->get(array('graphids' => $_REQUEST['graphid'], 'output' => API_OUTPUT_EXTEND, 'expandName' => 1));
// _ex($dbGraph,0);
if (!$dbGraph) {
access_deny();
} else {
$dbGraph = reset($dbGraph);
}
$host = API::Host()->get(array('nodeids' => get_current_nodeid(true), 'graphids' => $_REQUEST['graphid'], 'output' => API_OUTPUT_EXTEND, 'templated_hosts' => true));
$host = reset($host);
/*
* Display
*/
$timeline = CScreenBase::calculateTime(array('profileIdx' => get_request('profileIdx', 'web.screens'), 'profileIdx2' => get_request('profileIdx2'), 'updateProfile' => get_request('updateProfile', true), 'period' => get_request('period'), 'stime' => get_request('stime')));
CProfile::update('web.screens.graphid', $_REQUEST['graphid'], PROFILE_TYPE_ID);
$chartHeader = '';
if (id2nodeid($dbGraph['graphid']) != get_current_nodeid()) {
$chartHeader = get_node_name_by_elid($dbGraph['graphid'], true, NAME_DELIMITER);
}
$chartHeader .= $host['name'] . NAME_DELIMITER . $dbGraph['name'];
$graph = new CLineGraphDraw_Zabbix($dbGraph['graphtype']);
$graph->setHeader($chartHeader);
$graph->setPeriod($timeline['period']);
$graph->setSTime($timeline['stime']);
示例15: inherit
protected function inherit($applications, $hostids = null)
{
if (empty($applications)) {
return $applications;
}
$applications = zbx_toHash($applications, 'applicationid');
$chdHosts = API::Host()->get(array('output' => array('hostid', 'host'), 'templateids' => zbx_objectValues($applications, 'hostid'), 'hostids' => $hostids, 'preservekeys' => 1, 'nopermissions' => 1, 'templated_hosts' => 1));
if (empty($chdHosts)) {
return true;
}
$insertApplications = array();
$updateApplications = array();
foreach ($chdHosts as $hostid => $host) {
$templateids = zbx_toHash($host['templates'], 'templateid');
// skip applications not from parent templates of current host
$parentApplications = array();
foreach ($applications as $parentApplicationId => $parentApplication) {
if (isset($templateids[$parentApplication['hostid']])) {
$parentApplications[$parentApplicationId] = $parentApplication;
}
}
// check existing items to decide insert or update
$exApplications = $this->get(array('output' => API_OUTPUT_EXTEND, 'hostids' => $hostid, 'preservekeys' => true, 'nopermissions' => true));
$exApplicationsNames = zbx_toHash($exApplications, 'name');
$exApplicationsTpl = zbx_toHash($exApplications, 'templateid');
foreach ($parentApplications as $parentApplicationId => $parentApplication) {
$exApplication = null;
// update by templateid
if (isset($exApplicationsTpl[$parentApplicationId])) {
$exApplication = $exApplicationsTpl[$parentApplicationId];
}
// update by name
if (isset($parentApplication['name']) && isset($exApplicationsNames[$parentApplication['name']])) {
$exApplication = $exApplicationsNames[$parentApplication['name']];
if ($exApplication['templateid'] > 0 && !idcmp($exApplication['templateid'], $parentApplication['applicationid'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Application "%1$s" already exists for host "%2$s".', $exApplication['name'], $host['name']));
}
}
$newApplication = $parentApplication;
$newApplication['hostid'] = $host['hostid'];
$newApplication['templateid'] = $parentApplication['applicationid'];
if ($exApplication) {
$newApplication['applicationid'] = $exApplication['applicationid'];
$updateApplications[] = $newApplication;
} else {
$insertApplications[] = $newApplication;
}
}
}
$this->createReal($insertApplications);
$this->updateReal($updateApplications);
$inheritedApplications = array_merge($insertApplications, $updateApplications);
$this->inherit($inheritedApplications);
return true;
}