/**
  * 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]));
 }
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * 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]));
 }
 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);
 }
Exemplo n.º 5
0
 /**
  * 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]));
 }
 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()]]));
 }
Exemplo n.º 7
0
 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;
 }
Exemplo n.º 8
0
 /**
  * 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]));
 }
 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);
 }
 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()]]));
 }
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
Exemplo n.º 12
0
 /**
  * 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);
 }
Exemplo n.º 13
0
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;
}
Exemplo n.º 14
0
 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;
 }
Exemplo n.º 15
0
 /**
  * Get map data.
  *
  * @param array  $options
  * @param array  $options['groupids']					HostGroup IDs
  * @param array  $options['hostids']					Host IDs
  * @param bool   $options['monitored_hosts']			only monitored Hosts
  * @param bool   $options['templated_hosts']			include templates in result
  * @param bool   $options['with_items']					only with items
  * @param bool   $options['with_monitored_items']		only with monitored items
  * @param bool   $options['with_triggers'] only with	triggers
  * @param bool   $options['with_monitored_triggers']	only with monitored triggers
  * @param bool   $options['with_httptests'] only with	http tests
  * @param bool   $options['with_monitored_httptests']	only with monitored http tests
  * @param bool   $options['with_graphs']				only with graphs
  * @param bool   $options['editable']					only with read-write permission. Ignored for SuperAdmins
  * @param int    $options['count']						count Hosts, returned column name is rowscount
  * @param string $options['pattern']					search hosts by pattern in host names
  * @param int    $options['limit']						limit selection
  * @param string $options['sortorder']
  * @param string $options['sortfield']
  *
  * @return array|boolean Host data as array or false if error
  */
 public function get(array $options = array())
 {
     $result = array();
     $userType = self::$userData['type'];
     $sqlParts = array('select' => array('sysmaps' => 's.sysmapid'), 'from' => array('sysmaps' => 'sysmaps s'), 'where' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('sysmapids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_EXTEND, 'selectSelements' => null, 'selectLinks' => null, 'selectIconMap' => null, 'selectUrls' => null, 'countOutput' => null, 'expandUrls' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($defOptions, $options);
     // sysmapids
     if (!is_null($options['sysmapids'])) {
         zbx_value2array($options['sysmapids']);
         $sqlParts['where']['sysmapid'] = dbConditionInt('s.sysmapid', $options['sysmapids']);
     }
     // search
     if (!is_null($options['search'])) {
         zbx_db_search('sysmaps s', $options, $sqlParts);
     }
     // filter
     if (!is_null($options['filter'])) {
         $this->dbFilter('sysmaps s', $options, $sqlParts);
     }
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sqlParts['limit'] = $options['limit'];
     }
     $sysmapids = array();
     $sqlParts = $this->applyQueryOutputOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
     $sqlParts = $this->applyQuerySortOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
     $res = DBselect($this->createSelectQueryFromParts($sqlParts), $sqlParts['limit']);
     while ($sysmap = DBfetch($res)) {
         if ($options['countOutput']) {
             $result = $sysmap['rowscount'];
         } else {
             $sysmapids[$sysmap['sysmapid']] = $sysmap['sysmapid'];
             // originally we intended not to pass those parameters if advanced labels are off, but they might be useful
             // leaving this block commented
             // if (isset($sysmap['label_format']) && ($sysmap['label_format'] == SYSMAP_LABEL_ADVANCED_OFF)) {
             // 	unset($sysmap['label_string_hostgroup'], $sysmap['label_string_host'], $sysmap['label_string_trigger'], $sysmap['label_string_map'], $sysmap['label_string_image']);
             // }
             $result[$sysmap['sysmapid']] = $sysmap;
         }
     }
     if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
         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;
 }
Exemplo n.º 16
0
/**
 * Create and return a DIV with web monitoring overview.
 *
 * @param array $filter
 * @param array $filter['groupids']
 * @param bool  $filter['maintenance']
 *
 * @return CDiv
 */
function make_webmon_overview($filter)
{
    $groups = API::HostGroup()->get(array('groupids' => $filter['groupids'], 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored_hosts' => true, 'with_monitored_httptests' => true, 'output' => array('groupid', 'name'), 'preservekeys' => true));
    foreach ($groups as &$group) {
        $group['nodename'] = get_node_name_by_elid($group['groupid']);
    }
    unset($group);
    CArrayHelper::sort($groups, array(array('field' => 'nodename', 'order' => ZBX_SORT_UP), array('field' => 'name', 'order' => ZBX_SORT_UP)));
    $groupIds = array_keys($groups);
    $availableHosts = API::Host()->get(array('groupids' => $groupIds, 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored_hosts' => true, 'filter' => array('maintenance_status' => $filter['maintenance']), 'output' => array('hostid'), 'preservekeys' => true));
    $availableHostIds = array_keys($availableHosts);
    $table = new CTableInfo(_('No web scenarios found.'));
    $table->setHeader(array(is_show_all_nodes() ? _('Node') : null, _('Host group'), _('Ok'), _('Failed'), _('Unknown')));
    $data = array();
    // fetch links between HTTP tests and host groups
    $result = DbFetchArray(DBselect('SELECT DISTINCT ht.httptestid,hg.groupid' . ' FROM httptest ht,hosts_groups hg' . ' WHERE ht.hostid=hg.hostid' . ' AND ' . dbConditionInt('hg.hostid', $availableHostIds) . ' AND ' . dbConditionInt('hg.groupid', $groupIds)));
    // fetch HTTP test execution data
    $httpTestData = Manager::HttpTest()->getLastData(zbx_objectValues($result, 'httptestid'));
    foreach ($result as $row) {
        if (!isset($httpTestData[$row['httptestid']])) {
            $data[$row['groupid']]['unknown'] = empty($data[$row['groupid']]['unknown']) ? 1 : ++$data[$row['groupid']]['unknown'];
        } elseif ($httpTestData[$row['httptestid']]['lastfailedstep'] != 0) {
            $data[$row['groupid']]['failed'] = empty($data[$row['groupid']]['failed']) ? 1 : ++$data[$row['groupid']]['failed'];
        } else {
            $data[$row['groupid']]['ok'] = empty($data[$row['groupid']]['ok']) ? 1 : ++$data[$row['groupid']]['ok'];
        }
    }
    foreach ($groups as $group) {
        if (!empty($data[$group['groupid']])) {
            $table->addRow(array(is_show_all_nodes() ? $group['nodename'] : null, $group['name'], new CSpan(empty($data[$group['groupid']]['ok']) ? 0 : $data[$group['groupid']]['ok'], 'off'), new CSpan(empty($data[$group['groupid']]['failed']) ? 0 : $data[$group['groupid']]['failed'], empty($data[$group['groupid']]['failed']) ? 'off' : 'on'), new CSpan(empty($data[$group['groupid']]['unknown']) ? 0 : $data[$group['groupid']]['unknown'], 'unknown')));
        }
    }
    $script = new CJSScript(get_js("jQuery('#hat_webovr_footer').html('" . _s('Updated: %s', zbx_date2str(_('H:i:s'))) . "')"));
    return new CDiv(array($table, $script));
}
Exemplo n.º 17
0
$page['title'] = _('Custom screens');
$page['file'] = 'screens.php';
$page['hist_arg'] = array('elementid', 'screenname');
$page['scripts'] = array('class.calendar.js', 'gtlc.js', 'flickerfreescreen.js');
$page['type'] = detect_page_type(PAGE_TYPE_HTML);
define('ZBX_PAGE_DO_JS_REFRESH', 1);
require_once dirname(__FILE__) . '/include/page_header.php';
// VAR	TYPE	OPTIONAL	FLAGS	VALIDATION	EXCEPTION
$fields = array('groupid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), 'hostid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), 'tr_groupid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), 'tr_hostid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), 'elementid' => array(T_ZBX_INT, O_OPT, P_SYS | P_NZERO, DB_ID, null), 'screenname' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'step' => array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0, 65535), null), 'period' => array(T_ZBX_INT, O_OPT, P_SYS, null, null), 'stime' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'reset' => array(T_ZBX_STR, O_OPT, P_SYS, IN("'reset'"), null), 'fullscreen' => array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1'), null), 'favobj' => array(T_ZBX_STR, O_OPT, P_ACT, null, null), 'favref' => array(T_ZBX_STR, O_OPT, P_ACT, NOT_EMPTY, null), 'favid' => array(T_ZBX_INT, O_OPT, P_ACT, null, null), 'favaction' => array(T_ZBX_STR, O_OPT, P_ACT, IN("'add','remove','flop'"), null), 'favstate' => array(T_ZBX_INT, O_OPT, P_ACT, NOT_EMPTY, null));
check_fields($fields);
/*
 * Permissions
 */
// validate group IDs
$validateGroupIds = array_filter(array(get_request('groupid'), get_request('tr_groupid')));
if ($validateGroupIds && !API::HostGroup()->isReadable($validateGroupIds)) {
    access_deny();
}
// validate host IDs
$validateHostIds = array_filter(array(get_request('hostid'), get_request('tr_hostid')));
if ($validateHostIds && !API::Host()->isReadable($validateHostIds)) {
    access_deny();
}
if (get_request('elementid')) {
    $screens = API::Screen()->get(array('screenids' => array($_REQUEST['elementid']), 'output' => array('screenid')));
    if (!$screens) {
        access_deny();
    }
}
/*
 * Filter
Exemplo n.º 18
0
 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     // selectGroups
     if ($options['selectGroups'] !== null && $options['selectGroups'] != API_OUTPUT_COUNT) {
         $relationMap = $this->createRelationMap($result, 'maintenanceid', 'groupid', 'maintenances_groups');
         $groups = API::HostGroup()->get(['output' => $options['selectGroups'], 'hostgroupids' => $relationMap->getRelatedIds(), 'preservekeys' => true]);
         $result = $relationMap->mapMany($result, $groups, 'groups');
     }
     // selectHosts
     if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) {
         $relationMap = $this->createRelationMap($result, 'maintenanceid', 'hostid', 'maintenances_hosts');
         $groups = API::Host()->get(['output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'preservekeys' => true]);
         $result = $relationMap->mapMany($result, $groups, 'hosts');
     }
     // selectTimeperiods
     if ($options['selectTimeperiods'] !== null && $options['selectTimeperiods'] != API_OUTPUT_COUNT) {
         $relationMap = $this->createRelationMap($result, 'maintenanceid', 'timeperiodid', 'maintenances_windows');
         $timeperiods = API::getApiService()->select('timeperiods', ['output' => $options['selectTimeperiods'], 'filter' => ['timeperiodid' => $relationMap->getRelatedIds()], 'preservekeys' => true]);
         $result = $relationMap->mapMany($result, $timeperiods, 'timeperiods');
     }
     return $result;
 }
Exemplo n.º 19
0
     $newOperationsTable->addItem(new CVar('new_operation[objectid]', 0));
     $newOperationsTable->addItem(new CVar('new_operation[shortdata]', ''));
     $newOperationsTable->addItem(new CVar('new_operation[longdata]', ''));
     break;
 case OPERATION_TYPE_GROUP_ADD:
 case OPERATION_TYPE_GROUP_REMOVE:
     if (!isset($this->data['new_operation']['opgroup'])) {
         $this->data['new_operation']['opgroup'] = array();
     }
     $groupList = new CTable();
     $groupList->setAttribute('id', 'opGroupList');
     $groupList->addRow(new CRow(new CCol(array(new CMultiSelect(array('name' => 'discoveryHostGroup', 'objectName' => 'hostGroup', 'objectOptions' => array('editable' => true))), new CButton('add', _('Add'), 'return addDiscoveryHostGroup();', 'link_menu')), null, 2), null, 'opGroupListFooter'));
     // load host groups
     $groupIds = isset($this->data['new_operation']['opgroup']) ? zbx_objectValues($this->data['new_operation']['opgroup'], 'groupid') : array();
     if ($groupIds) {
         $hostGroups = API::HostGroup()->get(array('groupids' => $groupIds, 'output' => array('groupid', 'name')));
         order_result($hostGroups, 'name');
         $jsInsert = '';
         $jsInsert .= 'addPopupValues(' . zbx_jsvalue(array('object' => 'dsc_groupid', 'values' => $hostGroups)) . ');';
         zbx_add_post_js($jsInsert);
     }
     $caption = OPERATION_TYPE_GROUP_ADD == $this->data['new_operation']['operationtype'] ? _('Add to host groups') : _('Remove from host groups');
     $newOperationsTable->addRow(array($caption, new CDiv($groupList, 'objectgroup inlineblock border_dotted ui-corner-all')));
     break;
 case OPERATION_TYPE_TEMPLATE_ADD:
 case OPERATION_TYPE_TEMPLATE_REMOVE:
     if (!isset($this->data['new_operation']['optemplate'])) {
         $this->data['new_operation']['optemplate'] = array();
     }
     $templateList = new CTable();
     $templateList->setAttribute('id', 'opTemplateList');
}
// LLD rule link
if ($isDiscovered) {
    $hostList->addRow(_('Discovered by'), new CLink($dbHost['discoveryRule']['name'], 'host_prototypes.php?parent_discoveryid=' . $dbHost['discoveryRule']['itemid'], 'highlight underline weight_normal'));
}
$hostTB = new CTextBox('host', $host, ZBX_TEXTBOX_STANDARD_SIZE, $isDiscovered);
$hostTB->setAttribute('maxlength', 64);
$hostTB->setAttribute('autofocus', 'autofocus');
$hostList->addRow(_('Host name'), $hostTB);
$visiblenameTB = new CTextBox('visiblename', $visiblename, ZBX_TEXTBOX_STANDARD_SIZE, $isDiscovered);
$visiblenameTB->setAttribute('maxlength', 64);
$hostList->addRow(_('Visible name'), $visiblenameTB);
// groups for normal hosts
if (!$isDiscovered) {
    $grp_tb = new CTweenBox($frmHost, 'groups', $host_groups, 10);
    $all_groups = API::HostGroup()->get(array('editable' => true, 'output' => API_OUTPUT_EXTEND));
    order_result($all_groups, 'name');
    foreach ($all_groups as $group) {
        $grp_tb->addItem($group['groupid'], $group['name']);
    }
    $hostList->addRow(_('Groups'), $grp_tb->get(_('In groups'), _('Other groups')));
    $newgroupTB = new CTextBox('newgroup', $newgroup, ZBX_TEXTBOX_SMALL_SIZE);
    $newgroupTB->setAttribute('maxlength', 64);
    $tmp_label = _('New group');
    if (CWebUser::$data['type'] != USER_TYPE_SUPER_ADMIN) {
        $tmp_label .= SPACE . _('(Only super admins can create groups)');
        $newgroupTB->setReadonly(true);
    }
    $hostList->addRow(SPACE, array(new CLabel($tmp_label, 'newgroup'), BR(), $newgroupTB), null, null, null, 'new');
} else {
    $groupBox = new CComboBox('groups');
Exemplo n.º 21
0
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
require_once dirname(__FILE__) . '/include/config.inc.php';
require_once dirname(__FILE__) . '/include/hosts.inc.php';
require_once dirname(__FILE__) . '/include/forms.inc.php';
$page['title'] = _('Host inventory');
$page['file'] = 'hostinventories.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], 'hostid' => [T_ZBX_INT, O_OPT, P_SYS, DB_ID, null], 'filter_set' => [T_ZBX_STR, O_OPT, P_SYS, null, null], 'filter_rst' => [T_ZBX_STR, O_OPT, P_SYS, null, null], 'filter_field' => [T_ZBX_STR, O_OPT, null, null, null], 'filter_field_value' => [T_ZBX_STR, O_OPT, null, null, null], 'filter_exact' => [T_ZBX_INT, O_OPT, null, 'IN(0,1)', null], 'sort' => [T_ZBX_STR, O_OPT, P_SYS, IN('"name","pr_macaddress_a","pr_name","pr_os","pr_serialno_a","pr_tag","pr_type"'), null], 'sortorder' => [T_ZBX_STR, O_OPT, P_SYS, IN('"' . ZBX_SORT_DOWN . '","' . ZBX_SORT_UP . '"'), null]];
check_fields($fields);
/*
 * Permissions
 */
if (getRequest('groupid') && !API::HostGroup()->isReadable([getRequest('groupid')])) {
    access_deny();
}
if (getRequest('hostid') && !API::Host()->isReadable([getRequest('hostid')])) {
    access_deny();
}
$sortField = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'name'));
$sortOrder = getRequest('sortorder', CProfile::get('web.' . $page['file'] . '.sortorder', ZBX_SORT_UP));
CProfile::update('web.' . $page['file'] . '.sort', $sortField, PROFILE_TYPE_STR);
CProfile::update('web.' . $page['file'] . '.sortorder', $sortOrder, PROFILE_TYPE_STR);
$hostId = getRequest('hostid', 0);
/*
 * Display
 */
