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


PHP API::HostGroup方法代码示例

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


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

示例1: get

 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     // fetch hosts
     $hosts = API::Host()->get(['output' => ['hostid', 'status'], 'selectGraphs' => $this->screenitem['style'] == STYLE_LEFT ? API_OUTPUT_COUNT : null, 'selectScreens' => $this->screenitem['style'] == STYLE_LEFT ? API_OUTPUT_COUNT : null, 'groupids' => $this->screenitem['resourceid'], 'preservekeys' => true]);
     $hostids = array_keys($hosts);
     $options = ['output' => ['triggerid', 'expression', 'description', 'url', 'value', 'priority', 'lastchange', 'flags'], 'selectHosts' => ['hostid', 'name', 'status'], 'selectItems' => ['itemid', 'hostid', 'name', 'key_', 'value_type'], 'hostids' => $hostids, 'monitored' => true, 'skipDependent' => true, 'sortfield' => 'description', 'preservekeys' => true];
     // application filter
     if ($this->screenitem['application'] !== '') {
         $applications = API::Application()->get(['output' => [], 'hostids' => $hostids, 'search' => ['name' => $this->screenitem['application']], 'preservekeys' => true]);
         $options['applicationids'] = array_keys($applications);
     }
     $triggers = API::Trigger()->get($options);
     $triggers = CMacrosResolverHelper::resolveTriggerUrls($triggers);
     /*
      * Each screen cell with "Triggers overview" depends on one specific group which in this case is 'resourceid'.
      * Pass it as 'groupid' to menu pop-up "Events" link.
      */
     foreach ($triggers as &$trigger) {
         $trigger['groupid'] = $this->screenitem['resourceid'];
     }
     unset($trigger);
     $groups = API::HostGroup()->get(['output' => ['name'], 'groupids' => [$this->screenitem['resourceid']]]);
     $header = (new CDiv([new CTag('h4', true, _('Triggers overview')), (new CList())->addItem([_('Group'), ':', SPACE, $groups[0]['name']])]))->addClass(ZBX_STYLE_DASHBRD_WIDGET_HEAD);
     $table = getTriggersOverview($hosts, $triggers, $this->pageFile, $this->screenitem['style'], $this->screenid);
     $footer = (new CList())->addItem(_s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)))->addClass(ZBX_STYLE_DASHBRD_WIDGET_FOOT);
     return $this->getOutput(new CUiWidget(uniqid(), [$header, $table, $footer]));
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:32,代码来源:CScreenTriggersOverview.php

示例2: validate

 /**
  * Checks is any of the given host groups are discovered.
  *
  * @param mixed $hostGroupIds
  *
  * @return bool
  */
 public function validate($hostGroupIds)
 {
     $hostGroups = API::HostGroup()->get(['output' => ['name'], 'groupids' => $hostGroupIds, 'filter' => ['flags' => ZBX_FLAG_DISCOVERY_CREATED], 'limit' => 1]);
     if ($hostGroups) {
         $hostGroup = reset($hostGroups);
         $this->error($this->message, $hostGroup['name']);
         return false;
     }
     return true;
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:17,代码来源:CHostGroupNormalValidator.php

示例3: get

 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $header = (new CDiv([new CTag('h4', true, _('Triggers info'))]))->addClass(ZBX_STYLE_DASHBRD_WIDGET_HEAD);
     if ($this->screenitem['resourceid'] != 0) {
         $groups = API::HostGroup()->get(['output' => ['name'], 'groupids' => [$this->screenitem['resourceid']]]);
         $header->addItem((new CList())->addItem([_('Host'), ':', SPACE, $groups[0]['name']]));
     }
     $table = (new CTriggersInfo($this->screenitem['resourceid']))->setOrientation($this->screenitem['style']);
     $footer = (new CList())->addItem(_s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)))->addClass(ZBX_STYLE_DASHBRD_WIDGET_FOOT);
     return $this->getOutput(new CUiWidget(uniqid(), [$header, $table, $footer]));
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:16,代码来源:CScreenTriggersInfo.php

