function delete_history_by_httptestid($httptestid) { $db_items = DBselect('SELECT DISTINCT i.itemid' . ' FROM items i,httpstepitem si,httpstep s' . ' WHERE i.itemid=si.itemid' . ' AND si.httpstepid=s.httpstepid' . ' AND s.httptestid=' . zbx_dbstr($httptestid)); while ($item_data = DBfetch($db_items)) { if (!delete_history_by_itemid($item_data['itemid'])) { return false; } } return true; }
function delete_item($itemids) { zbx_value2array($itemids); if (empty($itemids)) { return true; } // Get items INFO before delete them! $items = array(); $item_res = DBselect('SELECT itemid, description, key_ FROM items WHERE ' . DBcondition('itemid', $itemids)); while ($item_rows = DBfetch($item_res)) { $items[$item_rows['itemid']] = $item_rows; } // -- $hosts = array(); $hosts = get_host_by_itemid($itemids); // first delete child items $del_cld_items = array(); $db_items = DBselect('SELECT itemid FROM items WHERE ' . DBcondition('templateid', $itemids)); while ($db_item = DBfetch($db_items)) { // recursion !!!! $del_cld_items[$db_item['itemid']] = $db_item['itemid']; } if (!empty($del_cld_items)) { $result = delete_item($del_cld_items); if (!$result) { return $result; } } //-- // triggers $result = delete_triggers_by_itemid($itemids); if (!$result) { return $result; } //-- // delete graphs $del_graphs = array(); $db_gitems = DBselect('SELECT DISTINCT graphid FROM graphs_items WHERE ' . DBcondition('itemid', $itemids)); while ($db_gitem = DBfetch($db_gitems)) { $del_graphs[$db_gitem['graphid']] = $db_gitem['graphid']; } if (!empty($del_graphs)) { $result = delete_graph($del_graphs); if (!$result) { return $result; } } //-- $result = delete_history_by_itemid($itemids, 1); if (!$result) { return $result; } $temp_arr = array(SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_PLAIN_TEXT); DBexecute('DELETE FROM screens_items WHERE ' . DBcondition('resourceid', $itemids) . ' AND ' . DBcondition('resourcetype', $temp_arr)); DBexecute('DELETE FROM items_applications WHERE ' . DBcondition('itemid', $itemids)); DBexecute("DELETE FROM profiles WHERE idx='web.favorite.graphids' AND source='itemid' AND " . DBcondition('value_id', $itemids)); foreach ($itemids as $id) { /* The section should be improved */ $item_old = get_item_by_itemid($id); $result = DBexecute('DELETE FROM items WHERE itemid=' . $id); if ($result) { add_audit_ext(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_ITEM, $id, $item_old['description'], 'items', NULL, NULL); } else { break; } } /* $result = DBexecute('DELETE FROM items WHERE '.DBcondition('itemid',$itemids));*/ if ($result) { foreach ($items as $itemid => $item) { info("Item '" . $hosts[$itemid]['host'] . ':' . $item['key_'] . "' deleted"); } } return $result; }
$db_hosts = DBselect('SELECT DISTINCT h.hostid' . ' FROM hosts h,hosts_groups hg' . ' WHERE h.hostid=hg.hostid' . ' AND ' . dbConditionInt('hg.groupid', $group_ids)); while ($db_host = DBfetch($db_hosts)) { $hosts_ids[] = $db_host['hostid']; } } DBstart(); $go_result = copyItemsToHosts($_REQUEST['group_itemid'], $hosts_ids); $go_result = DBend($go_result); show_messages($go_result, _('Items copied'), _('Cannot copy items')); $_REQUEST['go'] = 'none2'; } else { show_error_message(_('No target selected.')); } } elseif ($_REQUEST['go'] == 'clean_history' && isset($_REQUEST['group_itemid'])) { DBstart(); $go_result = delete_history_by_itemid($_REQUEST['group_itemid']); DBexecute('UPDATE items SET lastvalue=null,lastclock=null,prevvalue=null WHERE ' . dbConditionInt('itemid', $_REQUEST['group_itemid'])); foreach ($_REQUEST['group_itemid'] as $id) { if (!($item = get_item_by_itemid($id))) { continue; } $host = get_host_by_hostid($item['hostid']); add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_ITEM, _('Item') . ' [' . $item['key_'] . '] [' . $id . '] ' . _('Host') . ' [' . $host['host'] . '] ' . _('History cleared')); } $go_result = DBend($go_result); show_messages($go_result, _('History cleared'), $go_result); } elseif ($_REQUEST['go'] == 'delete' && isset($_REQUEST['group_itemid'])) { DBstart(); $group_itemid = $_REQUEST['group_itemid']; $itemsToDelete = API::Item()->get(array('output' => array('key_', 'itemid'), 'selectHosts' => array('name'), 'itemids' => $group_itemid, 'preservekeys' => true)); $go_result = API::Item()->delete($group_itemid);
show_messages($result, S_ITEMS_COPIED, S_CANNOT_COPY_ITEMS); $_REQUEST['go'] = 'none'; } else { error('No target selection.'); } show_messages(); } else { if ($_REQUEST['go'] == 'clean_history' && isset($_REQUEST['group_itemid'])) { $result = false; $group_itemid = $_REQUEST['group_itemid']; DBstart(); foreach ($group_itemid as $id) { if (!($item = get_item_by_itemid($id))) { continue; } $cur_result = delete_history_by_itemid($id); $result |= $cur_result; if ($cur_result) { DBexecute('update items set nextcheck=0,lastvalue=null,lastclock=null,prevvalue=null where itemid=' . $id); $host = get_host_by_hostid($item['hostid']); add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_ITEM, S_ITEM . ' [' . $item['key_'] . '] [' . $id . '] ' . S_HOST . ' [' . $host['host'] . '] ' . S_HISTORY_CLEANED); } } $result = DBend($result); show_messages($result, S_HISTORY_CLEANED, $result); } else { if ($_REQUEST['go'] == 'delete' && isset($_REQUEST['group_itemid'])) { global $USER_DETAILS; $result = true; $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_WRITE); $group_itemid = $_REQUEST['group_itemid'];