'Delete', 2 => 'Change Graph Template', 5 => 'Change Device', 6 => 'Reapply Suggested Names', 7 => 'Resize Graphs', 3 => 'Duplicate', 4 => 'Convert to Graph Template', 'aggregate' => 'Create Aggregate Graph', 'aggregate_template' => 'Create Aggregate from Template', 8 => 'Apply Automation Rules' ); $graph_actions = api_plugin_hook_function('graphs_action_array', $graph_actions); /* set default action */ set_default_action(); switch (get_request_var('action')) { case 'save': form_save(); break; case 'actions': form_actions(); break; case 'graph_diff': top_header(); graph_diff(); bottom_footer(); break; case 'item': top_header(); item(); bottom_footer(); break; case 'graph_remove': graph_remove(); header('Location: graphs.php?header=false'); break; case 'ajax_hosts': get_allowed_ajax_hosts(); break; case 'ajax_hosts_noany': get_allowed_ajax_hosts(false); break; case 'lock': case 'unlock': $_SESSION['sess_graph_lock_id'] = get_filter_request_var('id'); $_SESSION['sess_graph_locked'] = (get_request_var('action') == 'lock' ? true:false); case 'graph_edit': top_header(); graph_edit(); bottom_footer(); break; default: top_header(); graph_management(); bottom_footer(); break; } /* -------------------------- Global Form Functions -------------------------- */ function add_tree_names_to_actions_array() { global $graph_actions; /* add a list of tree names to the actions dropdown */ $trees = db_fetch_assoc('SELECT id, name FROM graph_tree ORDER BY name'); if (sizeof($trees) > 0) { foreach ($trees as $tree) { $graph_actions{'tr_' . $tree['id']} = 'Place on a Tree (' . $tree['name'] . ')'; } } } /* -------------------------- The Save Function -------------------------- */ function form_save() { /* ================= input validation ================= */ get_filter_request_var('graph_template_id'); get_filter_request_var('_graph_template_id'); get_filter_request_var('local_graph_id'); get_filter_request_var('host_id'); get_filter_request_var('graph_template_graph_id'); /* ==================================================== */ if ((isset_request_var('save_component_graph_new')) && (!isempty_request_var('graph_template_id'))) { /* ================= input validation ================= */ get_filter_request_var('graph_template_id'); get_filter_request_var('local_graph_id'); get_filter_request_var('host_id'); /* ==================================================== */ $save['id'] = get_nfilter_request_var('local_graph_id'); $save['graph_template_id'] = get_nfilter_request_var('graph_template_id'); $save['host_id'] = get_nfilter_request_var('host_id'); $local_graph_id = sql_save($save, 'graph_local'); change_graph_template($local_graph_id, get_nfilter_request_var('graph_template_id'), true); /* update the title cache */ update_graph_title_cache($local_graph_id); } if (isset_request_var('save_component_graph')) { /* ================= input validation ================= */ get_filter_request_var('graph_template_id'); get_filter_request_var('_graph_template_id'); get_filter_request_var('local_graph_id'); get_filter_request_var('host_id'); get_filter_request_var('graph_template_graph_id'); get_filter_request_var('local_graph_template_graph_id'); /* ==================================================== */ $save1['id'] = get_nfilter_request_var('local_graph_id'); $save1['host_id'] = get_nfilter_request_var('host_id'); $save1['graph_template_id'] = get_nfilter_request_var('graph_template_id'); $save2['id'] = get_nfilter_request_var('graph_template_graph_id'); $save2['local_graph_template_graph_id'] = get_nfilter_request_var('local_graph_template_graph_id'); $save2['graph_template_id'] = get_nfilter_request_var('graph_template_id'); $save2['image_format_id'] = form_input_validate(get_nfilter_request_var('image_format_id'), 'image_format_id', '^[0-9]+$', true, 3); $save2['title'] = form_input_validate(get_nfilter_request_var('title'), 'title', '', false, 3); $save2['height'] = form_input_validate(get_nfilter_request_var('height'), 'height', '^[0-9]+$', false, 3); $save2['width'] = form_input_validate(get_nfilter_request_var('width'), 'width', '^[0-9]+$', false, 3); $save2['upper_limit'] = form_input_validate(get_nfilter_request_var('upper_limit'), 'upper_limit', "^(-?([0-9]+(\.[0-9]*)?|[0-9]*\.[0-9]+)([eE][+\-]?[0-9]+)?)|U$", ((strlen(get_nfilter_request_var('upper_limit')) === 0) ? true : false), 3); $save2['lower_limit'] = form_input_validate(get_nfilter_request_var('lower_limit'), 'lower_limit', "^(-?([0-9]+(\.[0-9]*)?|[0-9]*\.[0-9]+)([eE][+\-]?[0-9]+)?)|U$", ((strlen(get_nfilter_request_var('lower_limit')) === 0) ? true : false), 3); $save2['vertical_label'] = form_input_validate(get_nfilter_request_var('vertical_label'), 'vertical_label', '', true, 3); $save2['slope_mode'] = form_input_validate((isset_request_var('slope_mode') ? get_nfilter_request_var('slope_mode') : ''), 'slope_mode', '', true, 3); $save2['auto_scale'] = form_input_validate((isset_request_var('auto_scale') ? get_nfilter_request_var('auto_scale') : ''), 'auto_scale', '', true, 3); $save2['auto_scale_opts'] = form_input_validate(get_nfilter_request_var('auto_scale_opts'), 'auto_scale_opts', '', true, 3); $save2['auto_scale_log'] = form_input_validate((isset_request_var('auto_scale_log') ? get_nfilter_request_var('auto_scale_log') : ''), 'auto_scale_log', '', true, 3); $save2['scale_log_units'] = form_input_validate((isset_request_var('scale_log_units') ? get_nfilter_request_var('scale_log_units') : ''), 'scale_log_units', '', true, 3); $save2['auto_scale_rigid'] = form_input_validate((isset_request_var('auto_scale_rigid') ? get_nfilter_request_var('auto_scale_rigid') : ''), 'auto_scale_rigid', '', true, 3); $save2['auto_padding'] = form_input_validate((isset_request_var('auto_padding') ? get_nfilter_request_var('auto_padding') : ''), 'auto_padding', '', true, 3); $save2['base_value'] = form_input_validate(get_nfilter_request_var('base_value'), 'base_value', '^[0-9]+$', false, 3); $save2['export'] = form_input_validate((isset_request_var('export') ? get_nfilter_request_var('export') : ''), 'export', '', true, 3); $save2['unit_value'] = form_input_validate(get_nfilter_request_var('unit_value'), 'unit_value', '', true, 3); $save2['unit_exponent_value'] = form_input_validate(get_nfilter_request_var('unit_exponent_value'), 'unit_exponent_value', '^-?[0-9]+$', true, 3); if (!is_error_message()) { $local_graph_id = sql_save($save1, 'graph_local'); } if (!is_error_message()) { $save2['local_graph_id'] = $local_graph_id; $graph_templates_graph_id = sql_save($save2, 'graph_templates_graph'); if ($graph_templates_graph_id) { raise_message(1); /* if template information changed, update all necessary template information */ if (get_nfilter_request_var('graph_template_id') != get_nfilter_request_var('_graph_template_id')) { /* check to see if the number of graph items differs, if it does; we need user input */ if ((!isempty_request_var('graph_template_id')) && (!isempty_request_var('local_graph_id')) && (sizeof(db_fetch_assoc_prepared('SELECT id FROM graph_templates_item WHERE local_graph_id = ?', array($local_graph_id))) != sizeof(db_fetch_assoc_prepared('SELECT id from graph_templates_item WHERE local_graph_id = 0 AND graph_template_id = ?', array(get_nfilter_request_var('graph_template_id')))))) { /* set the template back, since the user may choose not to go through with the change at this point */ db_execute_prepared('UPDATE graph_local SET graph_template_id = ? WHERE id = ?', array(get_nfilter_request_var('_graph_template_id'), $local_graph_id)); db_execute_prepared('UPDATE graph_templates_graph SET graph_template_id = ? WHERE local_graph_id = ?', array(get_nfilter_request_var('_graph_template_id'), $local_graph_id)); header("Location: graphs.php?action=graph_diff&header=false&id=$local_graph_id&graph_template_id=" . get_nfilter_request_var('graph_template_id')); exit; } } }else{ raise_message(2); } /* update the title cache */ update_graph_title_cache($local_graph_id); } if ((!is_error_message()) && (get_nfilter_request_var('graph_template_id') != get_nfilter_request_var('_graph_template_id'))) { change_graph_template($local_graph_id, get_nfilter_request_var('graph_template_id'), true); }elseif (!isempty_request_var('graph_template_id')) { update_graph_data_query_cache($local_graph_id); } } if (isset_request_var('save_component_input')) { /* ================= input validation ================= */ get_filter_request_var('local_graph_id'); /* ==================================================== */ /* first; get the current graph template id */ $graph_template_id = db_fetch_cell_prepared('SELECT graph_template_id FROM graph_local WHERE id = ?', array(get_nfilter_request_var('local_graph_id'))); /* get all inputs that go along with this graph template, if templated */ if ($graph_template_id > 0) { $input_list = db_fetch_assoc_prepared('SELECT id, column_name FROM graph_template_input WHERE graph_template_id = ?', array($graph_template_id)); if (sizeof($input_list) > 0) { foreach ($input_list as $input) { /* we need to find out which graph items will be affected by saving this particular item */ $item_list = db_fetch_assoc_prepared('SELECT graph_templates_item.id FROM (graph_template_input_defs, graph_templates_item) WHERE graph_template_input_defs.graph_template_item_id = graph_templates_item.local_graph_template_item_id AND graph_templates_item.local_graph_id = ? AND graph_template_input_defs.graph_template_input_id = ?', array(get_nfilter_request_var('local_graph_id'), $input['id'])); /* loop through each item affected and update column data */ if (sizeof($item_list) > 0) { foreach ($item_list as $item) { /* if we are changing templates, the POST vars we are searching for here will not exist. this is because the db and form are out of sync here, but it is ok to just skip over saving the inputs in this case. */ if (isset_request_var($input['column_name'] . '_' . $input['id'])) { db_execute_prepared('UPDATE graph_templates_item SET ' . $input['column_name'] . ' = ? WHERE id = ?', array(get_nfilter_request_var($input['column_name'] . '_' . $input['id']), $item['id'])); } } } } } } } if (isset_request_var('save_component_graph_diff')) { if (get_nfilter_request_var('type') == '1') { $intrusive = true; }elseif (get_nfilter_request_var('type') == '2') { $intrusive = false; } change_graph_template(get_nfilter_request_var('local_graph_id'), get_nfilter_request_var('graph_template_id'), $intrusive); } if ((isset_request_var('save_component_graph_new')) && (isempty_request_var('graph_template_id'))) { header('Location: graphs.php?action=graph_edit&header=false&host_id=' . get_nfilter_request_var('host_id') . '&new=1'); }elseif ((is_error_message()) || (isempty_request_var('local_graph_id')) || (isset_request_var('save_component_graph_diff')) || (get_nfilter_request_var('graph_template_id') != get_nfilter_request_var('_graph_template_id')) || (get_nfilter_request_var('host_id') != get_nfilter_request_var('_host_id'))) { header('Location: graphs.php?action=graph_edit&header=false&id=' . (empty($local_graph_id) ? get_nfilter_request_var('local_graph_id') : $local_graph_id) . (isset_request_var('host_id') ? '&host_id=' . get_nfilter_request_var('host_id') : '')); }else{ header('Location: graphs.php?header=false'); } } /* ------------------------ The "actions" function ------------------------ */ function form_actions() { global $graph_actions; /* ================= input validation ================= */ get_filter_request_var('drp_action', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-zA-Z0-9_]+)$/'))); /* ==================================================== */ /* if we are to save this form, instead of display it */ if (isset_request_var('selected_items')) { $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items')); if ($selected_items != false) { if (get_nfilter_request_var('drp_action') == '1') { /* delete */ if (!isset_request_var('delete_type')) { set_request_var('delete_type', 1); } switch (get_nfilter_request_var('delete_type')) { case '2': /* delete all data sources referenced by this graph */ $data_sources = array_rekey(db_fetch_assoc('SELECT data_template_data.local_data_id FROM (data_template_rrd, data_template_data, graph_templates_item) WHERE graph_templates_item.task_item_id=data_template_rrd.id AND data_template_rrd.local_data_id=data_template_data.local_data_id AND ' . array_to_sql_or($selected_items, 'graph_templates_item.local_graph_id') . ' AND data_template_data.local_data_id > 0'), 'local_data_id', 'local_data_id'); if (sizeof($data_sources)) { api_data_source_remove_multi($data_sources); api_plugin_hook_function('data_source_remove', $data_sources); } break; } api_graph_remove_multi($selected_items); api_plugin_hook_function('graphs_remove', $selected_items); }elseif (get_nfilter_request_var('drp_action') == '2') { /* change graph template */ get_filter_request_var('graph_template_id'); for ($i=0;($i graph template */ for ($i=0;($i $data) { $item_new = array(); $item_new['aggregate_graph_id'] = $aggregate_graph_id; $item_new['graph_templates_item_id'] = $item_id; $item_new['color_template'] = isset($data['color_template']) ? $data['color_template']:-1; $item_new['item_skip'] = isset($data['item_skip']) ? 'on':''; $item_new['item_total'] = isset($data['item_total']) ? 'on':''; $item_new['sequence'] = isset($data['sequence']) ? $data['sequence']:-1; $aggregate_graph_items[] = $item_new; } aggregate_graph_items_save($aggregate_graph_items, 'aggregate_graphs_graph_item'); } else { $aggregate_graph_items = db_fetch_assoc('SELECT * FROM aggregate_graph_templates_item WHERE aggregate_template_id=' . $ag_data['aggregate_template_id']); } $attribs = $ag_data; $attribs['graph_title'] = $ag_data['title_format']; $attribs['reorder'] = $ag_data['order_type']; $attribs['item_no'] = $item_no; $attribs['color_templates'] = array(); $attribs['skipped_items'] = array(); $attribs['total_items'] = array(); $attribs['graph_item_types']= array(); $attribs['cdefs'] = array(); foreach ($aggregate_graph_items as $item) { if (isset($item['color_template']) && $item['color_template'] > 0) $attribs['color_templates'][ $item['sequence'] ] = $item['color_template']; if (isset($item['item_skip']) && $item['item_skip'] == 'on') $attribs['skipped_items'][ $item['sequence'] ] = $item['sequence']; if (isset($item['item_total']) && $item['item_total'] == 'on') $attribs['total_items'][ $item['sequence'] ] = $item['sequence']; if (isset($item['cdef_id']) && isset($item['t_cdef_id']) && $item['t_cdef_id'] == 'on') $attribs['cdefs'][ $item['sequence'] ] = $item['cdef_id']; if (isset($item['graph_type_id']) && isset($item['t_graph_type_id']) && $item['t_graph_type_id'] == 'on') $attribs['graph_item_types'][ $item['sequence'] ] = $item['graph_type_id']; } /* create actual graph items */ aggregate_create_update($local_graph_id, $member_graphs, $attribs); header("Location: aggregate_graphs.php?header=false&action=edit&tab=details&id=$local_graph_id"); exit; }elseif ($action == 8) { /* automation */ cacti_log('automation_graph_action_execute called: ' . $action, true, 'AUTM8 TRACE', POLLER_VERBOSITY_MEDIUM); /* work on all selected graphs */ for ($i=0;($i'; $graph_array[$i] = $matches[1]; $i++; } } top_header(); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); form_start('graphs.php'); html_start_box($graph_actions{get_nfilter_request_var('drp_action')}, '60%', '', '3', 'center', ''); if (isset($graph_array) && sizeof($graph_array)) { if (get_nfilter_request_var('drp_action') == '1') { /* delete */ /* find out which (if any) data sources are being used by this graph, so we can tell the user */ if (isset($graph_array) && sizeof($graph_array)) { $data_sources = db_fetch_assoc('select data_template_data.local_data_id, data_template_data.name_cache from (data_template_rrd,data_template_data,graph_templates_item) where graph_templates_item.task_item_id=data_template_rrd.id and data_template_rrd.local_data_id=data_template_data.local_data_id and ' . array_to_sql_or($graph_array, 'graph_templates_item.local_graph_id') . ' and data_template_data.local_data_id > 0 group by data_template_data.local_data_id order by data_template_data.name_cache'); } print "

Click 'Continue' to delete the following Graph(s).

    $graph_list

"; if (isset($data_sources) && sizeof($data_sources)) { print "

The following Data Source(s) are in use by these Graph(s):

\n"; print '

    '; foreach ($data_sources as $data_source) { print '
  • ' . $data_source['name_cache'] . "
  • \n"; } print '

'; print ''; form_radio_button('delete_type', '2', '2', 'Delete all Data Source(s) referenced by these Graph(s).', '2'); print '
'; form_radio_button('delete_type', '1', '2', "Leave the Data Source(s) untouched.", '2'); print '
'; print '
'; print ''; } print "\n"; $save_html = " "; }elseif (get_nfilter_request_var('drp_action') == '2') { /* change graph template */ print "

Choose a Graph Template and click \"Continue\" to change the Graph Template for the following Graph(s). Be aware that all warnings will be suppressed during the conversion, so Graph data loss is possible.

    $graph_list

New Graph Template
"; form_dropdown('graph_template_id',db_fetch_assoc('SELECT graph_templates.id,graph_templates.name FROM graph_templates ORDER BY name'),'name','id','','','0'); print "

\n"; $save_html = " "; }elseif (get_nfilter_request_var('drp_action') == '3') { /* duplicate */ print "

Click 'Continue' to duplicate the following Graph(s). You can optionally change the title format for the new Graph(s).

    $graph_list

Title Format
"; form_text_box('title_format', ' (1)', '', '255', '30', 'text'); print "

\n"; $save_html = " "; }elseif (get_nfilter_request_var('drp_action') == '4') { /* graph -> graph template */ print "

Click 'Continue' to convert the following Graph(s) into Graph Template(s). You can optionally change the title format for the new Graph Template(s).

    $graph_list

Title Format
"; form_text_box('title_format', ' Template', '', '255', '30', 'text'); print "

\n"; $save_html = " "; }elseif (preg_match('/^tr_([0-9]+)$/', get_nfilter_request_var('drp_action'), $matches)) { /* place on tree */ print "

Click 'Continue' to place the following Graph(s) under the Tree Branch selected below.

    $graph_list

Destination Branch
"; grow_dropdown_tree($matches[1], '0', 'tree_item_id', '0'); print "

\n"; $save_html = " "; }elseif (get_nfilter_request_var('drp_action') == '5') { /* change host */ print "

Choose a new Device for these Graph(s) and click \"Continue\"

    $graph_list

New Device
"; form_dropdown('host_id',db_fetch_assoc("SELECT id,CONCAT_WS('',description,' (',hostname,')') as name FROM host ORDER BY description,hostname"),'name','id','','','0'); print "

\n"; $save_html = " "; }elseif (get_nfilter_request_var('drp_action') == '6') { /* reapply suggested naming to host */ print "

Click 'Continue' to re-apply suggested naming to the following Graph(s).

    $graph_list

\n"; $save_html = " "; }elseif (get_nfilter_request_var('drp_action') == '7') { /* resize graphs */ print "

Click 'Continue' to resize the following Graph(s).

    $graph_list

Graph Height
"; form_text_box('graph_height', '', '', '255', '30', 'text'); print '

Graph Width
'; form_text_box('graph_width', '', '', '255', '30', 'text'); print "

\n"; $save_html = " "; } elseif (get_nfilter_request_var('drp_action') == 'aggregate') { include_once('./lib/api_aggregate.php'); /* initialize return code and graphs array */ $return_code = false; $data_sources = array(); $graph_template = ''; if (aggregate_get_data_sources($_POST, $data_sources, $graph_template)) { # provide a new prefix for GPRINT lines $gprint_prefix = '|host_hostname|'; /* list affected graphs */ print ''; print "

Click 'Continue' to create an Aggregate Graph from the selected Graph(s)

    " . get_nfilter_request_var('graph_list') . "

\n"; /* list affected data sources */ if (sizeof($data_sources) > 0) { print "" . '

The following data sources are in use by these graphs:

    '; foreach ($data_sources as $data_source) { print '
  • ' . $data_source['name_cache'] . "
  • \n"; } print "
\n"; } print "\n"; $ttitle = get_nfilter_request_var('graph_array'); $ttitle = $ttitle[0]; /* aggregate form */ $_aggregate_defaults = array( 'title_format' => auto_title($ttitle), 'graph_template_id' => $graph_template, 'gprint_prefix' => $gprint_prefix ); draw_edit_form(array( 'config' => array('no_form_tag' => true), 'fields' => inject_form_variables($struct_aggregate, $_aggregate_defaults) )); # draw all graph items of first graph, including a html_start_box draw_aggregate_graph_items_list(0, $graph_template); # again, a new html_start_box. Using the one from above would yield ugly formatted NO and YES buttons html_start_box('Please confirm', '100%', '', '3', 'center', ''); ?>  "; }else{ $save_html = ""; } }elseif (get_nfilter_request_var('drp_action') == 'aggregate_template') { /* aggregate template */ include_once('./lib/api_aggregate.php'); /* initialize return code and graphs array */ $data_sources = array(); $graph_template = ''; /* find out which (if any) data sources are being used by this graph, so we can tell the user */ if (aggregate_get_data_sources($graph_array, $data_sources, $graph_template)) { $aggregate_templates = db_fetch_assoc("SELECT id, name FROM aggregate_graph_templates WHERE graph_template_id=$graph_template ORDER BY name"); if (sizeof($aggregate_templates)) { /* list affected graphs */ print "

Select the Aggregate Template to use and press 'Continue' to create your Aggregate Graph. Otherwise press 'Cancel' to return.

    " . $graph_list . "

\n"; print "
Graph Title
Aggregate Template
\n"; $save_html = " "; }else{ print "

There are presently no Aggregate Templates defined for this Graph Template. Please either first create an Aggregate Template for the selected Graph's Graph Template and try again, or simply crease an un-templated Aggregate Graph.

Press 'Return' to return and select different Graphs

\n"; $save_html = ""; } }else{ $save_html = ""; } }elseif (get_nfilter_request_var('drp_action') == 8) { /* automation */ print "

Click 'Continue' to apply Automation Rules to the following Graphs.

    $graph_list

\n"; $save_html = " "; } else { $save['drp_action'] = get_nfilter_request_var('drp_action'); $save['graph_list'] = $graph_list; $save['graph_array'] = (isset($graph_array) ? $graph_array : array()); api_plugin_hook_function('graphs_action_prepare', $save); $save_html = " "; } }else{ print "You must select at least one Graph.\n"; $save_html = ""; } print " $save_html \n"; html_end_box(); form_end(); bottom_footer(); } /* ----------------------- item - Graph Items ----------------------- */ function item() { global $consolidation_functions, $graph_item_types, $struct_graph_item; /* ================= input validation ================= */ get_filter_request_var('id'); /* ==================================================== */ if (isempty_request_var('id')) { $template_item_list = array(); $header_label = '[new]'; }else{ $template_item_list = db_fetch_assoc_prepared('SELECT graph_templates_item.id, graph_templates_item.text_format, graph_templates_item.value, graph_templates_item.hard_return, graph_templates_item.graph_type_id, graph_templates_item.consolidation_function_id, data_template_rrd.data_source_name, cdef.name AS cdef_name, colors.hex FROM graph_templates_item LEFT JOIN data_template_rrd ON (graph_templates_item.task_item_id = data_template_rrd.id) LEFT JOIN data_local ON (data_template_rrd.local_data_id = data_local.id) LEFT JOIN data_template_data ON (data_local.id = data_template_data.local_data_id) LEFT JOIN cdef ON (cdef_id = cdef.id) LEFT JOIN colors ON (color_id = colors.id) WHERE graph_templates_item.local_graph_id = ? ORDER BY graph_templates_item.sequence', array(get_request_var('id'))); $host_id = db_fetch_cell_prepared('SELECT host_id FROM graph_local WHERE id = ?', array(get_request_var('id'))); $header_label = '[edit: ' . htmlspecialchars(get_graph_title(get_request_var('id'))) . ']'; } $graph_template_id = db_fetch_cell_prepared('SELECT graph_template_id FROM graph_local WHERE id = ?', array(get_request_var('id'))); if (empty($graph_template_id)) { $add_text = 'graphs_items.php?action=item_edit&local_graph_id=' . get_request_var('id') . "&host_id=$host_id"; }else{ $add_text = ''; } html_start_box("Graph Items $header_label", '100%', '', '3', 'center', $add_text); draw_graph_items_list($template_item_list, 'graphs_items.php', 'local_graph_id=' . get_request_var('id'), (empty($graph_template_id) ? false : true)); html_end_box(); } /* ------------------------------------ graph - Graphs ------------------------------------ */ function graph_diff() { global $struct_graph_item, $graph_item_types, $consolidation_functions; /* ================= input validation ================= */ get_filter_request_var('id'); get_filter_request_var('graph_template_id'); /* ==================================================== */ $template_query = "SELECT graph_templates_item.id, graph_templates_item.text_format, graph_templates_item.value, graph_templates_item.hard_return, graph_templates_item.consolidation_function_id, graph_templates_item.graph_type_id, CONCAT_WS(' - ', data_template_data.name, data_template_rrd.data_source_name) AS task_item_id, cdef.name AS cdef_id, colors.hex AS color_id FROM graph_templates_item LEFT JOIN data_template_rrd ON (graph_templates_item.task_item_id = data_template_rrd.id) LEFT JOIN data_local ON (data_template_rrd.local_data_id = data_local.id) LEFT JOIN data_template_data ON (data_local.id = data_template_data.local_data_id) LEFT JOIN cdef ON (cdef_id = cdef.id) LEFT JOIN colors ON (color_id = colors.id)"; /* first, get information about the graph template as that's what we're going to model this graph after */ $graph_template_items = db_fetch_assoc_prepared(" $template_query WHERE graph_templates_item.graph_template_id = ? AND graph_templates_item.local_graph_id = 0 ORDER BY graph_templates_item.sequence", array(get_request_var('graph_template_id'))); /* next, get information about the current graph so we can make the appropriate comparisons */ $graph_items = db_fetch_assoc_prepared(" $template_query WHERE graph_templates_item.local_graph_id = ? ORDER BY graph_templates_item.sequence", array(get_request_var('id'))); $graph_template_inputs = db_fetch_assoc_prepared('SELECT graph_template_input.column_name, graph_template_input_defs.graph_template_item_id FROM (graph_template_input, graph_template_input_defs) WHERE graph_template_input.id = graph_template_input_defs.graph_template_input_id AND graph_template_input.graph_template_id = ?', array(get_request_var('graph_template_id'))); /* ok, we want to loop through the array with the GREATEST number of items so we don't have to worry about tacking items on the end */ if (sizeof($graph_template_items) > sizeof($graph_items)) { $items = $graph_template_items; }else{ $items = $graph_items; } ?>
The template you have selected requires some changes to be made to the structure of your graph. Below is a preview of your graph along with changes that need to be completed as shown in the left-hand column.

'', 'add' => '+', 'delete' => '-'); $group_counter = 0; $i = 0; $mode = 'normal'; $_graph_type_name = ''; if (sizeof($items) > 0) { foreach ($items as $item) { reset($struct_graph_item); /* graph grouping display logic */ $bold_this_row = false; $use_custom_row_color = false; $action_css = ''; unset($graph_preview_item_values); if ((sizeof($graph_template_items) > sizeof($graph_items)) && ($i >= sizeof($graph_items))) { $mode = 'add'; $user_message = "Click save, the items marked with a '+' will be added (Recommended)."; }elseif ((sizeof($graph_template_items) < sizeof($graph_items)) && ($i >= sizeof($graph_template_items))) { $mode = 'delete'; $user_message = "Click save, the items marked with a '-' will be removed (Recommended)."; } /* here is the fun meshing part. first we check the graph template to see if there is an input for each field of this row. if there is, we revert to the value stored in the graph, if not we revert to the value stored in the template. got that? ;) */ for ($j=0; ($j < count($graph_template_inputs)); $j++) { if ($graph_template_inputs[$j]['graph_template_item_id'] == (isset($graph_template_items[$i]['id']) ? $graph_template_items[$i]['id'] : '')) { /* if we find out that there is an "input" covering this field/item, use the value FROM the graph, not the template */ $graph_item_field_name = (isset($graph_template_inputs[$j]['column_name']) ? $graph_template_inputs[$j]['column_name'] : ''); $graph_preview_item_values[$graph_item_field_name] = (isset($graph_items[$i][$graph_item_field_name]) ? $graph_items[$i][$graph_item_field_name] : ''); } } /* go back through each graph field and find out which ones haven't been covered by the "inputs" above. for each one, use the value FROM the template */ while (list($field_name, $field_array) = each($struct_graph_item)) { if ($mode == 'delete') { $graph_preview_item_values[$field_name] = (isset($graph_items[$i][$field_name]) ? $graph_items[$i][$field_name] : ''); }elseif (!isset($graph_preview_item_values[$field_name])) { $graph_preview_item_values[$field_name] = (isset($graph_template_items[$i][$field_name]) ? $graph_template_items[$i][$field_name] : ''); } } /* "prepare" array values */ $consolidation_function_id = $graph_preview_item_values['consolidation_function_id']; $graph_type_id = $graph_preview_item_values['graph_type_id']; /* color logic */ if (($graph_item_types[$graph_type_id] != 'GPRINT') && ($graph_item_types[$graph_type_id] != $_graph_type_name)) { $bold_this_row = true; $use_custom_row_color = true; $hard_return = ''; if ($group_counter % 2 == 0) { $alternate_color_1 = 'graphItemGr1Alt1'; $alternate_color_2 = 'graphItemGr1Alt2'; $custom_row_color = 'graphItemGr1Cust'; }else{ $alternate_color_1 = 'graphItemGr2Alt1'; $alternate_color_2 = 'graphItemGr2Alt2'; $custom_row_color = 'graphItemGr2Cust'; } $group_counter++; } $_graph_type_name = $graph_item_types[$graph_type_id]; if ($use_custom_row_color == false) { if ($i % 2 == 0) { $action_column_color = $alternate_color_1; }else{ $action_column_color = $alternate_color_2; } }else{ $action_column_color = $custom_row_color; } print ""; $i++; /* make the left-hand column blue or red depending on if "add"/"remove" mode is set */ if ($mode == 'add') { $action_column_color = 'graphItemAdd'; $action_css = ''; }elseif ($mode == 'delete') { $action_column_color = 'graphItemDel'; $action_css = 'text-decoration: line-through;'; } if ($bold_this_row == true) { $action_css .= ' font-weight:bold;'; } /* draw the TD that shows the user whether we are going to: KEEP, ADD, or DROP the item */ print "" . $graph_item_actions[$mode] . ''; print "Item # " . $i . "\n"; if (empty($graph_preview_item_values['task_item_id'])) { $graph_preview_item_values['task_item_id'] = 'No Task'; } switch (true) { case preg_match('/(AREA|STACK|GPRINT|LINE[123])/', $_graph_type_name): $matrix_title = '(' . $graph_preview_item_values['task_item_id'] . '): ' . $graph_preview_item_values['text_format']; break; case preg_match('/(HRULE|VRULE)/', $_graph_type_name): $matrix_title = 'HRULE: ' . $graph_preview_item_values['value']; break; case preg_match('/(COMMENT)/', $_graph_type_name): $matrix_title = 'COMMENT: ' . $graph_preview_item_values['text_format']; break; } /* use the cdef name (if in use) if all else fails */ if ($matrix_title == '') { if ($graph_preview_item_values['cdef_id'] != '') { $matrix_title .= 'CDEF: ' . $graph_preview_item_values['cdef_id']; } } if ($graph_preview_item_values['hard_return'] == 'on') { $hard_return = "<HR>"; } print "" . htmlspecialchars($matrix_title) . $hard_return . "\n"; print "" . $graph_item_types{$graph_preview_item_values['graph_type_id']} . "\n"; print "" . $consolidation_functions{$graph_preview_item_values['consolidation_function_id']} . "\n"; print ' \n"; print "" . $graph_preview_item_values['color_id'] . "\n"; print ''; } }else{ print "No Items\n"; } html_end_box(); form_start('graphs.php'); ?>
 
 Click save, the graph items will remain untouched (could cause inconsistencies).

*'>Turn Graph Debug Mode.
*'>Edit Graph Template.
*'>Edit Device.
* Unlock Graph* Lock Graph
array( 'method' => 'drop_sql', 'friendly_name' => 'Selected Graph Template', 'description' => 'Choose a Graph Template to apply to this Graph. Please note that Graph Data may be lost if you change the Graph Template after one is already applied.', 'value' => (isset($graph) ? $graph['graph_template_id'] : '0'), 'none_value' => 'None', 'sql' => 'SELECT graph_templates.id,graph_templates.name FROM graph_templates ORDER BY name' ), 'host_id' => array( 'method' => 'drop_callback', 'friendly_name' => 'Device', 'description' => 'Choose the Device that this Graph belongs to.', 'sql' => 'SELECT id, description as name FROM host ORDER BY name', 'action' => 'ajax_hosts_noany', 'id' => (isset_request_var('host_id') ? get_request_var('host_id') : $host_id), 'value' => db_fetch_cell_prepared('SELECT description FROM host WHERE id = ?', (isset_request_var('host_id') ? array(get_request_var('host_id')) : array($host_id))), ), 'graph_template_graph_id' => array( 'method' => 'hidden', 'value' => (isset($graph) ? $graph['id'] : '0') ), 'local_graph_id' => array( 'method' => 'hidden', 'value' => (isset($graph) ? $graph['local_graph_id'] : '0') ), 'local_graph_template_graph_id' => array( 'method' => 'hidden', 'value' => (isset($graph) ? $graph['local_graph_template_graph_id'] : '0') ), '_graph_template_id' => array( 'method' => 'hidden', 'value' => (isset($graph) ? $graph['graph_template_id'] : '0') ), '_host_id' => array( 'method' => 'hidden', 'value' => (isset($host_id) ? $host_id : '0') ) ); draw_edit_form( array( 'config' => array(), 'fields' => $form_array ) ); html_end_box(); /* only display the "inputs" area if we are using a graph template for this graph */ if (!empty($graph['graph_template_id'])) { html_start_box('Supplemental Graph Template Data', '100%', '', '3', 'center', ''); draw_nontemplated_fields_graph($graph['graph_template_id'], $graph, '|field|', 'Graph Fields', true, true, 0); draw_nontemplated_fields_graph_item($graph['graph_template_id'], get_request_var('id'), '|field|_|id|', 'Graph Item Fields', true, $locked); html_end_box(); } /* graph item list goes here */ if ((!isempty_request_var('id')) && (empty($graph['graph_template_id']))) { item(); } if (!isempty_request_var('id')) { ?>
src="" alt=""> RRDTool Command:
RRDTool Says:

$struct_graph[$field_name]); $form_array[$field_name]['value'] = (isset($graph) ? $graph[$field_name] : ''); $form_array[$field_name]['form_id'] = (isset($graph) ? $graph['id'] : '0'); if (!(($use_graph_template == false) || ($graph_template{'t_' . $field_name} == 'on'))) { $form_array[$field_name]['method'] = 'template_' . $form_array[$field_name]['method']; $form_array[$field_name]['description'] = ''; } } draw_edit_form( array( 'config' => array( 'no_form_tag' => true ), 'fields' => $form_array ) ); html_end_box(); } if ((isset_request_var('id')) || (isset_request_var('new'))) { form_hidden_box('save_component_graph','1',''); form_hidden_box('save_component_input','1',''); }else{ form_hidden_box('save_component_graph_new','1',''); } form_hidden_box('rrdtool_version', read_config_option('rrdtool_version'), ''); form_save_button('graphs.php'); //Now we need some javascript to make it dynamic ?> array( 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => read_config_option('num_rows_table') ), 'page' => array( 'filter' => FILTER_VALIDATE_INT, 'default' => '1' ), 'filter' => array( 'filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string') ), 'sort_column' => array( 'filter' => FILTER_CALLBACK, 'default' => 'title_cache', 'options' => array('options' => 'sanitize_search_string') ), 'sort_direction' => array( 'filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string') ), 'host_id' => array( 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ), 'template_id' => array( 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ) ); validate_store_request_vars($filters, 'sess_graph'); /* ================= input validation ================= */ /* if the number of rows is -1, set it to the default */ if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); }else{ $rows = get_request_var('rows'); } ?>
Template
Search '> Graphs
'>
array('display' => 'Graph Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The Title of this Graph. Generally programatically generated from the Graph Template definition or Suggested Naming rules. The max length of the Title is controlled under Settings->Visual.'), 'local_graph_id' => array('display' => 'ID', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The internal database ID fro this Graph. Useful when performing automation or debugging.'), 'name' => array('display' => 'Template Name', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The Graph Template that this Graph was based upon.'), 'height' => array('display' => 'Size', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The size of this Graph when not in Preview mode.')); html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false); $i = 0; if (sizeof($graph_list) > 0) { foreach ($graph_list as $graph) { /* we're escaping strings here, so no need to escape them on form_selectable_cell */ $template_name = ((empty($graph['name'])) ? 'None' : htmlspecialchars($graph['name'])); form_alternate_row('line' . $graph['local_graph_id'], true); form_selectable_cell("" . ((get_request_var('filter') != '') ? preg_replace('/(' . preg_quote(get_request_var('filter'), '/') . ')/i', "\\1", title_trim(htmlspecialchars($graph['title_cache']), read_config_option('max_title_length'))) : title_trim(htmlspecialchars($graph['title_cache']), read_config_option('max_title_length'))) . '', $graph['local_graph_id']); form_selectable_cell($graph['local_graph_id'], $graph['local_graph_id'], '', 'text-align:right'); form_selectable_cell(((get_request_var('filter') != '') ? preg_replace('/(' . preg_quote(get_request_var('filter'), '/') . ')/i', "\\1", $template_name) : $template_name), $graph['local_graph_id']); form_selectable_cell($graph['height'] . 'x' . $graph['width'], $graph['local_graph_id']); form_checkbox_cell($graph['title_cache'], $graph['local_graph_id']); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; }else{ print "No Graphs Found"; } html_end_box(false); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($graph_actions); form_end(); }