function api_device_remove($device_id, $remove_dependencies = false) { require_once(CACTI_BASE_PATH . "/lib/data_source/data_source_info.php"); require_once(CACTI_BASE_PATH . "/lib/data_source/data_source_update.php"); require_once(CACTI_BASE_PATH . "/lib/graph/graph_update.php"); /* sanity checks */ validate_id_die($device_id, "device_id"); db_execute("delete from host where id = " . sql_sanitize($device_id)); db_execute("delete from host_graph where host_id = " . sql_sanitize($device_id)); db_execute("delete from host_data_query where host_id = " . sql_sanitize($device_id)); db_execute("delete from host_data_query_cache where host_id = " . sql_sanitize($device_id)); db_execute("delete from poller_item where host_id = " . sql_sanitize($device_id)); db_execute("delete from graph_tree_items where host_id = " . sql_sanitize($device_id)); if ($remove_dependencies == true) { /* obtain a list of all data sources associated with this device */ $data_sources = api_data_source_list(array("host_id" => $device_id)); /* delete each data source associated with this device */ if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { api_data_source_remove($data_source["id"]); } } /* obtain a list of all graphs associated with this device */ $graphs = api_graph_list(array("host_id" => $device_id)); /* delete each graph associated with this device */ if (sizeof($graphs) > 0) { foreach ($graphs as $graph) { api_graph_remove($graph["id"]); } } }else{ /* obtain a list of all data sources associated with this device */ $data_sources = api_data_source_list(array("host_id" => $device_id)); /* disable each data source associated with this device */ if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { api_data_source_disable($data_source["id"]); } } } }
function graph() { $current_page = get_get_var_number("page", "1"); $menu_items = array("remove" => "Remove", "duplicate" => "Duplicate", "change_graph_template" => "Change Graph Template", "change_host" => "Change Host", "convert_graph_template" => "Convert to Graph Template", "place_tree" => "Place on Tree"); $filter_array = array(); /* search field: device template */ if (isset_get_var("search_device")) { $filter_array["host_id"] = get_get_var("search_device"); } /* search field: filter (searches data source name) */ if (isset_get_var("search_filter")) { $filter_array["filter"] = array("title_cache|title" => get_get_var("search_filter")); } /* get a list of all graphs on this page */ $graphs = api_graph_list($filter_array, $current_page, read_config_option("num_rows_data_source")); /* get the total number of graphs on all pages */ $total_rows = api_graph_total_get($filter_array); /* generate page list */ $url_string = build_get_url_string(array("search_device", "search_filter")); $url_page_select = get_page_list($current_page, MAX_DISPLAY_PAGES, read_config_option("num_rows_graph"), $total_rows, "graphs.php" . $url_string . ($url_string == "" ? "?" : "&") . "page=|PAGE_NUM|"); form_start("graphs.php"); $box_id = "1"; html_start_box("<strong>" . _("Graphs") . "</strong>", "graphs.php?action=edit", $url_page_select); html_header_checkbox(array(_("Graph Title"), _("Template Name"), _("Size")), $box_id); $i = 0; if (sizeof($graphs) > 0) { foreach ($graphs as $graph) { ?> <tr class="item" id="box-<?php echo $box_id; ?> -row-<?php echo $graph["id"]; ?> " onClick="display_row_select('<?php echo $box_id; ?> ',document.forms[0],'box-<?php echo $box_id; ?> -row-<?php echo $graph["id"]; ?> ', 'box-<?php echo $box_id; ?> -chk-<?php echo $graph["id"]; ?> ')" onMouseOver="display_row_hover('box-<?php echo $box_id; ?> -row-<?php echo $graph["id"]; ?> ')" onMouseOut="display_row_clear('box-<?php echo $box_id; ?> -row-<?php echo $graph["id"]; ?> ')"> <td class="title"> <a onClick="display_row_block('box-<?php echo $box_id; ?> -row-<?php echo $graph["id"]; ?> ')" href="graphs.php?action=edit&id=<?php echo $graph["id"]; ?> "><span id="box-<?php echo $box_id; ?> -text-<?php echo $graph["id"]; ?> "><?php echo html_highlight_words(get_get_var("search_filter"), $graph["title_cache"]); ?> </span></a> </td> <td> <?php echo empty($graph["template_name"]) ? "<em>" . _("None") . "</em>" : $graph["template_name"]; ?> </td> <td> <?php echo $graph["height"]; ?> x<?php echo $graph["width"]; ?> </td> <td class="checkbox" align="center"> <input type='checkbox' name='box-<?php echo $box_id; ?> -chk-<?php echo $graph["id"]; ?> ' id='box-<?php echo $box_id; ?> -chk-<?php echo $graph["id"]; ?> ' title="<?php echo $graph["title_cache"]; ?> "> </td> </tr> <?php } } else { ?> <tr class="empty"> <td colspan="6"> No graphs found. </td> </tr> <?php } html_box_toolbar_draw($box_id, "0", "3", sizeof($filter_array) == 0 ? HTML_BOX_SEARCH_INACTIVE : HTML_BOX_SEARCH_ACTIVE, $url_page_select); html_end_box(false); html_box_actions_menu_draw($box_id, "0", $menu_items); html_box_actions_area_create($box_id); form_hidden_box("action_post", "graph_list"); form_end(); /* pre-cache the device list since we need it in more than one place below */ $device_list = array_rekey(api_device_list(), "id", "description"); /* fill in the list of available devices for the search dropdown */ $search_devices = array(); $search_devices["-1"] = "Any"; $search_devices["0"] = "None"; $search_devices += $device_list; /* fill in the list of available devices for the change host dropdown */ $change_host_list = array(); $change_host_list["0"] = "None"; $change_host_list += $device_list; ?> <script language="JavaScript"> <!-- function action_area_handle_type(box_id, type, parent_div, parent_form) { if (type == 'remove') { parent_div.appendChild(document.createTextNode('Are you sure you want to remove these graphs?')); parent_div.appendChild(action_area_generate_selected_rows(box_id)); action_area_update_header_caption(box_id, 'Remove Graph'); action_area_update_submit_caption(box_id, 'Remove'); action_area_update_selected_rows(box_id, parent_form); }else if (type == 'duplicate') { parent_div.appendChild(document.createTextNode('Are you sure you want to duplicate these graphs?')); parent_div.appendChild(action_area_generate_selected_rows(box_id)); parent_div.appendChild(action_area_generate_input('text', 'box-' + box_id + '-action-area-txt1', '')); action_area_update_header_caption(box_id, 'Duplicate Graph'); action_area_update_submit_caption(box_id, 'Duplicate'); action_area_update_selected_rows(box_id, parent_form); }else if (type == 'search') { _elm_dt_input = action_area_generate_select('box-' + box_id + '-search_device'); <?php echo get_js_dropdown_code('_elm_dt_input', $search_devices, isset_get_var("search_device") ? get_get_var("search_device") : "-1"); ?> _elm_ht_input = action_area_generate_input('text', 'box-' + box_id + '-search_filter', '<?php echo get_get_var("search_filter"); ?> '); _elm_ht_input.size = '30'; parent_div.appendChild(action_area_generate_search_field(_elm_dt_input, 'Device', true, false)); parent_div.appendChild(action_area_generate_search_field(_elm_ht_input, 'Filter', false, true)); action_area_update_header_caption(box_id, 'Search'); action_area_update_submit_caption(box_id, 'Search'); }else if (type == 'change_host') { parent_div.appendChild(document.createTextNode('Are you sure you want to change the host for these graphs?')); parent_div.appendChild(action_area_generate_selected_rows(box_id)); _elm_dt_input = action_area_generate_select('box-' + box_id + '-change_device'); <?php echo get_js_dropdown_code('_elm_dt_input', $change_host_list, "0"); ?> parent_div.appendChild(action_area_generate_search_field(_elm_dt_input, 'New Device', true, true)); action_area_update_header_caption(box_id, 'Change Host'); action_area_update_submit_caption(box_id, 'Change'); action_area_update_selected_rows(box_id, parent_form); } } --> </script> <?php }
function _graph_tree_item_field__graph($field_name, $field_value = "", $field_id = 0) { require_once(CACTI_BASE_PATH . "/lib/sys/html_form.php"); require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php"); ?> <tr class="<?php echo field_get_row_style();?>" id="row_field_graph_<?php echo $field_id;?>"> <td width="50%" class="field-row"> <span class="textEditTitle"><?php echo _("Graph");?></span><br> <?php echo _("Choose a graph from this list to add it to the tree.");?> </td> <td class="field-row" colspan="2"> <?php form_dropdown($field_name, api_graph_list(), "title_cache", "id", $field_value, "", 1);?> </td> </tr> <?php }