当前位置: 首页>>代码示例>>PHP>>正文


PHP API::TriggerPrototype方法代码示例

本文整理汇总了PHP中API::TriggerPrototype方法的典型用法代码示例。如果您正苦于以下问题:PHP API::TriggerPrototype方法的具体用法?PHP API::TriggerPrototype怎么用?PHP API::TriggerPrototype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在API的用法示例。


在下文中一共展示了API::TriggerPrototype方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: unlink

 /**
  * Unlinks the templates from the given hosts. If $tragetids is set to null, the templates will be unlinked from
  * all hosts.
  *
  * @param array      $templateids
  * @param null|array $targetids		the IDs of the hosts to unlink the templates from
  * @param bool       $clear			delete all of the inherited objects from the hosts
  */
 protected function unlink($templateids, $targetids = null, $clear = false)
 {
     $flags = $clear ? array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_RULE) : array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_RULE, ZBX_FLAG_DISCOVERY_PROTOTYPE);
     // check that all triggers on templates that we unlink, don't have items from another templates
     $sql = 'SELECT DISTINCT t.description' . ' FROM triggers t,functions f,items i' . ' WHERE t.triggerid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND ' . dbConditionInt('i.hostid', $templateids) . ' AND EXISTS (' . 'SELECT ff.triggerid' . ' FROM functions ff,items ii' . ' WHERE ff.itemid=ii.itemid' . ' AND ff.triggerid=t.triggerid' . ' AND ' . dbConditionInt('ii.hostid', $templateids, true) . ')' . ' AND t.flags=' . ZBX_FLAG_DISCOVERY_NORMAL;
     if ($dbTrigger = DBfetch(DBSelect($sql, 1))) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _s('Cannot unlink trigger "%s", it has items from template that is left linked to host.', $dbTrigger['description']));
     }
     $sqlFrom = ' triggers t,hosts h';
     $sqlWhere = ' EXISTS (' . 'SELECT ff.triggerid' . ' FROM functions ff,items ii' . ' WHERE ff.triggerid=t.templateid' . ' AND ii.itemid=ff.itemid' . ' AND ' . dbConditionInt('ii.hostid', $templateids) . ')' . ' AND ' . dbConditionInt('t.flags', $flags);
     if (!is_null($targetids)) {
         $sqlFrom = ' triggers t,functions f,items i,hosts h';
         $sqlWhere .= ' AND ' . dbConditionInt('i.hostid', $targetids) . ' AND f.itemid=i.itemid' . ' AND t.triggerid=f.triggerid' . ' AND h.hostid=i.hostid';
     }
     $sql = 'SELECT DISTINCT t.triggerid,t.description,t.flags,t.expression,h.name as host' . ' FROM ' . $sqlFrom . ' WHERE ' . $sqlWhere;
     $dbTriggers = DBSelect($sql);
     $triggers = array(ZBX_FLAG_DISCOVERY_NORMAL => array(), ZBX_FLAG_DISCOVERY_PROTOTYPE => array());
     $triggerids = array();
     while ($trigger = DBfetch($dbTriggers)) {
         $triggers[$trigger['flags']][$trigger['triggerid']] = array('description' => $trigger['description'], 'expression' => explode_exp($trigger['expression']), 'triggerid' => $trigger['triggerid'], 'host' => $trigger['host']);
         if (!in_array($trigger['triggerid'], $triggerids)) {
             array_push($triggerids, $trigger['triggerid']);
         }
     }
     if (!empty($triggers[ZBX_FLAG_DISCOVERY_NORMAL])) {
         if ($clear) {
             $result = API::Trigger()->delete(array_keys($triggers[ZBX_FLAG_DISCOVERY_NORMAL]), true);
             if (!$result) {
                 self::exception(ZBX_API_ERROR_INTERNAL, _('Cannot unlink and clear triggers'));
             }
         } else {
             DB::update('triggers', array('values' => array('templateid' => 0), 'where' => array('triggerid' => array_keys($triggers[ZBX_FLAG_DISCOVERY_NORMAL]))));
             foreach ($triggers[ZBX_FLAG_DISCOVERY_NORMAL] as $trigger) {
                 info(_s('Unlinked: Trigger "%1$s" on "%2$s".', $trigger['description'], $trigger['host']));
             }
         }
     }
     if (!empty($triggers[ZBX_FLAG_DISCOVERY_PROTOTYPE])) {
         if ($clear) {
             $result = API::TriggerPrototype()->delete(array_keys($triggers[ZBX_FLAG_DISCOVERY_PROTOTYPE]), true);
             if (!$result) {
                 self::exception(ZBX_API_ERROR_INTERNAL, _('Cannot unlink and clear triggers'));
             }
         } else {
             DB::update('triggers', array('values' => array('templateid' => 0), 'where' => array('triggerid' => array_keys($triggers[ZBX_FLAG_DISCOVERY_PROTOTYPE]))));
             foreach ($triggers[ZBX_FLAG_DISCOVERY_PROTOTYPE] as $trigger) {
                 info(_s('Unlinked: Trigger prototype "%1$s" on "%2$s".', $trigger['description'], $trigger['host']));
             }
         }
     }
     /* ITEMS, DISCOVERY RULES {{{ */
     $sqlFrom = ' items i1,items i2,hosts h';
     $sqlWhere = ' i2.itemid=i1.templateid' . ' AND ' . dbConditionInt('i2.hostid', $templateids) . ' AND ' . dbConditionInt('i1.flags', $flags) . ' AND h.hostid=i1.hostid';
     if (!is_null($targetids)) {
         $sqlWhere .= ' AND ' . dbConditionInt('i1.hostid', $targetids);
     }
     $sql = 'SELECT DISTINCT i1.itemid,i1.flags,i1.name,i1.hostid,h.name as host' . ' FROM ' . $sqlFrom . ' WHERE ' . $sqlWhere;
     $dbItems = DBSelect($sql);
     $items = array(ZBX_FLAG_DISCOVERY_NORMAL => array(), ZBX_FLAG_DISCOVERY_RULE => array(), ZBX_FLAG_DISCOVERY_PROTOTYPE => array());
     while ($item = DBfetch($dbItems)) {
         $items[$item['flags']][$item['itemid']] = array('name' => $item['name'], 'host' => $item['host']);
     }
     if (!empty($items[ZBX_FLAG_DISCOVERY_RULE])) {
         if ($clear) {
             $result = API::DiscoveryRule()->delete(array_keys($items[ZBX_FLAG_DISCOVERY_RULE]), true);
             if (!$result) {
                 self::exception(ZBX_API_ERROR_INTERNAL, _('Cannot unlink and clear discovery rules'));
             }
         } else {
             DB::update('items', array('values' => array('templateid' => 0), 'where' => array('itemid' => array_keys($items[ZBX_FLAG_DISCOVERY_RULE]))));
             foreach ($items[ZBX_FLAG_DISCOVERY_RULE] as $discoveryRule) {
                 info(_s('Unlinked: Discovery rule "%1$s" on "%2$s".', $discoveryRule['name'], $discoveryRule['host']));
             }
         }
     }
     if (!empty($items[ZBX_FLAG_DISCOVERY_NORMAL])) {
         if ($clear) {
             $result = API::Item()->delete(array_keys($items[ZBX_FLAG_DISCOVERY_NORMAL]), true);
             if (!$result) {
                 self::exception(ZBX_API_ERROR_INTERNAL, _('Cannot unlink and clear items'));
             }
         } else {
             DB::update('items', array('values' => array('templateid' => 0), 'where' => array('itemid' => array_keys($items[ZBX_FLAG_DISCOVERY_NORMAL]))));
             foreach ($items[ZBX_FLAG_DISCOVERY_NORMAL] as $item) {
                 info(_s('Unlinked: Item "%1$s" on "%2$s".', $item['name'], $item['host']));
             }
         }
     }
     if (!empty($items[ZBX_FLAG_DISCOVERY_PROTOTYPE])) {
         if ($clear) {
             $result = API::Itemprototype()->delete(array_keys($items[ZBX_FLAG_DISCOVERY_PROTOTYPE]), true);
             if (!$result) {
//.........这里部分代码省略.........
开发者ID:omidmt,项目名称:zabbix-greenplum,代码行数:101,代码来源:CHostGeneral.php

示例2: 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;
 }
开发者ID:SandipSingh14,项目名称:Zabbix_,代码行数:70,代码来源:CConfigurationExport.php

示例3: delete

 /**
  * Delete items.
  *
  * @param array $itemIds
  * @param bool  $noPermissions
  *
  * @return array
  */
 public function delete(array $itemIds, $noPermissions = false)
 {
     if (!$itemIds) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty input parameter.'));
     }
     $itemIds = array_keys(array_flip($itemIds));
     $delItems = $this->get(array('output' => array('name', 'templateid'), 'selectHosts' => array('name'), 'itemids' => $itemIds, 'editable' => true, 'preservekeys' => true));
     // TODO: remove $nopermissions hack
     if (!$noPermissions) {
         foreach ($itemIds as $itemId) {
             if (!isset($delItems[$itemId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
             }
             if ($delItems[$itemId]['templateid'] != 0) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot delete templated item.'));
             }
         }
     }
     // first delete child items
     $parentItemIds = $itemIds;
     do {
         $dbItems = DBselect('SELECT i.itemid FROM items i WHERE ' . dbConditionInt('i.templateid', $parentItemIds));
         $parentItemIds = array();
         while ($dbItem = DBfetch($dbItems)) {
             $parentItemIds[] = $dbItem['itemid'];
             $itemIds[$dbItem['itemid']] = $dbItem['itemid'];
         }
     } while ($parentItemIds);
     // delete graphs, leave if graph still have item
     $delGraphs = array();
     $dbGraphs = DBselect('SELECT gi.graphid' . ' FROM graphs_items gi' . ' WHERE ' . dbConditionInt('gi.itemid', $itemIds) . ' AND NOT EXISTS (' . 'SELECT NULL' . ' FROM graphs_items gii' . ' WHERE gii.graphid=gi.graphid' . ' AND ' . dbConditionInt('gii.itemid', $itemIds, true) . ')');
     while ($dbGraph = DBfetch($dbGraphs)) {
         $delGraphs[$dbGraph['graphid']] = $dbGraph['graphid'];
     }
     if ($delGraphs) {
         API::Graph()->delete($delGraphs, true);
     }
     // check if any graphs are referencing this item
     $this->checkGraphReference($itemIds);
     $triggers = API::Trigger()->get(array('output' => array(), 'itemids' => $itemIds, 'nopermissions' => true, 'preservekeys' => true));
     if ($triggers) {
         API::Trigger()->delete(array_keys($triggers), true);
     }
     $triggerPrototypes = API::TriggerPrototype()->get(array('output' => array(), 'itemids' => $itemIds, 'nopermissions' => true, 'preservekeys' => true));
     if ($triggerPrototypes) {
         API::TriggerPrototype()->delete(array_keys($triggerPrototypes), true);
     }
     DB::delete('screens_items', array('resourceid' => $itemIds, 'resourcetype' => array(SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_PLAIN_TEXT, SCREEN_RESOURCE_CLOCK)));
     DB::delete('items', array('itemid' => $itemIds));
     DB::delete('profiles', array('idx' => 'web.favorite.graphids', 'source' => 'itemid', 'value_id' => $itemIds));
     $itemDataTables = array('trends', 'trends_uint', 'history_text', 'history_log', 'history_uint', 'history_str', 'history');
     $insert = array();
     foreach ($itemIds as $itemId) {
         foreach ($itemDataTables as $table) {
             $insert[] = array('tablename' => $table, 'field' => 'itemid', 'value' => $itemId);
         }
     }
     DB::insert('housekeeper', $insert);
     // TODO: remove info from API
     foreach ($delItems as $item) {
         $host = reset($item['hosts']);
         info(_s('Deleted: Item "%1$s" on "%2$s".', $item['name'], $host['name']));
     }
     return array('itemids' => $itemIds);
 }
开发者ID:omidmt,项目名称:zabbix-greenplum,代码行数:73,代码来源:CItem.php

示例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();
     }
     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;
 }
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:50,代码来源:CConfigurationExport.php

