コード例 #1
0
ファイル: graphs.php プロジェクト: songyuanjie/zabbix-stats
 if (isset($_REQUEST['move_up']) && isset($_REQUEST['items'])) {
     if (isset($_REQUEST['items'][$_REQUEST['move_up']])) {
         $tmp = $_REQUEST['items'][$_REQUEST['move_up']];
         $_REQUEST['items'][$_REQUEST['move_up']]['sortorder'] = $_REQUEST['items'][$_REQUEST['move_up'] - 1]['sortorder'];
         $_REQUEST['items'][$_REQUEST['move_up'] - 1]['sortorder'] = $tmp['sortorder'];
     }
 } else {
     if (isset($_REQUEST['move_down']) && isset($_REQUEST['items'])) {
         if (isset($_REQUEST['items'][$_REQUEST['move_down']])) {
             $tmp = $_REQUEST['items'][$_REQUEST['move_down']];
             $_REQUEST['items'][$_REQUEST['move_down']]['sortorder'] = $_REQUEST['items'][$_REQUEST['move_down'] + 1]['sortorder'];
             $_REQUEST['items'][$_REQUEST['move_down'] + 1]['sortorder'] = $tmp['sortorder'];
         }
     } else {
         if ($_REQUEST['go'] == 'delete' && isset($_REQUEST['group_graphid'])) {
             $go_result = CGraph::delete($_REQUEST['group_graphid']);
             show_messages($go_result, S_GRAPHS_DELETED, S_CANNOT_DELETE_GRAPHS);
         } else {
             if ($_REQUEST['go'] == 'copy_to' && isset($_REQUEST['copy']) && isset($_REQUEST['group_graphid'])) {
                 if (isset($_REQUEST['copy_targetid']) && $_REQUEST['copy_targetid'] > 0 && isset($_REQUEST['copy_type'])) {
                     $go_result = true;
                     $options = array('editable' => 1, 'nodes' => get_current_nodeid(true), 'templated_hosts' => 1);
                     if (0 == $_REQUEST['copy_type']) {
                         // hosts
                         $options['hostids'] = $_REQUEST['copy_targetid'];
                     } else {
                         // groups
                         zbx_value2array($_REQUEST['copy_targetid']);
                         $opt = array('groupids' => $_REQUEST['copy_targetid'], 'editable' => 1, 'nodes' => get_current_nodeid(true));
                         $db_groups = CHostGroup::get($opt);
                         $db_groups = zbx_toHash($db_groups, 'groupid');
コード例 #2
0
ファイル: class.czbxrpc.php プロジェクト: phedders/zabbix
 private static function graph($action, $params)
 {
     CGraph::$error = array();
     switch ($action) {
         case 'add':
             $result = CGraph::add($params);
             break;
         case 'get':
             $result = CGraph::get($params);
             break;
         case 'getById':
             $result = CGraph::getById($params);
             break;
         case 'getId':
             $result = CGraph::getId($params);
             break;
         case 'update':
             $result = CGraph::update($params);
             break;
         case 'addItems':
             $result = CGraph::addItems($params);
             break;
         case 'deleteItems':
             $result = CGraph::deleteItems($params);
             break;
         case 'delete':
             $result = CGraph::delete($params);
             break;
         default:
             self::$result = array('error' => ZBX_API_ERROR_NO_METHOD, 'data' => 'Method: "' . $action . '" doesn\'t exist.');
             return;
             //exit function
     }
     if ($result !== false) {
         self::$result = array('result' => $result);
     } else {
         self::$result = CGraph::$error;
     }
 }
コード例 #3
0
 /**
  * Delete items
  *
  * @param array $itemids
  * @return
  */
 public static function delete($itemids)
 {
     if (empty($itemids)) {
         return true;
     }
     $itemids = zbx_toArray($itemids);
     $insert = array();
     try {
         self::BeginTransaction(__METHOD__);
         $options = array('itemids' => $itemids, 'editable' => 1, 'preservekeys' => 1, 'output' => API_OUTPUT_EXTEND);
         $del_items = self::get($options);
         foreach ($itemids as $itemid) {
             if (!isset($del_items[$itemid])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSIONS);
             }
             if ($del_items[$itemid]['templateid'] != 0) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot delete templated items');
             }
             if ($del_items[$itemid]['type'] == ITEM_TYPE_HTTPTEST) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot delete web items');
             }
         }
         // first delete child items
         $parent_itemids = $itemids;
         do {
             $db_items = DBselect('SELECT itemid FROM items WHERE ' . DBcondition('templateid', $parent_itemids));
             $parent_itemids = array();
             while ($db_item = DBfetch($db_items)) {
                 $parent_itemids[] = $db_item['itemid'];
                 $itemids[] = $db_item['itemid'];
             }
         } while (!empty($parent_itemids));
         // delete triggers
         $result = delete_triggers_by_itemid($itemids);
         if (!$result) {
             self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot delete item');
         }
         // delete graphs
         $del_graphs = array();
         $sql = 'SELECT gi.graphid' . ' FROM graphs_items gi' . ' WHERE ' . DBcondition('gi.itemid', $itemids) . ' AND NOT EXISTS (' . ' SELECT gii.gitemid' . ' FROM graphs_items gii' . ' WHERE gii.graphid=gi.graphid' . ' AND ' . DBcondition('gii.itemid', $itemids, true, false) . ' )';
         $db_graphs = DBselect($sql);
         while ($db_graph = DBfetch($db_graphs)) {
             $del_graphs[$db_graph['graphid']] = $db_graph['graphid'];
         }
         if (!empty($del_graphs)) {
             $result = CGraph::delete($del_graphs);
             if (!$result) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, 'Cannot delete item');
             }
         }
         //--
         $itemids_condition = DBcondition('itemid', $itemids);
         DB::delete('graphs_items', array($itemids_condition));
         DB::delete('screens_items', array(DBcondition('resourceid', $itemids), DBcondition('resourcetype', array(SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_PLAIN_TEXT))));
         DB::delete('items_applications', array($itemids_condition));
         DB::delete('items', array($itemids_condition));
         DB::delete('profiles', array('idx=' . zbx_dbstr('web.favorite.graphids'), 'source=' . zbx_dbstr('itemid'), DBcondition('value_id', $itemids)));
         $item_data_tables = array('trends', 'trends_uint', 'history_text', 'history_log', 'history_uint', 'history_str', 'history');
         foreach ($itemids as $id => $itemid) {
             foreach ($item_data_tables as $table) {
                 $insert[] = array('tablename' => $table, 'field' => 'itemid', 'value' => $itemid);
             }
         }
         DB::insert('housekeeper', $insert);
         self::EndTransaction(true, __METHOD__);
         return array('itemids' => $itemids);
     } catch (APIException $e) {
         self::EndTransaction(false, __METHOD__);
         $error = $e->getErrors();
         $error = reset($error);
         self::setError(__METHOD__, $e->getCode(), $error);
         return false;
     }
 }