本文整理汇总了PHP中API::HttpTest方法的典型用法代码示例。如果您正苦于以下问题:PHP API::HttpTest方法的具体用法?PHP API::HttpTest怎么用?PHP API::HttpTest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API
的用法示例。
在下文中一共展示了API::HttpTest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete
/**
* Delete Host
*
* @param string|array $hostIds
* @param bool $nopermissions
*
* @return array|boolean
*/
public function delete($hostIds, $nopermissions = false)
{
$hostIds = zbx_toArray($hostIds);
// deprecated input support
if ($hostIds && is_array($hostIds[0])) {
$this->deprecated('Passing objects is deprecated, use an array of IDs instead.');
foreach ($hostIds as $host) {
if (!check_db_fields(array('hostid' => null), $host)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('No host ID given.'));
}
}
$hostIds = zbx_objectValues($hostIds, 'hostid');
}
$this->validateDelete($hostIds, $nopermissions);
// delete the discovery rules first
$delRules = API::DiscoveryRule()->get(array('hostids' => $hostIds, 'nopermissions' => true, 'preservekeys' => true));
if ($delRules) {
API::DiscoveryRule()->delete(array_keys($delRules), true);
}
// delete the items
$delItems = API::Item()->get(array('templateids' => $hostIds, 'output' => array('itemid'), 'nopermissions' => true, 'preservekeys' => true));
if ($delItems) {
API::Item()->delete(array_keys($delItems), true);
}
// delete web tests
$delHttptests = array();
$dbHttptests = get_httptests_by_hostid($hostIds);
while ($dbHttptest = DBfetch($dbHttptests)) {
$delHttptests[$dbHttptest['httptestid']] = $dbHttptest['httptestid'];
}
if (!empty($delHttptests)) {
API::HttpTest()->delete($delHttptests, true);
}
// delete screen items
DB::delete('screens_items', array('resourceid' => $hostIds, 'resourcetype' => SCREEN_RESOURCE_HOST_TRIGGERS));
// delete host from maps
if (!empty($hostIds)) {
DB::delete('sysmaps_elements', array('elementtype' => SYSMAP_ELEMENT_TYPE_HOST, 'elementid' => $hostIds));
}
// disable actions
// actions from conditions
$actionids = array();
$sql = 'SELECT DISTINCT actionid' . ' FROM conditions' . ' WHERE conditiontype=' . CONDITION_TYPE_HOST . ' AND ' . dbConditionString('value', $hostIds);
$dbActions = DBselect($sql);
while ($dbAction = DBfetch($dbActions)) {
$actionids[$dbAction['actionid']] = $dbAction['actionid'];
}
// actions from operations
$sql = 'SELECT DISTINCT o.actionid' . ' FROM operations o, opcommand_hst oh' . ' WHERE o.operationid=oh.operationid' . ' AND ' . dbConditionInt('oh.hostid', $hostIds);
$dbActions = DBselect($sql);
while ($dbAction = DBfetch($dbActions)) {
$actionids[$dbAction['actionid']] = $dbAction['actionid'];
}
if (!empty($actionids)) {
$update = array();
$update[] = array('values' => array('status' => ACTION_STATUS_DISABLED), 'where' => array('actionid' => $actionids));
DB::update('actions', $update);
}
// delete action conditions
DB::delete('conditions', array('conditiontype' => CONDITION_TYPE_HOST, 'value' => $hostIds));
// delete action operation commands
$operationids = array();
$sql = 'SELECT DISTINCT oh.operationid' . ' FROM opcommand_hst oh' . ' WHERE ' . dbConditionInt('oh.hostid', $hostIds);
$dbOperations = DBselect($sql);
while ($dbOperation = DBfetch($dbOperations)) {
$operationids[$dbOperation['operationid']] = $dbOperation['operationid'];
}
DB::delete('opcommand_hst', array('hostid' => $hostIds));
// delete empty operations
$delOperationids = array();
$sql = 'SELECT DISTINCT o.operationid' . ' FROM operations o' . ' WHERE ' . dbConditionInt('o.operationid', $operationids) . ' AND NOT EXISTS(SELECT oh.opcommand_hstid FROM opcommand_hst oh WHERE oh.operationid=o.operationid)';
$dbOperations = DBselect($sql);
while ($dbOperation = DBfetch($dbOperations)) {
$delOperationids[$dbOperation['operationid']] = $dbOperation['operationid'];
}
DB::delete('operations', array('operationid' => $delOperationids));
$hosts = API::Host()->get(array('output' => array('hostid', 'name'), 'hostids' => $hostIds, 'nopermissions' => true));
// delete host inventory
DB::delete('host_inventory', array('hostid' => $hostIds));
// delete host applications
DB::delete('applications', array('hostid' => $hostIds));
// delete host
DB::delete('hosts', array('hostid' => $hostIds));
// TODO: remove info from API
foreach ($hosts as $host) {
info(_s('Deleted: Host "%1$s".', $host['name']));
add_audit_ext(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_HOST, $host['hostid'], $host['name'], 'hosts', NULL, NULL);
}
// remove Monitoring > Latest data toggle profile values related to given hosts
CProfile::delete('web.latest.toggle_other', $hostIds);
return array('hostids' => $hostIds);
}
示例2: delete
/**
* Delete Host.
*
* @param array $hostIds
* @param bool $nopermissions
*
* @return array
*/
public function delete(array $hostIds, $nopermissions = false)
{
$this->validateDelete($hostIds, $nopermissions);
// delete the discovery rules first
$delRules = API::DiscoveryRule()->get(['output' => ['itemid'], 'hostids' => $hostIds, 'nopermissions' => true, 'preservekeys' => true]);
if ($delRules) {
API::DiscoveryRule()->delete(array_keys($delRules), true);
}
// delete the items
$delItems = API::Item()->get(['templateids' => $hostIds, 'output' => ['itemid'], 'nopermissions' => true, 'preservekeys' => true]);
if ($delItems) {
API::Item()->delete(array_keys($delItems), true);
}
// delete web tests
$delHttptests = [];
$dbHttptests = get_httptests_by_hostid($hostIds);
while ($dbHttptest = DBfetch($dbHttptests)) {
$delHttptests[$dbHttptest['httptestid']] = $dbHttptest['httptestid'];
}
if (!empty($delHttptests)) {
API::HttpTest()->delete($delHttptests, true);
}
// delete screen items
DB::delete('screens_items', ['resourceid' => $hostIds, 'resourcetype' => SCREEN_RESOURCE_HOST_TRIGGERS]);
// delete host from maps
if (!empty($hostIds)) {
DB::delete('sysmaps_elements', ['elementtype' => SYSMAP_ELEMENT_TYPE_HOST, 'elementid' => $hostIds]);
}
// disable actions
// actions from conditions
$actionids = [];
$sql = 'SELECT DISTINCT actionid' . ' FROM conditions' . ' WHERE conditiontype=' . CONDITION_TYPE_HOST . ' AND ' . dbConditionString('value', $hostIds);
$dbActions = DBselect($sql);
while ($dbAction = DBfetch($dbActions)) {
$actionids[$dbAction['actionid']] = $dbAction['actionid'];
}
// actions from operations
$sql = 'SELECT DISTINCT o.actionid' . ' FROM operations o, opcommand_hst oh' . ' WHERE o.operationid=oh.operationid' . ' AND ' . dbConditionInt('oh.hostid', $hostIds);
$dbActions = DBselect($sql);
while ($dbAction = DBfetch($dbActions)) {
$actionids[$dbAction['actionid']] = $dbAction['actionid'];
}
if (!empty($actionids)) {
$update = [];
$update[] = ['values' => ['status' => ACTION_STATUS_DISABLED], 'where' => ['actionid' => $actionids]];
DB::update('actions', $update);
}
// delete action conditions
DB::delete('conditions', ['conditiontype' => CONDITION_TYPE_HOST, 'value' => $hostIds]);
// delete action operation commands
$operationids = [];
$sql = 'SELECT DISTINCT oh.operationid' . ' FROM opcommand_hst oh' . ' WHERE ' . dbConditionInt('oh.hostid', $hostIds);
$dbOperations = DBselect($sql);
while ($dbOperation = DBfetch($dbOperations)) {
$operationids[$dbOperation['operationid']] = $dbOperation['operationid'];
}
DB::delete('opcommand_hst', ['hostid' => $hostIds]);
// delete empty operations
$delOperationids = [];
$sql = 'SELECT DISTINCT o.operationid' . ' FROM operations o' . ' WHERE ' . dbConditionInt('o.operationid', $operationids) . ' AND NOT EXISTS(SELECT oh.opcommand_hstid FROM opcommand_hst oh WHERE oh.operationid=o.operationid)';
$dbOperations = DBselect($sql);
while ($dbOperation = DBfetch($dbOperations)) {
$delOperationids[$dbOperation['operationid']] = $dbOperation['operationid'];
}
DB::delete('operations', ['operationid' => $delOperationids]);
$hosts = API::Host()->get(['output' => ['hostid', 'name'], 'hostids' => $hostIds, 'nopermissions' => true]);
// delete host inventory
DB::delete('host_inventory', ['hostid' => $hostIds]);
// delete host applications
DB::delete('applications', ['hostid' => $hostIds]);
// delete host
DB::delete('hosts', ['hostid' => $hostIds]);
// TODO: remove info from API
foreach ($hosts as $host) {
info(_s('Deleted: Host "%1$s".', $host['name']));
add_audit_ext(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_HOST, $host['hostid'], $host['name'], 'hosts', NULL, NULL);
}
// remove Monitoring > Latest data toggle profile values related to given hosts
DB::delete('profiles', ['idx' => 'web.latest.toggle_other', 'idx2' => $hostIds]);
return ['hostids' => $hostIds];
}
示例3: dirname
}
// saving fixed/dynamic setting to profile
if ($_REQUEST['favobj'] == 'timelinefixedperiod') {
if (isset($_REQUEST['favid'])) {
CProfile::update('web.httptest.timelinefixed', $_REQUEST['favid'], PROFILE_TYPE_INT);
}
}
}
if ($page['type'] == PAGE_TYPE_JS || $page['type'] == PAGE_TYPE_HTML_BLOCK) {
require_once dirname(__FILE__) . '/include/page_footer.php';
exit;
}
/*
* Collect data
*/
$httpTest = API::HttpTest()->get(array('httptestids' => get_request('httptestid'), 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true));
$httpTest = reset($httpTest);
if (!$httpTest) {
access_deny();
}
$httpTest['lastfailedstep'] = 0;
$httpTest['error'] = '';
// fetch http test execution data
$httpTestData = Manager::HttpTest()->getLastData(array($httpTest['httptestid']));
if ($httpTestData) {
$httpTestData = reset($httpTestData);
}
// fetch HTTP step items
$query = DBselect('SELECT i.value_type,i.valuemapid,i.units,i.itemid,hi.type AS httpitem_type,hs.httpstepid' . ' FROM items i,httpstepitem hi,httpstep hs' . ' WHERE hi.itemid=i.itemid' . ' AND hi.httpstepid=hs.httpstepid' . ' AND hs.httptestid=' . zbx_dbstr($httpTest['httptestid']));
$httpStepItems = array();
$items = array();
示例4: array
}
// screens
$screens = API::TemplateScreen()->get(array('inherited' => false, 'templateids' => $templateid, 'output' => array('screenid', 'name')));
if (!empty($screens)) {
$screensList = array();
foreach ($screens as $screen) {
$screensList[$screen['screenid']] = $screen['name'];
}
order_result($screensList);
$listBox = new CListBox('screens', null, 8);
$listBox->setAttribute('disabled', 'disabled');
$listBox->addItems($screensList);
$templateList->addRow(_('Screens'), $listBox);
}
// web scenarios
$httpTests = API::HttpTest()->get(array('output' => array('httptestid', 'name'), 'hostids' => $templateid, 'inherited' => false));
if ($httpTests) {
$httpTestList = array();
foreach ($httpTests as $httpTest) {
$httpTestList[$httpTest['httptestid']] = $httpTest['name'];
}
order_result($httpTestList);
$listBox = new CListBox('httpTests', null, 8);
$listBox->setAttribute('disabled', 'disabled');
$listBox->addItems($httpTestList);
$templateList->addRow(_('Web scenarios'), $listBox);
}
}
$divTabs->addTab('templateTab', _('Template'), $templateList);
// FULL CLONE }
// } TEMPLATE WIDGET
示例5: addRelatedObjects
//.........这里部分代码省略.........
$relationMap = $this->createRelationMap($items, 'hostid', 'itemid');
$items = $this->unsetExtraFields($items, array('hostid', 'itemid'), $options['selectDiscoveries']);
$result = $relationMap->mapMany($result, $items, 'discoveries', $options['limitSelects']);
} else {
$items = API::DiscoveryRule()->get(array('hostids' => $hostids, 'nopermissions' => true, 'countOutput' => true, 'groupCount' => true));
$items = zbx_toHash($items, 'hostid');
foreach ($result as $hostid => $host) {
$result[$hostid]['discoveries'] = isset($items[$hostid]) ? $items[$hostid]['rowscount'] : 0;
}
}
}
// adding triggers
if ($options['selectTriggers'] !== null) {
if ($options['selectTriggers'] != API_OUTPUT_COUNT) {
// discovered items
$res = DBselect('SELECT i.hostid,f.triggerid' . ' FROM items i,functions f' . ' WHERE ' . dbConditionInt('i.hostid', $hostids) . ' AND i.itemid=f.itemid');
$relationMap = new CRelationMap();
while ($relation = DBfetch($res)) {
$relationMap->addRelation($relation['hostid'], $relation['triggerid']);
}
$triggers = API::Trigger()->get(array('output' => $options['selectTriggers'], 'triggerids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
if (!is_null($options['limitSelects'])) {
order_result($triggers, 'description');
}
$result = $relationMap->mapMany($result, $triggers, 'triggers', $options['limitSelects']);
} else {
$triggers = API::Trigger()->get(array('hostids' => $hostids, 'countOutput' => true, 'groupCount' => true));
$triggers = zbx_toHash($triggers, 'hostid');
foreach ($result as $hostid => $host) {
$result[$hostid]['triggers'] = isset($triggers[$hostid]) ? $triggers[$hostid]['rowscount'] : 0;
}
}
}
// adding graphs
if ($options['selectGraphs'] !== null) {
if ($options['selectGraphs'] != API_OUTPUT_COUNT) {
// discovered items
$res = DBselect('SELECT i.hostid,gi.graphid' . ' FROM items i,graphs_items gi' . ' WHERE ' . dbConditionInt('i.hostid', $hostids) . ' AND i.itemid=gi.itemid');
$relationMap = new CRelationMap();
while ($relation = DBfetch($res)) {
$relationMap->addRelation($relation['hostid'], $relation['graphid']);
}
$graphs = API::Graph()->get(array('output' => $options['selectGraphs'], 'graphids' => $relationMap->getRelatedIds(), 'preservekeys' => true));
if (!is_null($options['limitSelects'])) {
order_result($graphs, 'name');
}
$result = $relationMap->mapMany($result, $graphs, 'graphs', $options['limitSelects']);
} else {
$graphs = API::Graph()->get(array('hostids' => $hostids, 'countOutput' => true, 'groupCount' => true));
$graphs = zbx_toHash($graphs, 'hostid');
foreach ($result as $hostid => $host) {
$result[$hostid]['graphs'] = isset($graphs[$hostid]) ? $graphs[$hostid]['rowscount'] : 0;
}
}
}
// adding http tests
if ($options['selectHttpTests'] !== null) {
if ($options['selectHttpTests'] != API_OUTPUT_COUNT) {
$httpTests = API::HttpTest()->get(array('output' => $this->outputExtend($options['selectHttpTests'], array('hostid', 'httptestid')), 'hostids' => $hostids, 'nopermissions' => true, 'preservekeys' => true));
if (!is_null($options['limitSelects'])) {
order_result($httpTests, 'name');
}
$relationMap = $this->createRelationMap($httpTests, 'hostid', 'httptestid');
$httpTests = $this->unsetExtraFields($httpTests, array('hostid', 'httptestid'), $options['selectHttpTests']);
$result = $relationMap->mapMany($result, $httpTests, 'httpTests', $options['limitSelects']);
} else {
$httpTests = API::HttpTest()->get(array('hostids' => $hostids, 'nopermissions' => true, 'countOutput' => true, 'groupCount' => true));
$httpTests = zbx_toHash($httpTests, 'hostid');
foreach ($result as $hostId => $host) {
$result[$hostId]['httpTests'] = isset($httpTests[$hostId]) ? $httpTests[$hostId]['rowscount'] : 0;
}
}
}
// adding applications
if ($options['selectApplications'] !== null) {
if ($options['selectApplications'] != API_OUTPUT_COUNT) {
$applications = API::Application()->get(array('output' => $this->outputExtend($options['selectApplications'], array('hostid', 'applicationid')), 'hostids' => $hostids, 'nopermissions' => true, 'preservekeys' => true));
if (!is_null($options['limitSelects'])) {
order_result($applications, 'name');
}
$relationMap = $this->createRelationMap($applications, 'hostid', 'applicationid');
$applications = $this->unsetExtraFields($applications, array('hostid', 'applicationid'), $options['selectApplications']);
$result = $relationMap->mapMany($result, $applications, 'applications', $options['limitSelects']);
} else {
$applications = API::Application()->get(array('output' => $options['selectApplications'], 'hostids' => $hostids, 'nopermissions' => true, 'countOutput' => true, 'groupCount' => true));
$applications = zbx_toHash($applications, 'hostid');
foreach ($result as $hostid => $host) {
$result[$hostid]['applications'] = isset($applications[$hostid]) ? $applications[$hostid]['rowscount'] : 0;
}
}
}
// adding macros
if ($options['selectMacros'] !== null && $options['selectMacros'] != API_OUTPUT_COUNT) {
$macros = API::UserMacro()->get(array('output' => $this->outputExtend($options['selectMacros'], array('hostid', 'hostmacroid')), 'hostids' => $hostids, 'preservekeys' => true));
$relationMap = $this->createRelationMap($macros, 'hostid', 'hostmacroid');
$macros = $this->unsetExtraFields($macros, array('hostid', 'hostmacroid'), $options['selectMacros']);
$result = $relationMap->mapMany($result, $macros, 'macros', $options['limitSelects']);
}
return $result;
}
示例6: getRequest
if (getRequest('hostid') != 0) {
$data['showInfoColumn'] = (bool) API::Host()->get(array('hostids' => getRequest('hostid'), 'output' => array('status')));
} else {
$data['showInfoColumn'] = true;
}
if ($data['pageFilter']->hostsSelected) {
$options = array('editable' => true, 'output' => array('httptestid', $sortField), 'limit' => $config['search_limit'] + 1);
if (empty($data['showDisabled'])) {
$options['filter']['status'] = HTTPTEST_STATUS_ACTIVE;
}
if ($data['pageFilter']->hostid > 0) {
$options['hostids'] = $data['pageFilter']->hostid;
} elseif ($data['pageFilter']->groupid > 0) {
$options['groupids'] = $data['pageFilter']->groupid;
}
$httpTests = API::HttpTest()->get($options);
$dbHttpTests = DBselect('SELECT ht.httptestid,ht.name,ht.delay,ht.status,ht.hostid,ht.templateid,h.name AS hostname,ht.retries,' . 'ht.authentication,ht.http_proxy,a.applicationid,a.name AS application_name' . ' FROM httptest ht' . ' INNER JOIN hosts h ON h.hostid=ht.hostid' . ' LEFT JOIN applications a ON a.applicationid=ht.applicationid' . ' WHERE ' . dbConditionInt('ht.httptestid', zbx_objectValues($httpTests, 'httptestid')));
$httpTests = array();
while ($dbHttpTest = DBfetch($dbHttpTests)) {
$httpTests[$dbHttpTest['httptestid']] = $dbHttpTest;
}
order_result($httpTests, $sortField, $sortOrder);
$data['paging'] = getPagingLine($httpTests, $sortOrder);
if ($data['showInfoColumn']) {
$httpTestsLastData = Manager::HttpTest()->getLastData(array_keys($httpTests));
foreach ($httpTestsLastData as $httpTestId => &$lastData) {
if ($lastData['lastfailedstep'] !== null) {
$lastData['failedstep'] = get_httpstep_by_no($httpTestId, $lastData['lastfailedstep']);
}
}
unset($lastData);
示例7: update
/**
* Update http tests.
*
* @param array $httpTests
*
* @return array
*/
public function update(array $httpTests)
{
$httpTestIds = zbx_objectValues($httpTests, 'httptestid');
$dbHttpTest = API::HttpTest()->get(array('output' => API_OUTPUT_EXTEND, 'httptestids' => $httpTestIds, 'selectSteps' => API_OUTPUT_EXTEND, 'editable' => true, 'preservekeys' => true));
foreach ($httpTests as $httpTest) {
DB::update('httptest', array('values' => $httpTest, 'where' => array('httptestid' => $httpTest['httptestid'])));
$checkItemsUpdate = $updateFields = array();
$dbCheckItems = DBselect('SELECT i.itemid,hi.type' . ' FROM items i,httptestitem hi' . ' WHERE hi.httptestid=' . zbx_dbstr($httpTest['httptestid']) . ' AND hi.itemid=i.itemid');
while ($checkitem = DBfetch($dbCheckItems)) {
$itemids[] = $checkitem['itemid'];
if (isset($httpTest['name'])) {
$updateFields['key_'] = $this->getTestKey($checkitem['type'], $httpTest['name']);
}
if (isset($httpTest['status'])) {
$updateFields['status'] = HTTPTEST_STATUS_ACTIVE == $httpTest['status'] ? ITEM_STATUS_ACTIVE : ITEM_STATUS_DISABLED;
}
if (isset($httpTest['delay'])) {
$updateFields['delay'] = $httpTest['delay'];
}
if (!empty($updateFields)) {
$checkItemsUpdate[] = array('values' => $updateFields, 'where' => array('itemid' => $checkitem['itemid']));
}
}
DB::update('items', $checkItemsUpdate);
if (isset($httpTest['applicationid'])) {
$this->updateItemsApplications($itemids, $httpTest['applicationid']);
}
// update steps
if (isset($httpTest['steps'])) {
$stepsCreate = $stepsUpdate = array();
$dbSteps = zbx_toHash($dbHttpTest[$httpTest['httptestid']]['steps'], 'httpstepid');
foreach ($httpTest['steps'] as $webstep) {
if (isset($webstep['httpstepid']) && isset($dbSteps[$webstep['httpstepid']])) {
$stepsUpdate[] = $webstep;
unset($dbSteps[$webstep['httpstepid']]);
} elseif (!isset($webstep['httpstepid'])) {
$stepsCreate[] = $webstep;
}
}
$stepidsDelete = array_keys($dbSteps);
if (!empty($stepidsDelete)) {
$this->deleteStepsReal($stepidsDelete);
}
if (!empty($stepsUpdate)) {
$this->updateStepsReal($httpTest, $stepsUpdate);
}
if (!empty($stepsCreate)) {
$this->createStepsReal($httpTest, $stepsCreate);
}
} else {
if (isset($httpTest['applicationid'])) {
$dbStepIds = DBfetchColumn(DBselect('SELECT i.itemid' . ' FROM items i' . ' INNER JOIN httpstepitem hi ON hi.itemid=i.itemid' . ' WHERE ' . dbConditionInt('hi.httpstepid', zbx_objectValues($dbHttpTest[$httpTest['httptestid']]['steps'], 'httpstepid'))), 'itemid');
$this->updateItemsApplications($dbStepIds, $httpTest['applicationid']);
}
if (isset($httpTest['status'])) {
$status = $httpTest['status'] == HTTPTEST_STATUS_ACTIVE ? ITEM_STATUS_ACTIVE : ITEM_STATUS_DISABLED;
$itemIds = DBfetchColumn(DBselect('SELECT hsi.itemid' . ' FROM httpstep hs,httpstepitem hsi' . ' WHERE hs.httpstepid=hsi.httpstepid' . ' AND hs.httptestid=' . zbx_dbstr($httpTest['httptestid'])), 'itemid');
DB::update('items', array('values' => array('status' => $status), 'where' => array('itemid' => $itemIds)));
}
}
}
// TODO: REMOVE info
$dbCursor = DBselect('SELECT ht.name,h.name AS hostname' . ' FROM httptest ht' . ' INNER JOIN hosts h ON ht.hostid=h.hostid' . ' WHERE ' . dbConditionInt('ht.httptestid', zbx_objectValues($httpTests, 'httptestid')));
while ($httpTest = DBfetch($dbCursor)) {
info(_s('Updated: Web scenario "%1$s" on "%2$s".', $httpTest['name'], $httpTest['hostname']));
}
return $httpTests;
}
示例8: array
}
// host prototypes
$hostPrototypes = API::HostPrototype()->get(array('discoveryids' => $hostDiscoveryRuleids, 'inherited' => false, 'output' => array('hostid', 'name')));
if ($hostPrototypes) {
$prototypeList = array();
foreach ($hostPrototypes as $hostPrototype) {
$prototypeList[$hostPrototype['hostid']] = $hostPrototype['name'];
}
order_result($prototypeList);
$listBox = new CListBox('hostPrototypes', null, 8);
$listBox->setAttribute('disabled', 'disabled');
$listBox->addItems($prototypeList);
$hostList->addRow(_('Host prototypes'), $listBox);
}
// web scenarios
$httpTests = API::HttpTest()->get(array('output' => array('httptestid', 'name'), 'hostids' => getRequest('hostid'), 'inherited' => false));
if ($httpTests) {
$httpTestList = array();
foreach ($httpTests as $httpTest) {
$httpTestList[$httpTest['httptestid']] = $httpTest['name'];
}
order_result($httpTestList);
$listBox = new CListBox('httpTests', null, 8);
$listBox->setAttribute('disabled', 'disabled');
$listBox->addItems($httpTestList);
$hostList->addRow(_('Web scenarios'), $listBox);
}
}
$divTabs->addTab('hostTab', _('Host'), $hostList);
// templates
$tmplList = new CFormList('tmpllist');
示例9: foreach
}
// host prototypes
$hostPrototypes = API::HostPrototype()->get(['output' => ['hostid', 'name'], 'discoveryids' => $hostDiscoveryRuleIds, 'inherited' => false]);
if ($hostPrototypes) {
$prototypeList = [];
foreach ($hostPrototypes as $hostPrototype) {
$prototypeList[$hostPrototype['hostid']] = $hostPrototype['name'];
}
order_result($prototypeList);
$listBox = new CListBox('hostPrototypes', null, 8);
$listBox->setAttribute('disabled', 'disabled');
$listBox->addItems($prototypeList);
$hostList->addRow(_('Host prototypes'), $listBox);
}
// web scenarios
$httpTests = API::HttpTest()->get(['output' => ['httptestid', 'name'], 'hostids' => [$data['clone_hostid']], 'inherited' => false]);
if ($httpTests) {
$httpTestList = [];
foreach ($httpTests as $httpTest) {
$httpTestList[$httpTest['httptestid']] = $httpTest['name'];
}
order_result($httpTestList);
$listBox = new CListBox('httpTests', null, 8);
$listBox->setAttribute('disabled', 'disabled');
$listBox->addItems($httpTestList);
$hostList->addRow(_('Web scenarios'), $listBox);
}
}
$divTabs->addTab('hostTab', _('Host'), $hostList);
// templates
$tmplList = new CFormList();
示例10: delete
/**
* Delete template.
*
* @param array $templateids
* @param array $templateids['templateids']
*
* @return array
*/
public function delete(array $templateids)
{
if (empty($templateids)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty input parameter.'));
}
$options = array('templateids' => $templateids, 'editable' => true, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true);
$delTemplates = $this->get($options);
foreach ($templateids as $templateid) {
if (!isset($delTemplates[$templateid])) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _('You do not have permission to perform this operation.'));
}
}
API::Template()->unlink($templateids, null, true);
// delete the discovery rules first
$delRules = API::DiscoveryRule()->get(array('output' => array('itemid'), 'hostids' => $templateids, 'nopermissions' => true, 'preservekeys' => true));
if ($delRules) {
API::DiscoveryRule()->delete(array_keys($delRules), true);
}
// delete the items
$delItems = API::Item()->get(array('templateids' => $templateids, 'output' => array('itemid'), 'nopermissions' => true, 'preservekeys' => true));
if ($delItems) {
API::Item()->delete(array_keys($delItems), true);
}
// delete host from maps
if (!empty($templateids)) {
DB::delete('sysmaps_elements', array('elementtype' => SYSMAP_ELEMENT_TYPE_HOST, 'elementid' => $templateids));
}
// disable actions
// actions from conditions
$actionids = array();
$sql = 'SELECT DISTINCT actionid' . ' FROM conditions' . ' WHERE conditiontype=' . CONDITION_TYPE_TEMPLATE . ' AND ' . dbConditionString('value', $templateids);
$dbActions = DBselect($sql);
while ($dbAction = DBfetch($dbActions)) {
$actionids[$dbAction['actionid']] = $dbAction['actionid'];
}
// actions from operations
$sql = 'SELECT DISTINCT o.actionid' . ' FROM operations o,optemplate ot' . ' WHERE o.operationid=ot.operationid' . ' AND ' . dbConditionInt('ot.templateid', $templateids);
$dbActions = DBselect($sql);
while ($dbAction = DBfetch($dbActions)) {
$actionids[$dbAction['actionid']] = $dbAction['actionid'];
}
if (!empty($actionids)) {
DB::update('actions', array('values' => array('status' => ACTION_STATUS_DISABLED), 'where' => array('actionid' => $actionids)));
}
// delete action conditions
DB::delete('conditions', array('conditiontype' => CONDITION_TYPE_TEMPLATE, 'value' => $templateids));
// delete action operation commands
$operationids = array();
$sql = 'SELECT DISTINCT ot.operationid' . ' FROM optemplate ot' . ' WHERE ' . dbConditionInt('ot.templateid', $templateids);
$dbOperations = DBselect($sql);
while ($dbOperation = DBfetch($dbOperations)) {
$operationids[$dbOperation['operationid']] = $dbOperation['operationid'];
}
DB::delete('optemplate', array('templateid' => $templateids));
// delete empty operations
$delOperationids = array();
$sql = 'SELECT DISTINCT o.operationid' . ' FROM operations o' . ' WHERE ' . dbConditionInt('o.operationid', $operationids) . ' AND NOT EXISTS(SELECT NULL FROM optemplate ot WHERE ot.operationid=o.operationid)';
$dbOperations = DBselect($sql);
while ($dbOperation = DBfetch($dbOperations)) {
$delOperationids[$dbOperation['operationid']] = $dbOperation['operationid'];
}
DB::delete('operations', array('operationid' => $delOperationids));
// http tests
$delHttpTests = API::HttpTest()->get(array('templateids' => $templateids, 'output' => array('httptestid'), 'nopermissions' => 1, 'preservekeys' => 1));
if (!empty($delHttpTests)) {
API::HttpTest()->delete(array_keys($delHttpTests), true);
}
// Applications
$delApplications = API::Application()->get(array('templateids' => $templateids, 'output' => array('applicationid'), 'nopermissions' => 1, 'preservekeys' => 1));
if (!empty($delApplications)) {
API::Application()->delete(array_keys($delApplications), true);
}
DB::delete('hosts', array('hostid' => $templateids));
// TODO: remove info from API
foreach ($delTemplates as $template) {
info(_s('Deleted: Template "%1$s".', $template['name']));
add_audit_ext(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_HOST, $template['templateid'], $template['host'], 'hosts', null, null);
}
return array('templateids' => $templateids);
}
示例11: copyHttpTests
/**
* Copies web scenarios from given host ID to destination host.
*
* @param string $srcHostId source host ID
* @param string $dstHostId destination host ID
*
* @return bool
*/
function copyHttpTests($srcHostId, $dstHostId)
{
$httpTests = API::HttpTest()->get(array('output' => array('name', 'applicationid', 'delay', 'status', 'variables', 'agent', 'authentication', 'http_user', 'http_password', 'http_proxy', 'retries', 'ssl_cert_file', 'ssl_key_file', 'ssl_key_password', 'verify_peer', 'verify_host', 'headers'), 'hostids' => $srcHostId, 'selectSteps' => array('name', 'no', 'url', 'timeout', 'posts', 'required', 'status_codes', 'variables', 'follow_redirects', 'retrieve_mode', 'headers'), 'inherited' => false));
if (!$httpTests) {
return true;
}
// get destination application IDs
$srcApplicationIds = array();
foreach ($httpTests as $httpTest) {
if ($httpTest['applicationid'] != 0) {
$srcApplicationIds[] = $httpTest['applicationid'];
}
}
if ($srcApplicationIds) {
$dstApplicationIds = get_same_applications_for_host($srcApplicationIds, $dstHostId);
}
foreach ($httpTests as &$httpTest) {
$httpTest['hostid'] = $dstHostId;
if (isset($dstApplicationIds[$httpTest['applicationid']])) {
$httpTest['applicationid'] = $dstApplicationIds[$httpTest['applicationid']];
} else {
unset($httpTest['applicationid']);
}
unset($httpTest['httptestid']);
}
unset($httpTest);
return (bool) API::HttpTest()->create($httpTests);
}
示例12: dirname
if (isset($_REQUEST['favobj'])) {
// saving fixed/dynamic setting to profile
if ($_REQUEST['favobj'] == 'timelinefixedperiod') {
if (isset($_REQUEST['favid'])) {
CProfile::update('web.httptest.timelinefixed', $_REQUEST['favid'], PROFILE_TYPE_INT);
}
}
}
if ($page['type'] == PAGE_TYPE_JS || $page['type'] == PAGE_TYPE_HTML_BLOCK) {
require_once dirname(__FILE__) . '/include/page_footer.php';
exit;
}
/*
* Collect data
*/
$httptest = API::HttpTest()->get(['output' => ['httptestid', 'name', 'hostid'], 'httptestids' => getRequest('httptestid'), 'preservekeys' => true]);
$httptest = reset($httptest);
if (!$httptest) {
access_deny();
}
$http_test_name = CMacrosResolverHelper::resolveHttpTestName($httptest['hostid'], $httptest['name']);
// Create details widget.
$details_screen = CScreenBuilder::getScreen(['resourcetype' => SCREEN_RESOURCE_HTTPTEST_DETAILS, 'mode' => SCREEN_MODE_JS, 'dataId' => 'httptest_details', 'profileIdx2' => $httptest['httptestid']]);
(new CWidget())->setTitle(_('Details of web scenario') . ': ' . $http_test_name)->setControls((new CForm())->cleanItems()->addItem((new CList())->addItem(get_icon('reset', ['id' => getRequest('httptestid')]))->addItem(get_icon('fullscreen', ['fullscreen' => $_REQUEST['fullscreen']]))))->addItem($details_screen->get())->show();
echo BR();
$graphs = [];
// dims
$graph_dims = getGraphDims();
$graph_dims['width'] = -50;
$graph_dims['graphHeight'] = 150;
/*
示例13: foreach
$templateList->addRow(_('Graph prototypes'), $listBox);
}
}
// screens
$screens = API::TemplateScreen()->get(['inherited' => false, 'templateids' => $data['templateId'], 'output' => ['screenid', 'name']]);
if (!empty($screens)) {
$screensList = [];
foreach ($screens as $screen) {
$screensList[$screen['screenid']] = $screen['name'];
}
order_result($screensList);
$listBox = (new CListBox('screens', null, 8))->setAttribute('disabled', 'disabled')->addItems($screensList);
$templateList->addRow(_('Screens'), $listBox);
}
// web scenarios
$httpTests = API::HttpTest()->get(['output' => ['httptestid', 'name'], 'hostids' => $data['templateId'], 'inherited' => false]);
if ($httpTests) {
$httpTestList = [];
foreach ($httpTests as $httpTest) {
$httpTestList[$httpTest['httptestid']] = $httpTest['name'];
}
order_result($httpTestList);
$listBox = (new CListBox('httpTests', null, 8))->setAttribute('disabled', 'disabled')->addItems($httpTestList);
$templateList->addRow(_('Web scenarios'), $listBox);
}
}
$cloneOrFullClone = $data['form'] === 'clone' || $data['form'] === 'full_clone';
$divTabs->addTab('templateTab', _('Template'), $templateList);
// FULL CLONE }
// } TEMPLATE WIDGET
// TEMPLATES{
示例14: dirname
** 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.
**/
require_once dirname(__FILE__) . '/include/config.inc.php';
require_once dirname(__FILE__) . '/include/graphs.inc.php';
$page['file'] = 'chart3.php';
$page['type'] = PAGE_TYPE_IMAGE;
require_once dirname(__FILE__) . '/include/page_header.php';
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$fields = array('period' => array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(ZBX_MIN_PERIOD, ZBX_MAX_PERIOD), null), 'stime' => array(T_ZBX_INT, O_OPT, P_NZERO, null, null), 'profileIdx' => array(T_ZBX_STR, O_OPT, null, null, null), 'profileIdx2' => array(T_ZBX_STR, O_OPT, null, null, null), 'httptestid' => array(T_ZBX_INT, O_OPT, P_NZERO, null, null), 'http_item_type' => array(T_ZBX_INT, O_OPT, null, null, null), 'name' => array(T_ZBX_STR, O_OPT, null, null, null), 'width' => array(T_ZBX_INT, O_OPT, null, BETWEEN(20, 65535), null), 'height' => array(T_ZBX_INT, O_OPT, null, BETWEEN(0, 65535), null), 'ymin_type' => array(T_ZBX_INT, O_OPT, null, IN('0,1,2'), null), 'ymax_type' => array(T_ZBX_INT, O_OPT, null, IN('0,1,2'), null), 'ymin_itemid' => array(T_ZBX_INT, O_OPT, null, DB_ID, null), 'ymax_itemid' => array(T_ZBX_INT, O_OPT, null, DB_ID, null), 'legend' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'showworkperiod' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'showtriggers' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'graphtype' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'yaxismin' => array(T_ZBX_DBL, O_OPT, null, null, null), 'yaxismax' => array(T_ZBX_DBL, O_OPT, null, null, null), 'percent_left' => array(T_ZBX_DBL, O_OPT, null, BETWEEN(0, 100), null), 'percent_right' => array(T_ZBX_DBL, O_OPT, null, BETWEEN(0, 100), null), 'items' => array(T_ZBX_STR, O_OPT, null, null, null));
if (!check_fields($fields)) {
exit;
}
if ($httptestid = getRequest('httptestid', false)) {
if (!API::HttpTest()->isReadable(array($_REQUEST['httptestid']))) {
access_deny();
}
$color = array('current' => 0, 0 => array('next' => '1'), 1 => array('color' => 'Red', 'next' => '2'), 2 => array('color' => 'Dark Green', 'next' => '3'), 3 => array('color' => 'Blue', 'next' => '4'), 4 => array('color' => 'Dark Yellow', 'next' => '5'), 5 => array('color' => 'Cyan', 'next' => '6'), 6 => array('color' => 'Gray', 'next' => '7'), 7 => array('color' => 'Dark Red', 'next' => '8'), 8 => array('color' => 'Green', 'next' => '9'), 9 => array('color' => 'Dark Blue', 'next' => '10'), 10 => array('color' => 'Yellow', 'next' => '11'), 11 => array('color' => 'Black', 'next' => '1'));
$items = array();
$dbItems = DBselect('SELECT i.itemid' . ' FROM httpstepitem hi,items i,httpstep hs' . ' WHERE i.itemid=hi.itemid' . ' AND hs.httptestid=' . zbx_dbstr($httptestid) . ' AND hs.httpstepid=hi.httpstepid' . ' AND hi.type=' . zbx_dbstr(getRequest('http_item_type', HTTPSTEP_ITEM_TYPE_TIME)) . ' ORDER BY hs.no DESC');
while ($item = DBfetch($dbItems)) {
$itemColor = $color[$color['current'] = $color[$color['current']]['next']]['color'];
$items[] = array('itemid' => $item['itemid'], 'color' => $itemColor);
}
$httpTest = get_httptest_by_httptestid($httptestid);
$name = CMacrosResolverHelper::resolveHttpTestName($httpTest['hostid'], $httpTest['name']);
} elseif ($items = getRequest('items', array())) {
asort_by_key($items, 'sortorder');
$dbItems = API::Item()->get(array('itemids' => zbx_objectValues($items, 'itemid'), 'output' => array('itemid'), 'filter' => array('flags' => array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_PROTOTYPE, ZBX_FLAG_DISCOVERY_CREATED)), 'webitems' => true, 'preservekeys' => true));
foreach ($items as $item) {
示例15: get
/**
* Process screen.
*
* @return CDiv (screen inside container)
*/
public function get()
{
$this->dataId = 'httptest_details';
$httptest = API::HttpTest()->get(['output' => ['httptestid', 'name', 'hostid'], 'selectSteps' => ['httpstepid', 'name', 'no'], 'httptestids' => $this->profileIdx2, 'preservekeys' => true]);
$httptest = reset($httptest);
if (!$httptest) {
$messages = [['type' => 'error', 'message' => _('No permissions to referred object or it does not exist!')]];
return $this->getOutput(makeMessageBox(false, $messages, null, false, false));
}
$httptest['lastfailedstep'] = 0;
$httptest['error'] = '';
// fetch http test execution data
$httptest_data = Manager::HttpTest()->getLastData([$httptest['httptestid']]);
if ($httptest_data) {
$httptest_data = reset($httptest_data);
}
// fetch HTTP step items
$items = DBfetchArray(DBselect('SELECT i.value_type,i.valuemapid,i.units,i.itemid,hi.type,hs.httpstepid' . ' FROM items i,httpstepitem hi,httpstep hs' . ' WHERE hi.itemid=i.itemid' . ' AND hi.httpstepid=hs.httpstepid' . ' AND hs.httptestid=' . zbx_dbstr($httptest['httptestid'])));
$step_items = [];
foreach ($items as $item) {
$step_items[$item['httpstepid']][$item['type']] = $item;
}
// fetch HTTP item history
$item_history = Manager::History()->getLast($items);
$table = (new CTableInfo())->setHeader([_('Step'), _('Speed'), _('Response time'), _('Response code'), _('Status')]);
$total_time = ['value' => 0, 'value_type' => null, 'valuemapid' => null, 'units' => null];
order_result($httptest['steps'], 'no');
foreach ($httptest['steps'] as $step_data) {
$items_by_type = $step_items[$step_data['httpstepid']];
$status['msg'] = _('OK');
$status['style'] = ZBX_STYLE_GREEN;
$status['afterError'] = false;
if (!array_key_exists('lastfailedstep', $httptest_data)) {
$status['msg'] = _('Never executed');
$status['style'] = ZBX_STYLE_GREY;
} elseif ($httptest_data['lastfailedstep'] != 0) {
if ($httptest_data['lastfailedstep'] == $step_data['no']) {
$status['msg'] = $httptest_data['error'] === null ? _('Unknown error') : _s('Error: %1$s', $httptest_data['error']);
$status['style'] = ZBX_STYLE_RED;
} elseif ($httptest_data['lastfailedstep'] < $step_data['no']) {
$status['msg'] = _('Unknown');
$status['style'] = ZBX_STYLE_GREY;
$status['afterError'] = true;
}
}
foreach ($items_by_type as &$item) {
// Calculate the total time it took to execute the scenario.
// Skip steps that come after a failed step.
if (!$status['afterError'] && $item['type'] == HTTPSTEP_ITEM_TYPE_TIME) {
$total_time['value_type'] = $item['value_type'];
$total_time['valuemapid'] = $item['valuemapid'];
$total_time['units'] = $item['units'];
if (array_key_exists($item['itemid'], $item_history)) {
$history = $item_history[$item['itemid']][0];
$total_time['value'] += $history['value'];
}
}
}
unset($item);
// step speed
$speed_item = $items_by_type[HTTPSTEP_ITEM_TYPE_IN];
if (!$status['afterError'] && array_key_exists($speed_item['itemid'], $item_history) && $item_history[$speed_item['itemid']][0]['value'] > 0) {
$speed = formatHistoryValue($item_history[$speed_item['itemid']][0]['value'], $speed_item);
} else {
$speed = UNKNOWN_VALUE;
}
// step response time
$resptime_item = $items_by_type[HTTPSTEP_ITEM_TYPE_TIME];
if (!$status['afterError'] && array_key_exists($resptime_item['itemid'], $item_history) && $item_history[$resptime_item['itemid']][0]['value'] > 0) {
$resp_time = formatHistoryValue($item_history[$resptime_item['itemid']][0]['value'], $resptime_item);
} else {
$resp_time = UNKNOWN_VALUE;
}
// step response code
$resp_item = $items_by_type[HTTPSTEP_ITEM_TYPE_RSPCODE];
if (!$status['afterError'] && array_key_exists($resp_item['itemid'], $item_history) && $item_history[$resp_item['itemid']][0]['value'] > 0) {
$resp = formatHistoryValue($item_history[$resp_item['itemid']][0]['value'], $resp_item);
} else {
$resp = UNKNOWN_VALUE;
}
$table->addRow([CMacrosResolverHelper::resolveHttpTestName($httptest['hostid'], $step_data['name']), $speed, $resp_time, $resp, (new CSpan($status['msg']))->addClass($status['style'])]);
}
if (!array_key_exists('lastfailedstep', $httptest_data)) {
$status['msg'] = _('Never executed');
$status['style'] = ZBX_STYLE_GREY;
} elseif ($httptest_data['lastfailedstep'] != 0) {
$status['msg'] = $httptest_data['error'] === null ? _('Unknown error') : _s('Error: %1$s', $httptest_data['error']);
$status['style'] = ZBX_STYLE_RED;
} else {
$status['msg'] = _('OK');
$status['style'] = ZBX_STYLE_GREEN;
}
$table->addRow([bold(_('TOTAL')), '', bold($total_time['value'] ? formatHistoryValue($total_time['value'], $total_time) : UNKNOWN_VALUE), '', (new CSpan($status['msg']))->addClass($status['style'])]);
return $this->getOutput($table);
}