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


PHP API::DiscoveryRule方法代码示例

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


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

示例1: get

 /**
  * Get TriggerPrototypes data
  *
  * @param array $options
  * @param array $options['itemids']
  * @param array $options['hostids']
  * @param array $options['groupids']
  * @param array $options['triggerids']
  * @param array $options['applicationids']
  * @param array $options['status']
  * @param array $options['editable']
  * @param array $options['count']
  * @param array $options['pattern']
  * @param array $options['limit']
  * @param array $options['order']
  * @return array|int item data as array or false if error
  */
 public function get(array $options = array())
 {
     $result = array();
     $userType = self::$userData['type'];
     $userid = self::$userData['userid'];
     // allowed columns for sorting
     $sortColumns = array('triggerid', 'description', 'status', 'priority');
     // allowed output options for [ select_* ] params
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
     $sqlParts = array('select' => array('triggers' => 't.triggerid'), 'from' => array('t' => 'triggers t'), 'where' => array('t.flags=' . ZBX_FLAG_DISCOVERY_CHILD), 'group' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'groupids' => null, 'templateids' => null, 'hostids' => null, 'triggerids' => null, 'itemids' => null, 'applicationids' => null, 'discoveryids' => null, 'functions' => null, 'inherited' => null, 'templated' => null, 'monitored' => null, 'active' => null, 'maintenance' => null, 'nopermissions' => null, 'editable' => null, 'group' => null, 'host' => null, 'min_severity' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'expandExpression' => null, 'expandData' => null, 'output' => API_OUTPUT_REFER, 'selectGroups' => null, 'selectHosts' => null, 'selectItems' => null, 'selectFunctions' => null, 'selectDiscoveryRule' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null, 'limitSelects' => null);
     $options = zbx_array_merge($defOptions, $options);
     if (is_array($options['output'])) {
         unset($sqlParts['select']['triggers']);
         $dbTable = DB::getSchema('triggers');
         $sqlParts['select']['triggerid'] = 't.triggerid';
         foreach ($options['output'] as $field) {
             if (isset($dbTable['fields'][$field])) {
                 $sqlParts['select'][$field] = 't.' . $field;
             }
         }
         // ignore the "expandExpression" parameter if the expression is not requested
         if ($options['expandExpression'] !== null && !str_in_array('expression', $options['output'])) {
             $options['expandExpression'] = null;
         }
         $options['output'] = API_OUTPUT_CUSTOM;
     }
     // editable + permission check
     if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
         $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY;
         $userGroups = getUserGroupsByUserId($userid);
         $sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM functions f,items i,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE t.triggerid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY f.triggerid' . ' HAVING MIN(r.permission)>=' . $permission . ')';
     }
     // nodeids
     $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
     // groupids
     if (!is_null($options['groupids'])) {
         zbx_value2array($options['groupids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['groupid'] = 'hg.groupid';
         }
         $sqlParts['from']['functions'] = 'functions f';
         $sqlParts['from']['items'] = 'items i';
         $sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
         $sqlParts['where']['hgi'] = 'hg.hostid=i.hostid';
         $sqlParts['where']['ft'] = 'f.triggerid=t.triggerid';
         $sqlParts['where']['fi'] = 'f.itemid=i.itemid';
         $sqlParts['where']['groupid'] = dbConditionInt('hg.groupid', $options['groupids']);
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['hg'] = 'hg.groupid';
         }
     }
     // templateids
     if (!is_null($options['templateids'])) {
         zbx_value2array($options['templateids']);
         if (!is_null($options['hostids'])) {
             zbx_value2array($options['hostids']);
             $options['hostids'] = array_merge($options['hostids'], $options['templateids']);
         } else {
             $options['hostids'] = $options['templateids'];
         }
     }
     // hostids
     if (!is_null($options['hostids'])) {
         zbx_value2array($options['hostids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['hostid'] = 'i.hostid';
         }
         $sqlParts['from']['functions'] = 'functions f';
         $sqlParts['from']['items'] = 'items i';
         $sqlParts['where']['hostid'] = dbConditionInt('i.hostid', $options['hostids']);
         $sqlParts['where']['ft'] = 'f.triggerid=t.triggerid';
         $sqlParts['where']['fi'] = 'f.itemid=i.itemid';
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['i'] = 'i.hostid';
         }
     }
     // triggerids
     if (!is_null($options['triggerids'])) {
         zbx_value2array($options['triggerids']);
         $sqlParts['where']['triggerid'] = dbConditionInt('t.triggerid', $options['triggerids']);
     }
     // itemids
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CTriggerPrototype.php

示例2: dirname

