本文整理汇总了PHP中API::ItemPrototype方法的典型用法代码示例。如果您正苦于以下问题:PHP API::ItemPrototype方法的具体用法?PHP API::ItemPrototype怎么用?PHP API::ItemPrototype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API
的用法示例。
在下文中一共展示了API::ItemPrototype方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkExpression
/**
* Check if trigger prototype has a correct trigger expression and has at least one item prototype and belongs to
* one discovery rule, does not belong to a host and a template simultaneously and has permissions to all hosts and
* templates in the expression.
*
* @param array $triggerPrototype
* @param string $triggerPrototype['description']
* @param string $triggerPrototype['expression']
*
* @throws APIException
*
* @return void
*/
protected function checkExpression(array $triggerPrototype)
{
$triggerExpression = new CTriggerExpression();
if (!$triggerExpression->parse($triggerPrototype['expression'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, $triggerExpression->error);
}
$lld_rules = [];
if ($triggerExpression->expressions) {
$expressions = [];
$hosts = [];
$has_host = false;
$has_template = false;
foreach ($triggerExpression->expressions as $expression) {
if (!array_key_exists($expression['host'], $expressions)) {
$expressions[$expression['host']] = ['hostid' => null, 'items' => []];
}
$expressions[$expression['host']]['items'][$expression['item']] = true;
$hosts[$expression['host']] = true;
}
$db_hosts = API::Host()->get(['output' => ['hostid', 'host'], 'filter' => ['host' => array_keys($hosts)]]);
foreach ($db_hosts as $db_host) {
$expressions[$db_host['host']]['hostid'] = $db_host['hostid'];
$has_host = true;
unset($hosts[$db_host['host']]);
}
if ($hosts) {
$db_templates = API::Template()->get(['output' => ['templateid', 'host'], 'filter' => ['host' => array_keys($hosts)]]);
foreach ($db_templates as $db_template) {
$expressions[$db_template['host']]['hostid'] = $db_template['templateid'];
$has_template = true;
}
}
if ($has_host && $has_template) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect trigger prototype expression.' . ' Trigger prototype expression elements should not belong to a template and a host simultaneously.'));
}
foreach ($expressions as $host => $expression) {
if ($expression['hostid'] === null) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect trigger prototype expression.' . ' Host "%1$s" does not exist or you have no access to this host.', $host));
}
$db_item_prototypes = API::ItemPrototype()->get(['output' => [], 'selectDiscoveryRule' => ['itemid'], 'hostids' => [$expression['hostid']], 'filter' => ['key_' => array_keys($expression['items'])], 'nopermissions' => true]);
foreach ($db_item_prototypes as $db_item_prototype) {
$lld_rules[$db_item_prototype['discoveryRule']['itemid']] = true;
}
}
if (count($lld_rules) > 1) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Trigger prototype "%1$s" contains item prototypes from multiple discovery rules.', $triggerPrototype['description']));
}
}
if (!$lld_rules) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Trigger prototype "%1$s" must contain at least one item prototype.', $triggerPrototype['description']));
}
}
示例2: array
// discovery rules
$hostDiscoveryRules = API::DiscoveryRule()->get(array('inherited' => false, 'hostids' => $templateid, 'output' => API_OUTPUT_EXTEND));
if ($hostDiscoveryRules) {
$hostDiscoveryRules = CMacrosResolverHelper::resolveItemNames($hostDiscoveryRules);
$discoveryRuleList = array();
foreach ($hostDiscoveryRules as $discoveryRule) {
$discoveryRuleList[$discoveryRule['itemid']] = $discoveryRule['name_expanded'];
}
order_result($discoveryRuleList);
$hostDiscoveryRuleids = array_keys($discoveryRuleList);
$listBox = new CListBox('discoveryRules', null, 8);
$listBox->setAttribute('disabled', 'disabled');
$listBox->addItems($discoveryRuleList);
$templateList->addRow(_('Discovery rules'), $listBox);
// item prototypes
$hostItemPrototypes = API::ItemPrototype()->get(array('hostids' => $templateid, 'discoveryids' => $hostDiscoveryRuleids, 'inherited' => false, 'output' => API_OUTPUT_EXTEND));
if ($hostItemPrototypes) {
$hostItemPrototypes = CMacrosResolverHelper::resolveItemNames($hostItemPrototypes);
$prototypeList = array();
foreach ($hostItemPrototypes as $itemPrototype) {
$prototypeList[$itemPrototype['itemid']] = $itemPrototype['name_expanded'];
}
order_result($prototypeList);
$listBox = new CListBox('itemsPrototypes', null, 8);
$listBox->setAttribute('disabled', 'disabled');
$listBox->addItems($prototypeList);
$templateList->addRow(_('Item prototypes'), $listBox);
}
// Trigger prototypes
$hostTriggerPrototypes = API::TriggerPrototype()->get(array('hostids' => $templateid, 'discoveryids' => $hostDiscoveryRuleids, 'inherited' => false, 'output' => API_OUTPUT_EXTEND));
if (!empty($hostTriggerPrototypes)) {
示例3: prepareDiscoveryRules
/**
* Get discovery rules related objects from database.
*
* @param array $items
*
* @return array
*/
protected function prepareDiscoveryRules(array $items)
{
foreach ($items as &$item) {
$item['itemPrototypes'] = array();
$item['graphPrototypes'] = array();
$item['triggerPrototypes'] = array();
}
unset($item);
// gather item prototypes
$prototypes = API::ItemPrototype()->get(array('discoveryids' => zbx_objectValues($items, 'itemid'), 'output' => array('hostid', 'multiplier', 'type', 'snmp_community', 'snmp_oid', 'name', 'key_', 'delay', 'history', 'trends', 'status', 'value_type', 'trapper_hosts', 'units', 'delta', 'snmpv3_securityname', 'snmpv3_securitylevel', 'snmpv3_authpassphrase', 'snmpv3_privpassphrase', 'formula', 'valuemapid', 'delay_flex', 'params', 'ipmi_sensor', 'data_type', 'authtype', 'username', 'password', 'publickey', 'privatekey', 'interfaceid', 'port', 'description', 'inventory_link', 'flags'), 'selectApplications' => API_OUTPUT_EXTEND, 'inherited' => false, 'preservekeys' => true));
// gather value maps
$valueMapIds = zbx_objectValues($prototypes, 'valuemapid');
$DbValueMaps = DBselect('SELECT vm.valuemapid, vm.name FROM valuemaps vm WHERE ' . dbConditionInt('vm.valuemapid', $valueMapIds));
$valueMaps = array();
while ($valueMap = DBfetch($DbValueMaps)) {
$valueMaps[$valueMap['valuemapid']] = $valueMap['name'];
}
foreach ($prototypes as $prototype) {
$prototype['valuemap'] = array();
if ($prototype['valuemapid']) {
$prototype['valuemap']['name'] = $valueMaps[$prototype['valuemapid']];
}
$items[$prototype['parent_itemid']]['itemPrototypes'][] = $prototype;
}
// gather graph prototypes
$graphs = API::GraphPrototype()->get(array('discoveryids' => zbx_objectValues($items, 'itemid'), 'selectDiscoveryRule' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND, 'inherited' => false, 'preservekeys' => true));
$graphs = $this->prepareGraphs($graphs);
foreach ($graphs as $graph) {
$items[$graph['discoveryRule']['itemid']]['graphPrototypes'][] = $graph;
}
// gather trigger prototypes
$triggers = API::TriggerPrototype()->get(array('discoveryids' => zbx_objectValues($items, 'itemid'), 'output' => API_OUTPUT_EXTEND, 'selectDiscoveryRule' => API_OUTPUT_EXTEND, 'selectItems' => array('flags', 'type'), 'inherited' => false, 'preservekeys' => true, 'expandData' => true));
foreach ($triggers as $trigger) {
foreach ($trigger['items'] as $item) {
if ($item['flags'] == ZBX_FLAG_DISCOVERY_CREATED || $item['type'] == ITEM_TYPE_HTTPTEST) {
continue 2;
}
}
$trigger['expression'] = explode_exp($trigger['expression']);
$items[$trigger['discoveryRule']['itemid']]['triggerPrototypes'][] = $trigger;
}
return $items;
}
示例4: prepareDiscoveryRules
/**
* Get discovery rules related objects from database.
*
* @param array $items
*
* @return array
*/
protected function prepareDiscoveryRules(array $items)
{
foreach ($items as &$item) {
$item['itemPrototypes'] = array();
$item['graphPrototypes'] = array();
$item['triggerPrototypes'] = array();
$item['hostPrototypes'] = array();
}
unset($item);
// gather item prototypes
$prototypes = API::ItemPrototype()->get(array('discoveryids' => zbx_objectValues($items, 'itemid'), 'output' => $this->dataFields['discoveryrule'], 'selectApplications' => API_OUTPUT_EXTEND, 'selectDiscoveryRule' => array('itemid'), 'inherited' => false, 'preservekeys' => true));
// gather value maps
$valueMapIds = zbx_objectValues($prototypes, 'valuemapid');
$DbValueMaps = DBselect('SELECT vm.valuemapid, vm.name FROM valuemaps vm WHERE ' . dbConditionInt('vm.valuemapid', $valueMapIds));
$valueMaps = array();
while ($valueMap = DBfetch($DbValueMaps)) {
$valueMaps[$valueMap['valuemapid']] = $valueMap['name'];
}
foreach ($prototypes as $prototype) {
$prototype['valuemap'] = array();
if ($prototype['valuemapid']) {
$prototype['valuemap']['name'] = $valueMaps[$prototype['valuemapid']];
}
$items[$prototype['discoveryRule']['itemid']]['itemPrototypes'][] = $prototype;
}
// gather graph prototypes
$graphs = API::GraphPrototype()->get(array('discoveryids' => zbx_objectValues($items, 'itemid'), 'selectDiscoveryRule' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND, 'inherited' => false, 'preservekeys' => true));
$graphs = $this->prepareGraphs($graphs);
foreach ($graphs as $graph) {
$items[$graph['discoveryRule']['itemid']]['graphPrototypes'][] = $graph;
}
// gather trigger prototypes
$triggers = API::TriggerPrototype()->get(array('discoveryids' => zbx_objectValues($items, 'itemid'), 'output' => API_OUTPUT_EXTEND, 'selectDiscoveryRule' => API_OUTPUT_EXTEND, 'selectItems' => array('flags', 'type'), 'inherited' => false, 'preservekeys' => true, 'expandData' => true));
foreach ($triggers as $trigger) {
foreach ($trigger['items'] as $item) {
if ($item['flags'] == ZBX_FLAG_DISCOVERY_CREATED || $item['type'] == ITEM_TYPE_HTTPTEST) {
continue 2;
}
}
$trigger['expression'] = explode_exp($trigger['expression']);
$items[$trigger['discoveryRule']['itemid']]['triggerPrototypes'][] = $trigger;
}
// gather host prototypes
$hostPrototypes = API::HostPrototype()->get(array('discoveryids' => zbx_objectValues($items, 'itemid'), 'output' => API_OUTPUT_EXTEND, 'selectGroupLinks' => API_OUTPUT_EXTEND, 'selectGroupPrototypes' => API_OUTPUT_EXTEND, 'selectDiscoveryRule' => API_OUTPUT_EXTEND, 'selectTemplates' => API_OUTPUT_EXTEND, 'inherited' => false, 'preservekeys' => true));
// replace group prototype group IDs with references
$groupIds = array();
foreach ($hostPrototypes as $hostPrototype) {
foreach ($hostPrototype['groupLinks'] as $groupLink) {
$groupIds[$groupLink['groupid']] = $groupLink['groupid'];
}
}
$groups = $this->getGroupsReferences($groupIds);
// export the groups used in group prototypes
$this->data['groups'] += $groups;
foreach ($hostPrototypes as $hostPrototype) {
foreach ($hostPrototype['groupLinks'] as &$groupLink) {
$groupLink['groupid'] = $groups[$groupLink['groupid']];
}
unset($groupLink);
$items[$hostPrototype['discoveryRule']['itemid']]['hostPrototypes'][] = $hostPrototype;
}
return $items;
}
示例5: getItemPrototype
/**
* Resolves and retrieves effective item prototype used in this screen item.
*
* @return array|bool
*/
protected function getItemPrototype()
{
if ($this->itemPrototype === null) {
$defaultOptions = array('output' => array('itemid', 'name'), 'selectHosts' => array('name'), 'selectDiscoveryRule' => array('hostid'));
$options = array();
/*
* If screen item is dynamic or is templated screen, real item prototype is looked up by "key"
* used as resource ID for this screen item and by current host.
*/
if (($this->screenitem['dynamic'] == SCREEN_DYNAMIC_ITEM || $this->isTemplatedScreen) && $this->hostid) {
$currentItemPrototype = API::ItemPrototype()->get(array('output' => array('key_'), 'itemids' => array($this->screenitem['resourceid'])));
$currentItemPrototype = reset($currentItemPrototype);
$options['hostids'] = array($this->hostid);
$options['filter'] = array('key_' => $currentItemPrototype['key_']);
} else {
$options['itemids'] = array($this->screenitem['resourceid']);
}
$options = zbx_array_merge($defaultOptions, $options);
$selectedItemPrototype = API::ItemPrototype()->get($options);
$this->itemPrototype = reset($selectedItemPrototype);
}
return $this->itemPrototype;
}
示例6: reset
$itemPrototype = reset($itemPrototype);
}
$data = getItemFormData($itemPrototype);
$data['config'] = select_config();
// render view
$itemView = new CView('configuration.item.prototype.edit', $data);
$itemView->render();
$itemView->show();
} else {
$sortField = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'name'));
$sortOrder = getRequest('sortorder', CProfile::get('web.' . $page['file'] . '.sortorder', ZBX_SORT_UP));
CProfile::update('web.' . $page['file'] . '.sort', $sortField, PROFILE_TYPE_STR);
CProfile::update('web.' . $page['file'] . '.sortorder', $sortOrder, PROFILE_TYPE_STR);
$config = select_config();
$data = ['form' => getRequest('form'), 'parent_discoveryid' => getRequest('parent_discoveryid'), 'hostid' => $discoveryRule['hostid'], 'sort' => $sortField, 'sortorder' => $sortOrder];
$data['items'] = API::ItemPrototype()->get(['discoveryids' => $data['parent_discoveryid'], 'output' => API_OUTPUT_EXTEND, 'editable' => true, 'selectApplications' => API_OUTPUT_EXTEND, 'sortfield' => $sortField, 'limit' => $config['search_limit'] + 1]);
foreach ($data['items'] as &$item) {
if ($item['value_type'] == ITEM_VALUE_TYPE_STR || $item['value_type'] == ITEM_VALUE_TYPE_LOG || $item['value_type'] == ITEM_VALUE_TYPE_TEXT) {
$item['trends'] = '';
}
if ($item['type'] == ITEM_TYPE_TRAPPER || $item['type'] == ITEM_TYPE_SNMPTRAP) {
$item['delay'] = '';
}
}
unset($item);
$data['items'] = CMacrosResolverHelper::resolveItemNames($data['items']);
order_result($data['items'], $sortField, $sortOrder);
$url = (new CUrl('disc_prototypes.php'))->setArgument('parent_discoveryid', $data['parent_discoveryid']);
$data['paging'] = getPagingLine($data['items'], $sortOrder, $url);
// render view
$itemView = new CView('configuration.item.prototype.list', $data);
示例7: prepareDiscoveryRules
/**
* Get discovery rules related objects from database.
*
* @param array $items
*
* @return array
*/
protected function prepareDiscoveryRules(array $items)
{
foreach ($items as &$item) {
$item['itemPrototypes'] = [];
$item['graphPrototypes'] = [];
$item['triggerPrototypes'] = [];
$item['hostPrototypes'] = [];
// unset unnecessary condition fields
foreach ($item['filter']['conditions'] as &$condition) {
unset($condition['item_conditionid'], $condition['itemid']);
}
unset($condition);
}
unset($item);
// gather item prototypes
$prototypes = API::ItemPrototype()->get(['output' => $this->dataFields['item_prototype'], 'selectApplications' => ['name'], 'selectApplicationPrototypes' => ['name'], 'selectDiscoveryRule' => ['itemid'], 'discoveryids' => zbx_objectValues($items, 'itemid'), 'inherited' => false, 'preservekeys' => true]);
$valuemapids = [];
foreach ($prototypes as $prototype) {
$valuemapids[$prototype['valuemapid']] = true;
}
// Value map IDs that are zeroes, should be skipped.
unset($valuemapids[0]);
if ($this->data['valueMaps']) {
/*
* If there is an option "valueMaps", some value maps may already been selected. Copy the result and remove
* value map IDs that should not be selected again.
*/
foreach ($this->data['valueMaps'] as $valuemapid => $valuemap) {
if (array_key_exists($valuemapid, $valuemapids)) {
unset($valuemapids[$valuemapid]);
}
}
}
if ($valuemapids) {
$this->data['valueMaps'] += API::ValueMap()->get(['output' => ['valuemapid', 'name'], 'selectMappings' => ['value', 'newvalue'], 'valuemapids' => array_keys($valuemapids), 'preservekeys' => true]);
}
foreach ($prototypes as $prototype) {
$prototype['valuemap'] = [];
if ($prototype['valuemapid'] != 0) {
$prototype['valuemap']['name'] = $this->data['valueMaps'][$prototype['valuemapid']]['name'];
}
$items[$prototype['discoveryRule']['itemid']]['itemPrototypes'][] = $prototype;
}
// gather graph prototypes
$graphs = API::GraphPrototype()->get(['discoveryids' => zbx_objectValues($items, 'itemid'), 'selectDiscoveryRule' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND, 'inherited' => false, 'preservekeys' => true]);
$graphs = $this->prepareGraphs($graphs);
foreach ($graphs as $graph) {
$items[$graph['discoveryRule']['itemid']]['graphPrototypes'][] = $graph;
}
// gather trigger prototypes
$triggers = API::TriggerPrototype()->get(['discoveryids' => zbx_objectValues($items, 'itemid'), 'output' => ['expression', 'description', 'url', 'status', 'priority', 'comments', 'type'], 'selectDiscoveryRule' => API_OUTPUT_EXTEND, 'selectDependencies' => ['description', 'expression'], 'selectItems' => ['itemid', 'flags', 'type'], 'inherited' => false, 'preservekeys' => true]);
$triggers = $this->prepareTriggers($triggers);
foreach ($triggers as $trigger) {
$items[$trigger['discoveryRule']['itemid']]['triggerPrototypes'][] = $trigger;
}
// gather host prototypes
$hostPrototypes = API::HostPrototype()->get(['discoveryids' => zbx_objectValues($items, 'itemid'), 'output' => API_OUTPUT_EXTEND, 'selectGroupLinks' => API_OUTPUT_EXTEND, 'selectGroupPrototypes' => API_OUTPUT_EXTEND, 'selectDiscoveryRule' => API_OUTPUT_EXTEND, 'selectTemplates' => API_OUTPUT_EXTEND, 'inherited' => false, 'preservekeys' => true]);
// replace group prototype group IDs with references
$groupIds = [];
foreach ($hostPrototypes as $hostPrototype) {
foreach ($hostPrototype['groupLinks'] as $groupLink) {
$groupIds[$groupLink['groupid']] = true;
}
}
$groups = $this->getGroupsReferences(array_keys($groupIds));
// export the groups used in group prototypes
$this->data['groups'] += $groups;
foreach ($hostPrototypes as $hostPrototype) {
foreach ($hostPrototype['groupLinks'] as &$groupLink) {
$groupLink['groupid'] = $groups[$groupLink['groupid']];
}
unset($groupLink);
$items[$hostPrototype['discoveryRule']['itemid']]['hostPrototypes'][] = $hostPrototype;
}
return $items;
}
示例8: array
$hostDiscoveryRuleids = array();
$hostDiscoveryRules = API::DiscoveryRule()->get(array('inherited' => false, 'hostids' => $_REQUEST['hostid'], 'output' => array('itemid', 'key_', 'name')));
if (!empty($hostDiscoveryRules)) {
$discoveryRuleList = array();
foreach ($hostDiscoveryRules as $discoveryRule) {
$discoveryRuleList[$discoveryRule['itemid']] = itemName($discoveryRule);
}
order_result($discoveryRuleList);
$hostDiscoveryRuleids = array_keys($discoveryRuleList);
$listBox = new CListBox('discoveryRules', null, 8);
$listBox->setAttribute('disabled', 'disabled');
$listBox->addItems($discoveryRuleList);
$hostList->addRow(_('Discovery rules'), $listBox);
}
// item prototypes
$hostItemPrototypes = API::ItemPrototype()->get(array('hostids' => $_REQUEST['hostid'], 'discoveryids' => $hostDiscoveryRuleids, 'inherited' => false, 'output' => array('itemid', 'key_', 'name')));
if (!empty($hostItemPrototypes)) {
$prototypeList = array();
foreach ($hostItemPrototypes as $itemPrototype) {
$prototypeList[$itemPrototype['itemid']] = itemName($itemPrototype);
}
order_result($prototypeList);
$listBox = new CListBox('itemsPrototypes', null, 8);
$listBox->setAttribute('disabled', 'disabled');
$listBox->addItems($prototypeList);
$hostList->addRow(_('Item prototypes'), $listBox);
}
// Trigger prototypes
$hostTriggerPrototypes = API::TriggerPrototype()->get(array('hostids' => $_REQUEST['hostid'], 'discoveryids' => $hostDiscoveryRuleids, 'inherited' => false, 'output' => array('triggerid', 'description'), 'selectItems' => array('type')));
if (!empty($hostTriggerPrototypes)) {
$prototypeList = array();
示例9: 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));
}
}
}
}
示例10: reset
$id = $resourceId;
$item = reset($items);
$item['host'] = reset($item['hosts']);
$caption = $item['host']['name'] . NAME_DELIMITER . $item['name_expanded'];
}
if ($this->data['screen']['templateid']) {
$selectButton = (new CButton('select', _('Select')))->addClass(ZBX_STYLE_BTN_GREY)->onClick('javascript: return PopUp("popup.php?srctbl=items&srcfld1=itemid&srcfld2=name' . '&dstfrm=' . $form->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&templated_hosts=1&only_hostid=' . $this->data['screen']['templateid'] . '&numeric=1");');
} else {
$selectButton = (new CButton('select', _('Select')))->addClass(ZBX_STYLE_BTN_GREY)->onClick('javascript: return PopUp("popup.php?srctbl=items&srcfld1=itemid&srcfld2=name' . '&dstfrm=' . $form->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&real_hosts=1&with_simple_graph_items=1&numeric=1");');
}
$form->addVar('resourceid', $id);
$screenFormList->addRow(_('Item'), [(new CTextBox('caption', $caption, true))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), $selectButton]);
} elseif ($resourceType == SCREEN_RESOURCE_LLD_SIMPLE_GRAPH) {
$caption = '';
$id = 0;
$items = API::ItemPrototype()->get(['output' => ['hostid', 'key_', 'name'], 'itemids' => $resourceId, 'selectHosts' => ['name']]);
if ($items) {
$items = CMacrosResolverHelper::resolveItemNames($items);
$id = $resourceId;
$item = reset($items);
$item['host'] = reset($item['hosts']);
$caption = $item['host']['name'] . NAME_DELIMITER . $item['name_expanded'];
}
if ($this->data['screen']['templateid']) {
$selectButton = (new CButton('select', _('Select')))->addClass(ZBX_STYLE_BTN_GREY)->onClick('javascript: return PopUp("popup.php?srctbl=item_prototypes&srcfld1=itemid&srcfld2=name' . '&dstfrm=' . $form->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&templated_hosts=1&only_hostid=' . $this->data['screen']['templateid'] . '&numeric=1");');
} else {
$selectButton = (new CButton('select', _('Select')))->addClass(ZBX_STYLE_BTN_GREY)->onClick('javascript: return PopUp("popup.php?srctbl=item_prototypes&srcfld1=itemid&srcfld2=name' . '&dstfrm=' . $form->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&real_hosts=1&with_discovery_rule=1&items=1&numeric=1");');
}
$form->addVar('resourceid', $id);
$screenFormList->addRow(_('Item prototype'), [(new CTextBox('caption', $caption, true))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), $selectButton]);
$screenFormList->addRow(_('Max columns'), (new CNumericBox('max_columns', $maxColumns, 3, false, false, false))->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH));
示例11: addRelatedObjects
protected function addRelatedObjects(array $options, array $result)
{
$result = parent::addRelatedObjects($options, $result);
$itemIds = array_keys($result);
// adding items
if (!is_null($options['selectItems'])) {
if ($options['selectItems'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'parent_itemid', 'itemid', 'item_discovery');
$items = API::ItemPrototype()->get(array('output' => $options['selectItems'], 'itemids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
$result = $relationMap->mapMany($result, $items, 'items', $options['limitSelects']);
} else {
$items = API::ItemPrototype()->get(array('discoveryids' => $itemIds, 'nopermissions' => true, 'countOutput' => true, 'groupCount' => true));
$items = zbx_toHash($items, 'parent_itemid');
foreach ($result as $itemid => $item) {
$result[$itemid]['items'] = isset($items[$itemid]) ? $items[$itemid]['rowscount'] : 0;
}
}
}
// adding triggers
if (!is_null($options['selectTriggers'])) {
if ($options['selectTriggers'] != API_OUTPUT_COUNT) {
$relationMap = new CRelationMap();
$res = DBselect('SELECT id.parent_itemid,f.triggerid' . ' FROM item_discovery id,items i,functions f' . ' WHERE ' . dbConditionInt('id.parent_itemid', $itemIds) . ' AND id.itemid=i.itemid' . ' AND i.itemid=f.itemid');
while ($relation = DBfetch($res)) {
$relationMap->addRelation($relation['parent_itemid'], $relation['triggerid']);
}
$triggers = API::TriggerPrototype()->get(array('output' => $options['selectTriggers'], 'triggerids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
$result = $relationMap->mapMany($result, $triggers, 'triggers', $options['limitSelects']);
} else {
$triggers = API::TriggerPrototype()->get(array('discoveryids' => $itemIds, 'countOutput' => true, 'groupCount' => true));
$triggers = zbx_toHash($triggers, 'parent_itemid');
foreach ($result as $itemid => $item) {
$result[$itemid]['triggers'] = isset($triggers[$itemid]) ? $triggers[$itemid]['rowscount'] : 0;
}
}
}
// adding graphs
if (!is_null($options['selectGraphs'])) {
if ($options['selectGraphs'] != API_OUTPUT_COUNT) {
$relationMap = new CRelationMap();
$res = DBselect('SELECT id.parent_itemid,gi.graphid' . ' FROM item_discovery id,items i,graphs_items gi' . ' WHERE ' . dbConditionInt('id.parent_itemid', $itemIds) . ' AND id.itemid=i.itemid' . ' AND i.itemid=gi.itemid');
while ($relation = DBfetch($res)) {
$relationMap->addRelation($relation['parent_itemid'], $relation['graphid']);
}
$graphs = API::GraphPrototype()->get(array('output' => $options['selectGraphs'], 'graphids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
$result = $relationMap->mapMany($result, $graphs, 'graphs', $options['limitSelects']);
} else {
$graphs = API::GraphPrototype()->get(array('discoveryids' => $itemIds, 'countOutput' => true, 'groupCount' => true));
$graphs = zbx_toHash($graphs, 'parent_itemid');
foreach ($result as $itemid => $item) {
$result[$itemid]['graphs'] = isset($graphs[$itemid]) ? $graphs[$itemid]['rowscount'] : 0;
}
}
}
// adding hosts
if ($options['selectHostPrototypes'] !== null) {
if ($options['selectHostPrototypes'] != API_OUTPUT_COUNT) {
$relationMap = $this->createRelationMap($result, 'parent_itemid', 'hostid', 'host_discovery');
$hostPrototypes = API::HostPrototype()->get(array('output' => $options['selectHostPrototypes'], 'hostids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
$result = $relationMap->mapMany($result, $hostPrototypes, 'hostPrototypes', $options['limitSelects']);
} else {
$hostPrototypes = API::HostPrototype()->get(array('discoveryids' => $itemIds, 'nopermissions' => true, 'countOutput' => true, 'groupCount' => true));
$hostPrototypes = zbx_toHash($hostPrototypes, 'parent_itemid');
foreach ($result as $itemid => $item) {
$result[$itemid]['hostPrototypes'] = isset($hostPrototypes[$itemid]) ? $hostPrototypes[$itemid]['rowscount'] : 0;
}
}
}
if ($options['selectFilter'] !== null) {
$formulaRequested = $this->outputIsRequested('formula', $options['selectFilter']);
$evalFormulaRequested = $this->outputIsRequested('eval_formula', $options['selectFilter']);
$conditionsRequested = $this->outputIsRequested('conditions', $options['selectFilter']);
$filters = array();
foreach ($result as $rule) {
$filters[$rule['itemid']] = array('evaltype' => $rule['evaltype'], 'formula' => isset($rule['formula']) ? $rule['formula'] : '');
}
// adding conditions
if ($formulaRequested || $evalFormulaRequested || $conditionsRequested) {
$conditions = API::getApiService()->select('item_condition', array('output' => array('item_conditionid', 'macro', 'value', 'itemid', 'operator'), 'filter' => array('itemid' => $itemIds), 'preservekeys' => true, 'sortfield' => 'item_conditionid'));
$relationMap = $this->createRelationMap($conditions, 'itemid', 'item_conditionid');
$filters = $relationMap->mapMany($filters, $conditions, 'conditions');
foreach ($filters as &$filter) {
// in case of a custom expression - use the given formula
if ($filter['evaltype'] == CONDITION_EVAL_TYPE_EXPRESSION) {
$formula = $filter['formula'];
} else {
// sort the conditions by macro before generating the formula
$conditions = zbx_toHash($filter['conditions'], 'item_conditionid');
$conditions = order_macros($conditions, 'macro');
$formulaConditions = array();
foreach ($conditions as $condition) {
$formulaConditions[$condition['item_conditionid']] = $condition['macro'];
}
$formula = CConditionHelper::getFormula($formulaConditions, $filter['evaltype']);
}
// generate formulaids from the effective formula
$formulaIds = CConditionHelper::getFormulaIds($formula);
foreach ($filter['conditions'] as &$condition) {
$condition['formulaid'] = $formulaIds[$condition['item_conditionid']];
}
//.........这里部分代码省略.........
示例12: zbx_add_post_js
}
zbx_add_post_js('chkbxRange.pageGoName = "items";');
$form->addItem($table);
$form->show();
} elseif ($srctbl == 'prototypes') {
$form = new CForm();
$form->setName('itemform');
$form->setAttribute('id', 'items');
$table = new CTableInfo(_('No item prototypes defined.'));
if ($multiselect) {
$header = array(array(new CCheckBox('all_items', null, "javascript: checkAll('" . $form->getName() . "', 'all_items', 'items');"), _('Name')), _('Key'), _('Type'), _('Type of information'), _('Status'));
} else {
$header = array(_('Name'), _('Key'), _('Type'), _('Type of information'), _('Status'));
}
$table->setHeader($header);
$items = API::ItemPrototype()->get(array('nodeids' => $nodeid, 'selectHosts' => array('name'), 'discoveryids' => get_request('parent_discoveryid'), 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true));
order_result($items, 'name');
foreach ($items as &$item) {
$host = reset($item['hosts']);
$description = new CSpan(itemName($item), 'link');
$item['name'] = $host['name'] . ': ' . $item['name'];
if ($multiselect) {
$js_action = 'javascript: addValue(' . zbx_jsvalue($reference) . ', ' . zbx_jsvalue($item['itemid']) . ');';
} else {
$values = array();
for ($i = 1; $i <= $dstfldCount; $i++) {
$dstfld = get_request('dstfld' . $i);
$srcfld = get_request('srcfld' . $i);
if (!empty($dstfld) && !empty($item[$srcfld])) {
$values[$dstfld] = $item[$srcfld];
}
示例13: foreach
$templateList->addRow(_('Graphs'), $listBox);
}
// discovery rules
$hostDiscoveryRules = API::DiscoveryRule()->get(['inherited' => false, 'hostids' => $data['templateId'], 'output' => API_OUTPUT_EXTEND]);
if ($hostDiscoveryRules) {
$hostDiscoveryRules = CMacrosResolverHelper::resolveItemNames($hostDiscoveryRules);
$discoveryRuleList = [];
foreach ($hostDiscoveryRules as $discoveryRule) {
$discoveryRuleList[$discoveryRule['itemid']] = $discoveryRule['name_expanded'];
}
order_result($discoveryRuleList);
$hostDiscoveryRuleids = array_keys($discoveryRuleList);
$listBox = (new CListBox('discoveryRules', null, 8))->setAttribute('disabled', 'disabled')->addItems($discoveryRuleList);
$templateList->addRow(_('Discovery rules'), $listBox);
// item prototypes
$hostItemPrototypes = API::ItemPrototype()->get(['hostids' => $data['templateId'], 'discoveryids' => $hostDiscoveryRuleids, 'inherited' => false, 'output' => API_OUTPUT_EXTEND]);
if ($hostItemPrototypes) {
$hostItemPrototypes = CMacrosResolverHelper::resolveItemNames($hostItemPrototypes);
$prototypeList = [];
foreach ($hostItemPrototypes as $itemPrototype) {
$prototypeList[$itemPrototype['itemid']] = $itemPrototype['name_expanded'];
}
order_result($prototypeList);
$listBox = (new CListBox('itemsPrototypes', null, 8))->setAttribute('disabled', 'disabled')->addItems($prototypeList);
$templateList->addRow(_('Item prototypes'), $listBox);
}
// Trigger prototypes
$hostTriggerPrototypes = API::TriggerPrototype()->get(['hostids' => $data['templateId'], 'discoveryids' => $hostDiscoveryRuleids, 'inherited' => false, 'output' => API_OUTPUT_EXTEND]);
if (!empty($hostTriggerPrototypes)) {
$prototypeList = [];
foreach ($hostTriggerPrototypes as $triggerPrototype) {
示例14: copyItemPrototypes
/**
* Copies all of the item prototypes from the source discovery to the target
* discovery rule.
*
* @throws APIException if prototype saving fails
*
* @param array $srcDiscovery The source discovery rule to copy from
* @param array $dstDiscovery The target discovery rule to copy to
* @param array $dstHost The target host to copy the deiscovery rule to
*
* @return array
*/
protected function copyItemPrototypes(array $srcDiscovery, array $dstDiscovery, array $dstHost)
{
$prototypes = API::ItemPrototype()->get(array('discoveryids' => $srcDiscovery['itemid'], 'selectApplications' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true));
$rs = array();
if ($prototypes) {
foreach ($prototypes as $key => $prototype) {
$prototype['ruleid'] = $dstDiscovery['itemid'];
$prototype['hostid'] = $dstDiscovery['hostid'];
unset($prototype['templateid']);
// map prototype interfaces
if ($dstHost['status'] != HOST_STATUS_TEMPLATE) {
// find a matching interface
$interface = self::findInterfaceForItem($prototype, $dstHost['interfaces']);
if ($interface) {
$prototype['interfaceid'] = $interface['interfaceid'];
} elseif ($interface !== false) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Cannot find host interface on "%1$s" for item key "%2$s".', $dstHost['name'], $prototype['key_']));
}
}
// add new applications
$prototype['applications'] = get_same_applications_for_host(zbx_objectValues($prototype['applications'], 'applicationid'), $dstHost['hostid']);
$prototypes[$key] = $prototype;
}
$rs = API::ItemPrototype()->create($prototypes);
if (!$rs) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot clone item prototypes.'));
}
}
return $rs;
}
示例15: foreach
$hostDiscoveryRules = API::DiscoveryRule()->get(['output' => ['itemid', 'hostid', 'key_', 'name'], 'hostids' => [$data['clone_hostid']], 'inherited' => false]);
if ($hostDiscoveryRules) {
$hostDiscoveryRules = CMacrosResolverHelper::resolveItemNames($hostDiscoveryRules);
$discoveryRuleList = [];
foreach ($hostDiscoveryRules as $discoveryRule) {
$discoveryRuleList[$discoveryRule['itemid']] = $discoveryRule['name_expanded'];
}
order_result($discoveryRuleList);
$hostDiscoveryRuleIds = array_keys($discoveryRuleList);
$listBox = new CListBox('discoveryRules', null, 8);
$listBox->setAttribute('disabled', 'disabled');
$listBox->addItems($discoveryRuleList);
$hostList->addRow(_('Discovery rules'), $listBox);
}
// item prototypes
$hostItemPrototypes = API::ItemPrototype()->get(['output' => ['itemid', 'hostid', 'key_', 'name'], 'hostids' => [$data['clone_hostid']], 'discoveryids' => $hostDiscoveryRuleIds, 'inherited' => false]);
if ($hostItemPrototypes) {
$hostItemPrototypes = CMacrosResolverHelper::resolveItemNames($hostItemPrototypes);
$prototypeList = [];
foreach ($hostItemPrototypes as $itemPrototype) {
$prototypeList[$itemPrototype['itemid']] = $itemPrototype['name_expanded'];
}
order_result($prototypeList);
$listBox = new CListBox('itemsPrototypes', null, 8);
$listBox->setAttribute('disabled', 'disabled');
$listBox->addItems($prototypeList);
$hostList->addRow(_('Item prototypes'), $listBox);
}
// Trigger prototypes
$hostTriggerPrototypes = API::TriggerPrototype()->get(['output' => ['triggerid', 'description'], 'selectItems' => ['type'], 'hostids' => [$data['clone_hostid']], 'discoveryids' => $hostDiscoveryRuleIds, 'inherited' => false]);
if ($hostTriggerPrototypes) {