コード例 #1
0
ファイル: class.cgraph.php プロジェクト: phedders/zabbix
 /**
  * Delete graphs
  *
  * @static
  * @param array $graphids
  * @return boolean
  */
 public static function delete($graphids)
 {
     $result = delete_graph($graphids);
     if ($result) {
         return true;
     } else {
         self::$error = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Internal zabbix error');
         return false;
     }
 }
コード例 #2
0
ファイル: graphs.inc.php プロジェクト: phedders/zabbix
function delete_template_graphs($hostid, $templateids = null, $unlink_mode = false)
{
    zbx_value2array($templateids);
    $db_graphs = get_graphs_by_hostid($hostid);
    while ($db_graph = DBfetch($db_graphs)) {
        if ($db_graph['templateid'] == 0) {
            continue;
        }
        if (!is_null($templateids)) {
            $tmp_hhosts = get_hosts_by_graphid($db_graph['templateid']);
            $tmp_host = DBfetch($tmp_hhosts);
            if (!uint_in_array($tmp_host['hostid'], $templateids)) {
                continue;
            }
        }
        if ($unlink_mode) {
            if (DBexecute('UPDATE graphs SET templateid=0 WHERE graphid=' . $db_graph['graphid'])) {
                info('Graph "' . $db_graph['name'] . '" unlinked');
            }
        } else {
            delete_graph($db_graph['graphid']);
        }
    }
}
コード例 #3
0
ファイル: graphs.php プロジェクト: rennhak/zabbix
     show_messages($result, S_GRAPH_DELETED, S_CANNOT_DELETE_GRAPH);
 } else {
     if (isset($_REQUEST['delete']) && isset($_REQUEST['group_graphid'])) {
         $group_graphid = $_REQUEST['group_graphid'];
         $group_graphid = zbx_uint_array_intersect($group_graphid, $available_graphs);
         $result = false;
         DBstart();
         foreach ($group_graphid as $id => $graphid) {
             $graph = get_graph_by_graphid($graphid);
             if ($graph['templateid'] != 0) {
                 continue;
             }
             add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_GRAPH, 'Graph [' . $graph['name'] . ']');
         }
         if (!empty($group_graphid)) {
             $result = delete_graph($group_graphid);
         }
         $result = DBend($result);
         show_messages($result, S_GRAPHS_DELETED, S_CANNOT_DELETE_GRAPHS);
     } else {
         if (isset($_REQUEST['copy']) && isset($_REQUEST['group_graphid']) && isset($_REQUEST['form_copy_to'])) {
             if (isset($_REQUEST['copy_targetid']) && $_REQUEST['copy_targetid'] > 0 && isset($_REQUEST['copy_type'])) {
                 if (0 == $_REQUEST['copy_type']) {
                     /* hosts */
                     $hosts_ids = $_REQUEST['copy_targetid'];
                 } else {
                     /* groups */
                     $hosts_ids = array();
                     $sql = 'SELECT DISTINCT h.hostid ' . ' FROM hosts h, hosts_groups hg' . ' WHERE h.hostid=hg.hostid ' . ' AND ' . DBcondition('hg.groupid', $_REQUEST['copy_targetid']) . ' AND ' . DBcondition('h.hostid', $available_hosts_all_nodes);
                     $db_hosts = DBselect($sql);
                     while ($db_host = DBfetch($db_hosts)) {
コード例 #4
0
 /**
  * Delete graphs
  *
  * @param array $graphs
  * @param array $graphs['graphids']
  * @return boolean
  */
 public static function delete($graphids)
 {
     $graphids = zbx_toArray($graphids);
     if (empty($graphids)) {
         return true;
     }
     try {
         self::BeginTransaction(__METHOD__);
         $options = array('graphids' => $graphids, 'editable' => 1, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1);
         $del_graphs = self::get($options);
         foreach ($graphids as $graphid) {
             if (!isset($del_graphs[$graphid])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION);
             }
             if ($del_graphs[$graphid]['templateid'] != 0) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, 'Cannot delete templated graphs');
             }
         }
         if (!delete_graph($graphids)) {
             self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot delete Graphs');
         }
         self::EndTransaction(true, __METHOD__);
         return true;
     } catch (APIException $e) {
         self::EndTransaction(false, __METHOD__);
         $error = $e->getErrors();
         $error = reset($error);
         self::setError(__METHOD__, $e->getCode(), $error);
         return false;
     }
 }
コード例 #5
0
ファイル: items.inc.php プロジェクト: rennhak/zabbix
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;
}