require_once dirname(__FILE__) . '/include/config.inc.php';
require_once dirname(__FILE__) . '/include/hosts.inc.php';
require_once dirname(__FILE__) . '/include/items.inc.php';
require_once dirname(__FILE__) . '/include/forms.inc.php';
$page['title'] = _('Configuration of item prototypes');
$page['file'] = 'disc_prototypes.php';
$page['scripts'] = ['effects.js', 'class.cviewswitcher.js', 'items.js'];
require_once dirname(__FILE__) . '/include/page_header.php';
$paramsFieldName = getParamFieldNameByType(getRequest('type', 0));
// VAR	TYPE	OPTIONAL	FLAGS	VALIDATION	EXCEPTION
$fields = ['parent_discoveryid' => [T_ZBX_INT, O_MAND, P_SYS, DB_ID, null], 'itemid' => [T_ZBX_INT, O_OPT, P_SYS, DB_ID, '(isset({form}) && ({form} == "update"))'], 'interfaceid' => [T_ZBX_INT, O_OPT, P_SYS, DB_ID, null, _('Interface')], 'name' => [T_ZBX_STR, O_OPT, null, NOT_EMPTY, 'isset({add}) || isset({update})', _('Name')], 'description' => [T_ZBX_STR, O_OPT, null, null, 'isset({add}) || isset({update})'], 'key' => [T_ZBX_STR, O_OPT, null, NOT_EMPTY, 'isset({add}) || isset({update})', _('Key')], 'delay' => [T_ZBX_INT, O_OPT, null, BETWEEN(0, SEC_PER_DAY), '(isset({add}) || isset({update}))' . ' && (isset({type}) && ({type} != ' . ITEM_TYPE_TRAPPER . ' && {type} != ' . ITEM_TYPE_SNMPTRAP . '))', _('Update interval (in sec)')], 'delay_flex' => [T_ZBX_STR, O_OPT, null, null, null], 'status' => [T_ZBX_INT, O_OPT, null, IN(ITEM_STATUS_ACTIVE), null], 'type' => [T_ZBX_INT, O_OPT, null, IN([-1, ITEM_TYPE_ZABBIX, ITEM_TYPE_SNMPV1, ITEM_TYPE_TRAPPER, ITEM_TYPE_SIMPLE, ITEM_TYPE_SNMPV2C, ITEM_TYPE_INTERNAL, ITEM_TYPE_SNMPV3, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_AGGREGATE, ITEM_TYPE_EXTERNAL, ITEM_TYPE_DB_MONITOR, ITEM_TYPE_IPMI, ITEM_TYPE_SSH, ITEM_TYPE_TELNET, ITEM_TYPE_JMX, ITEM_TYPE_CALCULATED, ITEM_TYPE_SNMPTRAP]), 'isset({add}) || isset({update})'], 'value_type' => [T_ZBX_INT, O_OPT, null, IN('0,1,2,3,4'), 'isset({add}) || isset({update})'], 'data_type' => [T_ZBX_INT, O_OPT, null, IN(ITEM_DATA_TYPE_DECIMAL . ',' . ITEM_DATA_TYPE_OCTAL . ',' . ITEM_DATA_TYPE_HEXADECIMAL . ',' . ITEM_DATA_TYPE_BOOLEAN), '(isset({add}) || isset({update})) && (isset({value_type}) && ({value_type} == ' . ITEM_VALUE_TYPE_UINT64 . '))'], 'valuemapid' => [T_ZBX_INT, O_OPT, null, DB_ID, '(isset({add}) || isset({update})) && isset({value_type})' . ' && ' . IN(ITEM_VALUE_TYPE_FLOAT . ',' . ITEM_VALUE_TYPE_UINT64, 'value_type')], 'authtype' => [T_ZBX_INT, O_OPT, null, IN(ITEM_AUTHTYPE_PASSWORD . ',' . ITEM_AUTHTYPE_PUBLICKEY), '(isset({add}) || isset({update})) && isset({type}) && ({type} == ' . ITEM_TYPE_SSH . ')'], 'username' => [T_ZBX_STR, O_OPT, null, NOT_EMPTY, '(isset({add}) || isset({update})) && isset({type}) && ' . IN(ITEM_TYPE_SSH . ',' . ITEM_TYPE_TELNET, 'type'), _('User name')], 'password' => [T_ZBX_STR, O_OPT, null, null, '(isset({add}) || isset({update})) && isset({type}) && ' . IN(ITEM_TYPE_SSH . ',' . ITEM_TYPE_TELNET, 'type')], 'publickey' => [T_ZBX_STR, O_OPT, null, null, '(isset({add}) || isset({update})) && isset({type})' . ' && ({type}) == ' . ITEM_TYPE_SSH . ' && ({authtype}) == ' . ITEM_AUTHTYPE_PUBLICKEY], 'privatekey' => [T_ZBX_STR, O_OPT, null, null, '(isset({add}) || isset({update})) && isset({type})' . ' && ({type}) == ' . ITEM_TYPE_SSH . ' && ({authtype}) == ' . ITEM_AUTHTYPE_PUBLICKEY], $paramsFieldName => [T_ZBX_STR, O_OPT, null, NOT_EMPTY, '(isset({add}) || isset({update})) && isset({type})' . ' && ' . IN(ITEM_TYPE_SSH . ',' . ITEM_TYPE_DB_MONITOR . ',' . ITEM_TYPE_TELNET . ',' . ITEM_TYPE_CALCULATED, 'type'), getParamFieldLabelByType(getRequest('type', 0))], 'snmp_community' => [T_ZBX_STR, O_OPT, null, NOT_EMPTY, '(isset({add}) || isset({update})) && isset({type}) && ' . IN(ITEM_TYPE_SNMPV1 . ',' . ITEM_TYPE_SNMPV2C, 'type'), _('SNMP community')], 'snmp_oid' => [T_ZBX_STR, O_OPT, null, NOT_EMPTY, '(isset({add}) || isset({update})) && isset({type})' . ' && ' . IN(ITEM_TYPE_SNMPV1 . ',' . ITEM_TYPE_SNMPV2C . ',' . ITEM_TYPE_SNMPV3, 'type'), _('SNMP OID')], 'port' => [T_ZBX_STR, O_OPT, null, BETWEEN(0, 65535), '(isset({add}) || isset({update})) && isset({type})' . ' && ' . IN(ITEM_TYPE_SNMPV1 . ',' . ITEM_TYPE_SNMPV2C . ',' . ITEM_TYPE_SNMPV3, 'type'), _('Port')], 'snmpv3_securitylevel' => [T_ZBX_INT, O_OPT, null, IN('0,1,2'), '(isset({add}) || isset({update})) && (isset({type}) && ({type} == ' . ITEM_TYPE_SNMPV3 . '))'], 'snmpv3_contextname' => [T_ZBX_STR, O_OPT, null, null, '(isset({add}) || isset({update})) && (isset({type}) && ({type} == ' . ITEM_TYPE_SNMPV3 . '))'], 'snmpv3_securityname' => [T_ZBX_STR, O_OPT, null, null, '(isset({add}) || isset({update})) && (isset({type}) && ({type} == ' . ITEM_TYPE_SNMPV3 . '))'], 'snmpv3_authprotocol' => [T_ZBX_INT, O_OPT, null, IN(ITEM_AUTHPROTOCOL_MD5 . ',' . ITEM_AUTHPROTOCOL_SHA), '(isset({add}) || isset({update})) && (isset({type})' . ' && ({type} == ' . ITEM_TYPE_SNMPV3 . ') && ({snmpv3_securitylevel} == ' . ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV . ' || {snmpv3_securitylevel} == ' . ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV . '))'], 'snmpv3_authpassphrase' => [T_ZBX_STR, O_OPT, null, null, '(isset({add}) || isset({update})) && (isset({type})' . ' && ({type} == ' . ITEM_TYPE_SNMPV3 . ') && ({snmpv3_securitylevel} == ' . ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV . ' || {snmpv3_securitylevel} == ' . ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV . '))'], 'snmpv3_privprotocol' => [T_ZBX_INT, O_OPT, null, IN(ITEM_PRIVPROTOCOL_DES . ',' . ITEM_PRIVPROTOCOL_AES), '(isset({add}) || isset({update})) && (isset({type}) && ({type} == ' . ITEM_TYPE_SNMPV3 . ')' . ' && ({snmpv3_securitylevel} == ' . ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV . '))'], 'snmpv3_privpassphrase' => [T_ZBX_STR, O_OPT, null, null, '(isset({add}) || isset({update})) && (isset({type}) && ({type} == ' . ITEM_TYPE_SNMPV3 . ')' . ' && ({snmpv3_securitylevel} == ' . ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV . '))'], 'ipmi_sensor' => [T_ZBX_STR, O_OPT, P_NO_TRIM, NOT_EMPTY, '(isset({add}) || isset({update})) && (isset({type}) && ({type} == ' . ITEM_TYPE_IPMI . '))', _('IPMI sensor')], 'trapper_hosts' => [T_ZBX_STR, O_OPT, null, null, '(isset({add}) || isset({update})) && isset({type}) && ({type} == 2)'], 'units' => [T_ZBX_STR, O_OPT, null, null, '(isset({add}) || isset({update})) && isset({value_type})' . ' && ' . IN('0,3', 'value_type') . ' (isset({data_type}) && ({data_type} != ' . ITEM_DATA_TYPE_BOOLEAN . '))'], 'multiplier' => [T_ZBX_INT, O_OPT, null, null, null], 'delta' => [T_ZBX_INT, O_OPT, null, IN('0,1,2'), '(isset({add}) || isset({update})) && isset({value_type})' . ' && ' . IN('0,3', 'value_type') . ' (isset({data_type}) && ({data_type} != ' . ITEM_DATA_TYPE_BOOLEAN . '))'], 'formula' => [T_ZBX_DBL_STR, O_OPT, null, '({value_type} == 0 && {} != 0) || ({value_type} == 3 && {} > 0)', '(isset({add}) || isset({update})) && isset({multiplier}) && {multiplier} == 1', _('Custom multiplier')], 'logtimefmt' => [T_ZBX_STR, O_OPT, null, null, '(isset({add}) || isset({update})) && (isset({value_type}) && ({value_type} == 2))'], 'group_itemid' => [T_ZBX_INT, O_OPT, null, DB_ID, null], 'new_application' => [T_ZBX_STR, O_OPT, null, null, 'isset({add}) || isset({update})'], 'applications' => [T_ZBX_INT, O_OPT, null, DB_ID, null], 'new_application_prototype' => [T_ZBX_STR, O_OPT, null, null, 'isset({parent_discoveryid}) && (isset({add}) || isset({update}))'], 'application_prototypes' => [T_ZBX_STR, O_OPT, null, null, null], 'history' => [T_ZBX_INT, O_OPT, null, BETWEEN(0, 65535), 'isset({add}) || isset({update})', _('History storage period')], 'trends' => [T_ZBX_INT, O_OPT, null, BETWEEN(0, 65535), '(isset({add}) || isset({update})) && isset({value_type})' . ' && ' . IN(ITEM_VALUE_TYPE_FLOAT . ',' . ITEM_VALUE_TYPE_UINT64, 'value_type'), _('Trend storage period')], 'action' => [T_ZBX_STR, O_OPT, P_SYS | P_ACT, IN('"itemprototype.massdelete","itemprototype.massdisable","itemprototype.massenable"'), null], 'add' => [T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null], 'update' => [T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null], 'clone' => [T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null], 'delete' => [T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null], 'cancel' => [T_ZBX_STR, O_OPT, P_SYS, null, null], 'form' => [T_ZBX_STR, O_OPT, P_SYS, null, null], 'form_refresh' => [T_ZBX_INT, O_OPT, null, null, null], 'filter_set' => [T_ZBX_STR, O_OPT, P_SYS, null, null], 'sort' => [T_ZBX_STR, O_OPT, P_SYS, IN('"delay","history","key_","name","status","trends","type"'), null], 'sortorder' => [T_ZBX_STR, O_OPT, P_SYS, IN('"' . ZBX_SORT_DOWN . '","' . ZBX_SORT_UP . '"'), null]];
check_fields($fields);
$_REQUEST['params'] = getRequest($paramsFieldName, '');
unset($_REQUEST[$paramsFieldName]);
// permissions
$discoveryRule = API::DiscoveryRule()->get(['output' => ['hostid'], 'itemids' => getRequest('parent_discoveryid'), 'editable' => true]);
$discoveryRule = reset($discoveryRule);
if (!$discoveryRule) {
    access_deny();
}
$itemPrototypeId = getRequest('itemid');
if ($itemPrototypeId && !API::ItemPrototype()->isWritable([$itemPrototypeId])) {
    access_deny();
}
/*
 * Actions
 */
