本文整理汇总了PHP中API::TemplateScreen方法的典型用法代码示例。如果您正苦于以下问题:PHP API::TemplateScreen方法的具体用法?PHP API::TemplateScreen怎么用?PHP API::TemplateScreen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API
的用法示例。
在下文中一共展示了API::TemplateScreen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
/**
* Import template screens.
*
* @param array $allScreens
*
* @return void
*/
public function import(array $allScreens)
{
$screensToCreate = array();
$screensToUpdate = array();
foreach ($allScreens as $template => $screens) {
// TODO: select all at once out of loop
$dbScreens = DBselect('SELECT s.screenid,s.name FROM screens s WHERE' . ' s.templateid=' . zbx_dbstr($this->referencer->resolveTemplate($template)) . ' AND ' . dbConditionString('s.name', array_keys($screens)));
while ($dbScreen = DBfetch($dbScreens)) {
$screens[$dbScreen['name']]['screenid'] = $dbScreen['screenid'];
}
foreach ($screens as $screen) {
$screen = $this->resolveScreenReferences($screen);
if (isset($screen['screenid'])) {
$screensToUpdate[] = $screen;
} else {
$screen['templateid'] = $this->referencer->resolveTemplate($template);
$screensToCreate[] = $screen;
}
}
}
if ($this->options['templateScreens']['createMissing'] && $screensToCreate) {
API::TemplateScreen()->create($screensToCreate);
}
if ($this->options['templateScreens']['updateExisting'] && $screensToUpdate) {
API::TemplateScreen()->update($screensToUpdate);
}
}
示例2: get
/**
* Get screen item data.
*
* @param array $options
* @param array $options['hostid'] Use hostid to get real resource id
* @param array $options['screenitemids'] Search by screen item IDs
* @param array $options['screenids'] Search by screen IDs
* @param array $options['filter'] Result filter
* @param array $options['limit'] The size of the result set
*
* @return array
*/
public function get(array $options = [])
{
$options = zbx_array_merge($this->getOptions, $options);
// build and execute query
$sql = $this->createSelectQuery($this->tableName(), $options);
$res = DBselect($sql, $options['limit']);
// fetch results
$result = [];
while ($row = DBfetch($res)) {
// count query, return a single result
if ($options['countOutput'] !== null) {
$result = $row['rowscount'];
} else {
if ($options['preservekeys'] !== null) {
$result[$row['screenitemid']] = $row;
} else {
$result[] = $row;
}
}
}
// fill result with real resourceid
if ($options['hostids'] && $result) {
if (empty($options['screenitemid'])) {
$options['screenitemid'] = zbx_objectValues($result, 'screenitemid');
}
$dbTemplateScreens = API::TemplateScreen()->get(['output' => ['screenitemid'], 'screenitemids' => $options['screenitemid'], 'hostids' => $options['hostids'], 'selectScreenItems' => API_OUTPUT_EXTEND]);
if ($dbTemplateScreens) {
foreach ($result as &$screenItem) {
foreach ($dbTemplateScreens as $dbTemplateScreen) {
foreach ($dbTemplateScreen['screenitems'] as $dbScreenItem) {
if ($screenItem['screenitemid'] == $dbScreenItem['screenitemid'] && isset($dbScreenItem['real_resourceid']) && $dbScreenItem['real_resourceid']) {
$screenItem['real_resourceid'] = $dbScreenItem['real_resourceid'];
}
}
}
}
unset($screenItem);
}
}
return $result;
}
示例3: get
//.........这里部分代码省略.........
}
} elseif (API_OUTPUT_COUNT == $options['selectGraphs']) {
$graphs = API::Graph()->get(array('nodeids' => $nodeids, 'hostids' => $templateids, 'countOutput' => true, 'groupCount' => true));
$graphs = zbx_toHash($graphs, 'hostid');
foreach ($result as $templateid => $template) {
if (isset($graphs[$templateid])) {
$result[$templateid]['graphs'] = $graphs[$templateid]['rowscount'];
} else {
$result[$templateid]['graphs'] = 0;
}
}
}
}
// Adding applications
if (!is_null($options['selectApplications'])) {
$objParams = array('nodeids' => $nodeids, 'hostids' => $templateids, 'nopermissions' => 1, 'preservekeys' => 1);
if (is_array($options['selectApplications']) || str_in_array($options['selectApplications'], $subselectsAllowedOutputs)) {
$objParams['output'] = $options['selectApplications'];
$applications = API::Application()->get($objParams);
if (!is_null($options['limitSelects'])) {
order_result($applications, 'name');
}
foreach ($applications as $applicationid => $application) {
unset($applications[$applicationid]['hosts']);
foreach ($application['hosts'] as $hnum => $host) {
if (!is_null($options['limitSelects'])) {
if (!isset($count[$host['hostid']])) {
$count[$host['hostid']] = 0;
}
$count[$host['hostid']]++;
if ($count[$host['hostid']] > $options['limitSelects']) {
continue;
}
}
$result[$host['hostid']]['applications'][] =& $applications[$applicationid];
}
}
} elseif (API_OUTPUT_COUNT == $options['selectApplications']) {
$objParams['countOutput'] = 1;
$objParams['groupCount'] = 1;
$applications = API::Application()->get($objParams);
$applications = zbx_toHash($applications, 'hostid');
foreach ($result as $templateid => $template) {
if (isset($applications[$templateid])) {
$result[$templateid]['applications'] = $applications[$templateid]['rowscount'];
} else {
$result[$templateid]['applications'] = 0;
}
}
}
}
// Adding screens
if (!is_null($options['selectScreens'])) {
$objParams = array('nodeids' => $nodeids, 'templateids' => $templateids, 'editable' => $options['editable'], 'nopermissions' => 1, 'preservekeys' => 1);
if (is_array($options['selectScreens']) || str_in_array($options['selectScreens'], $subselectsAllowedOutputs)) {
$objParams['output'] = $options['selectScreens'];
$screens = API::TemplateScreen()->get($objParams);
if (!is_null($options['limitSelects'])) {
order_result($screens, 'name');
}
foreach ($screens as $screenid => $screen) {
if (!is_null($options['limitSelects'])) {
if (count($result[$screen['hostid']]['screens']) >= $options['limitSelects']) {
continue;
}
}
unset($screens[$screenid]['templates']);
$result[$screen['hostid']]['screens'][] =& $screens[$screenid];
}
} elseif (API_OUTPUT_COUNT == $options['selectScreens']) {
$objParams['countOutput'] = 1;
$objParams['groupCount'] = 1;
$screens = API::TemplateScreen()->get($objParams);
$screens = zbx_toHash($screens, 'hostid');
foreach ($result as $templateid => $template) {
if (isset($screens[$templateid])) {
$result[$templateid]['screens'] = $screens[$templateid]['rowscount'];
} else {
$result[$templateid]['screens'] = 0;
}
}
}
}
// Adding macros
if (!is_null($options['selectMacros']) && str_in_array($options['selectMacros'], $subselectsAllowedOutputs)) {
$objParams = array('nodeids' => $nodeids, 'output' => $options['selectMacros'], 'hostids' => $templateids, 'preservekeys' => 1);
$macros = API::UserMacro()->get($objParams);
foreach ($macros as $macroid => $macro) {
unset($macros[$macroid]['hosts']);
foreach ($macro['hosts'] as $hnum => $host) {
$result[$host['hostid']]['macros'][] = $macros[$macroid];
}
}
}
// removing keys (hash -> array)
if (is_null($options['preservekeys'])) {
$result = zbx_cleanHashes($result);
}
return $result;
}
示例4: gatherTemplates
/**
* Get templates for export from database.
*
* @param array $templateIds
*/
protected function gatherTemplates(array $templateIds)
{
$templates = API::Template()->get(array('templateids' => $templateIds, 'output' => array('host', 'name'), 'selectMacros' => API_OUTPUT_EXTEND, 'selectGroups' => API_OUTPUT_EXTEND, 'selectParentTemplates' => API_OUTPUT_EXTEND, 'preservekeys' => true));
// merge host groups with all groups
$templateGroups = array();
foreach ($templates as &$template) {
$templateGroups += zbx_toHash($template['groups'], 'groupid');
$template['screens'] = array();
$template['applications'] = array();
$template['discoveryRules'] = array();
$template['items'] = array();
}
unset($template);
$this->data['groups'] += $templateGroups;
// applications
$applications = API::Application()->get(array('hostids' => $templateIds, 'output' => API_OUTPUT_EXTEND, 'inherited' => false, 'preservekeys' => true));
foreach ($applications as $application) {
if (!isset($templates[$application['hostid']]['applications'])) {
$templates[$application['hostid']]['applications'] = array();
}
$templates[$application['hostid']]['applications'][] = $application;
}
// screens
$screens = API::TemplateScreen()->get(array('templateids' => $templateIds, 'selectScreenItems' => API_OUTPUT_EXTEND, 'noInheritance' => true, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true));
$this->prepareScreenExport($screens);
foreach ($screens as $screen) {
if (!isset($templates[$screen['templateid']]['screens'])) {
$templates[$screen['templateid']]['screens'] = array();
}
$templates[$screen['templateid']]['screens'][] = $screen;
}
$this->data['templates'] = $templates;
$this->gatherTemplateItems($templateIds);
$this->gatherTemplateDiscoveryRules($templateIds);
}
示例5: foreach
$templateList->addRow(_('Trigger prototypes'), $listBox);
}
// Graph prototypes
$hostGraphPrototypes = API::GraphPrototype()->get(['hostids' => $data['templateId'], 'discoveryids' => $hostDiscoveryRuleids, 'inherited' => false, 'output' => API_OUTPUT_EXTEND]);
if (!empty($hostGraphPrototypes)) {
$prototypeList = [];
foreach ($hostGraphPrototypes as $graphPrototype) {
$prototypeList[$graphPrototype['graphid']] = $graphPrototype['name'];
}
order_result($prototypeList);
$listBox = (new CListBox('graphPrototypes', null, 8))->setAttribute('disabled', 'disabled')->addItems($prototypeList);
$templateList->addRow(_('Graph prototypes'), $listBox);
}
}
// screens
$screens = API::TemplateScreen()->get(['inherited' => false, 'templateids' => $data['templateId'], 'output' => ['screenid', 'name']]);
if (!empty($screens)) {
$screensList = [];
foreach ($screens as $screen) {
$screensList[$screen['screenid']] = $screen['name'];
}
order_result($screensList);
$listBox = (new CListBox('screens', null, 8))->setAttribute('disabled', 'disabled')->addItems($screensList);
$templateList->addRow(_('Screens'), $listBox);
}
// web scenarios
$httpTests = API::HttpTest()->get(['output' => ['httptestid', 'name'], 'hostids' => $data['templateId'], 'inherited' => false]);
if ($httpTests) {
$httpTestList = [];
foreach ($httpTests as $httpTest) {
$httpTestList[$httpTest['httptestid']] = $httpTest['name'];
示例6: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$hostids = array_keys($result);
// adding inventories
if ($options['selectInventory'] !== null) {
$relationMap = $this->createRelationMap($result, 'hostid', 'hostid');
$inventory = API::getApiService()->select('host_inventory', ['output' => $options['selectInventory'], 'filter' => ['hostid' => $hostids]]);
$result = $relationMap->mapOne($result, zbx_toHash($inventory, 'hostid'), 'inventory');
}
// adding hostinterfaces
if ($options['selectInterfaces'] !== null) {
if ($options['selectInterfaces'] != API_OUTPUT_COUNT) {
$interfaces = API::HostInterface()->get(['output' => $this->outputExtend($options['selectInterfaces'], ['hostid', 'interfaceid']), 'hostids' => $hostids, 'nopermissions' => true, 'preservekeys' => true]);
// we need to order interfaces for proper linkage and viewing
order_result($interfaces, 'interfaceid', ZBX_SORT_UP);
$relationMap = $this->createRelationMap($interfaces, 'hostid', 'interfaceid');
$interfaces = $this->unsetExtraFields($interfaces, ['hostid', 'interfaceid'], $options['selectInterfaces']);
$result = $relationMap->mapMany($result, $interfaces, 'interfaces', $options['limitSelects']);
} else {
$interfaces = API::HostInterface()->get(['hostids' => $hostids, 'nopermissions' => true, 'countOutput' => true, 'groupCount' => true]);
$interfaces = zbx_toHash($interfaces, 'hostid');
foreach ($result as $hostid => $host) {
$result[$hostid]['interfaces'] = isset($interfaces[$hostid]) ? $interfaces[$hostid]['rowscount'] : 0;
}
}
}
// adding screens
if ($options['selectScreens'] !== null) {
if ($options['selectScreens'] != API_OUTPUT_COUNT) {
$screens = API::TemplateScreen()->get(['output' => $this->outputExtend($options['selectScreens'], ['hostid']), 'hostids' => $hostids, 'nopermissions' => true]);
if (!is_null($options['limitSelects'])) {
order_result($screens, 'name');
}
// inherited screens do not have a unique screenid, so we're building a map using array keys
$relationMap = new CRelationMap();
foreach ($screens as $key => $screen) {
$relationMap->addRelation($screen['hostid'], $key);
}
$screens = $this->unsetExtraFields($screens, ['hostid'], $options['selectScreens']);
$result = $relationMap->mapMany($result, $screens, 'screens', $options['limitSelects']);
} else {
$screens = API::TemplateScreen()->get(['hostids' => $hostids, 'nopermissions' => true, 'countOutput' => true, 'groupCount' => true]);
$screens = zbx_toHash($screens, 'hostid');
foreach ($result as $hostid => $host) {
$result[$hostid]['screens'] = isset($screens[$hostid]) ? $screens[$hostid]['rowscount'] : 0;
}
}
}
// adding discovery rule
if ($options['selectDiscoveryRule'] !== null && $options['selectDiscoveryRule'] != API_OUTPUT_COUNT) {
// discovered items
$discoveryRules = DBFetchArray(DBselect('SELECT hd.hostid,hd2.parent_itemid' . ' FROM host_discovery hd,host_discovery hd2' . ' WHERE ' . dbConditionInt('hd.hostid', $hostids) . ' AND hd.parent_hostid=hd2.hostid'));
$relationMap = $this->createRelationMap($discoveryRules, 'hostid', 'parent_itemid');
$discoveryRules = API::DiscoveryRule()->get(['output' => $options['selectDiscoveryRule'], 'itemids' => $relationMap->getRelatedIds(), 'preservekeys' => true]);
$result = $relationMap->mapOne($result, $discoveryRules, 'discoveryRule');
}
// adding host discovery
if ($options['selectHostDiscovery'] !== null) {
$hostDiscoveries = API::getApiService()->select('host_discovery', ['output' => $this->outputExtend($options['selectHostDiscovery'], ['hostid']), 'filter' => ['hostid' => $hostids], 'preservekeys' => true]);
$relationMap = $this->createRelationMap($hostDiscoveries, 'hostid', 'hostid');
$hostDiscoveries = $this->unsetExtraFields($hostDiscoveries, ['hostid'], $options['selectHostDiscovery']);
$result = $relationMap->mapOne($result, $hostDiscoveries, 'hostDiscovery');
}
return $result;
}
示例7: delete
/**
* Deletes missing template screens.
*
* @param array $allScreens
*
* @return null
*/
public function delete(array $allScreens)
{
if (!$this->options['templateScreens']['deleteMissing']) {
return;
}
$templateIdsXML = $this->importedObjectContainer->getTemplateIds();
// no templates have been processed
if (!$templateIdsXML) {
return;
}
$templateScreenIdsXML = array();
if ($allScreens) {
foreach ($allScreens as $template => $screens) {
$templateId = $this->referencer->resolveTemplate($template);
if ($templateId) {
foreach ($screens as $screenName => $screen) {
$templateScreenId = $this->referencer->resolveTemplateScreen($templateId, $screenName);
if ($templateScreenId) {
$templateScreenIdsXML[$templateScreenId] = $templateScreenId;
}
}
}
}
}
$dbTemplateScreenIds = API::TemplateScreen()->get(array('output' => array('screenid'), 'hostids' => $templateIdsXML, 'nopermissions' => true, 'preservekeys' => true));
$templateScreensToDelete = array_diff_key($dbTemplateScreenIds, $templateScreenIdsXML);
if ($templateScreensToDelete) {
API::TemplateScreen()->delete(array_keys($templateScreensToDelete));
}
}
示例8: parseMain
//.........这里部分代码省略.........
}
if (!($item = get_item_by_key($item_data[1], $item_data[0]))) {
throw new Exception(_s('Missing item "%1$s" for host "%2$s".', $graph_db['ymax_item_key'], $host_db['host']));
}
$graph_db['ymax_itemid'] = $item['itemid'];
}
$graph_db['gitems'] = $graph_items;
if ($current_graph) {
$graph_db['graphid'] = $current_graph['graphid'];
$graphs_to_upd[] = $graph_db;
} else {
$graphs_to_add[] = $graph_db;
}
}
if (!empty($graphs_to_add)) {
$r = API::Graph()->create($graphs_to_add);
if ($r === false) {
throw new Exception();
}
}
if (!empty($graphs_to_upd)) {
$r = API::Graph()->update($graphs_to_upd);
if ($r === false) {
throw new Exception();
}
}
}
// SCREENS
if (!empty($rules['screens']['updateExisting']) || !empty($rules['screens']['createMissing'])) {
$screens_node = $xpath->query('screens', $host);
if ($screens_node->length > 0) {
$importScreens = self::XMLtoArray($screens_node->item(0));
foreach ($importScreens as $screen) {
$current_screen = API::TemplateScreen()->get(array('filter' => array('name' => $screen['name']), 'templateids' => $current_hostid, 'output' => API_OUTPUT_EXTEND, 'editable' => 1));
$current_screen = reset($current_screen);
if (!$current_screen && empty($rules['screens']['createMissing'])) {
info(_s('Screen "%1$s" skipped - user rule.', $screen['name']));
continue;
}
if ($current_screen && empty($rules['screens']['updateExisting'])) {
info(_s('Screen "%1$s" skipped - user rule.', $screen['name']));
continue;
}
if (isset($screen['screenitems'])) {
foreach ($screen['screenitems'] as &$screenitem) {
$nodeCaption = isset($screenitem['resourceid']['node']) ? $screenitem['resourceid']['node'] . ':' : '';
if (!isset($screenitem['resourceid'])) {
$screenitem['resourceid'] = 0;
}
if (is_array($screenitem['resourceid'])) {
switch ($screenitem['resourcetype']) {
case SCREEN_RESOURCE_GRAPH:
$db_graphs = API::Graph()->getObjects($screenitem['resourceid']);
if (empty($db_graphs)) {
$error = _s('Cannot find graph "%1$s" used in screen "%2$s".', $nodeCaption . $screenitem['resourceid']['host'] . ':' . $screenitem['resourceid']['name'], $screen['name']);
throw new Exception($error);
}
$tmp = reset($db_graphs);
$screenitem['resourceid'] = $tmp['graphid'];
break;
case SCREEN_RESOURCE_SIMPLE_GRAPH:
case SCREEN_RESOURCE_PLAIN_TEXT:
$db_items = API::Item()->getObjects($screenitem['resourceid']);
if (empty($db_items)) {
$error = _s('Cannot find item "%1$s" used in screen "%2$s".', $nodeCaption . $screenitem['resourceid']['host'] . ':' . $screenitem['resourceid']['key_'], $screen['name']);
throw new Exception($error);
示例9: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$templateids = array_keys($result);
// Adding Templates
if ($options['selectTemplates'] !== null) {
if ($options['selectTemplates'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'templateid', 'hostid', 'hosts_templates');
$templates = API::Template()->get(array('output' => $options['selectTemplates'], 'templateids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
if (!is_null($options['limitSelects'])) {
order_result($templates, 'host');
}
$result = $relationMap->mapMany($result, $templates, 'templates', $options['limitSelects']);
} else {
$templates = API::Template()->get(array('parentTemplateids' => $templateids, 'countOutput' => true, 'groupCount' => true));
$templates = zbx_toHash($templates, 'templateid');
foreach ($result as $templateid => $template) {
if (isset($templates[$templateid])) {
$result[$templateid]['templates'] = $templates[$templateid]['rowscount'];
} else {
$result[$templateid]['templates'] = 0;
}
}
}
}
// Adding Hosts
if ($options['selectHosts'] !== null) {
if ($options['selectHosts'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'templateid', 'hostid', 'hosts_templates');
$hosts = API::Host()->get(array('output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
if (!is_null($options['limitSelects'])) {
order_result($hosts, 'host');
}
$result = $relationMap->mapMany($result, $hosts, 'hosts', $options['limitSelects']);
} else {
$hosts = API::Host()->get(array('templateids' => $templateids, 'countOutput' => true, 'groupCount' => true));
$hosts = zbx_toHash($hosts, 'templateid');
foreach ($result as $templateid => $template) {
if (isset($hosts[$templateid])) {
$result[$templateid]['hosts'] = $hosts[$templateid]['rowscount'];
} else {
$result[$templateid]['hosts'] = 0;
}
}
}
}
// Adding screens
if ($options['selectScreens'] !== null) {
if ($options['selectScreens'] != API_OUTPUT_COUNT) {
$screens = API::TemplateScreen()->get(array('output' => $this->outputExtend($options['selectScreens'], array('templateid')), 'templateids' => $templateids, 'nopermissions' => true));
if (!is_null($options['limitSelects'])) {
order_result($screens, 'name');
}
// preservekeys is not supported by templatescreen.get, so we're building a map using array keys
$relationMap = new CRelationMap();
foreach ($screens as $key => $screen) {
$relationMap->addRelation($screen['templateid'], $key);
}
$screens = $this->unsetExtraFields($screens, array('templateid'), $options['selectScreens']);
$result = $relationMap->mapMany($result, $screens, 'screens', $options['limitSelects']);
} else {
$screens = API::TemplateScreen()->get(array('templateids' => $templateids, 'nopermissions' => true, 'countOutput' => true, 'groupCount' => true));
$screens = zbx_toHash($screens, 'templateid');
foreach ($result as $templateid => $template) {
if (isset($screens[$templateid])) {
$result[$templateid]['screens'] = $screens[$templateid]['rowscount'];
} else {
$result[$templateid]['screens'] = 0;
}
}
}
}
return $result;
}
示例10: appendTemplatedScreenOption
/**
* Appends boolean option 'isTemplatedScreen' to ouput options.
*
* @param array $options
*
* @return array
*/
protected static function appendTemplatedScreenOption(array $options)
{
if (array_key_exists('screen', $options)) {
$options['isTemplatedScreen'] = (bool) $options['screen']['templateid'];
} elseif (array_key_exists('screenid', $options) && $options['screenid'] > 0) {
$options['isTemplatedScreen'] = (bool) API::TemplateScreen()->get(['screenids' => [$options['screenid']], 'output' => []]);
}
return $options;
}
示例11: checkInput
//.........这里部分代码省略.........
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect value "%1$s" for "%2$s" field: must be between %3$s and %4$s.', $screenItem['elements'], 'elements', 1, 100));
}
break;
}
}
// check 'max_columns' parameter for LLD screen resources:
// is set and valid for create method, and is valid for update method, if set
$dbScreenItem = isset($screenItem['screenitemid']) ? $dbScreenItems[$screenItem['screenitemid']] : null;
$lldResources = array(SCREEN_RESOURCE_LLD_GRAPH, SCREEN_RESOURCE_LLD_SIMPLE_GRAPH);
if (in_array($screenItem['resourcetype'], $lldResources)) {
$set = isset($screenItem['max_columns']);
$valid = $set && $this->isValidMaxColumns($screenItem['max_columns']);
$error = $dbScreenItem ? $set && !$valid : !$set || !$valid;
if ($error) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect max columns provided for screen element.'));
}
}
if (isset($validStyles[$screenItem['resourcetype']]) && !in_array($screenItem['style'], $validStyles[$screenItem['resourcetype']])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect style provided for screen element.'));
}
}
// check host groups
if ($hostGroupsIds) {
$dbHostGroups = API::HostGroup()->get(array('output' => array('groupid'), 'groupids' => $hostGroupsIds, 'editable' => true, 'preservekeys' => true));
foreach ($hostGroupsIds as $hostGroupsId) {
if (!isset($dbHostGroups[$hostGroupsId])) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect host group ID "%1$s" provided for screen element.', $hostGroupsId));
}
}
}
// check hosts
if ($hostIds) {
$dbHosts = API::Host()->get(array('output' => array('hostid'), 'hostids' => $hostIds, 'editable' => true, 'preservekeys' => true));
foreach ($hostIds as $hostId) {
if (!isset($dbHosts[$hostId])) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect host ID "%1$s" provided for screen element.', $hostId));
}
}
}
// check graphs
if ($graphIds) {
$dbGraphs = API::Graph()->get(array('output' => array('graphid'), 'graphids' => $graphIds, 'editable' => true, 'preservekeys' => true));
foreach ($graphIds as $graphId) {
if (!isset($dbGraphs[$graphId])) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect graph ID "%1$s" provided for screen element.', $graphId));
}
}
}
// check graph prototypes
if ($graphPrototypeIds) {
$dbGraphPrototypes = API::GraphPrototype()->get(array('output' => array('graphid'), 'graphids' => $graphPrototypeIds, 'editable' => true, 'preservekeys' => true));
foreach ($graphPrototypeIds as $graphPrototypeId) {
if (!isset($dbGraphPrototypes[$graphPrototypeId])) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect graph prototype ID "%1$s" provided for screen element.', $graphPrototypeId));
}
}
}
// check items
if ($itemIds) {
$dbItems = API::Item()->get(array('output' => array('itemid'), 'itemids' => $itemIds, 'editable' => true, 'preservekeys' => true, 'webitems' => true));
foreach ($itemIds as $itemId) {
if (!isset($dbItems[$itemId])) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect item ID "%1$s" provided for screen element.', $itemId));
}
}
}
// check item prototypes
if ($itemPrototypeIds) {
$dbItemPrototypes = API::ItemPrototype()->get(array('output' => array('itemid'), 'itemids' => $itemPrototypeIds, 'editable' => true, 'preservekeys' => true));
foreach ($itemPrototypeIds as $itemPrototypeId) {
if (!isset($dbItemPrototypes[$itemPrototypeId])) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect item prototype ID "%1$s" provided for screen element.', $itemPrototypeId));
}
}
}
// check maps
if ($mapIds) {
$dbMaps = API::Map()->get(array('output' => array('sysmapid'), 'sysmapids' => $mapIds, 'editable' => true, 'preservekeys' => true));
foreach ($mapIds as $mapId) {
if (!isset($dbMaps[$mapId])) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect map ID "%1$s" provided for screen element.', $mapId));
}
}
}
// check screens
if ($screenIds) {
$dbScreens = API::Screen()->get(array('output' => array('screenid'), 'screenids' => $screenIds, 'editable' => true, 'preservekeys' => true));
if (count($dbScreens) < count($screenIds)) {
$dbTemplateScreens = API::TemplateScreen()->get(array('output' => array('screenid'), 'screenids' => $screenIds, 'editable' => true, 'preservekeys' => true));
if ($dbTemplateScreens) {
$dbScreens = zbx_array_merge($dbScreens, $dbTemplateScreens);
}
}
foreach ($screenIds as $screenId) {
if (!isset($dbScreens[$screenId])) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect screen ID "%1$s" provided for screen element.', $screenId));
}
}
}
}
示例12: appendTemplatedScreenOption
/**
* Appends boolean option 'isTemplatedScreen' to ouput options.
*
* @param array $options
*
* @return array
*/
protected static function appendTemplatedScreenOption(array $options)
{
if (isset($options['screen'])) {
$options['isTemplatedScreen'] = (bool) $options['screen']['templateid'];
} elseif (isset($options['screenid'])) {
$options['isTemplatedScreen'] = (bool) API::TemplateScreen()->get(array('screenids' => array($options['screenid']), 'output' => array()));
}
return $options;
}
示例13: selectTemplateScreens
/**
* Select template screen IDs for previously added screen names and template IDs.
*/
protected function selectTemplateScreens()
{
if ($this->templateScreens) {
$this->templateScreensRefs = [];
$db_template_screens = API::TemplateScreen()->get(['filter' => ['name' => $this->templateScreens], 'output' => ['screenid', 'name', 'templateid']]);
foreach ($db_template_screens as $screen) {
$this->templateScreensRefs[$screen['templateid']][$screen['name']] = $screen['screenid'];
}
$this->templateScreens = [];
}
}
示例14: array
// Graph prototypes
$hostGraphPrototypes = API::GraphPrototype()->get(array('hostids' => $templateid, 'discoveryids' => $hostDiscoveryRuleids, 'inherited' => false, 'output' => API_OUTPUT_EXTEND));
if (!empty($hostGraphPrototypes)) {
$prototypeList = array();
foreach ($hostGraphPrototypes as $graphPrototype) {
$prototypeList[$graphPrototype['graphid']] = $graphPrototype['name'];
}
order_result($prototypeList);
$listBox = new CListBox('graphPrototypes', null, 8);
$listBox->setAttribute('disabled', 'disabled');
$listBox->addItems($prototypeList);
$templateList->addRow(_('Graph prototypes'), $listBox);
}
}
// screens
$screens = API::TemplateScreen()->get(array('inherited' => false, 'templateids' => $templateid, 'output' => array('screenid', 'name')));
if (!empty($screens)) {
$screensList = array();
foreach ($screens as $screen) {
$screensList[$screen['screenid']] = $screen['name'];
}
order_result($screensList);
$listBox = new CListBox('screens', null, 8);
$listBox->setAttribute('disabled', 'disabled');
$listBox->addItems($screensList);
$templateList->addRow(_('Screens'), $listBox);
}
// web scenarios
$httpTests = API::HttpTest()->get(array('output' => array('httptestid', 'name'), 'hostids' => $templateid, 'inherited' => false));
if ($httpTests) {
$httpTestList = array();
示例15: get_header_host_table
/**
* 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'])));
}
/*
//.........这里部分代码省略.........