示例4: doAction

 protected function doAction()
 {
     $sortField = $this->getInput('sort', CProfile::get('web.scripts.php.sort', 'name'));
     $sortOrder = $this->getInput('sortorder', CProfile::get('web.scripts.php.sortorder', ZBX_SORT_UP));
     CProfile::update('web.scripts.php.sort', $sortField, PROFILE_TYPE_STR);
     CProfile::update('web.scripts.php.sortorder', $sortOrder, PROFILE_TYPE_STR);
     $config = select_config();
     $data = ['uncheck' => $this->hasInput('uncheck'), 'sort' => $sortField, 'sortorder' => $sortOrder];
     // list of scripts
     $data['scripts'] = API::Script()->get(['output' => ['scriptid', 'name', 'command', 'host_access', 'usrgrpid', 'groupid', 'type', 'execute_on'], 'editable' => true, 'limit' => $config['search_limit'] + 1]);
     // sorting & paging
     order_result($data['scripts'], $sortField, $sortOrder);
     $url = (new CUrl('zabbix.php'))->setArgument('action', 'script.list');
     $data['paging'] = getPagingLine($data['scripts'], $sortOrder, $url);
     // find script host group name and user group name. set to '' if all host/user groups used.
     $usrgrpids = [];
     $groupids = [];
     foreach ($data['scripts'] as &$script) {
         $script['userGroupName'] = null;
         // all user groups
         $script['hostGroupName'] = null;
         // all host groups
         if ($script['usrgrpid'] != 0) {
             $usrgrpids[] = $script['usrgrpid'];
         }
         if ($script['groupid'] != 0) {
             $groupids[] = $script['groupid'];
         }
     }
     unset($script);
     if ($usrgrpids) {
         $userGroups = API::UserGroup()->get(['output' => ['name'], 'usrgrpids' => $usrgrpids, 'preservekeys' => true]);
         foreach ($data['scripts'] as &$script) {
             if ($script['usrgrpid'] != 0 && array_key_exists($script['usrgrpid'], $userGroups)) {
                 $script['userGroupName'] = $userGroups[$script['usrgrpid']]['name'];
             }
             unset($script['usrgrpid']);
         }
         unset($script);
     }
     if ($groupids) {
         $hostGroups = API::HostGroup()->get(['output' => ['name'], 'groupids' => $groupids, 'preservekeys' => true]);
         foreach ($data['scripts'] as &$script) {
             if ($script['groupid'] != 0 && array_key_exists($script['groupid'], $hostGroups)) {
                 $script['hostGroupName'] = $hostGroups[$script['groupid']]['name'];
             }
             unset($script['groupid']);
         }
         unset($script);
     }
     $response = new CControllerResponseData($data);
     $response->setTitle(_('Configuration of scripts'));
     $this->setResponse($response);
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:54,代码来源:CControllerScriptList.php

示例5: get

 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $total = 0;
     // fetch accessible host ids
     $hosts = API::Host()->get(['output' => ['hostid'], 'preservekeys' => true]);
     $hostids = array_keys($hosts);
     if ($this->screenitem['resourceid'] != 0) {
         $cond_from = ',hosts_groups hg';
         $cond_where = ' AND hg.hostid=h.hostid AND hg.groupid=' . zbx_dbstr($this->screenitem['resourceid']);
     } else {
         $cond_from = '';
         $cond_where = '';
     }
     $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_TRUE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostids) . $cond_where);
     $host_cnt = DBfetch($db_host_cnt);
     $avail = $host_cnt['cnt'];
     $total += $host_cnt['cnt'];
     $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_FALSE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostids) . $cond_where);
     $host_cnt = DBfetch($db_host_cnt);
     $notav = $host_cnt['cnt'];
     $total += $host_cnt['cnt'];
     $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_UNKNOWN . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostids) . $cond_where);
     $host_cnt = DBfetch($db_host_cnt);
     $uncn = $host_cnt['cnt'];
     $total += $host_cnt['cnt'];
     $avail = (new CCol($avail . '  ' . _('Available')))->addClass(ZBX_STYLE_GREEN);
     $notav = (new CCol($notav . '  ' . _('Not available')))->addClass(ZBX_STYLE_RED);
     $uncn = (new CCol($uncn . '  ' . _('Unknown')))->addClass(ZBX_STYLE_GREY);
     $total = new CCol($total . '  ' . _('Total'));
     $header = (new CDiv([new CTag('h4', true, _('Hosts info'))]))->addClass(ZBX_STYLE_DASHBRD_WIDGET_HEAD);
     if ($this->screenitem['resourceid'] != 0) {
         $groups = API::HostGroup()->get(['output' => ['name'], 'groupids' => [$this->screenitem['resourceid']]]);
         $header->addItem((new CList())->addItem([_('Group'), ':', SPACE, $groups[0]['name']]));
     }
     $table = new CTableInfo();
     if ($this->screenitem['style'] == STYLE_HORIZONTAL) {
         $table->addRow([$avail, $notav, $uncn, $total]);
     } else {
         $table->addRow($avail);
         $table->addRow($notav);
         $table->addRow($uncn);
         $table->addRow($total);
     }
     $footer = (new CList())->addItem(_s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)))->addClass(ZBX_STYLE_DASHBRD_WIDGET_FOOT);
     return $this->getOutput(new CUiWidget(uniqid(), [$header, $table, $footer]));
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:51,代码来源:CScreenHostsInfo.php