if (hasRequest('delete') && hasRequest('itemid')) {
    DBstart();
    $result = API::Itemprototype()->delete([getRequest('itemid')]);
    $result = DBend($result);
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:31,代码来源:disc_prototypes.php

示例3: clearCookies

    clearCookies($goResult, $_REQUEST['hostid']);
}
/*
 * Display
 */
if (isset($_REQUEST['form'])) {
    $data = getItemFormData(array('is_discovery_rule' => true));
    $data['page_header'] = _('CONFIGURATION OF DISCOVERY RULES');
    // render view
    $itemView = new CView('configuration.item.edit', $data);
    $itemView->render();
    $itemView->show();
} else {
    $data = array('hostid' => get_request('hostid', 0), 'host' => $host, 'showErrorColumn' => $host['status'] != HOST_STATUS_TEMPLATE);
    $sortfield = getPageSortField('name');
    // discoveries
    $data['discoveries'] = API::DiscoveryRule()->get(array('hostids' => $data['hostid'], 'output' => API_OUTPUT_EXTEND, 'editable' => true, 'selectItems' => API_OUTPUT_COUNT, 'selectGraphs' => API_OUTPUT_COUNT, 'selectTriggers' => API_OUTPUT_COUNT, 'selectHostPrototypes' => API_OUTPUT_COUNT, 'sortfield' => $sortfield, 'limit' => $config['search_limit'] + 1));
    $data['discoveries'] = CMacrosResolverHelper::resolveItemNames($data['discoveries']);
    if ($sortfield === 'status') {
        orderItemsByStatus($data['discoveries'], getPageSortOrder());
    } else {
        order_result($data['discoveries'], $sortfield, getPageSortOrder());
    }
    // paging
    $data['paging'] = getPagingLine($data['discoveries'], array('itemid'), array('hostid' => get_request('hostid')));
    // render view
    $discoveryView = new CView('configuration.host.discovery.list', $data);
    $discoveryView->render();
    $discoveryView->show();
}
require_once dirname(__FILE__) . '/include/page_footer.php';
开发者ID:itnihao,项目名称:zatree-2.2,代码行数:31,代码来源:host_discovery.php

