$options = array('output' => array('httptestid'), 'templated' => false, 'filter' => array('status' => HTTPTEST_STATUS_ACTIVE), 'limit' => $config['search_limit'] + 1); if ($pageFilter->hostid > 0) { $options['hostids'] = $pageFilter->hostid; } elseif ($pageFilter->groupid > 0) { $options['groupids'] = $pageFilter->groupid; } $httpTests = API::HttpTest()->get($options); $paging = getPagingLine($httpTests); $httpTests = API::HttpTest()->get(array('httptestids' => zbx_objectValues($httpTests, 'httptestid'), 'preservekeys' => true, 'output' => API_OUTPUT_EXTEND, 'selectHosts' => array('name', 'status'), 'selectSteps' => API_OUTPUT_COUNT)); foreach ($httpTests as &$httpTest) { $httpTest['host'] = reset($httpTest['hosts']); $httpTest['hostname'] = $httpTest['host']['name']; unset($httpTest['hosts']); } unset($httpTest); $httpTests = resolveHttpTestMacros($httpTests, true, false); order_result($httpTests, getPageSortField('name'), getPageSortOrder()); // fetch the latest results of the web scenario $lastHttpTestData = Manager::HttpTest()->getLastData(array_keys($httpTests)); foreach ($httpTests as $httpTest) { $lastData = isset($lastHttpTestData[$httpTest['httptestid']]) ? $lastHttpTestData[$httpTest['httptestid']] : null; // test has history data if ($lastData) { $lastcheck = zbx_date2str(_('d M Y H:i:s'), $lastData['lastcheck']); if ($lastData['lastfailedstep'] != 0) { $step_data = get_httpstep_by_no($httpTest['httptestid'], $lastData['lastfailedstep']); $status['msg'] = _s('Step "%1$s" [%2$s of %3$s] failed: %4$s', $step_data['name'], $lastData['lastfailedstep'], $httpTest['steps'], $lastData['error']); $status['style'] = 'disabled'; } else { $status['msg'] = _('OK'); $status['style'] = 'enabled';
/** * Get data about web scenarios. * * @param array $options * * @return array */ public function get($options = array()) { $result = array(); $userType = self::$userData['type']; $userid = self::$userData['userid']; $sqlParts = array('select' => array('httptests' => 'ht.httptestid'), 'from' => array('httptest' => 'httptest ht'), 'where' => array(), 'group' => array(), 'order' => array(), 'limit' => null); $defOptions = array('httptestids' => null, 'applicationids' => null, 'hostids' => null, 'groupids' => null, 'templateids' => null, 'editable' => null, 'inherited' => null, 'templated' => null, 'monitored' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'output' => API_OUTPUT_EXTEND, 'expandName' => null, 'expandStepName' => null, 'selectHosts' => null, 'selectSteps' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null); $options = zbx_array_merge($defOptions, $options); // editable + PERMISSION CHECK if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) { $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ; $userGroups = getUserGroupsByUserId($userid); $sqlParts['where'][] = 'EXISTS (' . 'SELECT NULL' . ' FROM hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE ht.hostid=hgg.hostid' . ' GROUP BY hgg.hostid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ' AND MAX(r.permission)>=' . zbx_dbstr($permission) . ')'; } // httptestids if (!is_null($options['httptestids'])) { zbx_value2array($options['httptestids']); $sqlParts['where']['httptestid'] = dbConditionInt('ht.httptestid', $options['httptestids']); } // 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']); $sqlParts['where']['hostid'] = dbConditionInt('ht.hostid', $options['hostids']); if (!is_null($options['groupCount'])) { $sqlParts['group']['hostid'] = 'ht.hostid'; } } // groupids if (!is_null($options['groupids'])) { zbx_value2array($options['groupids']); $sqlParts['from']['hosts_groups'] = 'hosts_groups hg'; $sqlParts['where'][] = dbConditionInt('hg.groupid', $options['groupids']); $sqlParts['where'][] = 'hg.hostid=ht.hostid'; if (!is_null($options['groupCount'])) { $sqlParts['group']['hg'] = 'hg.groupid'; } } // applicationids if (!is_null($options['applicationids'])) { zbx_value2array($options['applicationids']); $sqlParts['where'][] = dbConditionInt('ht.applicationid', $options['applicationids']); } // inherited if (isset($options['inherited'])) { $sqlParts['where'][] = $options['inherited'] ? 'ht.templateid IS NOT NULL' : 'ht.templateid IS NULL'; } // templated if (isset($options['templated'])) { $sqlParts['from']['hosts'] = 'hosts h'; $sqlParts['where']['ha'] = 'h.hostid=ht.hostid'; if ($options['templated']) { $sqlParts['where'][] = 'h.status=' . HOST_STATUS_TEMPLATE; } else { $sqlParts['where'][] = 'h.status<>' . HOST_STATUS_TEMPLATE; } } // monitored if (!is_null($options['monitored'])) { $sqlParts['from']['hosts'] = 'hosts h'; $sqlParts['where']['hht'] = 'h.hostid=ht.hostid'; if ($options['monitored']) { $sqlParts['where'][] = 'h.status=' . HOST_STATUS_MONITORED; $sqlParts['where'][] = 'ht.status=' . ITEM_STATUS_ACTIVE; } else { $sqlParts['where'][] = '(h.status<>' . HOST_STATUS_MONITORED . ' OR ht.status<>' . ITEM_STATUS_ACTIVE . ')'; } } // search if (is_array($options['search'])) { zbx_db_search('httptest ht', $options, $sqlParts); } // filter if (is_array($options['filter'])) { $this->dbFilter('httptest ht', $options, $sqlParts); } // limit if (zbx_ctype_digit($options['limit']) && $options['limit']) { $sqlParts['limit'] = $options['limit']; } $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 ($httpTest = DBfetch($res)) { if (!is_null($options['countOutput'])) { if (!is_null($options['groupCount'])) { $result[] = $httpTest; } else { $result = $httpTest['rowscount']; } } else { $result[$httpTest['httptestid']] = $httpTest; } } if (!is_null($options['countOutput'])) { return $result; } if ($result) { $result = $this->addRelatedObjects($options, $result); // expandName $nameRequested = is_array($options['output']) && in_array('name', $options['output']) || $options['output'] == API_OUTPUT_EXTEND; $expandName = $options['expandName'] !== null && $nameRequested; // expandStepName $stepNameRequested = $options['selectSteps'] == API_OUTPUT_EXTEND || is_array($options['selectSteps']) && in_array('name', $options['selectSteps']); $expandStepName = $options['expandStepName'] !== null && $stepNameRequested; if ($expandName || $expandStepName) { $result = resolveHttpTestMacros($result, $expandName, $expandStepName); } $result = $this->unsetExtraFields($result, array('hostid'), $options['output']); } // removing keys (hash -> array) if (is_null($options['preservekeys'])) { $result = zbx_cleanHashes($result); } return $result; }