示例6: doAction

 protected function doAction()
 {
     $filter = ['groupids' => null, 'maintenance' => null, 'severity' => null, 'trigger_name' => '', 'extAck' => 0];
     if (CProfile::get('web.dashconf.filter.enable', 0) == 1) {
         // groups
         if (CProfile::get('web.dashconf.groups.grpswitch', 0) == 0) {
             // null mean all groups
             $filter['groupids'] = null;
         } else {
             $filter['groupids'] = zbx_objectValues(CFavorite::get('web.dashconf.groups.groupids'), 'value');
             $hideHostGroupIds = zbx_objectValues(CFavorite::get('web.dashconf.groups.hide.groupids'), 'value');
             if ($hideHostGroupIds) {
                 // get all groups if no selected groups defined
                 if (!$filter['groupids']) {
                     $dbHostGroups = API::HostGroup()->get(['output' => ['groupid']]);
                     $filter['groupids'] = zbx_objectValues($dbHostGroups, 'groupid');
                 }
                 $filter['groupids'] = array_diff($filter['groupids'], $hideHostGroupIds);
                 // get available hosts
                 $dbAvailableHosts = API::Host()->get(['groupids' => $filter['groupids'], 'output' => ['hostid']]);
                 $availableHostIds = zbx_objectValues($dbAvailableHosts, 'hostid');
                 $dbDisabledHosts = API::Host()->get(['groupids' => $hideHostGroupIds, 'output' => ['hostid']]);
                 $disabledHostIds = zbx_objectValues($dbDisabledHosts, 'hostid');
                 $filter['hostids'] = array_diff($availableHostIds, $disabledHostIds);
             } else {
                 if (!$filter['groupids']) {
                     // null mean all groups
                     $filter['groupids'] = null;
                 }
             }
         }
         // hosts
         $maintenance = CProfile::get('web.dashconf.hosts.maintenance', 1);
         $filter['maintenance'] = $maintenance == 0 ? 0 : null;
         // triggers
         $severity = CProfile::get('web.dashconf.triggers.severity', null);
         $filter['severity'] = zbx_empty($severity) ? null : explode(';', $severity);
         $filter['severity'] = zbx_toHash($filter['severity']);
         $filter['trigger_name'] = CProfile::get('web.dashconf.triggers.name', '');
         $config = select_config();
         $filter['extAck'] = $config['event_ack_enable'] ? CProfile::get('web.dashconf.events.extAck', 0) : 0;
     }
     $this->setResponse(new CControllerResponseData(['filter' => $filter, 'user' => ['debug_mode' => $this->getDebugMode()]]));
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:44,代码来源:CControllerWidgetSystemView.php

示例7: checkPermissions

 protected function checkPermissions()
 {
     if ($this->getUserType() < USER_TYPE_ZABBIX_USER) {
         return false;
     }
     if ($this->hasInput('groupid') && $this->getInput('groupid') != 0) {
         $groups = API::HostGroup()->get(['output' => [], 'groupids' => [$this->getInput('groupid')]]);
         if (!$groups) {
             return false;
         }
     }
     if ($this->hasInput('hostid') && $this->getInput('hostid') != 0) {
         $hosts = API::Host()->get(['output' => [], 'hostids' => [$this->getInput('hostid')]]);
         if (!$hosts) {
             return false;
         }
     }
     return true;
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:19,代码来源:CControllerWebView.php

示例8: get

 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $hostids = [];
     $dbHostGroups = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . zbx_dbstr($this->screenitem['resourceid']));
     while ($dbHostGroup = DBfetch($dbHostGroups)) {
         $hostids[$dbHostGroup['hostid']] = $dbHostGroup['hostid'];
     }
     // application filter
     $applicationIds = null;
     if ($this->screenitem['application'] !== '') {
         $applications = API::Application()->get(['output' => ['applicationid'], 'hostids' => $hostids, 'search' => ['name' => $this->screenitem['application']]]);
         $applicationIds = zbx_objectValues($applications, 'applicationid');
     }
     $groups = API::HostGroup()->get(['output' => ['name'], 'groupids' => [$this->screenitem['resourceid']]]);
     $header = (new CDiv([new CTag('h4', true, _('Data overview')), (new CList())->addItem([_('Group'), ':', SPACE, $groups[0]['name']])]))->addClass(ZBX_STYLE_DASHBRD_WIDGET_HEAD);
     $table = getItemsDataOverview($hostids, $applicationIds, $this->screenitem['style']);
     $footer = (new CList())->addItem(_s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)))->addClass(ZBX_STYLE_DASHBRD_WIDGET_FOOT);
     return $this->getOutput(new CUiWidget(uniqid(), [$header, $table, $footer]));
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:24,代码来源:CScreenDataOverview.php