示例4: addRelatedObjects

 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     $eventIds = array_keys($result);
     // adding hosts
     if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) {
         // trigger events
         if ($options['object'] == EVENT_OBJECT_TRIGGER) {
             $query = DBselect('SELECT e.eventid,i.hostid' . ' FROM events e,functions f,items i' . ' WHERE ' . dbConditionInt('e.eventid', $eventIds) . ' AND e.objectid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND e.object=' . zbx_dbstr($options['object']) . ' AND e.source=' . zbx_dbstr($options['source']));
         } elseif ($options['object'] == EVENT_OBJECT_ITEM || $options['object'] == EVENT_OBJECT_LLDRULE) {
             $query = DBselect('SELECT e.eventid,i.hostid' . ' FROM events e,items i' . ' WHERE ' . dbConditionInt('e.eventid', $eventIds) . ' AND e.objectid=i.itemid' . ' AND e.object=' . zbx_dbstr($options['object']) . ' AND e.source=' . zbx_dbstr($options['source']));
         }
         $relationMap = new CRelationMap();
         while ($relation = DBfetch($query)) {
             $relationMap->addRelation($relation['eventid'], $relation['hostid']);
         }
         $hosts = API::Host()->get(array('output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
         $result = $relationMap->mapMany($result, $hosts, 'hosts');
     }
     // adding the related object
     if ($options['selectRelatedObject'] !== null && $options['selectRelatedObject'] != API_OUTPUT_COUNT && $options['object'] != EVENT_OBJECT_AUTOREGHOST) {
         $relationMap = new CRelationMap();
         foreach ($result as $event) {
             $relationMap->addRelation($event['eventid'], $event['objectid']);
         }
         switch ($options['object']) {
             case EVENT_OBJECT_TRIGGER:
                 $api = API::Trigger();
                 break;
             case EVENT_OBJECT_DHOST:
                 $api = API::DHost();
                 break;
             case EVENT_OBJECT_DSERVICE:
                 $api = API::DService();
                 break;
             case EVENT_OBJECT_ITEM:
                 $api = API::Item();
                 break;
             case EVENT_OBJECT_LLDRULE:
                 $api = API::DiscoveryRule();
                 break;
         }
         $objects = $api->get(array('output' => $options['selectRelatedObject'], $api->pkOption() => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
         $result = $relationMap->mapOne($result, $objects, 'relatedObject');
     }
     // adding alerts
     if ($options['select_alerts'] !== null && $options['select_alerts'] != API_OUTPUT_COUNT) {
         $relationMap = $this->createRelationMap($result, 'eventid', 'alertid', 'alerts');
         $alerts = API::Alert()->get(array('output' => $options['select_alerts'], 'selectMediatypes' => API_OUTPUT_EXTEND, 'alertids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true, 'sortfield' => 'clock', 'sortorder' => ZBX_SORT_DOWN));
         $result = $relationMap->mapMany($result, $alerts, 'alerts');
     }
     // adding acknowledges
     if ($options['select_acknowledges'] !== null) {
         if ($options['select_acknowledges'] != API_OUTPUT_COUNT) {
             // create the base query
             $sqlParts = API::getApiService()->createSelectQueryParts('acknowledges', 'a', array('output' => $this->outputExtend($options['select_acknowledges'], array('acknowledgeid', 'eventid', 'clock')), 'filter' => array('eventid' => $eventIds)));
             $sqlParts['order'][] = 'a.clock DESC';
             // if the user data is requested via extended output or specified fields, join the users table
             $userFields = array('alias', 'name', 'surname');
             $requestUserData = array();
             foreach ($userFields as $userField) {
                 if ($this->outputIsRequested($userField, $options['select_acknowledges'])) {
                     $requestUserData[] = $userField;
                 }
             }
             if ($requestUserData) {
                 foreach ($requestUserData as $userField) {
                     $sqlParts = $this->addQuerySelect('u.' . $userField, $sqlParts);
                 }
                 $sqlParts['from'][] = 'users u';
                 $sqlParts['where'][] = 'a.userid=u.userid';
             }
             $acknowledges = DBFetchArrayAssoc(DBselect($this->createSelectQueryFromParts($sqlParts)), 'acknowledgeid');
             $relationMap = $this->createRelationMap($acknowledges, 'eventid', 'acknowledgeid');
             $acknowledges = $this->unsetExtraFields($acknowledges, array('eventid', 'acknowledgeid', 'clock'), $options['select_acknowledges']);
             $result = $relationMap->mapMany($result, $acknowledges, 'acknowledges');
         } else {
             $acknowledges = DBFetchArrayAssoc(DBselect('SELECT COUNT(a.acknowledgeid) AS rowscount,a.eventid' . ' FROM acknowledges a' . ' WHERE ' . dbConditionInt('a.eventid', $eventIds) . ' GROUP BY a.eventid'), 'eventid');
             foreach ($result as &$event) {
                 if (isset($acknowledges[$event['eventid']])) {
                     $event['acknowledges'] = $acknowledges[$event['eventid']]['rowscount'];
                 } else {
                     $event['acknowledges'] = 0;
                 }
             }
             unset($event);
         }
     }
     return $result;
 }
开发者ID:TonywalkerCN,项目名称:Zabbix,代码行数:90,代码来源:CEvent.php

示例5: get

 /**
  * Get GraphPrototype data
  *
  * @param array $options
  * @return array
  */
 public function get($options = array())
 {
     $result = array();
     $userType = self::$userData['type'];
     $userid = self::$userData['userid'];
     // allowed columns for sorting
     $sortColumns = array('graphid', 'name', 'graphtype');
     // allowed output options for [ select_* ] params
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM);
     $sqlParts = array('select' => array('graphs' => 'g.graphid'), 'from' => array('graphs' => 'graphs g'), 'where' => array('g.flags=' . ZBX_FLAG_DISCOVERY_CHILD), 'group' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'groupids' => null, 'templateids' => null, 'hostids' => null, 'graphids' => null, 'itemids' => null, 'discoveryids' => null, 'type' => null, 'templated' => null, 'inherited' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectGroups' => null, 'selectTemplates' => null, 'selectHosts' => null, 'selectItems' => null, 'selectGraphItems' => null, 'selectDiscoveryRule' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($defOptions, $options);
     if (is_array($options['output'])) {
         unset($sqlParts['select']['graphs']);
         $dbTable = DB::getSchema('graphs');
         foreach ($options['output'] as $field) {
             if (isset($dbTable['fields'][$field])) {
                 $sqlParts['select'][$field] = 'g.' . $field;
             }
         }
         $options['output'] = API_OUTPUT_CUSTOM;
     }
     // editable + PERMISSION CHECK
     if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
         $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY;
         $userGroups = getUserGroupsByUserId($userid);
         $sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM graphs_items gi,items i,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE g.graphid=gi.graphid' . ' AND gi.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY gi.graphid' . ' HAVING MIN(r.permission)>=' . $permission . ')';
     }
     // nodeids
     $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
     // groupids
     if (!is_null($options['groupids'])) {
         zbx_value2array($options['groupids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['groupid'] = 'hg.groupid';
         }
         $sqlParts['from']['graphs_items'] = 'graphs_items gi';
         $sqlParts['from']['items'] = 'items i';
         $sqlParts['from']['hosts_groups'] = 'hosts_groups hg';
         $sqlParts['where'][] = dbConditionInt('hg.groupid', $options['groupids']);
         $sqlParts['where'][] = 'hg.hostid=i.hostid';
         $sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
         $sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
         $sqlParts['where']['hgi'] = 'hg.hostid=i.hostid';
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['hg'] = 'hg.groupid';
         }
     }
     // templateids
     if (!is_null($options['templateids'])) {
         zbx_value2array($options['templateids']);
         if (!is_null($options['hostids'])) {
             zbx_value2array($options['hostids']);
             $options['hostids'] = array_merge($options['hostids'], $options['templateids']);
         } else {
             $options['hostids'] = $options['templateids'];
         }
     }
     // hostids
     if (!is_null($options['hostids'])) {
         zbx_value2array($options['hostids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['hostid'] = 'i.hostid';
         }
         $sqlParts['from']['graphs_items'] = 'graphs_items gi';
         $sqlParts['from']['items'] = 'items i';
         $sqlParts['where'][] = dbConditionInt('i.hostid', $options['hostids']);
         $sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
         $sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['i'] = 'i.hostid';
         }
     }
     // graphids
     if (!is_null($options['graphids'])) {
         zbx_value2array($options['graphids']);
         $sqlParts['where'][] = dbConditionInt('g.graphid', $options['graphids']);
     }
     // itemids
     if (!is_null($options['itemids'])) {
         zbx_value2array($options['itemids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['itemid'] = 'gi.itemid';
         }
         $sqlParts['from']['graphs_items'] = 'graphs_items gi';
         $sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
         $sqlParts['where'][] = dbConditionInt('gi.itemid', $options['itemids']);
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['gi'] = 'gi.itemid';
         }
     }
     // discoveryids
     if (!is_null($options['discoveryids'])) {
         zbx_value2array($options['discoveryids']);
//.........这里部分代码省略.........
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:101,代码来源:CGraphPrototype.php

示例6: deleteMissingDiscoveryRules

 /**
  * Deletes discovery rules and prototypes from DB that are missing in XML.
  *
  * @return null
  */
 protected function deleteMissingDiscoveryRules()
 {
     if (!$this->options['discoveryRules']['deleteMissing']) {
         return;
     }
     $processedHostIds = $this->importedObjectContainer->getHostIds();
     $processedTemplateIds = $this->importedObjectContainer->getTemplateIds();
     $processedHostIds = array_merge($processedHostIds, $processedTemplateIds);
     // no hosts or templates have been processed
     if (!$processedHostIds) {
         return;
     }
     $discoveryRuleIdsXML = array();
     $allDiscoveryRules = $this->getFormattedDiscoveryRules();
     if ($allDiscoveryRules) {
         foreach ($allDiscoveryRules as $host => $discoveryRules) {
             $hostId = $this->referencer->resolveHostOrTemplate($host);
             foreach ($discoveryRules as $discoveryRule) {
                 $discoveryRuleId = $this->referencer->resolveItem($hostId, $discoveryRule['key_']);
                 if ($discoveryRuleId) {
                     $discoveryRuleIdsXML[$discoveryRuleId] = $discoveryRuleId;
                 }
             }
         }
     }
     $dbDiscoveryRuleIds = API::DiscoveryRule()->get(array('output' => array('itemid'), 'hostids' => $processedHostIds, 'preservekeys' => true, 'nopermissions' => true, 'inherited' => false));
     $discoveryRulesToDelete = array_diff_key($dbDiscoveryRuleIds, $discoveryRuleIdsXML);
     if ($discoveryRulesToDelete) {
         API::DiscoveryRule()->delete(array_keys($discoveryRulesToDelete));
     }
     // refresh discovery rules because templated ones can be inherited to host and used for prototypes
     $this->referencer->refreshItems();
     $hostPrototypeIdsXML = array();
     $triggerPrototypeIdsXML = array();
     $itemPrototypeIdsXML = array();
     $graphPrototypeIdsXML = array();
     foreach ($allDiscoveryRules as $host => $discoveryRules) {
         $hostId = $this->referencer->resolveHostOrTemplate($host);
         foreach ($discoveryRules as $discoveryRule) {
             $discoveryRuleId = $this->referencer->resolveItem($hostId, $discoveryRule['key_']);
             if ($discoveryRuleId) {
                 // gather host prototype IDs to delete
                 foreach ($discoveryRule['host_prototypes'] as $hostPrototype) {
                     $hostPrototypeId = $this->referencer->resolveHostPrototype($hostId, $discoveryRuleId, $hostPrototype['host']);
                     if ($hostPrototypeId) {
                         $hostPrototypeIdsXML[$hostPrototypeId] = $hostPrototypeId;
                     }
                 }
                 // gather trigger prototype IDs to delete
                 foreach ($discoveryRule['trigger_prototypes'] as $triggerPrototype) {
                     $triggerPrototypeId = $this->referencer->resolveTrigger($triggerPrototype['description'], $triggerPrototype['expression']);
                     if ($triggerPrototypeId) {
                         $triggerPrototypeIdsXML[$triggerPrototypeId] = $triggerPrototypeId;
                     }
                 }
                 // gather graph prototype IDs to delete
                 foreach ($discoveryRule['graph_prototypes'] as $graphPrototype) {
                     $graphPrototypeId = $this->referencer->resolveGraph($hostId, $graphPrototype['name']);
                     if ($graphPrototypeId) {
                         $graphPrototypeIdsXML[$graphPrototypeId] = $graphPrototypeId;
                     }
                 }
                 // gather item prototype IDs to delete
                 foreach ($discoveryRule['item_prototypes'] as $itemPrototype) {
                     $itemPrototypeId = $this->referencer->resolveItem($hostId, $itemPrototype['key_']);
                     if ($itemPrototypeId) {
                         $itemPrototypeIdsXML[$itemPrototypeId] = $itemPrototypeId;
                     }
                 }
             }
         }
     }
     // delete missing host prototypes
     $dbHostPrototypeIds = API::HostPrototype()->get(array('output' => array('hostid'), 'discoveryids' => $discoveryRuleIdsXML, 'preservekeys' => true, 'nopermissions' => true, 'inherited' => false));
     $hostPrototypesToDelete = array_diff_key($dbHostPrototypeIds, $hostPrototypeIdsXML);
     if ($hostPrototypesToDelete) {
         API::HostPrototype()->delete(array_keys($hostPrototypesToDelete));
     }
     // delete missing trigger prototypes
     $dbTriggerPrototypeIds = API::TriggerPrototype()->get(array('output' => array('triggerid'), 'hostids' => $processedHostIds, 'preservekeys' => true, 'nopermissions' => true, 'inherited' => false));
     $triggerPrototypesToDelete = array_diff_key($dbTriggerPrototypeIds, $triggerPrototypeIdsXML);
     // unlike triggers that belong to multiple hosts, trigger prototypes do not, so we just delete them
     if ($triggerPrototypesToDelete) {
         API::TriggerPrototype()->delete(array_keys($triggerPrototypesToDelete));
     }
     // delete missing graph prototypes
     $dbGraphPrototypeIds = API::GraphPrototype()->get(array('output' => array('graphid'), 'hostids' => $processedHostIds, 'preservekeys' => true, 'nopermissions' => true, 'inherited' => false));
     $graphPrototypesToDelete = array_diff_key($dbGraphPrototypeIds, $graphPrototypeIdsXML);
     // unlike graphs that belong to multiple hosts, graph prototypes do not, so we just delete them
     if ($graphPrototypesToDelete) {
         API::GraphPrototype()->delete(array_keys($graphPrototypesToDelete));
     }
     // delete missing item prototypes
     $dbItemPrototypeIds = API::ItemPrototype()->get(array('output' => array('itemid'), 'hostids' => $processedHostIds, 'preservekeys' => true, 'nopermissions' => true, 'inherited' => false));
     $itemPrototypesToDelete = array_diff_key($dbItemPrototypeIds, $itemPrototypeIdsXML);
//.........这里部分代码省略.........
开发者ID:TonywalkerCN,项目名称:Zabbix,代码行数:101,代码来源:CConfigurationImport.php

示例7: processDiscoveryRules

 /**
  * Import discovery rules.
  *
  * @throws Exception
  */
 protected function processDiscoveryRules()
 {
     $allDiscoveryRules = $this->getFormattedDiscoveryRules();
     if (empty($allDiscoveryRules)) {
         return;
     }
     // unset rules that are related to hosts we did not process
     foreach ($allDiscoveryRules as $host => $discoveryRules) {
         if (!$this->referencer->isProcessedHost($host)) {
             unset($allDiscoveryRules[$host]);
         }
     }
     $itemsToCreate = array();
     $itemsToUpdate = array();
     foreach ($allDiscoveryRules as $host => $discoveryRules) {
         $hostid = $this->referencer->resolveHostOrTemplate($host);
         foreach ($discoveryRules as $item) {
             $item['hostid'] = $hostid;
             if (isset($item['interface_ref'])) {
                 $item['interfaceid'] = $this->referencer->interfacesCache[$hostid][$item['interface_ref']];
             }
             unset($item['item_prototypes']);
             unset($item['trigger_prototypes']);
             unset($item['graph_prototypes']);
             unset($item['host_prototypes']);
             $itemId = $this->referencer->resolveItem($hostid, $item['key_']);
             if ($itemId) {
                 $item['itemid'] = $itemId;
                 $itemsToUpdate[] = $item;
             } else {
                 $itemsToCreate[] = $item;
             }
         }
     }
     // create/update discovery rules and add processed rules to array $processedRules
     $processedRules = array();
     if ($this->options['discoveryRules']['createMissing'] && $itemsToCreate) {
         $newItemsIds = API::DiscoveryRule()->create($itemsToCreate);
         foreach ($newItemsIds['itemids'] as $inum => $itemid) {
             $item = $itemsToCreate[$inum];
             $this->referencer->addItemRef($item['hostid'], $item['key_'], $itemid);
         }
         foreach ($itemsToCreate as $item) {
             $processedRules[$item['hostid']][$item['key_']] = 1;
         }
     }
     if ($this->options['discoveryRules']['updateExisting'] && $itemsToUpdate) {
         API::DiscoveryRule()->update($itemsToUpdate);
         foreach ($itemsToUpdate as $item) {
             $processedRules[$item['hostid']][$item['key_']] = 1;
         }
     }
     // refresh discovery rules because templated ones can be inherited to host and used for prototypes
     $this->referencer->refreshItems();
     // process prototypes
     $prototypesToUpdate = array();
     $prototypesToCreate = array();
     $hostPrototypesToUpdate = array();
     $hostPrototypesToCreate = array();
     foreach ($allDiscoveryRules as $host => $discoveryRules) {
         $hostid = $this->referencer->resolveHostOrTemplate($host);
         foreach ($discoveryRules as $item) {
             // if rule was not processed we should not create/update any of its prototypes
             if (!isset($processedRules[$hostid][$item['key_']])) {
                 continue;
             }
             $item['hostid'] = $hostid;
             $itemId = $this->referencer->resolveItem($hostid, $item['key_']);
             // prototypes
             foreach ($item['item_prototypes'] as $prototype) {
                 $prototype['hostid'] = $hostid;
                 $applicationsIds = array();
                 foreach ($prototype['applications'] as $application) {
                     $applicationsIds[] = $this->referencer->resolveApplication($hostid, $application['name']);
                 }
                 $prototype['applications'] = $applicationsIds;
                 if (isset($prototype['interface_ref'])) {
                     $prototype['interfaceid'] = $this->referencer->interfacesCache[$hostid][$prototype['interface_ref']];
                 }
                 if ($prototype['valuemap']) {
                     $valueMapId = $this->referencer->resolveValueMap($prototype['valuemap']['name']);
                     if (!$valueMapId) {
                         throw new Exception(_s('Cannot find value map "%1$s" used for item prototype "%2$s" of discovery rule "%3$s" on "%4$s".', $prototype['valuemap']['name'], $prototype['name'], $item['name'], $host));
                     }
                     $prototype['valuemapid'] = $valueMapId;
                 }
                 $prototypeId = $this->referencer->resolveItem($hostid, $prototype['key_']);
                 $prototype['rule'] = array('hostid' => $hostid, 'key' => $item['key_']);
                 if ($prototypeId) {
                     $prototype['itemid'] = $prototypeId;
                     $prototypesToUpdate[] = $prototype;
                 } else {
                     $prototypesToCreate[] = $prototype;
                 }
             }
//.........这里部分代码省略.........
开发者ID:itnihao,项目名称:zatree-2.2,代码行数:101,代码来源:CConfigurationImport.php

示例8: 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'])));
    }
    /*
//.........这里部分代码省略.........
开发者ID:itnihao,项目名称:Zabbix_,代码行数:101,代码来源:html.inc.php

示例9: array

     $dbTriggers = API::Trigger()->get(array('output' => array('triggerid'), 'hostids' => $cloneTemplateId, 'inherited' => false));
     if ($dbTriggers) {
         $result &= copyTriggersToHosts(zbx_objectValues($dbTriggers, 'triggerid'), $templateId, $cloneTemplateId);
         if (!$result) {
             throw new Exception();
         }
     }
     // copy graphs
     $dbGraphs = API::Graph()->get(array('output' => array('graphid'), 'hostids' => $cloneTemplateId, 'inherited' => false));
     foreach ($dbGraphs as $dbGraph) {
         copyGraphToHost($dbGraph['graphid'], $templateId);
     }
     // copy discovery rules
     $dbDiscoveryRules = API::DiscoveryRule()->get(array('output' => array('itemid'), 'hostids' => $cloneTemplateId, 'inherited' => false));
     if ($dbDiscoveryRules) {
         $result &= API::DiscoveryRule()->copy(array('discoveryids' => zbx_objectValues($dbDiscoveryRules, 'itemid'), 'hostids' => array($templateId)));
         if (!$result) {
             throw new Exception();
         }
     }
     // copy template screens
     $dbTemplateScreens = API::TemplateScreen()->get(array('output' => array('screenid'), 'templateids' => $cloneTemplateId, 'preservekeys' => true, 'inherited' => false));
     if ($dbTemplateScreens) {
         $result &= API::TemplateScreen()->copy(array('screenIds' => zbx_objectValues($dbTemplateScreens, 'screenid'), 'templateIds' => $templateId));
         if (!$result) {
             throw new Exception();
         }
     }
 }
 if ($result) {
     add_audit_ext($auditAction, AUDIT_RESOURCE_TEMPLATE, $templateId, $templateName, 'hosts', null, null);
开发者ID:TonywalkerCN,项目名称:Zabbix,代码行数:31,代码来源:templates.php

示例10: addRelatedObjects

 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     $hostPrototypeIds = array_keys($result);
     // adding discovery rule
     if ($options['selectDiscoveryRule'] !== null && $options['selectDiscoveryRule'] != API_OUTPUT_COUNT) {
         $relationMap = $this->createRelationMap($result, 'hostid', 'parent_itemid', 'host_discovery');
         $discoveryRules = API::DiscoveryRule()->get(['output' => $options['selectDiscoveryRule'], 'itemids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true]);
         $result = $relationMap->mapOne($result, $discoveryRules, 'discoveryRule');
     }
     // adding group links
     if ($options['selectGroupLinks'] !== null && $options['selectGroupLinks'] != API_OUTPUT_COUNT) {
         $groupPrototypes = DBFetchArray(DBselect('SELECT hg.group_prototypeid,hg.hostid' . ' FROM group_prototype hg' . ' WHERE ' . dbConditionInt('hg.hostid', $hostPrototypeIds) . ' AND hg.groupid IS NOT NULL'));
         $relationMap = $this->createRelationMap($groupPrototypes, 'hostid', 'group_prototypeid');
         $groupPrototypes = API::getApiService()->select('group_prototype', ['output' => $options['selectGroupLinks'], 'group_prototypeids' => $relationMap->getRelatedIds(), 'preservekeys' => true]);
         foreach ($groupPrototypes as &$groupPrototype) {
             unset($groupPrototype['name']);
         }
         unset($groupPrototype);
         $result = $relationMap->mapMany($result, $groupPrototypes, 'groupLinks');
     }
     // adding group prototypes
     if ($options['selectGroupPrototypes'] !== null && $options['selectGroupPrototypes'] != API_OUTPUT_COUNT) {
         $groupPrototypes = DBFetchArray(DBselect('SELECT hg.group_prototypeid,hg.hostid' . ' FROM group_prototype hg' . ' WHERE ' . dbConditionInt('hg.hostid', $hostPrototypeIds) . ' AND hg.groupid IS NULL'));
         $relationMap = $this->createRelationMap($groupPrototypes, 'hostid', 'group_prototypeid');
         $groupPrototypes = API::getApiService()->select('group_prototype', ['output' => $options['selectGroupPrototypes'], 'group_prototypeids' => $relationMap->getRelatedIds(), 'preservekeys' => true]);
         foreach ($groupPrototypes as &$groupPrototype) {
             unset($groupPrototype['groupid']);
         }
         unset($groupPrototype);
         $result = $relationMap->mapMany($result, $groupPrototypes, 'groupPrototypes');
     }
     // adding host
     if ($options['selectParentHost'] !== null && $options['selectParentHost'] != API_OUTPUT_COUNT) {
         $relationMap = new CRelationMap();
         $dbRules = DBselect('SELECT hd.hostid,i.hostid AS parent_hostid' . ' FROM host_discovery hd,items i' . ' WHERE ' . dbConditionInt('hd.hostid', $hostPrototypeIds) . ' AND hd.parent_itemid=i.itemid');
         while ($relation = DBfetch($dbRules)) {
             $relationMap->addRelation($relation['hostid'], $relation['parent_hostid']);
         }
         $hosts = API::Host()->get(['output' => $options['selectParentHost'], 'hostids' => $relationMap->getRelatedIds(), 'templated_hosts' => true, 'nopermissions' => true, 'preservekeys' => true]);
         $result = $relationMap->mapOne($result, $hosts, 'parentHost');
     }
     // adding templates
     if ($options['selectTemplates'] !== null) {
         if ($options['selectTemplates'] != API_OUTPUT_COUNT) {
             $relationMap = $this->createRelationMap($result, 'hostid', 'templateid', 'hosts_templates');
             $templates = API::Template()->get(['output' => $options['selectTemplates'], 'templateids' => $relationMap->getRelatedIds(), 'preservekeys' => true]);
             $result = $relationMap->mapMany($result, $templates, 'templates');
         } else {
             $templates = API::Template()->get(['hostids' => $hostPrototypeIds, 'countOutput' => true, 'groupCount' => true]);
             $templates = zbx_toHash($templates, 'hostid');
             foreach ($result as $hostid => $host) {
                 $result[$hostid]['templates'] = isset($templates[$hostid]) ? $templates[$hostid]['rowscount'] : 0;
             }
         }
     }
     // adding inventory
     if ($options['selectInventory'] !== null) {
         $relationMap = $this->createRelationMap($result, 'hostid', 'hostid');
         // only allow to retrieve the hostid and inventory_mode fields
         $output = [];
         if ($this->outputIsRequested('hostid', $options['selectInventory'])) {
             $output[] = 'hostid';
         }
         if ($this->outputIsRequested('inventory_mode', $options['selectInventory'])) {
             $output[] = 'inventory_mode';
         }
         $inventory = API::getApiService()->select('host_inventory', ['output' => $output, 'filter' => ['hostid' => $hostPrototypeIds]]);
         $result = $relationMap->mapOne($result, zbx_toHash($inventory, 'hostid'), 'inventory');
     }
     return $result;
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:72,代码来源:CHostPrototype.php

示例11: addRelatedObjects

 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     $hostids = array_keys($result);
     // adding groups
     if ($options['selectGroups'] !== null) {
         $relationMap = $this->createRelationMap($result, 'hostid', 'groupid', 'hosts_groups');
         $groups = API::HostGroup()->get(array('output' => $options['selectGroups'], 'groupids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
         $result = $relationMap->mapMany($result, $groups, 'groups');
     }
     // adding templates
     if ($options['selectParentTemplates'] !== null) {
         if ($options['selectParentTemplates'] != API_OUTPUT_COUNT) {
             $relationMap = $this->createRelationMap($result, 'hostid', 'templateid', 'hosts_templates');
             $templates = API::Template()->get(array('output' => $options['selectParentTemplates'], 'templateids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
             if (!is_null($options['limitSelects'])) {
                 order_result($templates, 'host');
             }
             $result = $relationMap->mapMany($result, $templates, 'parentTemplates', $options['limitSelects']);
         } else {
             $templates = API::Template()->get(array('hostids' => $hostids, 'countOutput' => true, 'groupCount' => true));
             $templates = zbx_toHash($templates, 'hostid');
             foreach ($result as $hostid => $host) {
                 $result[$hostid]['parentTemplates'] = isset($templates[$hostid]) ? $templates[$hostid]['rowscount'] : 0;
             }
         }
     }
     // adding items
     if ($options['selectItems'] !== null) {
         if ($options['selectItems'] != API_OUTPUT_COUNT) {
             $items = API::Item()->get(array('output' => $this->outputExtend($options['selectItems'], array('hostid', 'itemid')), 'hostids' => $hostids, 'nopermissions' => true, 'preservekeys' => true));
             if (!is_null($options['limitSelects'])) {
                 order_result($items, 'name');
             }
             $relationMap = $this->createRelationMap($items, 'hostid', 'itemid');
             $items = $this->unsetExtraFields($items, array('hostid', 'itemid'), $options['selectItems']);
             $result = $relationMap->mapMany($result, $items, 'items', $options['limitSelects']);
         } else {
             $items = API::Item()->get(array('hostids' => $hostids, 'nopermissions' => true, 'countOutput' => true, 'groupCount' => true));
             $items = zbx_toHash($items, 'hostid');
             foreach ($result as $hostid => $host) {
                 $result[$hostid]['items'] = isset($items[$hostid]) ? $items[$hostid]['rowscount'] : 0;
             }
         }
     }
     // adding discoveries
     if ($options['selectDiscoveries'] !== null) {
         if ($options['selectDiscoveries'] != API_OUTPUT_COUNT) {
             $items = API::DiscoveryRule()->get(array('output' => $this->outputExtend($options['selectDiscoveries'], array('hostid', 'itemid')), 'hostids' => $hostids, 'nopermissions' => true, 'preservekeys' => true));
             if (!is_null($options['limitSelects'])) {
                 order_result($items, 'name');
             }
             $relationMap = $this->createRelationMap($items, 'hostid', 'itemid');
             $items = $this->unsetExtraFields($items, array('hostid', 'itemid'), $options['selectDiscoveries']);
             $result = $relationMap->mapMany($result, $items, 'discoveries', $options['limitSelects']);
         } else {
             $items = API::DiscoveryRule()->get(array('hostids' => $hostids, 'nopermissions' => true, 'countOutput' => true, 'groupCount' => true));
             $items = zbx_toHash($items, 'hostid');
             foreach ($result as $hostid => $host) {
                 $result[$hostid]['discoveries'] = isset($items[$hostid]) ? $items[$hostid]['rowscount'] : 0;
             }
         }
     }
     // adding triggers
     if ($options['selectTriggers'] !== null) {
         if ($options['selectTriggers'] != API_OUTPUT_COUNT) {
             // discovered items
             $res = DBselect('SELECT i.hostid,f.triggerid' . ' FROM items i,functions f' . ' WHERE ' . dbConditionInt('i.hostid', $hostids) . ' AND i.itemid=f.itemid');
             $relationMap = new CRelationMap();
             while ($relation = DBfetch($res)) {
                 $relationMap->addRelation($relation['hostid'], $relation['triggerid']);
             }
             $triggers = API::Trigger()->get(array('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::Trigger()->get(array('hostids' => $hostids, 'countOutput' => true, 'groupCount' => true));
             $triggers = zbx_toHash($triggers, 'hostid');
             foreach ($result as $hostid => $host) {
                 $result[$hostid]['triggers'] = isset($triggers[$hostid]) ? $triggers[$hostid]['rowscount'] : 0;
             }
         }
     }
     // adding graphs
     if ($options['selectGraphs'] !== null) {
         if ($options['selectGraphs'] != API_OUTPUT_COUNT) {
             // discovered items
             $res = DBselect('SELECT i.hostid,gi.graphid' . ' FROM items i,graphs_items gi' . ' WHERE ' . dbConditionInt('i.hostid', $hostids) . ' AND i.itemid=gi.itemid');
             $relationMap = new CRelationMap();
             while ($relation = DBfetch($res)) {
                 $relationMap->addRelation($relation['hostid'], $relation['graphid']);
             }
             $graphs = API::Graph()->get(array('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 {
//.........这里部分代码省略.........
开发者ID:omidmt,项目名称:zabbix-greenplum,代码行数:101,代码来源:CHostGeneral.php

示例12: Exception

 }
 // copy web scenarios
 if (!copyHttpTests($srcHostId, $hostId)) {
     throw new Exception();
 }
 // copy triggers
 $dbTriggers = API::Trigger()->get(['output' => ['triggerid'], 'hostids' => $srcHostId, 'inherited' => false]);
 if ($dbTriggers) {
     if (!copyTriggersToHosts(zbx_objectValues($dbTriggers, 'triggerid'), $hostId, $srcHostId)) {
         throw new Exception();
     }
 }
 // copy discovery rules
 $dbDiscoveryRules = API::DiscoveryRule()->get(['output' => ['itemid'], 'hostids' => $srcHostId, 'inherited' => false]);
 if ($dbDiscoveryRules) {
     $copyDiscoveryRules = API::DiscoveryRule()->copy(['discoveryids' => zbx_objectValues($dbDiscoveryRules, 'itemid'), 'hostids' => [$hostId]]);
     if (!$copyDiscoveryRules) {
         throw new Exception();
     }
 }
 // copy graphs
 $dbGraphs = API::Graph()->get(['output' => API_OUTPUT_EXTEND, 'selectHosts' => ['hostid'], 'selectItems' => ['type'], 'hostids' => $srcHostId, 'filter' => ['flags' => ZBX_FLAG_DISCOVERY_NORMAL], 'inherited' => false]);
 foreach ($dbGraphs as $dbGraph) {
     if (count($dbGraph['hosts']) > 1) {
         continue;
     }
     if (httpItemExists($dbGraph['items'])) {
         continue;
     }
     if (!copyGraphToHost($dbGraph['graphid'], $hostId)) {
         throw new Exception();
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:31,代码来源:hosts.php

示例13: addRelatedObjects

 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     $triggerids = array_keys($result);
     // adding trigger dependencies
     if ($options['selectDependencies'] !== null && $options['selectDependencies'] != API_OUTPUT_COUNT) {
         $res = DBselect('SELECT td.triggerid_up,td.triggerid_down' . ' FROM trigger_depends td' . ' WHERE ' . dbConditionInt('td.triggerid_down', $triggerids));
         $relationMap = new CRelationMap();
         while ($relation = DBfetch($res)) {
             $relationMap->addRelation($relation['triggerid_down'], $relation['triggerid_up']);
         }
         $dependencies = $this->get(array('triggerids' => $relationMap->getRelatedIds(), 'output' => $options['selectDependencies'], 'expandData' => true, 'preservekeys' => true));
         $result = $relationMap->mapMany($result, $dependencies, 'dependencies');
     }
     // adding items
     if ($options['selectItems'] !== null && $options['selectItems'] != API_OUTPUT_COUNT) {
         $relationMap = $this->createRelationMap($result, 'triggerid', 'itemid', 'functions');
         $items = API::Item()->get(array('nodeids' => $options['nodeids'], 'output' => $options['selectItems'], 'itemids' => $relationMap->getRelatedIds(), 'webitems' => true, 'nopermissions' => true, 'preservekeys' => true));
         $result = $relationMap->mapMany($result, $items, 'items');
     }
     // adding discoveryrule
     if ($options['selectDiscoveryRule'] !== null && $options['selectDiscoveryRule'] != API_OUTPUT_COUNT) {
         $dbRules = DBselect('SELECT id.parent_itemid,td.triggerid' . ' FROM trigger_discovery td,item_discovery id,functions f' . ' WHERE ' . dbConditionInt('td.triggerid', $triggerids) . ' AND td.parent_triggerid=f.triggerid' . ' AND f.itemid=id.itemid');
         $relationMap = new CRelationMap();
         while ($rule = DBfetch($dbRules)) {
             $relationMap->addRelation($rule['triggerid'], $rule['parent_itemid']);
         }
         $discoveryRules = API::DiscoveryRule()->get(array('output' => $options['selectDiscoveryRule'], 'nodeids' => $options['nodeids'], 'itemids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
         $result = $relationMap->mapOne($result, $discoveryRules, 'discoveryRule');
     }
     // adding last event
     if ($options['selectLastEvent'] !== null) {
         foreach ($result as $triggerId => $trigger) {
             $lastEvent = API::Event()->get(array('source' => EVENT_SOURCE_TRIGGERS, 'object' => EVENT_OBJECT_TRIGGER, 'objectids' => $triggerId, 'output' => $options['selectLastEvent'], 'nopermissions' => true, 'sortfield' => array('clock', 'eventid'), 'sortorder' => ZBX_SORT_DOWN, 'limit' => 1));
             $result[$triggerId]['lastEvent'] = $lastEvent ? reset($lastEvent) : array();
         }
     }
     return $result;
 }
开发者ID:itnihao,项目名称:Zabbix_,代码行数:39,代码来源:CTrigger.php

示例14: addRelatedObjects

 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     $groupIds = array_keys($result);
     sort($groupIds);
     // adding hosts
     if ($options['selectHosts'] !== null) {
         if ($options['selectHosts'] !== API_OUTPUT_COUNT) {
             $relationMap = $this->createRelationMap($result, 'groupid', 'hostid', 'hosts_groups');
             $hosts = API::Host()->get(array('output' => $options['selectHosts'], 'nodeids' => $options['nodeids'], '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('nodeids' => $options['nodeids'], 'groupids' => $groupIds, 'countOutput' => true, 'groupCount' => true));
             $hosts = zbx_toHash($hosts, 'groupid');
             foreach ($result as $groupid => $group) {
                 if (isset($hosts[$groupid])) {
                     $result[$groupid]['hosts'] = $hosts[$groupid]['rowscount'];
                 } else {
                     $result[$groupid]['hosts'] = 0;
                 }
             }
         }
     }
     // adding templates
     if ($options['selectTemplates'] !== null) {
         if ($options['selectTemplates'] !== API_OUTPUT_COUNT) {
             $relationMap = $this->createRelationMap($result, 'groupid', 'hostid', 'hosts_groups');
             $hosts = API::Template()->get(array('output' => $options['selectTemplates'], 'nodeids' => $options['nodeids'], 'templateids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
             if (!is_null($options['limitSelects'])) {
                 order_result($hosts, 'host');
             }
             $result = $relationMap->mapMany($result, $hosts, 'templates', $options['limitSelects']);
         } else {
             $hosts = API::Template()->get(array('nodeids' => $options['nodeids'], 'groupids' => $groupIds, 'countOutput' => true, 'groupCount' => true));
             $hosts = zbx_toHash($hosts, 'groupid');
             foreach ($result as $groupid => $group) {
                 if (isset($hosts[$groupid])) {
                     $result[$groupid]['templates'] = $hosts[$groupid]['rowscount'];
                 } else {
                     $result[$groupid]['templates'] = 0;
                 }
             }
         }
     }
     // adding discovery rule
     if ($options['selectDiscoveryRule'] !== null && $options['selectDiscoveryRule'] != API_OUTPUT_COUNT) {
         // discovered items
         $discoveryRules = DBFetchArray(DBselect('SELECT gd.groupid,hd.parent_itemid' . ' FROM group_discovery gd,group_prototype gp,host_discovery hd' . ' WHERE ' . dbConditionInt('gd.groupid', $groupIds) . ' AND gd.parent_group_prototypeid=gp.group_prototypeid' . ' AND gp.hostid=hd.hostid'));
         $relationMap = $this->createRelationMap($discoveryRules, 'groupid', 'parent_itemid');
         $discoveryRules = API::DiscoveryRule()->get(array('output' => $options['selectDiscoveryRule'], 'nodeids' => $options['nodeids'], 'itemids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
         $result = $relationMap->mapOne($result, $discoveryRules, 'discoveryRule');
     }
     // adding group discovery
     if ($options['selectGroupDiscovery'] !== null) {
         $groupDiscoveries = API::getApi()->select('group_discovery', array('output' => $this->outputExtend('group_discovery', array('groupid'), $options['selectGroupDiscovery']), 'filter' => array('groupid' => $groupIds), 'preservekeys' => true, 'nodeids' => get_current_nodeid(true)));
         $relationMap = $this->createRelationMap($groupDiscoveries, 'groupid', 'groupid');
         $groupDiscoveries = $this->unsetExtraFields($groupDiscoveries, array('groupid'), $options['selectGroupDiscovery']);
         $result = $relationMap->mapOne($result, $groupDiscoveries, 'groupDiscovery');
     }
     return $result;
 }
开发者ID:hujingguang,项目名称:work,代码行数:64,代码来源:CHostGroup.php

示例15: Exception

     throw new Exception();
 }
 if (!copyItems($srcHostId, $hostId)) {
     throw new Exception();
 }
 // clone triggers
 $triggers = API::Trigger()->get(array('output' => array('triggerid'), 'hostids' => $srcHostId, 'inherited' => false));
 if ($triggers) {
     if (!copyTriggersToHosts(zbx_objectValues($triggers, 'triggerid'), $hostId, $srcHostId)) {
         throw new Exception();
     }
 }
 // clone discovery rules
 $discoveryRules = API::DiscoveryRule()->get(array('output' => array('itemid'), 'hostids' => $srcHostId, 'inherited' => false));
 if ($discoveryRules) {
     $copyDiscoveryRules = API::DiscoveryRule()->copy(array('discoveryids' => zbx_objectValues($discoveryRules, 'itemid'), 'hostids' => array($hostId)));
     if (!$copyDiscoveryRules) {
         throw new Exception();
     }
 }
 $graphs = API::Graph()->get(array('hostids' => $srcHostId, 'selectItems' => array('type'), 'output' => API_OUTPUT_EXTEND, 'inherited' => false, 'selectHosts' => array('hostid'), 'filter' => array('flags' => ZBX_FLAG_DISCOVERY_NORMAL)));
 foreach ($graphs as $graph) {
     if (count($graph['hosts']) > 1) {
         continue;
     }
     if (httpItemExists($graph['items'])) {
         continue;
     }
     if (!copyGraphToHost($graph['graphid'], $hostId)) {
         throw new Exception();
     }
开发者ID:micromachine,项目名称:RackTables-ZABBIX-bridge,代码行数:31,代码来源:hosts.php


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