function api_data_preset_gprint_remove($data_preset_gprint_id) { /* sanity checks */ validate_id_die($data_preset_gprint_id, "data_preset_gprint_id"); db_delete("preset_gprint", array( "id" => array("type" => DB_TYPE_INTEGER, "value" => $data_preset_gprint_id) )); }
function api_rra_consolidation_function_id_save($rra_id, $_fields_consolidation_function_id) { /* sanity checks */ validate_id_die($rra_id, "rra_id", true); /* clear out the existing template -> RRA mappings */ db_delete("data_template_rra", array( "data_template_id" => array("type" => DB_TYPE_INTEGER, "value" => $rra_id) )); /* insert new data template -> RRA mappings */ if (is_array($_fields_consolidation_function_id) > 0) { foreach ($_fields_consolidation_function_id as $consolidation_function_id) { db_insert("rra_cf", array( "consolidation_function_id" => array("type" => DB_TYPE_INTEGER, "value" => $consolidation_function_id), "rra_id" => array("type" => DB_TYPE_INTEGER, "value" => $rra_id) ), array("consolidation_function_id", "rra_id")); } } }
function api_graph_tree_item_available_order_key_get($graph_tree_id, $order_key) { /* sanity checks */ validate_id_die($graph_tree_id, "graph_tree_id"); if (($order_key != "") && (!api_graph_tree_item_order_key_validate($order_key))) { die("Invalid order key '$order_key'"); } if (preg_match("/^" . str_repeat('0', CHARS_PER_TIER) . "/", $order_key)) { $tier = 0; $parent_root = ''; }else{ $tier = api_graph_tree_item_depth_get($order_key); $parent_root = substr($order_key, 0, ($tier * CHARS_PER_TIER)); } $order_key = db_fetch_cell("SELECT order_key FROM graph_tree_items WHERE graph_tree_id = $graph_tree_id AND order_key LIKE '$parent_root%' ORDER BY order_key DESC LIMIT 1"); $complete_root = substr($order_key, 0, ($tier * CHARS_PER_TIER) + CHARS_PER_TIER); $order_key_suffix = (substr($complete_root, - CHARS_PER_TIER) + 1); $order_key_suffix = str_pad($order_key_suffix, CHARS_PER_TIER, '0', STR_PAD_LEFT); $order_key_suffix = str_pad($parent_root . $order_key_suffix, (MAX_TREE_DEPTH * CHARS_PER_TIER), '0', STR_PAD_RIGHT); return $order_key_suffix; }
function api_graph_tree_item_move($graph_tree_item_id, $direction) { require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_info.php"); /* sanity checks */ validate_id_die($graph_tree_item_id, "graph_tree_item_id"); if (($direction != "up") && ($direction != "down")) { return false; } /* obtain a copy of the current graph tree item */ $graph_tree_item = api_graph_tree_item_get($graph_tree_item_id); /* find out where in the tree this item is located */ $current_depth = api_graph_tree_item_depth_get($graph_tree_item["order_key"]); $displaced_row = db_fetch_row("select order_key from graph_tree_items where order_key " . ($direction == "up" ? "<" : ">") . " " . sql_sanitize($graph_tree_item["order_key"]) . " and order_key like '%" . sql_sanitize(substr($graph_tree_item["order_key"], ($current_depth * CHARS_PER_TIER))) . "' and order_key not like '%" . sql_sanitize(str_repeat('0', CHARS_PER_TIER) . substr($graph_tree_item["order_key"], ($current_depth * CHARS_PER_TIER))) . "' and graph_tree_id = " . $graph_tree_item["graph_tree_id"] . " order by order_key " . ($direction == "up" ? "DESC" : "ASC")); if ((is_array($displaced_row)) && (isset($displaced_row["order_key"]))) { $old_root = sql_sanitize(substr($graph_tree_item["order_key"], 0, ($current_depth * CHARS_PER_TIER))); $new_root = sql_sanitize(substr($displaced_row["order_key"], 0, ($current_depth * CHARS_PER_TIER))); db_execute("UPDATE graph_tree_items SET order_key = CONCAT('" . str_pad('', ($current_depth * CHARS_PER_TIER), 'Z') . "',SUBSTRING(order_key," . (($current_depth * CHARS_PER_TIER) + 1).")) WHERE order_key LIKE '$new_root%' AND graph_tree_id = " . $graph_tree_item["graph_tree_id"]); db_execute("UPDATE graph_tree_items SET order_key = CONCAT('$new_root',SUBSTRING(order_key," . (($current_depth * CHARS_PER_TIER) + 1) . ")) WHERE order_key LIKE '$old_root%' AND graph_tree_id = " . $graph_tree_item["graph_tree_id"]); db_execute("UPDATE graph_tree_items SET order_key = CONCAT('$old_root',SUBSTRING(order_key," . (($current_depth * CHARS_PER_TIER) + 1) . ")) WHERE order_key LIKE '" . str_pad('', ($current_depth * CHARS_PER_TIER), 'Z') . "%' AND graph_tree_id = " . $graph_tree_item["graph_tree_id"]); } }
function api_data_template_suggested_values_list($data_template_id, $field_name = "") { /* sanity checks */ validate_id_die($data_template_id, "data_template_id"); return db_fetch_assoc("select * from data_template_suggested_value where data_template_id = " . sql_sanitize($data_template_id) . ($field_name == "" ? "" : " and field_name = '" . sql_sanitize($field_name) . "'") . " order by field_name,sequence"); }
function api_package_metadata_remove($package_metadata_id) { /* sanity checks */ validate_id_die($package_metadata_id, "package_metadata_id"); return db_delete("package_metadata", array( "id" => array("type" => DB_TYPE_INTEGER, "value" => $package_metadata_id) )); }
function api_graph_get($graph_id) { /* sanity checks */ validate_id_die($graph_id, "graph_id"); $graph = db_fetch_row("select * from graph where id = " . sql_sanitize($graph_id)); if (sizeof($graph) == 0) { log_save("Invalid graph [ID#$graph] specified in api_graph_get()", SEV_ERROR); return false; }else{ return $graph; } }
function api_script_field_get($script_field_id) { /* sanity checks */ validate_id_die($script_field_id, "script_field_id"); return db_fetch_row("select * from data_input_fields where id = " . sql_sanitize($script_field_id)); }
function api_package_author_get($package_author_id) { /* sanity checks */ validate_id_die($package_author_id, "package_author_id"); return db_fetch_row("select * from package_author where id = " . sql_sanitize($package_author_id)); }
function api_script_field_remove($script_field_id) { /* sanity checks */ validate_id_die($script_field_id, "script_field_id"); /* base tables */ db_delete("data_input_fields", array( "id" => array("type" => DB_TYPE_INTEGER, "value" => $script_field_id) )); db_delete("data_input_data", array( "data_input_field_id" => array("type" => DB_TYPE_INTEGER, "value" => $script_field_id) )); }
function api_data_source_title_cache_update($data_source_id) { require_once(CACTI_BASE_PATH . "/lib/data_source/data_source_info.php"); /* sanity checks */ validate_id_die($data_source_id, "data_source_id"); db_execute("UPDATE data_source SET name_cache = '" . sql_sanitize(addslashes(api_data_source_title_get($data_source_id))) . "' WHERE id = " . sql_sanitize($data_source_id)); }
function api_rra_consolidation_function_list($rra_id) { /* sanity checks */ validate_id_die($rra_id, "rra_id"); return array_rekey(db_fetch_assoc("select * from rra_cf where rra_id = " . sql_sanitize($rra_id)), "", "consolidation_function_id"); }
function api_data_template_item_remove($data_template_item_id) { require_once(CACTI_BASE_PATH . "/lib/data_template/data_template_info.php"); /* sanity checks */ validate_id_die($data_template_item_id, "data_template_item_id"); /* retrieve information about this data template */ $data_template_item = api_data_template_item_get($data_template_item_id); $data_sources = db_fetch_assoc("select id from data_source where data_template_id = " . $data_template_item["data_template_id"]); /* delete all attached data source items */ if (is_array($data_sources) > 0) { foreach ($data_sources as $item) { db_delete("data_source_item", array( "data_source_id" => array("type" => DB_TYPE_INTEGER, "value" => $item["id"]), "data_source_name" => array("type" => DB_TYPE_STRING, "value" => $data_template_item["data_source_name"]) )); } } db_delete("data_template_item", array( "id" => array("type" => DB_TYPE_INTEGER, "value" => $data_template_item_id) )); }
function api_data_query_graphed_indexes_list($graph_template_id, $host_id) { require_once(CACTI_BASE_PATH . "/include/data_source/data_source_constants.php"); /* sanity checks */ validate_id_die($graph_template_id, "graph_template_id"); validate_id_die($host_id, "host_id"); return db_fetch_assoc("select distinct data_source_field.value as data_query_index from graph,graph_item,data_source_item,data_source,data_source_field where graph.id=graph_item.graph_id and graph_item.data_source_item_id=data_source_item.id and data_source_item.data_source_id=data_source.id and data_source.id=data_source_field.data_source_id and graph.graph_template_id = " . sql_sanitize($graph_template_id) . " and graph.host_id = " . sql_sanitize($host_id) . " and data_source.data_input_type = " . DATA_INPUT_TYPE_DATA_QUERY . " and data_source_field.name = 'data_query_index'"); }
function api_graph_host_update($graph_id, $host_id) { /* sanity checks */ validate_id_die($graph_id, "graph_id"); validate_id_die($host_id, "host_id", true); db_update("graph", array( "host_id" => array("type" => DB_TYPE_STRING, "value" => $host_id), "id" => array("type" => DB_TYPE_INTEGER, "value" => $graph_id) ), array("id")); /* make sure that host variables in the title stay up to date */ api_graph_title_cache_update($graph_id); }
function api_graph_template_item_remove($graph_template_item_id, $delete_attached = true) { /* sanity checks */ validate_id_die($graph_template_item_id, "graph_template_item_id"); /* base tables */ db_delete("graph_template_item", array( "id" => array("type" => DB_TYPE_INTEGER, "value" => $graph_template_item_id) )); db_delete("graph_template_item_input_item", array( "graph_template_item_id" => array("type" => DB_TYPE_INTEGER, "value" => $graph_template_item_id) )); /* attached graph items */ if ($delete_attached === true) { db_delete("graph_item", array( "graph_template_item_id" => array("type" => DB_TYPE_INTEGER, "value" => $graph_template_item_id) )); }else{ db_execute("UPDATE graph_item SET graph_template_item_id = 0 WHERE graph_template_item_id = " . sql_sanitize($graph_template_item_id)); } }
function api_graph_template_data_template_list($graph_template_id) { /* sanity checks */ validate_id_die($graph_template_id, "graph_template_id"); return db_fetch_assoc("select distinct data_template_item.data_template_id as id, data_template.template_name from graph_template_item,data_template_item,data_template where graph_template_item.data_template_item_id=data_template_item.id and data_template_item.data_template_id=data_template.id and graph_template_item.graph_template_id = " . sql_sanitize($graph_template_id) . " order by data_template.template_name"); }
function api_data_preset_cdef_get($preset_cdef_id) { /* sanity checks */ validate_id_die($preset_cdef_id, "preset_cdef_id"); return db_fetch_row("select * from preset_cdef where id = " . sql_sanitize($preset_cdef_id)); }
function api_device_graph_template_used_get($device_id, $graph_template_id) { /* sanity checks */ validate_id_die($device_id, "device_id"); validate_id_die($graph_template_id, "graph_template_id"); $graph_template_id = db_fetch_cell("select id from graph where graph_template_id = $graph_template_id and host_id = $device_id, limit 0,1"); return empty($graph_template_id) ? false : $graph_template_id; }
function api_data_preset_package_vendor_get($preset_id) { /* sanity checks */ validate_id_die($preset_id, "preset_id"); return db_fetch_cell("select name from preset_package_vendor where id = " . sql_sanitize($preset_id)); }
function api_device_gt_remove($device_id, $graph_template_id) { /* sanity checks */ validate_id_die($device_id, "device_id"); validate_id_die($graph_template_id, "graph_template_id"); db_execute("delete from host_graph where graph_template_id = " . sql_sanitize($graph_template_id) . " and host_id = " . sql_sanitize($device_id)); }
function api_graph_tree_item_get($graph_tree_item_id) { /* sanity checks */ validate_id_die($graph_tree_item_id, "graph_tree_item_id"); return db_fetch_row("select * from graph_tree_items where id = " . sql_sanitize($graph_tree_item_id)); }
function api_data_source_item_list($data_source_id) { /* sanity checks */ validate_id_die($data_source_id, "data_source_id"); return db_fetch_assoc("select data_source_item.rrd_heartbeat, data_source_item.rrd_minimum, data_source_item.rrd_maximum, data_source_item.data_source_name, data_source_item.data_source_type from data_source_item where data_source_item.data_source_id = " . sql_sanitize($data_source_id)); }
function api_data_preset_rra_item_remove($data_preset_rra_item_id) { /* sanity checks */ validate_id_die($data_preset_rra_item_id, "data_preset_rra_item_id"); api_data_preset_rra_fingerprint_update($data_preset_rra_item_id, true); return db_delete("preset_rra_item", array( "id" => array("type" => DB_TYPE_INTEGER, "value" => $data_preset_rra_item_id) )); }
function api_data_query_remove($data_query_id) { /* sanity checks */ validate_id_die($data_query_id, "data_query_id"); db_execute("delete from data_query_field where data_query_id = " . sql_sanitize($data_query_id)); db_execute("delete from data_query where id = " . sql_sanitize($data_query_id)); db_execute("delete from host_data_query where data_query_id = " . sql_sanitize($data_query_id)); db_execute("delete from host_template_data_query where data_query_id = " . sql_sanitize($data_query_id)); db_execute("delete from host_data_query_cache where data_query_id = " . sql_sanitize($data_query_id)); }