示例9: doAction

 protected function doAction()
 {
     // default values
     $data = ['sid' => $this->getUserSID(), 'scriptid' => 0, 'name' => '', 'type' => ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT, 'execute_on' => ZBX_SCRIPT_EXECUTE_ON_AGENT, 'command' => '', 'commandipmi' => '', 'description' => '', 'usrgrpid' => 0, 'groupid' => 0, 'host_access' => 0, 'confirmation' => '', 'enable_confirmation' => 0, 'hgstype' => 0];
     // get values from the dabatase
     if ($this->hasInput('scriptid')) {
         $scripts = API::Script()->get(['output' => ['scriptid', 'name', 'type', 'execute_on', 'command', 'description', 'usrgrpid', 'groupid', 'host_access', 'confirmation'], 'scriptids' => $this->getInput('scriptid')]);
         $script = $scripts[0];
         $data['scriptid'] = $script['scriptid'];
         $data['name'] = $script['name'];
         $data['type'] = $script['type'];
         $data['execute_on'] = $script['execute_on'];
         $data['command'] = $script['type'] == ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT ? $script['command'] : '';
         $data['commandipmi'] = $script['type'] == ZBX_SCRIPT_TYPE_IPMI ? $script['command'] : '';
         $data['description'] = $script['description'];
         $data['usrgrpid'] = $script['usrgrpid'];
         $data['groupid'] = $script['groupid'];
         $data['host_access'] = $script['host_access'];
         $data['confirmation'] = $script['confirmation'];
         $data['enable_confirmation'] = $script['confirmation'] !== '';
         $data['hgstype'] = $script['groupid'] != 0 ? 1 : 0;
     }
     // overwrite with input variables
     $this->getInputs($data, ['name', 'type', 'execute_on', 'command', 'commandipmi', 'description', 'usrgrpid', 'groupid', 'host_access', 'confirmation', 'enable_confirmation', 'hgstype']);
     // get host group
     if ($data['groupid'] == 0) {
         $data['hostgroup'] = null;
     } else {
         $hostgroups = API::HostGroup()->get(['groupids' => [$data['groupid']], 'output' => ['groupid', 'name']]);
         $hostgroup = $hostgroups[0];
         $data['hostgroup'][] = ['id' => $hostgroup['groupid'], 'name' => $hostgroup['name']];
     }
     // get list of user groups
     $usergroups = API::UserGroup()->get(['output' => ['usrgrpid', 'name']]);
     order_result($usergroups, 'name');
     $data['usergroups'] = $usergroups;
     $response = new CControllerResponseData($data);
     $response->setTitle(_('Configuration of scripts'));
     $this->setResponse($response);
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:40,代码来源:CControllerScriptEdit.php

示例10: doAction

 protected function doAction()
 {
     $filter = ['groupids' => null, 'maintenance' => null];
     if (CProfile::get('web.dashconf.filter.enable', 0) == 1) {
         // groups
         if (CProfile::get('web.dashconf.groups.grpswitch', 0) == 0) {
             // null mean all groups
             $filter['groupids'] = null;
         } else {
             $filter['groupids'] = zbx_objectValues(CFavorite::get('web.dashconf.groups.groupids'), 'value');
             $hideHostGroupIds = zbx_objectValues(CFavorite::get('web.dashconf.groups.hide.groupids'), 'value');
             if ($hideHostGroupIds) {
                 // get all groups if no selected groups defined
                 if (!$filter['groupids']) {
                     $dbHostGroups = API::HostGroup()->get(['output' => ['groupid']]);
                     $filter['groupids'] = zbx_objectValues($dbHostGroups, 'groupid');
                 }
                 $filter['groupids'] = array_diff($filter['groupids'], $hideHostGroupIds);
                 // get available hosts
                 $dbAvailableHosts = API::Host()->get(['groupids' => $filter['groupids'], 'output' => ['hostid']]);
                 $availableHostIds = zbx_objectValues($dbAvailableHosts, 'hostid');
                 $dbDisabledHosts = API::Host()->get(['groupids' => $hideHostGroupIds, 'output' => ['hostid']]);
                 $disabledHostIds = zbx_objectValues($dbDisabledHosts, 'hostid');
                 $filter['hostids'] = array_diff($availableHostIds, $disabledHostIds);
             } else {
                 if (!$filter['groupids']) {
                     // null mean all groups
                     $filter['groupids'] = null;
                 }
             }
         }
         // hosts
         $maintenance = CProfile::get('web.dashconf.hosts.maintenance', 1);
         $filter['maintenance'] = $maintenance == 0 ? 0 : null;
     }
     $this->setResponse(new CControllerResponseData(['filter' => $filter, 'user' => ['debug_mode' => $this->getDebugMode()]]));
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:37,代码来源:CControllerWidgetWebView.php

示例11: dirname

require_once dirname(__FILE__) . '/include/hosts.inc.php';
require_once dirname(__FILE__) . '/include/forms.inc.php';
$page['title'] = _('Host inventory overview');
$page['file'] = 'hostinventoriesoverview.php';
require_once dirname(__FILE__) . '/include/page_header.php';
//		VAR			TYPE	OPTIONAL FLAGS	VALIDATION	EXCEPTION
$fields = ['groupid' => [T_ZBX_INT, O_OPT, P_SYS, DB_ID, null], 'groupby' => [T_ZBX_STR, O_OPT, P_SYS, null, null], 'sort' => [T_ZBX_STR, O_OPT, P_SYS, IN('"host_count","inventory_field"'), null], 'sortorder' => [T_ZBX_STR, O_OPT, P_SYS, IN('"' . ZBX_SORT_DOWN . '","' . ZBX_SORT_UP . '"'), null]];
check_fields($fields);
$sortField = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'host_count'));
$sortOrder = getRequest('sortorder', CProfile::get('web.' . $page['file'] . '.sortorder', ZBX_SORT_DOWN));
CProfile::update('web.' . $page['file'] . '.sort', $sortField, PROFILE_TYPE_STR);
CProfile::update('web.' . $page['file'] . '.sortorder', $sortOrder, PROFILE_TYPE_STR);
/*
 * Permissions
 */