if ($hostId > 0) {
    $data = [];
Exemplo n.º 22
0
 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     $triggerids = array_keys($result);
     // adding groups
     if ($options['selectGroups'] !== null && $options['selectGroups'] != API_OUTPUT_COUNT) {
         $res = DBselect('SELECT f.triggerid,hg.groupid' . ' FROM functions f,items i,hosts_groups hg' . ' WHERE ' . dbConditionInt('f.triggerid', $triggerids) . ' AND f.itemid=i.itemid' . ' AND i.hostid=hg.hostid');
         $relationMap = new CRelationMap();
         while ($relation = DBfetch($res)) {
             $relationMap->addRelation($relation['triggerid'], $relation['groupid']);
         }
         $groups = API::HostGroup()->get(array('output' => $options['selectGroups'], 'groupids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
         $result = $relationMap->mapMany($result, $groups, 'groups');
     }
     // adding hosts
     if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) {
         $res = DBselect('SELECT f.triggerid,i.hostid' . ' FROM functions f,items i' . ' WHERE ' . dbConditionInt('f.triggerid', $triggerids) . ' AND f.itemid=i.itemid');
         $relationMap = new CRelationMap();
         while ($relation = DBfetch($res)) {
             $relationMap->addRelation($relation['triggerid'], $relation['hostid']);
         }
         $hosts = API::Host()->get(array('output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'templated_hosts' => true, 'nopermissions' => true, 'preservekeys' => true));
         if (!is_null($options['limitSelects'])) {
             order_result($hosts, 'host');
         }
         $result = $relationMap->mapMany($result, $hosts, 'hosts', $options['limitSelects']);
     }
     // adding functions
     if ($options['selectFunctions'] !== null && $options['selectFunctions'] != API_OUTPUT_COUNT) {
         $functions = API::getApiService()->select('functions', array('output' => $this->outputExtend($options['selectFunctions'], array('triggerid', 'functionid')), 'filter' => array('triggerid' => $triggerids), 'preservekeys' => true));
         $relationMap = $this->createRelationMap($functions, 'triggerid', 'functionid');
         $functions = $this->unsetExtraFields($functions, array('triggerid', 'functionid'), $options['selectFunctions']);
         $result = $relationMap->mapMany($result, $functions, 'functions');
     }
     return $result;
 }
 /**
  * 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']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sqlParts['select']['itemid'] = 'id.parent_itemid';
         }
         $sqlParts['from']['graphs_items'] = 'graphs_items gi';
         $sqlParts['from']['item_discovery'] = 'item_discovery id';
         $sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
         $sqlParts['where']['giid'] = 'gi.itemid=id.itemid';
         $sqlParts['where'][] = dbConditionInt('id.parent_itemid', $options['discoveryids']);
         if (!is_null($options['groupCount'])) {
             $sqlParts['group']['id'] = 'id.parent_itemid';
         }
     }
     // type
     if (!is_null($options['type'])) {
         $sqlParts['where'][] = 'g.type=' . zbx_dbstr($options['type']);
     }
     // templated
     if (!is_null($options['templated'])) {
         $sqlParts['from']['graphs_items'] = 'graphs_items gi';
         $sqlParts['from']['items'] = 'items i';
         $sqlParts['from']['hosts'] = 'hosts h';
         $sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
         $sqlParts['where']['ggi'] = 'g.graphid=gi.graphid';
         $sqlParts['where']['hi'] = 'h.hostid=i.hostid';
         if ($options['templated']) {
             $sqlParts['where'][] = 'h.status=' . HOST_STATUS_TEMPLATE;
         } else {
             $sqlParts['where'][] = 'h.status<>' . HOST_STATUS_TEMPLATE;
         }
     }
     // inherited
     if (!is_null($options['inherited'])) {
         if ($options['inherited']) {
             $sqlParts['where'][] = 'g.templateid IS NOT NULL';
         } else {
             $sqlParts['where'][] = 'g.templateid IS NULL';
         }
     }
     // output
     if ($options['output'] == API_OUTPUT_EXTEND) {
         $sqlParts['select']['graphs'] = 'g.*';
     }
     // countOutput
     if (!is_null($options['countOutput'])) {
         $options['sortfield'] = '';
         $sqlParts['select'] = array('count(DISTINCT g.graphid) as rowscount');
         // groupCount
         if (!is_null($options['groupCount'])) {
             foreach ($sqlParts['group'] as $key => $fields) {
                 $sqlParts['select'][$key] = $fields;
             }
         }
     }
     // search
     if (is_array($options['search'])) {
         zbx_db_search('graphs g', $options, $sqlParts);
     }
     // filter
     if (is_array($options['filter'])) {
         $this->dbFilter('graphs g', $options, $sqlParts);
         if (isset($options['filter']['host'])) {
             zbx_value2array($options['filter']['host']);
             $sqlParts['from']['graphs_items'] = 'graphs_items gi';
             $sqlParts['from']['items'] = 'items i';
             $sqlParts['from']['hosts'] = 'hosts h';
             $sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
             $sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
             $sqlParts['where']['hi'] = 'h.hostid=i.hostid';
             $sqlParts['where']['host'] = dbConditionString('h.host', $options['filter']['host']);
         }
         if (isset($options['filter']['hostid'])) {
             zbx_value2array($options['filter']['hostid']);
             $sqlParts['from']['graphs_items'] = 'graphs_items gi';
             $sqlParts['from']['items'] = 'items i';
             $sqlParts['where']['gig'] = 'gi.graphid=g.graphid';
             $sqlParts['where']['igi'] = 'i.itemid=gi.itemid';
             $sqlParts['where']['hostid'] = dbConditionInt('i.hostid', $options['filter']['hostid']);
         }
     }
     // sorting
     zbx_db_sorting($sqlParts, $options, $sortColumns, 'g');
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sqlParts['limit'] = $options['limit'];
     }
     $graphids = array();
     $sqlParts['select'] = array_unique($sqlParts['select']);
     $sqlParts['from'] = array_unique($sqlParts['from']);
     $sqlParts['where'] = array_unique($sqlParts['where']);
     $sqlParts['group'] = array_unique($sqlParts['group']);
     $sqlParts['order'] = array_unique($sqlParts['order']);
     $sqlSelect = '';
     $sqlFrom = '';
     $sqlWhere = '';
     $sqlGroup = '';
     $sqlOrder = '';
     if (!empty($sqlParts['select'])) {
         $sqlSelect .= implode(',', $sqlParts['select']);
     }
     if (!empty($sqlParts['from'])) {
         $sqlFrom .= implode(',', $sqlParts['from']);
     }
     if (!empty($sqlParts['where'])) {
         $sqlWhere .= ' AND ' . implode(' AND ', $sqlParts['where']);
     }
     if (!empty($sqlParts['group'])) {
         $sqlWhere .= ' GROUP BY ' . implode(',', $sqlParts['group']);
     }
     if (!empty($sqlParts['order'])) {
         $sqlOrder .= ' ORDER BY ' . implode(',', $sqlParts['order']);
     }
     $sqlLimit = $sqlParts['limit'];
     $sql = 'SELECT ' . zbx_db_distinct($sqlParts) . ' ' . $sqlSelect . ' FROM ' . $sqlFrom . ' WHERE ' . DBin_node('g.graphid', $nodeids) . $sqlWhere . $sqlGroup . $sqlOrder;
     $dbRes = DBselect($sql, $sqlLimit);
     while ($graph = DBfetch($dbRes)) {
         if (!is_null($options['countOutput'])) {
             if (!is_null($options['groupCount'])) {
                 $result[] = $graph;
             } else {
                 $result = $graph['rowscount'];
             }
         } else {
             $graphids[$graph['graphid']] = $graph['graphid'];
             if ($options['output'] == API_OUTPUT_SHORTEN) {
                 $result[$graph['graphid']] = array('graphid' => $graph['graphid']);
             } else {
                 if (!isset($result[$graph['graphid']])) {
                     $result[$graph['graphid']] = array();
                 }
                 if (!is_null($options['selectHosts']) && !isset($result[$graph['graphid']]['hosts'])) {
                     $result[$graph['graphid']]['hosts'] = array();
                 }
                 if (!is_null($options['selectGraphItems']) && !isset($result[$graph['graphid']]['gitems'])) {
                     $result[$graph['graphid']]['gitems'] = array();
                 }
                 if (!is_null($options['selectTemplates']) && !isset($result[$graph['graphid']]['templates'])) {
                     $result[$graph['graphid']]['templates'] = array();
                 }
                 if (!is_null($options['selectItems']) && !isset($result[$graph['graphid']]['items'])) {
                     $result[$graph['graphid']]['items'] = array();
                 }
                 if (!is_null($options['selectDiscoveryRule']) && !isset($result[$graph['graphid']]['discoveryRule'])) {
                     $result[$graph['graphid']]['discoveryRule'] = array();
                 }
                 // hostids
                 if (isset($graph['hostid']) && is_null($options['selectHosts'])) {
                     if (!isset($result[$graph['graphid']]['hosts'])) {
                         $result[$graph['graphid']]['hosts'] = array();
                     }
                     $result[$graph['graphid']]['hosts'][] = array('hostid' => $graph['hostid']);
                     unset($graph['hostid']);
                 }
                 // itemids
                 if (isset($graph['itemid']) && is_null($options['selectItems'])) {
                     if (!isset($result[$graph['graphid']]['items'])) {
                         $result[$graph['graphid']]['items'] = array();
                     }
                     $result[$graph['graphid']]['items'][] = array('itemid' => $graph['itemid']);
                     unset($graph['itemid']);
                 }
                 $result[$graph['graphid']] += $graph;
             }
         }
     }
     if (!is_null($options['countOutput'])) {
         return $result;
     }
     // adding GraphItems
     if (!is_null($options['selectGraphItems']) && str_in_array($options['selectGraphItems'], $subselectsAllowedOutputs)) {
         $gitems = API::GraphItem()->get(array('nodeids' => $nodeids, 'output' => $options['selectGraphItems'], 'graphids' => $graphids, 'nopermissions' => true, 'preservekeys' => true));
         foreach ($gitems as $gitem) {
             $ggraphs = $gitem['graphs'];
             unset($gitem['graphs']);
             foreach ($ggraphs as $graph) {
                 $result[$graph['graphid']]['gitems'][$gitem['gitemid']] = $gitem;
             }
         }
     }
     // adding Hostgroups
     if (!is_null($options['selectGroups'])) {
         if (is_array($options['selectGroups']) || str_in_array($options['selectGroups'], $subselectsAllowedOutputs)) {
             $groups = API::HostGroup()->get(array('nodeids' => $nodeids, 'output' => $options['selectGroups'], 'graphids' => $graphids, 'nopermissions' => true, 'preservekeys' => true));
             foreach ($groups as $group) {
                 $ggraphs = $group['graphs'];
                 unset($group['graphs']);
                 foreach ($ggraphs as $graph) {
                     $result[$graph['graphid']]['groups'][] = $group;
                 }
             }
         }
     }
     // adding Hosts
     if (!is_null($options['selectHosts'])) {
         if (is_array($options['selectHosts']) || str_in_array($options['selectHosts'], $subselectsAllowedOutputs)) {
             $hosts = API::Host()->get(array('nodeids' => $nodeids, 'output' => $options['selectHosts'], 'graphids' => $graphids, 'nopermissions' => true, 'preservekeys' => true));
             foreach ($hosts as $host) {
                 $hgraphs = $host['graphs'];
                 unset($host['graphs']);
                 foreach ($hgraphs as $graph) {
                     $result[$graph['graphid']]['hosts'][] = $host;
                 }
             }
         }
     }
     // adding Templates
     if (!is_null($options['selectTemplates']) && str_in_array($options['selectTemplates'], $subselectsAllowedOutputs)) {
         $templates = API::Template()->get(array('nodeids' => $nodeids, 'output' => $options['selectTemplates'], 'graphids' => $graphids, 'nopermissions' => true, 'preservekeys' => true));
         foreach ($templates as $template) {
             $tgraphs = $template['graphs'];
             unset($template['graphs']);
             foreach ($tgraphs as $graph) {
                 $result[$graph['graphid']]['templates'][] = $template;
             }
         }
     }
     // adding Items
     if (!is_null($options['selectItems']) && str_in_array($options['selectItems'], $subselectsAllowedOutputs)) {
         $items = API::Item()->get(array('nodeids' => $nodeids, 'output' => $options['selectItems'], 'graphids' => $graphids, 'nopermissions' => true, 'preservekeys' => true, 'filter' => array('flags' => null)));
         foreach ($items as $item) {
             $igraphs = $item['graphs'];
             unset($item['graphs']);
             foreach ($igraphs as $graph) {
                 $result[$graph['graphid']]['items'][] = $item;
             }
         }
     }
     // adding discoveryRule
     if (!is_null($options['selectDiscoveryRule'])) {
         $ruleids = $ruleMap = array();
         $dbRules = DBselect('SELECT id.parent_itemid,gi.graphid' . ' FROM item_discovery id,graphs_items gi' . ' WHERE ' . dbConditionInt('gi.graphid', $graphids) . ' AND gi.itemid=id.itemid');
         while ($rule = DBfetch($dbRules)) {
             $ruleids[$rule['parent_itemid']] = $rule['parent_itemid'];
             $ruleMap[$rule['graphid']] = $rule['parent_itemid'];
         }
         $objParams = array('nodeids' => $nodeids, 'itemids' => $ruleids, 'nopermissions' => true, 'preservekeys' => true);
         if (is_array($options['selectDiscoveryRule']) || str_in_array($options['selectDiscoveryRule'], $subselectsAllowedOutputs)) {
             $objParams['output'] = $options['selectDiscoveryRule'];
             $discoveryRules = API::DiscoveryRule()->get($objParams);
             foreach ($result as $graphid => $graph) {
                 if (isset($ruleMap[$graphid]) && isset($discoveryRules[$ruleMap[$graphid]])) {
                     $result[$graphid]['discoveryRule'] = $discoveryRules[$ruleMap[$graphid]];
                 }
             }
         }
     }
     // removing keys (hash -> array)
     if (is_null($options['preservekeys'])) {
         $result = zbx_cleanHashes($result);
     }
     return $result;
 }
Exemplo n.º 24
0
 /**
  * Import groups.
  */
 protected function processGroups()
 {
     $groups = $this->getFormattedGroups();
     if (empty($groups)) {
         return;
     }
     // skip the groups that already exist
     foreach ($groups as $gnum => $group) {
         if ($this->referencer->resolveGroup($group['name'])) {
             unset($groups[$gnum]);
         }
     }
     if ($groups) {
         // reset indexing because ids from api does not preserve input array keys
         $groups = array_values($groups);
         $newGroups = API::HostGroup()->create($groups);
         foreach ($newGroups['groupids'] as $gnum => $groupid) {
             $this->referencer->addGroupRef($groups[$gnum]['name'], $groupid);
         }
     }
 }
Exemplo n.º 25
0
/**
 * Prepare map elements data.
 * Calculate problem triggers and priorities. Populate map elements with automatic icon mapping, acknowledging and
 * recent change markers.
 *
 * @param array $sysmap
 * @param int   $options
 * @param int   $options['severity_min'] Minimum trigger severity, default value is maximal (Disaster)
 *
 * @return array
 */
function getSelementsInfo($sysmap, array $options = array())
{
    if (!isset($options['severity_min'])) {
        $options['severity_min'] = TRIGGER_SEVERITY_NOT_CLASSIFIED;
    }
    $config = select_config();
    $showUnacknowledged = $config['event_ack_enable'] ? $sysmap['show_unack'] : EXTACK_OPTION_ALL;
    $triggerIdToSelementIds = array();
    $subSysmapTriggerIdToSelementIds = array();
    $hostGroupIdToSelementIds = array();
    $hostIdToSelementIds = array();
    if ($sysmap['sysmapid']) {
        $iconMap = API::IconMap()->get(array('sysmapids' => $sysmap['sysmapid'], 'selectMappings' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND));
        $iconMap = reset($iconMap);
    }
    $hostsToGetInventories = array();
    $selements = $sysmap['selements'];
    $selementIdToSubSysmaps = array();
    foreach ($selements as $selementId => &$selement) {
        $selement['hosts'] = array();
        $selement['triggers'] = array();
        switch ($selement['elementtype']) {
            case SYSMAP_ELEMENT_TYPE_MAP:
                $sysmapIds = array($selement['elementid']);
                while (!empty($sysmapIds)) {
                    $subSysmaps = API::Map()->get(array('sysmapids' => $sysmapIds, 'output' => array('sysmapid'), 'selectSelements' => API_OUTPUT_EXTEND, 'nopermissions' => true, 'preservekeys' => true));
                    if (!isset($selementIdToSubSysmaps[$selementId])) {
                        $selementIdToSubSysmaps[$selementId] = array();
                    }
                    $selementIdToSubSysmaps[$selementId] += $subSysmaps;
                    $sysmapIds = array();
                    foreach ($subSysmaps as $subSysmap) {
                        foreach ($subSysmap['selements'] as $subSysmapSelement) {
                            switch ($subSysmapSelement['elementtype']) {
                                case SYSMAP_ELEMENT_TYPE_MAP:
                                    $sysmapIds[] = $subSysmapSelement['elementid'];
                                    break;
                                case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                                    $hostGroupIdToSelementIds[$subSysmapSelement['elementid']][$selementId] = $selementId;
                                    break;
                                case SYSMAP_ELEMENT_TYPE_HOST:
                                    $hostIdToSelementIds[$subSysmapSelement['elementid']][$selementId] = $selementId;
                                    break;
                                case SYSMAP_ELEMENT_TYPE_TRIGGER:
                                    $subSysmapTriggerIdToSelementIds[$subSysmapSelement['elementid']][$selementId] = $selementId;
                                    break;
                            }
                        }
                    }
                }
                break;
            case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                $hostGroupId = $selement['elementid'];
                $hostGroupIdToSelementIds[$hostGroupId][$selementId] = $selementId;
                break;
            case SYSMAP_ELEMENT_TYPE_HOST:
                $hostId = $selement['elementid'];
                $hostIdToSelementIds[$hostId][$selementId] = $selementId;
                // if we have icon map applied, we need to get inventories for all hosts,
                // where automatic icon selection is enabled.
                if ($sysmap['iconmapid'] && $selement['use_iconmap']) {
                    $hostsToGetInventories[] = $hostId;
                }
                break;
            case SYSMAP_ELEMENT_TYPE_TRIGGER:
                $triggerId = $selement['elementid'];
                $triggerIdToSelementIds[$triggerId][$selementId] = $selementId;
                break;
        }
    }
    unset($selement);
    // get host inventories
    if ($sysmap['iconmapid']) {
        $hostInventories = API::Host()->get(array('hostids' => $hostsToGetInventories, 'output' => array('hostid'), 'nopermissions' => true, 'preservekeys' => true, 'selectInventory' => API_OUTPUT_EXTEND));
    }
    $allHosts = array();
    if (!empty($hostIdToSelementIds)) {
        $hosts = API::Host()->get(array('hostids' => array_keys($hostIdToSelementIds), 'output' => array('name', 'status', 'maintenance_status', 'maintenanceid'), 'nopermissions' => true, 'preservekeys' => true));
        $allHosts = array_merge($allHosts, $hosts);
        foreach ($hosts as $hostId => $host) {
            foreach ($hostIdToSelementIds[$hostId] as $selementId) {
                $selements[$selementId]['hosts'][$hostId] = $hostId;
            }
        }
    }
    $hostsFromHostGroups = array();
    if (!empty($hostGroupIdToSelementIds)) {
        $hostsFromHostGroups = API::Host()->get(array('groupids' => array_keys($hostGroupIdToSelementIds), 'output' => array('name', 'status', 'maintenance_status', 'maintenanceid'), 'selectGroups' => array('groupid'), 'nopermissions' => true, 'preservekeys' => true));
        foreach ($hostsFromHostGroups as $hostId => $host) {
            foreach ($host['groups'] as $group) {
                $groupId = $group['groupid'];
                if (isset($hostGroupIdToSelementIds[$groupId])) {
                    foreach ($hostGroupIdToSelementIds[$groupId] as $selementId) {
                        $selement =& $selements[$selementId];
                        $selement['hosts'][$hostId] = $hostId;
                        // add hosts to hosts_map for trigger selection;
                        if (!isset($hostIdToSelementIds[$hostId])) {
                            $hostIdToSelementIds[$hostId] = array();
                        }
                        $hostIdToSelementIds[$hostId][$selementId] = $selementId;
                        unset($selement);
                    }
                }
            }
        }
        $allHosts = array_merge($allHosts, $hostsFromHostGroups);
    }
    $allHosts = zbx_toHash($allHosts, 'hostid');
    // get triggers data, triggers from current map, select all
    $allTriggers = array();
    if (!empty($triggerIdToSelementIds)) {
        $triggerOptions = array('output' => array('triggerid', 'status', 'value', 'priority', 'lastchange', 'description', 'expression'), 'triggerids' => array_keys($triggerIdToSelementIds), 'filter' => array('state' => null), 'nopermissions' => true, 'preservekeys' => true);
        if ($showUnacknowledged) {
            $triggerOptions['selectLastEvent'] = array('acknowledged');
        }
        $triggers = API::Trigger()->get($triggerOptions);
        $allTriggers = array_merge($allTriggers, $triggers);
        foreach ($triggers as $triggerId => $trigger) {
            foreach ($triggerIdToSelementIds[$triggerId] as $selementId) {
                $selements[$selementId]['triggers'][$triggerId] = $triggerId;
            }
        }
    }
    // triggers from submaps, skip dependent
    if (!empty($subSysmapTriggerIdToSelementIds)) {
        $triggerOptions = array('output' => array('triggerid', 'status', 'value', 'priority', 'lastchange', 'description', 'expression'), 'triggerids' => array_keys($subSysmapTriggerIdToSelementIds), 'filter' => array('state' => null), 'skipDependent' => true, 'nopermissions' => true, 'preservekeys' => true, 'only_true' => true);
        if ($showUnacknowledged) {
            $triggerOptions['selectLastEvent'] = array('acknowledged');
        }
        $triggers = API::Trigger()->get($triggerOptions);
        $allTriggers = array_merge($allTriggers, $triggers);
        foreach ($triggers as $triggerId => $trigger) {
            foreach ($subSysmapTriggerIdToSelementIds[$triggerId] as $selementId) {
                $selements[$selementId]['triggers'][$triggerId] = $triggerId;
            }
        }
    }
    $monitoredHostIds = array();
    foreach ($allHosts as $hostId => $host) {
        if ($host['status'] == HOST_STATUS_MONITORED) {
            $monitoredHostIds[$hostId] = $hostId;
        }
    }
    // triggers from all hosts/hostgroups, skip dependent
    if ($monitoredHostIds) {
        $triggerOptions = array('output' => array('triggerid', 'status', 'value', 'priority', 'lastchange', 'description', 'expression'), 'selectHosts' => array('hostid'), 'selectItems' => array('itemid'), 'hostids' => $monitoredHostIds, 'filter' => array('state' => null), 'monitored' => true, 'skipDependent' => true, 'nopermissions' => true, 'preservekeys' => true, 'only_true' => true);
        if ($showUnacknowledged) {
            $triggerOptions['selectLastEvent'] = array('acknowledged');
        }
        $triggersFromMonitoredHosts = API::Trigger()->get($triggerOptions);
        foreach ($triggersFromMonitoredHosts as $triggerId => $trigger) {
            foreach ($trigger['hosts'] as $host) {
                $hostId = $host['hostid'];
                if (isset($hostIdToSelementIds[$hostId])) {
                    foreach ($hostIdToSelementIds[$hostId] as $selementId) {
                        $selements[$selementId]['triggers'][$triggerId] = $triggerId;
                    }
                }
            }
        }
        $subSysmapHostApplicationFilters = getSelementHostApplicationFilters($selements, $selementIdToSubSysmaps, $hostsFromHostGroups);
        $selements = filterSysmapTriggers($selements, $subSysmapHostApplicationFilters, $triggersFromMonitoredHosts, $subSysmapTriggerIdToSelementIds);
        $allTriggers = array_merge($allTriggers, $triggersFromMonitoredHosts);
    }
    $allTriggers = zbx_toHash($allTriggers, 'triggerid');
    $info = array();
    foreach ($selements as $selementId => $selement) {
        $i = array('disabled' => 0, 'maintenance' => 0, 'problem' => 0, 'problem_unack' => 0, 'priority' => 0, 'trigger_disabled' => 0, 'latelyChanged' => false, 'ack' => true);
        foreach ($selement['hosts'] as $hostId) {
            $host = $allHosts[$hostId];
            $last_hostid = $hostId;
            if ($host['status'] == HOST_STATUS_NOT_MONITORED) {
                $i['disabled']++;
            } elseif ($host['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON) {
                $i['maintenance']++;
            }
        }
        foreach ($selement['triggers'] as $triggerId) {
            $trigger = $allTriggers[$triggerId];
            if ($options['severity_min'] <= $trigger['priority']) {
                if ($trigger['status'] == TRIGGER_STATUS_DISABLED) {
                    $i['trigger_disabled']++;
                } else {
                    if ($trigger['value'] == TRIGGER_VALUE_TRUE) {
                        $i['problem']++;
                        $lastProblemId = $triggerId;
                        if ($i['priority'] < $trigger['priority']) {
                            $i['priority'] = $trigger['priority'];
                        }
                    }
                    if ($showUnacknowledged && $trigger['lastEvent'] && !$trigger['lastEvent']['acknowledged']) {
                        $i['problem_unack']++;
                    }
                    $i['latelyChanged'] |= time() - $trigger['lastchange'] < $config['blink_period'];
                }
            }
        }
        $i['ack'] = (bool) (!$i['problem_unack']);
        if ($sysmap['expandproblem'] && $i['problem'] == 1) {
            if (!isset($lastProblemId)) {
                $lastProblemId = null;
            }
            $i['problem_title'] = CMacrosResolverHelper::resolveTriggerName($allTriggers[$lastProblemId]);
        }
        if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST && $i['maintenance'] == 1) {
            $mnt = get_maintenance_by_maintenanceid($allHosts[$last_hostid]['maintenanceid']);
            $i['maintenance_title'] = $mnt['name'];
        }
        // replace default icons
        if (!$selement['iconid_on']) {
            $selement['iconid_on'] = $selement['iconid_off'];
        }
        if (!$selement['iconid_maintenance']) {
            $selement['iconid_maintenance'] = $selement['iconid_off'];
        }
        if (!$selement['iconid_disabled']) {
            $selement['iconid_disabled'] = $selement['iconid_off'];
        }
        switch ($selement['elementtype']) {
            case SYSMAP_ELEMENT_TYPE_MAP:
                $info[$selementId] = getMapsInfo($selement, $i, $showUnacknowledged);
                break;
            case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                $info[$selementId] = getHostGroupsInfo($selement, $i, $showUnacknowledged);
                break;
            case SYSMAP_ELEMENT_TYPE_HOST:
                $info[$selementId] = getHostsInfo($selement, $i, $showUnacknowledged);
                if ($sysmap['iconmapid'] && $selement['use_iconmap']) {
                    $info[$selementId]['iconid'] = getIconByMapping($iconMap, $hostInventories[$selement['elementid']]);
                }
                break;
            case SYSMAP_ELEMENT_TYPE_TRIGGER:
                $info[$selementId] = getTriggersInfo($selement, $i, $showUnacknowledged);
                break;
            case SYSMAP_ELEMENT_TYPE_IMAGE:
                $info[$selementId] = getImagesInfo($selement);
                break;
        }
    }
    if ($sysmap['label_format'] == SYSMAP_LABEL_ADVANCED_OFF) {
        $hlabel = $hglabel = $tlabel = $mlabel = $sysmap['label_type'] == MAP_LABEL_TYPE_NAME;
    } else {
        $hlabel = $sysmap['label_type_host'] == MAP_LABEL_TYPE_NAME;
        $hglabel = $sysmap['label_type_hostgroup'] == MAP_LABEL_TYPE_NAME;
        $tlabel = $sysmap['label_type_trigger'] == MAP_LABEL_TYPE_NAME;
        $mlabel = $sysmap['label_type_map'] == MAP_LABEL_TYPE_NAME;
    }
    // get names if needed
    $elems = separateMapElements($sysmap);
    if (!empty($elems['sysmaps']) && $mlabel) {
        $subSysmaps = API::Map()->get(array('sysmapids' => zbx_objectValues($elems['sysmaps'], 'elementid'), 'nopermissions' => true, 'output' => array('name')));
        $subSysmaps = zbx_toHash($subSysmaps, 'sysmapid');
        foreach ($elems['sysmaps'] as $elem) {
            $info[$elem['selementid']]['name'] = $subSysmaps[$elem['elementid']]['name'];
        }
    }
    if (!empty($elems['hostgroups']) && $hglabel) {
        $hostgroups = API::HostGroup()->get(array('groupids' => zbx_objectValues($elems['hostgroups'], 'elementid'), 'nopermissions' => true, 'output' => array('name')));
        $hostgroups = zbx_toHash($hostgroups, 'groupid');
        foreach ($elems['hostgroups'] as $elem) {
            $info[$elem['selementid']]['name'] = $hostgroups[$elem['elementid']]['name'];
        }
    }
    if (!empty($elems['triggers']) && $tlabel) {
        foreach ($elems['triggers'] as $elem) {
            $info[$elem['selementid']]['name'] = CMacrosResolverHelper::resolveTriggerName($allTriggers[$elem['elementid']]);
        }
    }
    if (!empty($elems['hosts']) && $hlabel) {
        foreach ($elems['hosts'] as $elem) {
            $info[$elem['selementid']]['name'] = $allHosts[$elem['elementid']]['name'];
        }
    }
    return $info;
}
Exemplo n.º 26
0
         $data['active_since'] = mktime($_REQUEST['active_since_hour'], $_REQUEST['active_since_minute'], 0, $_REQUEST['active_since_month'], $_REQUEST['active_since_day'], $_REQUEST['active_since_year']);
     } else {
         $data['active_since'] = strtotime('today');
     }
     if (isset($_REQUEST['active_till'])) {
         $data['active_till'] = mktime($_REQUEST['active_till_hour'], $_REQUEST['active_till_minute'], 0, $_REQUEST['active_till_month'], $_REQUEST['active_till_day'], $_REQUEST['active_till_year']);
     } else {
         $data['active_till'] = strtotime('tomorrow');
     }
     $data['description'] = get_request('description', '');
     $data['timeperiods'] = get_request('timeperiods', array());
     $data['hostids'] = get_request('hostids', array());
     $data['groupids'] = get_request('groupids', array());
 }
 // get groups
 $data['all_groups'] = API::HostGroup()->get(array('editable' => true, 'output' => array('groupid', 'name'), 'real_hosts' => true, 'preservekeys' => true));
 order_result($data['all_groups'], 'name');
 $data['twb_groupid'] = get_request('twb_groupid', 0);
 if (!isset($data['all_groups'][$data['twb_groupid']])) {
     $twb_groupid = reset($data['all_groups']);
     $data['twb_groupid'] = $twb_groupid['groupid'];
 }
 // get hosts from selected twb group
 $data['hosts'] = API::Host()->get(array('output' => array('hostid', 'name'), 'real_hosts' => true, 'editable' => true, 'groupids' => $data['twb_groupid']));
 // selected hosts
 $hostsSelected = API::Host()->get(array('output' => array('hostid', 'name'), 'real_hosts' => true, 'editable' => true, 'hostids' => $data['hostids']));
 $data['hosts'] = array_merge($data['hosts'], $hostsSelected);
 $data['hosts'] = zbx_toHash($data['hosts'], 'hostid');
 order_result($data['hosts'], 'name');
 // nodes
 if ($data['displayNodes']) {
Exemplo n.º 27
0
 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     // adding groups
     if ($options['selectGroups'] !== null && $options['selectGroups'] != API_OUTPUT_COUNT) {
         foreach ($result as $scriptId => $script) {
             $result[$scriptId]['groups'] = API::HostGroup()->get(array('output' => $options['selectGroups'], 'groupids' => $script['groupid'] ? $script['groupid'] : null, 'editable' => $script['host_access'] == PERM_READ_WRITE ? true : null));
         }
     }
     // adding hosts
     if ($options['selectHosts'] !== null && $options['selectHosts'] != API_OUTPUT_COUNT) {
         $processedGroups = array();
         foreach ($result as $scriptId => $script) {
             if (isset($processedGroups[$script['groupid'] . '_' . $script['host_access']])) {
                 $result[$scriptId]['hosts'] = $result[$processedGroups[$script['groupid'] . '_' . $script['host_access']]]['hosts'];
             } else {
                 $result[$scriptId]['hosts'] = API::Host()->get(array('output' => $options['selectHosts'], 'groupids' => $script['groupid'] ? $script['groupid'] : null, 'hostids' => $options['hostids'] ? $options['hostids'] : null, 'editable' => $script['host_access'] == PERM_READ_WRITE ? true : null));
                 $processedGroups[$script['groupid'] . '_' . $script['host_access']] = $scriptId;
             }
         }
     }
     return $result;
 }
Exemplo n.º 28
0
        $data['type'] = $script['type'];
        $data['execute_on'] = $script['execute_on'];
        $data['command'] = $data['commandipmi'] = $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['enableConfirmation'] = !zbx_empty($script['confirmation']);
        $data['hgstype'] = empty($data['groupid']) ? 0 : 1;
    }
    $scriptView = new CView('administration.script.edit', $data);
    // get host gruop
    $hostGroup = null;
    if (!empty($data['groupid'])) {
        $groups = API::HostGroup()->get(array('groupids' => array($data['groupid']), 'output' => array('groupid', 'name')));
        $groups = reset($groups);
        $hostGroup[] = array('id' => $groups['groupid'], 'name' => $groups['name']);
    }
    $scriptView->set('hostGroup', $hostGroup);
    // get list of user groups
    $usergroups = API::UserGroup()->get(array('output' => array('usrgrpid', 'name')));
    order_result($usergroups, 'name');
    $scriptView->set('usergroups', $usergroups);
    // render view
    $scriptView->render();
    $scriptView->show();
} else {
    $sortField = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'name'));
    $sortOrder = getRequest('sortorder', CProfile::get('web.' . $page['file'] . '.sortorder', ZBX_SORT_UP));
    CProfile::update('web.' . $page['file'] . '.sort', $sortField, PROFILE_TYPE_STR);
