本文整理汇总了PHP中zbx_toArray函数的典型用法代码示例。如果您正苦于以下问题:PHP zbx_toArray函数的具体用法?PHP zbx_toArray怎么用?PHP zbx_toArray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zbx_toArray函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Executes API requests.
*
* @return string JSON encoded value
*/
public function execute()
{
if ($this->json->hasError()) {
$this->jsonError(null, '-32700', null, null, true);
return $this->json->encode($this->_response[0]);
}
if ($this->_jsonDecoded === null || $this->_jsonDecoded == []) {
$this->jsonError(null, '-32600', null, null, true);
return $this->json->encode($this->_response[0]);
}
foreach (zbx_toArray($this->_jsonDecoded) as $call) {
$call = is_array($call) ? $call : [$call];
// notification
if (!array_key_exists('id', $call)) {
$call['id'] = null;
}
if (!$this->validate($call)) {
continue;
}
list($api, $method) = array_merge(explode('.', $call['method']), [null, null]);
$result = $this->apiClient->callMethod($api, $method, $call['params'], $call['auth']);
$this->processResult($call, $result);
}
if (is_array($this->_jsonDecoded) && array_keys($this->_jsonDecoded) === range(0, count($this->_jsonDecoded) - 1)) {
// Return response as encoded batch if $this->_jsonDecoded is associative array.
return $this->json->encode($this->_response);
}
return $this->json->encode($this->_response[0]);
}
示例2: delete
/**
* Delete web scenario.
*
* @param $httpTestIds
*
* @return array|bool
*/
public function delete($httpTestIds, $nopermissions = false)
{
if (empty($httpTestIds)) {
return true;
}
$httpTestIds = zbx_toArray($httpTestIds);
$delHttpTests = $this->get(array('httptestids' => $httpTestIds, 'output' => API_OUTPUT_EXTEND, 'editable' => true, 'selectHosts' => API_OUTPUT_EXTEND, 'preservekeys' => true));
if (!$nopermissions) {
foreach ($httpTestIds as $httpTestId) {
if (!empty($delHttpTests[$httpTestId]['templateid'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Cannot delete templated web scenario "%1$s".', $delHttpTests[$httpTestId]['name']));
}
if (!isset($delHttpTests[$httpTestId])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('No permissions to referred object or it does not exist!'));
}
}
}
$parentHttpTestIds = $httpTestIds;
$childHttpTestIds = array();
do {
$dbTests = DBselect('SELECT ht.httptestid FROM httptest ht WHERE ' . dbConditionInt('ht.templateid', $parentHttpTestIds));
$parentHttpTestIds = array();
while ($dbTest = DBfetch($dbTests)) {
$parentHttpTestIds[] = $dbTest['httptestid'];
$childHttpTestIds[$dbTest['httptestid']] = $dbTest['httptestid'];
}
} while (!empty($parentHttpTestIds));
$options = array('httptestids' => $childHttpTestIds, 'output' => API_OUTPUT_EXTEND, 'nopermissions' => true, 'preservekeys' => true, 'selectHosts' => API_OUTPUT_EXTEND);
$delHttpTestChilds = $this->get($options);
$delHttpTests = zbx_array_merge($delHttpTests, $delHttpTestChilds);
$httpTestIds = array_merge($httpTestIds, $childHttpTestIds);
$itemidsDel = array();
$dbTestItems = DBselect('SELECT hsi.itemid' . ' FROM httptestitem hsi' . ' WHERE ' . dbConditionInt('hsi.httptestid', $httpTestIds));
while ($testitem = DBfetch($dbTestItems)) {
$itemidsDel[] = $testitem['itemid'];
}
$dbStepItems = DBselect('SELECT DISTINCT hsi.itemid' . ' FROM httpstepitem hsi,httpstep hs' . ' WHERE ' . dbConditionInt('hs.httptestid', $httpTestIds) . ' AND hs.httpstepid=hsi.httpstepid');
while ($stepitem = DBfetch($dbStepItems)) {
$itemidsDel[] = $stepitem['itemid'];
}
if (!empty($itemidsDel)) {
API::Item()->delete($itemidsDel, true);
}
DB::delete('httptest', array('httptestid' => $httpTestIds));
// TODO: REMOVE
foreach ($delHttpTests as $httpTest) {
$host = reset($httpTest['hosts']);
info(_s('Deleted: Web scenario "%1$s" on "%2$s".', $httpTest['name'], $host['host']));
add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_SCENARIO, 'Web scenario "' . $httpTest['name'] . '" "' . $httpTest['httptestid'] . '" host "' . $host['host'] . '".');
}
return array('httptestids' => $httpTestIds);
}
示例3: update
/**
* Update scripts.
*
* @param array $scripts
* @param array $scripts['name']
* @param array $scripts['hostid']
*
* @return array
*/
public function update(array $scripts)
{
$scripts = zbx_toArray($scripts);
$this->validateUpdate($scripts);
$scripts = $this->trimMenuPath($scripts);
$this->validateMenuPath($scripts, __FUNCTION__);
$scripts = $this->unsetExecutionType($scripts);
$update = array();
foreach ($scripts as $script) {
$scriptId = $script['scriptid'];
unset($script['scriptid']);
$update[] = array('values' => $script, 'where' => array('scriptid' => $scriptId));
}
DB::update('scripts', $update);
return array('scriptids' => zbx_objectValues($scripts, 'scriptid'));
}
示例4: delete
/**
* Delete Host
*
* @param array $hosts
* @param array $hosts[0, ...]['hostid'] Host ID to delete
* @return array|boolean
*/
public static function delete($hosts)
{
$hosts = zbx_toArray($hosts);
$hostids = zbx_objectValues($hosts, 'hostid');
if (empty($hostids)) {
return true;
}
try {
self::BeginTransaction(__METHOD__);
$options = array('hostids' => $hostids, 'editable' => 1, 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => 1);
$del_hosts = self::get($options);
foreach ($hostids as $hnum => $hostid) {
if (!isset($del_hosts[$hostid])) {
self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION);
}
}
$result = delete_host($hostids, false);
if (!$result) {
self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot delete host');
}
self::EndTransaction(true, __METHOD__);
return array('hostids' => $hostids);
} catch (APIException $e) {
self::EndTransaction(false, __METHOD__);
$error = $e->getErrors();
$error = reset($error);
self::setError(__METHOD__, $e->getCode(), $error);
return false;
}
}
示例5: syncTemplates
/**
* Inherit template graphs from template to host.
*
* @param array $data
*
* @return bool
*/
public function syncTemplates($data)
{
$data['templateids'] = zbx_toArray($data['templateids']);
$data['hostids'] = zbx_toArray($data['hostids']);
$dbLinks = DBSelect('SELECT ht.hostid,ht.templateid' . ' FROM hosts_templates ht' . ' WHERE ' . dbConditionInt('ht.hostid', $data['hostids']) . ' AND ' . dbConditionInt('ht.templateid', $data['templateids']));
$linkage = array();
while ($link = DBfetch($dbLinks)) {
if (!isset($linkage[$link['templateid']])) {
$linkage[$link['templateid']] = array();
}
$linkage[$link['templateid']][$link['hostid']] = 1;
}
$graphs = $this->get(array('hostids' => $data['templateids'], 'preservekeys' => true, 'output' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND, 'selectHosts' => array('hostid'), 'filter' => array('flags' => null)));
foreach ($graphs as $graph) {
foreach ($data['hostids'] as $hostid) {
if (isset($linkage[$graph['hosts'][0]['hostid']][$hostid])) {
$this->inherit($graph, $hostid);
}
}
}
return true;
}
示例6: syncTemplates
public function syncTemplates($data)
{
$data['templateids'] = zbx_toArray($data['templateids']);
$data['hostids'] = zbx_toArray($data['hostids']);
$applications = $this->get(array('hostids' => $data['templateids'], 'preservekeys' => true, 'output' => API_OUTPUT_EXTEND));
$this->inherit($applications, $data['hostids']);
return true;
}
示例7: delete
/**
* Delete proxy.
*
* @param string|array $proxyIds
*
* @return array
*/
public function delete($proxyIds)
{
$proxyIds = zbx_toArray($proxyIds);
// deprecated input support
if ($proxyIds && is_array($proxyIds[0])) {
$this->deprecated('Passing objects is deprecated, use an array of IDs instead.');
foreach ($proxyIds as $proxyId) {
if (!check_db_fields(array('proxyid' => null), $proxyId)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('No proxy ID given.'));
}
}
$proxyIds = zbx_objectValues($proxyIds, 'proxyid');
}
$this->validateDelete($proxyIds);
$dbProxies = DBselect('SELECT h.hostid,h.host' . ' FROM hosts h' . ' WHERE ' . dbConditionInt('h.hostid', $proxyIds));
$dbProxies = DBfetchArrayAssoc($dbProxies, 'hostid');
$actionIds = array();
// get conditions
$dbActions = DBselect('SELECT DISTINCT c.actionid' . ' FROM conditions c' . ' WHERE c.conditiontype=' . CONDITION_TYPE_PROXY . ' AND ' . dbConditionString('c.value', $proxyIds));
while ($dbAction = DBfetch($dbActions)) {
$actionIds[$dbAction['actionid']] = $dbAction['actionid'];
}
if ($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_PROXY, 'value' => $proxyIds));
// delete interface
DB::delete('interface', array('hostid' => $proxyIds));
// delete host
DB::delete('hosts', array('hostid' => $proxyIds));
// TODO: remove info from API
foreach ($dbProxies as $proxy) {
info(_s('Deleted: Proxy "%1$s".', $proxy['host']));
add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_PROXY, '[' . $proxy['host'] . '] [' . $proxy['hostid'] . ']');
}
return array('proxyids' => $proxyIds);
}
示例8: massRemove
/**
* Additionally allows to remove interfaces from hosts.
*
* Checks write permissions for hosts.
*
* Additional supported $data parameters are:
* - interfaces - an array of interfaces to delete from the hosts
*
* @param array $data
*
* @return array
*/
public function massRemove(array $data)
{
$hostids = zbx_toArray($data['hostids']);
$this->checkPermissions($hostids);
if (isset($data['interfaces'])) {
$options = ['hostids' => $hostids, 'interfaces' => zbx_toArray($data['interfaces'])];
API::HostInterface()->massRemove($options);
}
// rename the "templates" parameter to the common "templates_link"
if (isset($data['templateids'])) {
$data['templateids_link'] = $data['templateids'];
unset($data['templateids']);
}
$data['templateids'] = [];
return parent::massRemove($data);
}
示例9: update
/**
* Update IconMap.
* @param array $iconMaps
* @return array
*/
public function update(array $iconMaps)
{
if (USER_TYPE_SUPER_ADMIN != self::$userData['type']) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _('Only Super Admins can update icon maps.'));
}
$iconMaps = zbx_toArray($iconMaps);
$iconMapids = zbx_objectValues($iconMaps, 'iconmapid');
$updates = [];
$duplicates = [];
foreach ($iconMaps as $iconMap) {
if (!check_db_fields(['iconmapid' => null], $iconMap)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect parameters for icon map update method "%s".', $iconMap['name']));
}
if (isset($iconMap['name'])) {
if (zbx_empty($iconMap['name'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map name cannot be empty.'));
} elseif (isset($duplicates[$iconMap['name']])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Cannot create icon maps with identical name "%s".', $iconMap['name']));
} else {
$duplicates[$iconMap['name']] = $iconMap['name'];
}
}
}
$this->validateMappings($iconMaps, false);
$iconMapsUpd = API::IconMap()->get(['iconmapids' => $iconMapids, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'selectMappings' => API_OUTPUT_EXTEND]);
$oldIconMappings = [];
$newIconMappings = [];
foreach ($iconMaps as $iconMap) {
if (!isset($iconMapsUpd[$iconMap['iconmapid']])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map with iconmapid "%s" does not exist.', $iconMap['iconmapid']));
}
// Existence
if (isset($iconMap['name'])) {
$iconMapExists = $this->get(['filter' => ['name' => $iconMap['name']], 'output' => ['iconmapid'], 'editable' => true, 'nopermissions' => true, 'preservekeys' => true]);
if (($iconMapExists = reset($iconMapExists)) && bccomp($iconMapExists['iconmapid'], $iconMap['iconmapid']) != 0) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map "%s" already exists.', $iconMap['name']));
}
}
if (isset($iconMap['mappings'])) {
$mappingsDb = $iconMapsUpd[$iconMap['iconmapid']]['mappings'];
foreach ($mappingsDb as $mapping) {
$oldIconMappings[] = $mapping;
}
foreach ($iconMap['mappings'] as $mapping) {
$mapping['iconmapid'] = $iconMap['iconmapid'];
$newIconMappings[] = $mapping;
}
}
$iconMapid = $iconMap['iconmapid'];
unset($iconMap['iconmapid']);
if (!empty($iconMap)) {
$updates[] = ['values' => $iconMap, 'where' => ['iconmapid' => $iconMapid]];
}
}
DB::save('icon_map', $iconMaps);
DB::replace('icon_mapping', $oldIconMappings, $newIconMappings);
return ['iconmapids' => $iconMapids];
}
示例10: syncTemplates
public function syncTemplates(array $data)
{
$data['templateids'] = zbx_toArray($data['templateids']);
$data['hostids'] = zbx_toArray($data['hostids']);
$triggers = $this->get(array('hostids' => $data['templateids'], 'preservekeys' => true, 'output' => array('triggerid', 'expression', 'description', 'url', 'status', 'priority', 'comments', 'type')));
foreach ($triggers as $trigger) {
$trigger['expression'] = explode_exp($trigger['expression']);
$this->inherit($trigger, $data['hostids']);
}
return true;
}
示例11: delete
/**
* Deletes screen items.
*
* @param array $screenItemIds
*
* @return array
*/
public function delete($screenItemIds)
{
$screenItemIds = zbx_toArray($screenItemIds);
// check permissions
$dbScreenItems = $this->get(array('screenitemids' => $screenItemIds, 'preservekeys' => true));
foreach ($screenItemIds as $screenItemId) {
if (!isset($dbScreenItems[$screenItemId])) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
}
}
// delete screen items
DB::delete($this->tableName(), array('screenitemid' => $screenItemIds));
return array('screenitemids' => $screenItemIds);
}
示例12: delete
/**
* Delete web scenario.
*
* @param $httpTestIds
*
* @return array|bool
*/
public function delete($httpTestIds)
{
if (empty($httpTestIds)) {
return true;
}
$httpTestIds = zbx_toArray($httpTestIds);
$delHttpTests = $this->get(array('httptestids' => $httpTestIds, 'output' => API_OUTPUT_EXTEND, 'editable' => true, 'selectHosts' => API_OUTPUT_EXTEND, 'preservekeys' => true));
foreach ($httpTestIds as $httpTestId) {
if (!isset($delHttpTests[$httpTestId])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('No permissions to referred object or it does not exist!'));
}
}
$itemidsDel = array();
$dbTestItems = DBselect('SELECT hsi.itemid' . ' FROM httptestitem hsi' . ' WHERE ' . dbConditionInt('hsi.httptestid', $httpTestIds));
while ($testitem = DBfetch($dbTestItems)) {
$itemidsDel[] = $testitem['itemid'];
}
$dbStepItems = DBselect('SELECT DISTINCT hsi.itemid' . ' FROM httpstepitem hsi,httpstep hs' . ' WHERE ' . dbConditionInt('hs.httptestid', $httpTestIds) . ' AND hs.httpstepid=hsi.httpstepid');
while ($stepitem = DBfetch($dbStepItems)) {
$itemidsDel[] = $stepitem['itemid'];
}
if (!empty($itemidsDel)) {
API::Item()->delete($itemidsDel, true);
}
DB::delete('httptest', array('httptestid' => $httpTestIds));
// TODO: REMOVE info
foreach ($delHttpTests as $httpTest) {
info(_s('Scenario "%s" deleted.', $httpTest['name']));
}
// TODO: REMOVE audit
foreach ($delHttpTests as $httpTest) {
$host = reset($httpTest['hosts']);
add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_SCENARIO, _s('Scenario "%1$s" "%2$s" host "%3$s".', $httpTest['name'], $httpTest['httptestid'], $host['host']));
}
return array('httptestids' => $httpTestIds);
}
示例13: 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);
}
示例14: delete
/**
* Delete IconMap.
* @param array $iconmapids
* @return array
*/
public function delete($iconmapids)
{
$iconmapids = zbx_toArray($iconmapids);
if (empty($iconmapids)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty input parameter.'));
}
if (!$this->isWritable($iconmapids)) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
}
$sql = 'SELECT m.name as mapname, im.name as iconmapname' . ' FROM sysmaps m, icon_map im' . ' WHERE m.iconmapid=im.iconmapid' . ' AND ' . dbConditionInt('m.iconmapid', $iconmapids);
if ($names = DBfetch(DBselect($sql))) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map "%1$s" cannot be deleted. Used in map "%2$s".', $names['iconmapname'], $names['mapname']));
}
DB::delete('icon_map', array('iconmapid' => $iconmapids));
return array('iconmapids' => $iconmapids);
}
示例15: delete
/**
* Delete Host
*
* @param array $hosts
* @param array $hosts[0, ...]['hostid'] Host ID to delete
*
* @return array|boolean
*/
public function delete($hosts)
{
if (empty($hosts)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty input parameter.'));
}
$hosts = zbx_toArray($hosts);
$hostids = zbx_objectValues($hosts, 'hostid');
$this->checkInput($hosts, __FUNCTION__);
// 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' => API_OUTPUT_SHORTEN, '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::WebCheck()->delete($delHttptests);
}
// 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);
}
return array('hostids' => $hostids);
}