if (getRequest('groupid') && !API::HostGroup()->isReadable([$_REQUEST['groupid']])) {
    access_deny();
}
if (PAGE_TYPE_JS == $page['type'] || PAGE_TYPE_HTML_BLOCK == $page['type']) {
    require_once dirname(__FILE__) . '/include/page_footer.php';
    exit;
}
$options = ['groups' => ['real_hosts' => 1], 'groupid' => getRequest('groupid')];
$pageFilter = new CPageFilter($options);
$_REQUEST['groupid'] = $pageFilter->groupid;
$_REQUEST['groupby'] = getRequest('groupby', '');
$groupFieldTitle = '';
$hostinvent_wdgt = (new CWidget())->setTitle(_('Host inventory overview'));
// getting inventory fields to make a drop down
$inventoryFields = getHostInventories(true);
// 'true' means list should be ordered by title
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:31,代码来源:hostinventoriesoverview.php

示例12: validateCreate

 /**
  * Validates the input parameters for the create() method.
  *
  * @param array $hosts		hosts data array
  *
  * @throws APIException if the input is invalid.
  */
 protected function validateCreate(array $hosts)
 {
     $host_db_fields = ['host' => null];
     $groupids = [];
     foreach ($hosts as &$host) {
         // Validate mandatory fields.
         if (!check_db_fields($host_db_fields, $host)) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Wrong fields for host "%1$s".', array_key_exists('host', $host) ? $host['host'] : ''));
         }
         // Validate "host" field.
         if (!preg_match('/^' . ZBX_PREG_HOST_FORMAT . '$/', $host['host'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect characters used for host name "%s".', $host['host']));
         }
         // If visible name is not given or empty it should be set to host name. Required for duplicate checks.
         if (!array_key_exists('name', $host) || !trim($host['name'])) {
             $host['name'] = $host['host'];
         }
         // Validate "groups" field.
         if (!array_key_exists('groups', $host) || !is_array($host['groups']) || !$host['groups']) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('No groups for host "%1$s".', $host['host']));
         }
         $groupids = array_merge($groupids, zbx_objectValues($host['groups'], 'groupid'));
     }
     unset($host);
     // Check for duplicate "host" and "name" fields.
     $duplicate = CArrayHelper::findDuplicate($hosts, 'host');
     if ($duplicate) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _s('Duplicate host. Host with the same host name "%s" already exists in data.', $duplicate['host']));
     }
     $duplicate = CArrayHelper::findDuplicate($hosts, 'name');
     if ($duplicate) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _s('Duplicate host. Host with the same visible name "%s" already exists in data.', $duplicate['name']));
     }
     // Validate permissions to host groups.
     if ($groupids) {
         $db_groups = API::HostGroup()->get(['output' => ['groupid'], 'groupids' => $groupids, 'editable' => true, 'preservekeys' => true]);
     }
     foreach ($hosts as $host) {
         foreach ($host['groups'] as $group) {
             if (!array_key_exists($group['groupid'], $db_groups)) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
             }
         }
     }
     $inventory_fields = zbx_objectValues(getHostInventories(), 'db_field');
     $status_validator = new CLimitedSetValidator(['values' => [HOST_STATUS_MONITORED, HOST_STATUS_NOT_MONITORED], 'messageInvalid' => _('Incorrect status for host "%1$s".')]);
     $host_names = [];
     foreach ($hosts as $host) {
         if (!array_key_exists('interfaces', $host) || !is_array($host['interfaces']) || !$host['interfaces']) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('No interfaces for host "%s".', $host['host']));
         }
         if (array_key_exists('status', $host)) {
             $status_validator->setObjectName($host['host']);
             $this->checkValidator($host['status'], $status_validator);
         }
         if (array_key_exists('inventory', $host) && $host['inventory']) {
             if (array_key_exists('inventory_mode', $host) && $host['inventory_mode'] == HOST_INVENTORY_DISABLED) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot set inventory fields for disabled inventory.'));
             }
             $fields = array_keys($host['inventory']);
             foreach ($fields as $field) {
                 if (!in_array($field, $inventory_fields)) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect inventory field "%s".', $field));
                 }
             }
         }
         // Collect technical and visible names to check if they exist in hosts and templates.
         $host_names['host'][$host['host']] = true;
         $host_names['name'][$host['name']] = true;
     }
     $filter = ['host' => array_keys($host_names['host']), 'name' => array_keys($host_names['name'])];
     $hosts_exists = $this->get(['output' => ['host', 'name'], 'filter' => $filter, 'searchByAny' => true, 'nopermissions' => true]);
     foreach ($hosts_exists as $host_exists) {
         if (array_key_exists($host_exists['host'], $host_names['host'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Host with the same name "%s" already exists.', $host_exists['host']));
         }
         if (array_key_exists($host_exists['name'], $host_names['name'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Host with the same visible name "%s" already exists.', $host_exists['name']));
         }
     }
     $templates_exists = API::Template()->get(['output' => ['host', 'name'], 'filter' => $filter, 'searchByAny' => true, 'nopermissions' => true]);
     foreach ($templates_exists as $template_exists) {
         if (array_key_exists($template_exists['host'], $host_names['host'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Template with the same name "%s" already exists.', $template_exists['host']));
         }
         if (array_key_exists($template_exists['name'], $host_names['name'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Template with the same visible name "%s" already exists.', $template_exists['name']));
         }
     }
     $this->validateEncryption($hosts);
 }
开发者ID:jbfavre,项目名称:debian-zabbix,代码行数:98,代码来源:CHost.php

示例13: getCopyElementsFormData

function getCopyElementsFormData($elementsField, $title = null)
{
    $data = array('title' => $title, 'elements_field' => $elementsField, 'elements' => getRequest($elementsField, array()), 'copy_type' => getRequest('copy_type', COPY_TYPE_TO_HOST_GROUP), 'copy_groupid' => getRequest('copy_groupid', 0), 'copy_targetid' => getRequest('copy_targetid', array()), 'hostid' => getRequest('hostid', 0), 'groups' => array(), 'hosts' => array(), 'templates' => array());
    // validate elements
    if (empty($data['elements']) || !is_array($data['elements'])) {
        error(_('Incorrect list of items.'));
        return null;
    }
    if ($data['copy_type'] == COPY_TYPE_TO_HOST_GROUP) {
        // get groups
        $data['groups'] = API::HostGroup()->get(array('output' => array('groupid', 'name')));
        order_result($data['groups'], 'name');
    } else {
        // hosts or templates
        $params = array('output' => array('name', 'groupid'));
        if ($data['copy_type'] == COPY_TYPE_TO_HOST) {
            $params['real_hosts'] = true;
        } else {
            $params['templated_hosts'] = true;
        }
        $data['groups'] = API::HostGroup()->get($params);
        order_result($data['groups'], 'name');
        $groupIds = zbx_objectValues($data['groups'], 'groupid');
        if (!in_array($data['copy_groupid'], $groupIds) || $data['copy_groupid'] == 0) {
            $data['copy_groupid'] = reset($groupIds);
        }
        if ($data['copy_type'] == COPY_TYPE_TO_TEMPLATE) {
            $data['templates'] = API::Template()->get(array('output' => array('name', 'templateid'), 'groupids' => $data['copy_groupid']));
            order_result($data['templates'], 'name');
        } elseif ($data['copy_type'] == COPY_TYPE_TO_HOST) {
            $data['hosts'] = API::Host()->get(array('output' => array('name', 'hostid'), 'groupids' => $data['copy_groupid']));
            order_result($data['hosts'], 'name');
        }
    }
    return $data;
}
开发者ID:omidmt,项目名称:zabbix-greenplum,代码行数:36,代码来源:forms.inc.php

示例14: addRelatedObjects

 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     if ($options['globalmacro'] === null) {
         $hostMacroIds = array_keys($result);
         /*
          * Adding objects
          */
         // adding groups
         if ($options['selectGroups'] !== null && $options['selectGroups'] != API_OUTPUT_COUNT) {
             $res = DBselect('SELECT hm.hostmacroid,hg.groupid' . ' FROM hostmacro hm,hosts_groups hg' . ' WHERE ' . dbConditionInt('hm.hostmacroid', $hostMacroIds) . ' AND hm.hostid=hg.hostid');
             $relationMap = new CRelationMap();
             while ($relation = DBfetch($res)) {
                 $relationMap->addRelation($relation['hostmacroid'], $relation['groupid']);
             }
             $groups = API::HostGroup()->get(array('output' => $options['selectGroups'], 'groupids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
             $result = $relationMap->mapMany($result, $groups, 'groups');
         }
         // adding templates
         if ($options['selectTemplates'] !== null && $options['selectTemplates'] != API_OUTPUT_COUNT) {
             $relationMap = $this->createRelationMap($result, 'hostmacroid', 'hostid');
             $templates = API::Template()->get(array('output' => $options['selectTemplates'], 'templateids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
             $result = $relationMap->mapMany($result, $templates, 'templates');
         }
         // adding templates
         if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) {
             $relationMap = $this->createRelationMap($result, 'hostmacroid', 'hostid');
             $templates = API::Host()->get(array('output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
             $result = $relationMap->mapMany($result, $templates, 'hosts');
         }
     }
     return $result;
 }
开发者ID:TonywalkerCN,项目名称:Zabbix,代码行数:33,代码来源:CUserMacro.php

示例15: get


//.........这里部分代码省略.........
         if ($result) {
             $linkTriggers = array();
             $dbLinkTriggers = DBselect('SELECT slt.triggerid,sl.sysmapid' . ' FROM sysmaps_link_triggers slt,sysmaps_links sl' . ' WHERE ' . dbConditionInt('sl.sysmapid', $sysmapids) . ' AND sl.linkid=slt.linkid');
             while ($linkTrigger = DBfetch($dbLinkTriggers)) {
                 $linkTriggers[$linkTrigger['sysmapid']] = $linkTrigger['triggerid'];
             }
             if ($linkTriggers) {
                 $trigOptions = array('triggerids' => $linkTriggers, 'editable' => $options['editable'], 'output' => array('triggerid'), 'preservekeys' => true);
                 $allTriggers = API::Trigger()->get($trigOptions);
                 foreach ($linkTriggers as $id => $triggerid) {
                     if (!isset($allTriggers[$triggerid])) {
                         unset($result[$id], $sysmapids[$id]);
                     }
                 }
             }
             $hostsToCheck = array();
             $mapsToCheck = array();
             $triggersToCheck = array();
             $hostGroupsToCheck = array();
             $selements = array();
             $dbSelements = DBselect('SELECT se.* FROM sysmaps_elements se WHERE ' . dbConditionInt('se.sysmapid', $sysmapids));
             while ($selement = DBfetch($dbSelements)) {
                 $selements[$selement['selementid']] = $selement;
                 switch ($selement['elementtype']) {
                     case SYSMAP_ELEMENT_TYPE_HOST:
                         $hostsToCheck[$selement['elementid']] = $selement['elementid'];
                         break;
                     case SYSMAP_ELEMENT_TYPE_MAP:
                         $mapsToCheck[$selement['elementid']] = $selement['elementid'];
                         break;
                     case SYSMAP_ELEMENT_TYPE_TRIGGER:
                         $triggersToCheck[$selement['elementid']] = $selement['elementid'];
                         break;
                     case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                         $hostGroupsToCheck[$selement['elementid']] = $selement['elementid'];
                         break;
                 }
             }
             if ($hostsToCheck) {
                 $allowedHosts = API::Host()->get(array('hostids' => $hostsToCheck, 'editable' => $options['editable'], 'preservekeys' => true, 'output' => array('hostid')));
                 foreach ($hostsToCheck as $elementid) {
                     if (!isset($allowedHosts[$elementid])) {
                         foreach ($selements as $selementid => $selement) {
                             if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST && bccomp($selement['elementid'], $elementid) == 0) {
                                 unset($result[$selement['sysmapid']], $selements[$selementid]);
                             }
                         }
                     }
                 }
             }
             if ($mapsToCheck) {
                 $allowedMaps = $this->get(array('sysmapids' => $mapsToCheck, 'editable' => $options['editable'], 'preservekeys' => true, 'output' => array('sysmapid')));
                 foreach ($mapsToCheck as $elementid) {
                     if (!isset($allowedMaps[$elementid])) {
                         foreach ($selements as $selementid => $selement) {
                             if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_MAP && bccomp($selement['elementid'], $elementid) == 0) {
                                 unset($result[$selement['sysmapid']], $selements[$selementid]);
                             }
                         }
                     }
                 }
             }
             if ($triggersToCheck) {
                 $allowedTriggers = API::Trigger()->get(array('triggerids' => $triggersToCheck, 'editable' => $options['editable'], 'preservekeys' => true, 'output' => array('triggerid')));
                 foreach ($triggersToCheck as $elementid) {
                     if (!isset($allowedTriggers[$elementid])) {
                         foreach ($selements as $selementid => $selement) {
                             if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_TRIGGER && bccomp($selement['elementid'], $elementid) == 0) {
                                 unset($result[$selement['sysmapid']], $selements[$selementid]);
                             }
                         }
                     }
                 }
             }
             if ($hostGroupsToCheck) {
                 $allowedHostGroups = API::HostGroup()->get(array('groupids' => $hostGroupsToCheck, 'editable' => $options['editable'], 'preservekeys' => true, 'output' => array('groupid')));
                 foreach ($hostGroupsToCheck as $elementid) {
                     if (!isset($allowedHostGroups[$elementid])) {
                         foreach ($selements as $selementid => $selement) {
                             if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST_GROUP && bccomp($selement['elementid'], $elementid) == 0) {
                                 unset($result[$selement['sysmapid']], $selements[$selementid]);
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!is_null($options['countOutput'])) {
         return $result;
     }
     if ($result) {
         $result = $this->addRelatedObjects($options, $result);
     }
     // removing keys (hash -> array)
     if (is_null($options['preservekeys'])) {
         $result = zbx_cleanHashes($result);
     }
     return $result;
 }
开发者ID:TonywalkerCN,项目名称:Zabbix,代码行数:101,代码来源:CMap.php


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