Exemplo n.º 29
0
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/
require_once dirname(__FILE__) . '/include/config.inc.php';
$page['title'] = _('Status of Web monitoring');
$page['file'] = 'httpmon.php';
$page['hist_arg'] = array('groupid', 'hostid');
define('ZBX_PAGE_DO_REFRESH', 1);
require_once dirname(__FILE__) . '/include/page_header.php';
//		VAR				TYPE		OPTIONAL	FLAGS	VALIDATION	EXCEPTION
$fields = array('fullscreen' => array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1'), null), 'groupid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), 'hostid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null));
check_fields($fields);
/*
 * Permissions
 */
if (get_request('groupid') && !API::HostGroup()->isReadable(array($_REQUEST['groupid']))) {
    access_deny();
}
if (get_request('hostid') && !API::Host()->isReadable(array($_REQUEST['hostid']))) {
    access_deny();
}
validate_sort_and_sortorder('name', ZBX_SORT_DOWN);
$options = array('groups' => array('real_hosts' => true, 'with_httptests' => true), 'hosts' => array('with_monitored_items' => true, 'with_httptests' => true), 'hostid' => get_request('hostid', null), 'groupid' => get_request('groupid', null));
$pageFilter = new CPageFilter($options);
$_REQUEST['groupid'] = $pageFilter->groupid;
$_REQUEST['hostid'] = $pageFilter->hostid;
$displayNodes = is_array(get_current_nodeid()) && $pageFilter->groupid == 0 && $pageFilter->hostid == 0;
$r_form = new CForm('get');
$r_form->addVar('fullscreen', $_REQUEST['fullscreen']);
$r_form->addItem(array(_('Group') . SPACE, $pageFilter->getGroupsCB(true)));
$r_form->addItem(array(SPACE . _('Host') . SPACE, $pageFilter->getHostsCB(true)));
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
$table = (new CTableInfo())->setHeader([_('Host group'), _('Without problems'), _('With problems'), _('Total')]);
// get host groups
$groups = API::HostGroup()->get(['output' => ['groupid', 'name'], 'groupids' => $data['filter']['groupids'], 'hostids' => isset($data['filter']['hostids']) ? $data['filter']['hostids'] : null, 'monitored_hosts' => true, 'preservekeys' => true]);
CArrayHelper::sort($groups, ['name']);
// get hosts
$hosts = API::Host()->get(['output' => ['hostid', 'name'], 'selectGroups' => ['groupid'], 'groupids' => array_keys($groups), 'hostids' => isset($data['filter']['hostids']) ? $data['filter']['hostids'] : null, 'filter' => ['maintenance_status' => $data['filter']['maintenance']], 'monitored_hosts' => true, 'preservekeys' => true]);
CArrayHelper::sort($hosts, ['name']);
// get triggers
$triggers = API::Trigger()->get(['output' => ['triggerid', 'priority'], 'selectHosts' => ['hostid'], 'search' => $data['filter']['trigger_name'] !== '' ? ['description' => $data['filter']['trigger_name']] : null, 'filter' => ['priority' => $data['filter']['severity'], 'value' => TRIGGER_VALUE_TRUE], 'maintenance' => $data['filter']['maintenance'], 'monitored' => true]);
if ($data['filter']['extAck']) {
    $hosts_with_unack_triggers = [];
    $triggers_unack = API::Trigger()->get(['output' => ['triggerid'], 'selectHosts' => ['hostid'], 'search' => $data['filter']['trigger_name'] !== '' ? ['description' => $data['filter']['trigger_name']] : null, 'filter' => ['priority' => $data['filter']['severity'], 'value' => TRIGGER_VALUE_TRUE], 'withLastEventUnacknowledged' => true, 'maintenance' => $data['filter']['maintenance'], 'monitored' => true, 'preservekeys' => true]);
    foreach ($triggers_unack as $tunack) {
        foreach ($tunack['hosts'] as $unack_host) {
            $hosts_with_unack_triggers[$unack_host['hostid']] = $unack_host['hostid'];
        }
    }
}