示例5: array

 }
 // 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();
     foreach ($hostTriggerPrototypes as $triggerPrototype) {
         // skip trigger prototypes with web items
         if (httpItemExists($triggerPrototype['items'])) {
             continue;
         }
         $prototypeList[$triggerPrototype['triggerid']] = $triggerPrototype['description'];
     }
     if ($prototypeList) {
         order_result($prototypeList);
         $listBox = new CListBox('triggerprototypes', null, 8);
         $listBox->setAttribute('disabled', 'disabled');
         $listBox->addItems($prototypeList);
         $hostList->addRow(_('Trigger prototypes'), $listBox);
开发者ID:SandipSingh14,项目名称:Zabbix_,代码行数:31,代码来源:configuration.host.edit.php

示例6: delete

 /**
  * Delete Item prototypes.
  *
  * @param int|string|array $prototypeids
  * @param bool             $nopermissions
  *
  * @return array
  */
 public function delete($prototypeids, $nopermissions = false)
 {
     if (empty($prototypeids)) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty input parameter.'));
     }
     $prototypeids = zbx_toHash($prototypeids);
     $options = array('itemids' => $prototypeids, 'editable' => true, 'preservekeys' => true, 'output' => API_OUTPUT_EXTEND, 'selectHosts' => array('name'));
     $delItemPrototypes = $this->get($options);
     // TODO: remove $nopermissions hack
     if (!$nopermissions) {
         foreach ($prototypeids as $prototypeid) {
             if (!isset($delItemPrototypes[$prototypeid])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
             }
             if ($delItemPrototypes[$prototypeid]['templateid'] != 0) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot delete templated items'));
             }
         }
     }
     // first delete child items
     $parentItemids = $prototypeids;
     $childPrototypeids = array();
     do {
         $dbItems = DBselect('SELECT itemid FROM items WHERE ' . dbConditionInt('templateid', $parentItemids));
         $parentItemids = array();
         while ($dbItem = DBfetch($dbItems)) {
             $parentItemids[$dbItem['itemid']] = $dbItem['itemid'];
             $childPrototypeids[$dbItem['itemid']] = $dbItem['itemid'];
         }
     } while (!empty($parentItemids));
     $options = array('output' => API_OUTPUT_EXTEND, 'itemids' => $childPrototypeids, 'nopermissions' => true, 'preservekeys' => true, 'selectHosts' => array('name'));
     $delItemPrototypesChilds = $this->get($options);
     $delItemPrototypes = array_merge($delItemPrototypes, $delItemPrototypesChilds);
     $prototypeids = array_merge($prototypeids, $childPrototypeids);
     // delete graphs with this item prototype
     $delGraphPrototypes = API::GraphPrototype()->get(array('itemids' => $prototypeids, 'output' => API_OUTPUT_SHORTEN, 'nopermissions' => true, 'preservekeys' => true));
     if (!empty($delGraphPrototypes)) {
         $result = API::GraphPrototype()->delete(zbx_objectValues($delGraphPrototypes, 'graphid'), true);
         if (!$result) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot delete graph prototype'));
         }
     }
     // check if any graphs are referencing this item
     $this->checkGraphReference($prototypeids);
     // CREATED ITEMS
     $createdItems = array();
     $sql = 'SELECT itemid FROM item_discovery WHERE ' . dbConditionInt('parent_itemid', $prototypeids);
     $dbItems = DBselect($sql);
     while ($item = DBfetch($dbItems)) {
         $createdItems[$item['itemid']] = $item['itemid'];
     }
     if (!empty($createdItems)) {
         $result = API::Item()->delete($createdItems, true);
         if (!$result) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot delete items created by low level discovery.'));
         }
     }
     // TRIGGER PROTOTYPES
     $delTriggerPrototypes = API::TriggerPrototype()->get(array('itemids' => $prototypeids, 'output' => API_OUTPUT_SHORTEN, 'nopermissions' => true, 'preservekeys' => true));
     if (!empty($delTriggerPrototypes)) {
         $result = API::TriggerPrototype()->delete(zbx_objectValues($delTriggerPrototypes, 'triggerid'), true);
         if (!$result) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot delete trigger prototype'));
         }
     }
     // ITEM PROTOTYPES
     DB::delete('items', array('itemid' => $prototypeids));
     // TODO: remove info from API
     foreach ($delItemPrototypes as $item) {
         $host = reset($item['hosts']);
         info(_s('Deleted: Item prototype "%1$s" on "%2$s".', $item['name'], $host['name']));
     }
     return array('prototypeids' => $prototypeids);
 }
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:82,代码来源:CItemPrototype.php

示例7: array

 }
 // item prototypes
 $hostItemPrototypes = API::ItemPrototype()->get(array('hostids' => $_REQUEST['hostid'], 'discoveryids' => $hostDiscoveryRuleids, 'inherited' => false, 'output' => API_OUTPUT_EXTEND));
 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' => API_OUTPUT_EXTEND, 'selectItems' => API_OUTPUT_EXTEND));
 if (!empty($hostTriggerPrototypes)) {
     $prototypeList = array();
     foreach ($hostTriggerPrototypes as $triggerPrototype) {
         // skip trigger prototypes with web items
         if (httpItemExists($triggerPrototype['items'])) {
             continue;
         }
         $prototypeList[$triggerPrototype['triggerid']] = $triggerPrototype['description'];
     }
     if ($prototypeList) {
         order_result($prototypeList);
         $listBox = new CListBox('triggerprototypes', null, 8);
         $listBox->setAttribute('disabled', 'disabled');
         $listBox->addItems($prototypeList);
         $hostList->addRow(_('Trigger prototypes'), $listBox);
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:31,代码来源:configuration.host.edit.php

示例8: copyTriggerPrototypes

 /**
  * Copies all of the triggers from the source discovery to the target discovery rule.
  *
  * @throws APIException if trigger saving fails
  *
  * @param array $srcDiscovery    The source discovery rule to copy from
  * @param array $dstDiscovery    The target discovery rule to copy to
  * @param array $srcHost         The host the source discovery belongs to
  * @param array $dstHost         The host the target discovery belongs to
  *
  * @return array
  */
 protected function copyTriggerPrototypes(array $srcDiscovery, array $dstDiscovery, array $srcHost, array $dstHost)
 {
     $srcTriggers = API::TriggerPrototype()->get(array('discoveryids' => $srcDiscovery['itemid'], 'output' => API_OUTPUT_EXTEND, 'selectHosts' => API_OUTPUT_EXTEND, 'selectItems' => API_OUTPUT_EXTEND, 'selectDiscoveryRule' => API_OUTPUT_EXTEND, 'selectFunctions' => API_OUTPUT_EXTEND, 'preservekeys' => true));
     if (!$srcTriggers) {
         return array();
     }
     foreach ($srcTriggers as $id => $trigger) {
         // skip triggers with web items
         if (httpItemExists($trigger['items'])) {
             unset($srcTriggers[$id]);
             continue;
         }
     }
     // save new triggers
     $dstTriggers = $srcTriggers;
     foreach ($dstTriggers as $id => $trigger) {
         unset($dstTriggers[$id]['templateid']);
         unset($dstTriggers[$id]['triggerid']);
         // update expression
         $dstTriggers[$id]['expression'] = explode_exp($trigger['expression'], false, false, $srcHost['host'], $dstHost['host']);
     }
     $rs = API::TriggerPrototype()->create($dstTriggers);
     if (!$rs) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot clone trigger prototypes.'));
     }
     return $rs;
 }
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:39,代码来源:CDiscoveryRule.php

示例9: addRelatedObjects

 public function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     $itemids = array_keys($result);
     // adding applications
     if ($options['selectApplications'] !== null && $options['selectApplications'] != API_OUTPUT_COUNT) {
         $relationMap = $this->createRelationMap($result, 'itemid', 'applicationid', 'items_applications');
         $applications = API::Application()->get(['output' => $options['selectApplications'], 'applicationids' => $relationMap->getRelatedIds(), 'preservekeys' => true]);
         $result = $relationMap->mapMany($result, $applications, 'applications');
     }
     // adding application prototypes
     if ($options['selectApplicationPrototypes'] !== null && $options['selectApplicationPrototypes'] != API_OUTPUT_COUNT) {
         $pkFieldId = $this->pk('application_prototype');
         $outputFields = [$pkFieldId => $this->fieldId($pkFieldId, 'ap')];
         if (is_array($options['selectApplicationPrototypes'])) {
             foreach ($options['selectApplicationPrototypes'] as $field) {
                 if ($this->hasField($field, 'application_prototype')) {
                     $outputFields[$field] = $this->fieldId($field, 'ap');
                 }
             }
             $outputFields = implode(',', $outputFields);
         } else {
             $outputFields = 'ap.*';
         }
         $relationMap = $this->createRelationMap($result, 'itemid', 'application_prototypeid', 'item_application_prototype');
         $application_prototypes = DBfetchArray(DBselect('SELECT ' . $outputFields . ' FROM application_prototype ap' . ' WHERE ' . dbConditionInt('ap.application_prototypeid', $relationMap->getRelatedIds())));
         $application_prototypes = zbx_toHash($application_prototypes, 'application_prototypeid');
         $result = $relationMap->mapMany($result, $application_prototypes, 'applicationPrototypes');
     }
     // adding triggers
     if (!is_null($options['selectTriggers'])) {
         if ($options['selectTriggers'] != API_OUTPUT_COUNT) {
             $relationMap = $this->createRelationMap($result, 'itemid', 'triggerid', 'functions');
             $triggers = API::TriggerPrototype()->get(['output' => $options['selectTriggers'], 'triggerids' => $relationMap->getRelatedIds(), 'preservekeys' => true]);
             if (!is_null($options['limitSelects'])) {
                 order_result($triggers, 'description');
             }
             $result = $relationMap->mapMany($result, $triggers, 'triggers', $options['limitSelects']);
         } else {
             $triggers = API::TriggerPrototype()->get(['countOutput' => true, 'groupCount' => true, 'itemids' => $itemids]);
             $triggers = zbx_toHash($triggers, 'itemid');
             foreach ($result as $itemid => $item) {
                 if (isset($triggers[$itemid])) {
                     $result[$itemid]['triggers'] = $triggers[$itemid]['rowscount'];
                 } else {
                     $result[$itemid]['triggers'] = 0;
                 }
             }
         }
     }
     // adding graphs
     if (!is_null($options['selectGraphs'])) {
         if ($options['selectGraphs'] != API_OUTPUT_COUNT) {
             $relationMap = $this->createRelationMap($result, 'itemid', 'graphid', 'graphs_items');
             $graphs = API::GraphPrototype()->get(['output' => $options['selectGraphs'], 'graphids' => $relationMap->getRelatedIds(), 'preservekeys' => true]);
             if (!is_null($options['limitSelects'])) {
                 order_result($graphs, 'name');
             }
             $result = $relationMap->mapMany($result, $graphs, 'graphs', $options['limitSelects']);
         } else {
             $graphs = API::GraphPrototype()->get(['countOutput' => true, 'groupCount' => true, 'itemids' => $itemids]);
             $graphs = zbx_toHash($graphs, 'itemid');
             foreach ($result as $itemid => $item) {
                 if (isset($graphs[$itemid])) {
                     $result[$itemid]['graphs'] = $graphs[$itemid]['rowscount'];
                 } else {
                     $result[$itemid]['graphs'] = 0;
                 }
             }
         }
     }
     // adding discoveryrule
     if ($options['selectDiscoveryRule'] !== null && $options['selectDiscoveryRule'] != API_OUTPUT_COUNT) {
         $relationMap = $this->createRelationMap($result, 'itemid', 'parent_itemid', 'item_discovery');
         $discoveryRules = API::DiscoveryRule()->get(['output' => $options['selectDiscoveryRule'], 'itemids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true]);
         $result = $relationMap->mapOne($result, $discoveryRules, 'discoveryRule');
     }
     return $result;
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:79,代码来源:CItemPrototype.php

示例10: getTriggerFormData

function getTriggerFormData()
{
    $data = array('form' => get_request('form'), 'form_refresh' => get_request('form_refresh'), 'parent_discoveryid' => get_request('parent_discoveryid'), 'dependencies' => get_request('dependencies', array()), 'db_dependencies' => array(), 'triggerid' => get_request('triggerid'), 'expression' => get_request('expression', ''), 'expr_temp' => get_request('expr_temp', ''), 'description' => get_request('description', ''), 'type' => get_request('type', 0), 'priority' => get_request('priority', 0), 'status' => get_request('status', 0), 'comments' => get_request('comments', ''), 'url' => get_request('url', ''), 'input_method' => get_request('input_method', IM_ESTABLISHED), 'limited' => null, 'templates' => array(), 'hostid' => get_request('hostid', 0));
    if (!empty($data['triggerid'])) {
        // get trigger
        $options = array('output' => API_OUTPUT_EXTEND, 'selectHosts' => array('hostid'), 'triggerids' => $data['triggerid']);
        $trigger = $data['parent_discoveryid'] ? API::TriggerPrototype()->get($options) : API::Trigger()->get($options);
        $data['trigger'] = reset($trigger);
        // get templates
        $tmp_triggerid = $data['triggerid'];
        do {
            $db_triggers = DBfetch(DBselect('SELECT t.triggerid,t.templateid,id.parent_itemid,h.name,h.hostid' . ' FROM triggers t' . ' LEFT JOIN functions f ON t.triggerid=f.triggerid' . ' LEFT JOIN items i ON f.itemid=i.itemid' . ' LEFT JOIN hosts h ON i.hostid=h.hostid' . ' LEFT JOIN item_discovery id ON i.itemid=id.itemid' . ' WHERE t.triggerid=' . zbx_dbstr($tmp_triggerid)));
            if (bccomp($data['triggerid'], $tmp_triggerid) != 0) {
                // parent trigger prototype link
                if ($data['parent_discoveryid']) {
                    $link = 'trigger_prototypes.php?form=update&triggerid=' . $db_triggers['triggerid'] . '&parent_discoveryid=' . $db_triggers['parent_itemid'] . '&hostid=' . $db_triggers['hostid'];
                } else {
                    $link = 'triggers.php?form=update&triggerid=' . $db_triggers['triggerid'] . '&hostid=' . $db_triggers['hostid'];
                }
                $data['templates'][] = new CLink($db_triggers['name'], $link, 'highlight underline weight_normal');
                $data['templates'][] = SPACE . RARR . SPACE;
            }
            $tmp_triggerid = $db_triggers['templateid'];
        } while ($tmp_triggerid != 0);
        $data['templates'] = array_reverse($data['templates']);
        array_shift($data['templates']);
        $data['limited'] = $data['trigger']['templateid'] ? 'yes' : null;
        // if no host has been selected for the navigation panel, use the first trigger host
        if (!$data['hostid']) {
            $hosts = reset($data['trigger']['hosts']);
            $data['hostid'] = $hosts['hostid'];
        }
    }
    if (!empty($data['triggerid']) && !isset($_REQUEST['form_refresh']) || !empty($data['limited'])) {
        $data['expression'] = explode_exp($data['trigger']['expression']);
        if (empty($data['limited']) || !isset($_REQUEST['form_refresh'])) {
            $data['description'] = $data['trigger']['description'];
            $data['type'] = $data['trigger']['type'];
            $data['priority'] = $data['trigger']['priority'];
            $data['status'] = $data['trigger']['status'];
            $data['comments'] = $data['trigger']['comments'];
            $data['url'] = $data['trigger']['url'];
            $db_triggers = DBselect('SELECT t.triggerid,t.description' . ' FROM triggers t,trigger_depends d' . ' WHERE t.triggerid=d.triggerid_up' . ' AND d.triggerid_down=' . zbx_dbstr($data['triggerid']));
            while ($trigger = DBfetch($db_triggers)) {
                if (uint_in_array($trigger['triggerid'], $data['dependencies'])) {
                    continue;
                }
                array_push($data['dependencies'], $trigger['triggerid']);
            }
        }
    }
    if ($data['input_method'] == IM_TREE) {
        $analyze = analyzeExpression($data['expression']);
        if ($analyze !== false) {
            list($data['outline'], $data['eHTMLTree']) = $analyze;
            if (isset($_REQUEST['expr_action']) && $data['eHTMLTree'] != null) {
                $new_expr = remakeExpression($data['expression'], $_REQUEST['expr_target_single'], $_REQUEST['expr_action'], $data['expr_temp']);
                if ($new_expr !== false) {
                    $data['expression'] = $new_expr;
                    $analyze = analyzeExpression($data['expression']);
                    if ($analyze !== false) {
                        list($data['outline'], $data['eHTMLTree']) = $analyze;
                    } else {
                        show_messages(false, '', _('Expression Syntax Error.'));
                    }
                    $data['expr_temp'] = '';
                } else {
                    show_messages(false, '', _('Expression Syntax Error.'));
                }
            }
            $data['expression_field_name'] = 'expr_temp';
            $data['expression_field_value'] = $data['expr_temp'];
            $data['expression_field_readonly'] = 'yes';
            $data['expression_field_params'] = 'this.form.elements["' . $data['expression_field_name'] . '"].value';
            $data['expression_macro_button'] = new CButton('insert_macro', _('Insert macro'), 'return call_ins_macro_menu(event);', 'formlist');
            if ($data['limited'] == 'yes') {
                $data['expression_macro_button']->setAttribute('disabled', 'disabled');
            }
        } else {
            show_messages(false, '', _('Expression Syntax Error.'));
            $data['input_method'] = IM_ESTABLISHED;
        }
    }
    if ($data['input_method'] != IM_TREE) {
        $data['expression_field_name'] = 'expression';
        $data['expression_field_value'] = $data['expression'];
        $data['expression_field_readonly'] = $data['limited'];
    }
    if (empty($data['parent_discoveryid'])) {
        $data['db_dependencies'] = API::Trigger()->get(array('triggerids' => $data['dependencies'], 'output' => array('triggerid', 'description'), 'preservekeys' => true, 'selectHosts' => array('name')));
        foreach ($data['db_dependencies'] as &$dependency) {
            if (!empty($dependency['hosts'][0]['name'])) {
                $dependency['host'] = $dependency['hosts'][0]['name'];
            }
            unset($dependency['hosts']);
        }
        order_result($data['db_dependencies'], 'description');
    }
    return $data;
}
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:100,代码来源:forms.inc.php

示例11: CView

 * Display
 */
if ($_REQUEST['go'] == 'massupdate' && isset($_REQUEST['g_triggerid'])) {
    $triggersView = new CView('configuration.triggers.massupdate', getTriggerMassupdateFormData());
    $triggersView->render();
    $triggersView->show();
} elseif (isset($_REQUEST['form'])) {
    $triggersView = new CView('configuration.triggers.edit', getTriggerFormData());
    $triggersView->render();
    $triggersView->show();
} else {
    $data = array('parent_discoveryid' => get_request('parent_discoveryid'), 'discovery_rule' => $discovery_rule, 'hostid' => get_request('hostid'), 'showdisabled' => get_request('showdisabled', 1), 'triggers' => array());
    CProfile::update('web.triggers.showdisabled', $data['showdisabled'], PROFILE_TYPE_INT);
    // get triggers
    $sortfield = getPageSortField('description');
    $options = array('editable' => true, 'output' => API_OUTPUT_SHORTEN, 'discoveryids' => $data['parent_discoveryid'], 'sortfield' => $sortfield, 'limit' => $config['search_limit'] + 1);
    if (empty($data['showdisabled'])) {
        $options['filter']['status'] = TRIGGER_STATUS_ENABLED;
    }
    $data['triggers'] = API::TriggerPrototype()->get($options);
    $data['paging'] = getPagingLine($data['triggers']);
    $data['triggers'] = API::TriggerPrototype()->get(array('triggerids' => zbx_objectValues($data['triggers'], 'triggerid'), 'output' => API_OUTPUT_EXTEND, 'selectHosts' => API_OUTPUT_EXTEND, 'selectItems' => API_OUTPUT_EXTEND, 'selectFunctions' => API_OUTPUT_EXTEND));
    order_result($data['triggers'], $sortfield, getPageSortOrder());
    // get real hosts
    $data['realHosts'] = getParentHostsByTriggers($data['triggers']);
    // render view
    $triggersView = new CView('configuration.triggers.list', $data);
    $triggersView->render();
    $triggersView->show();
}
require_once dirname(__FILE__) . '/include/page_footer.php';
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:31,代码来源:trigger_prototypes.php

示例12: CListBox

 $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) {
         $prototypeList[$triggerPrototype['triggerid']] = $triggerPrototype['description'];
     }
     order_result($prototypeList);
     $listBox = (new CListBox('triggerprototypes', null, 8))->setAttribute('disabled', 'disabled')->addItems($prototypeList);
     $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'];
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:31,代码来源:configuration.template.edit.php

示例13: CForm

 $form = (new CForm())->setName('triggerform')->setId('triggers');
 $table = (new CTableInfo())->setHeader([$multiselect ? (new CColHeader((new CCheckBox('all_triggers'))->onClick("checkAll('" . $form->getName() . "', 'all_triggers', 'triggers');")))->addClass(ZBX_STYLE_CELL_WIDTH) : null, _('Name'), _('Severity'), _('Status')]);
 $options = ['output' => ['triggerid', 'expression', 'description', 'status', 'priority', 'state'], 'selectHosts' => ['name'], 'selectDependencies' => ['triggerid', 'expression', 'description'], 'expandDescription' => true];
 if ($srctbl === 'trigger_prototypes') {
     if ($parentDiscoveryId) {
         $options['discoveryids'] = [$parentDiscoveryId];
     } else {
         $options['hostids'] = [$hostid];
     }
     if ($writeonly !== null) {
         $options['editable'] = true;
     }
     if ($templated !== null) {
         $options['templated'] = $templated;
     }
     $triggers = API::TriggerPrototype()->get($options);
 } else {
     if ($hostid === null) {
         $options['groupids'] = $groupid;
     } else {
         $options['hostids'] = [$hostid];
     }
     if ($writeonly !== null) {
         $options['editable'] = true;
     }
     if ($templated !== null) {
         $options['templated'] = $templated;
     }
     if ($withMonitoredTriggers) {
         $options['monitored'] = true;
     }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:31,代码来源:popup.php

示例14: array

 // 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)) {
     $prototypeList = array();
     foreach ($hostTriggerPrototypes as $triggerPrototype) {
         $prototypeList[$triggerPrototype['triggerid']] = $triggerPrototype['description'];
     }
     order_result($prototypeList);
     $listBox = new CListBox('triggerprototypes', null, 8);
     $listBox->setAttribute('disabled', 'disabled');
     $listBox->addItems($prototypeList);
     $templateList->addRow(_('Trigger prototypes'), $listBox);
 }
 // Graph prototypes
 $hostGraphPrototypes = API::GraphPrototype()->get(array('hostids' => $templateid, 'discoveryids' => $hostDiscoveryRuleids, 'inherited' => false, 'output' => API_OUTPUT_EXTEND));
 if (!empty($hostGraphPrototypes)) {
     $prototypeList = array();
开发者ID:itnihao,项目名称:zatree-2.2,代码行数:31,代码来源:configuration.template.edit.php

示例15: 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']];
                 }
//.........这里部分代码省略.........
开发者ID:TonywalkerCN,项目名称:Zabbix,代码行数:101,代码来源:CDiscoveryRule.php


注:本文中的API::TriggerPrototype方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。