0) { $selected_graphs['cg']{get_nfilter_request_var('cg_g')}{get_nfilter_request_var('cg_g')} = true; } }elseif (preg_match('/^sg_(\d+)_([a-f0-9]{32})$/', $var, $matches)) { $selected_graphs['sg']{$matches[1]}{get_nfilter_request_var('sgg_' . $matches[1])}{$matches[2]} = true; } } if (!isset_request_var('host_id')) { $host_id = 0; }else{ $host_id = get_filter_request_var('host_id'); } if (!isset_request_var('host_template_id')) { $host_template_id = 0; }else{ $host_template_id = get_filter_request_var('host_template_id'); } if (isset($selected_graphs)) { host_new_graphs($host_id, $host_template_id, $selected_graphs); exit; } header('Location: graphs_new.php?host_id=' . $host_id . '&header=false'); } if (isset_request_var('save_component_new_graphs')) { host_new_graphs_save(get_filter_request_var('host_id')); header('Location: graphs_new.php?host_id=' . get_filter_request_var('host_id') . '&header=false'); } } /* --------------------- Misc Functions --------------------- */ function draw_edit_form_row($field_array, $field_name, $previous_value) { $field_array['value'] = $previous_value; draw_edit_form( array( 'config' => array( 'no_form_tag' => true, 'force_row_color' => 'F5F5F5' ), 'fields' => array( $field_name => $field_array ) ) ); } /* ------------------- Data Query Functions ------------------- */ function host_reload_query() { /* ================= input validation ================= */ get_filter_request_var('id'); get_filter_request_var('host_id'); /* ==================================================== */ run_data_query(get_request_var('host_id'), get_request_var('id')); } /* ------------------- New Graph Functions ------------------- */ function host_new_graphs_save($host_id) { $selected_graphs_array = unserialize(stripslashes(get_nfilter_request_var('selected_graphs_array'))); /* form an array that contains all of the data on the previous form */ while (list($var, $val) = each($_POST)) { if (preg_match('/^g_(\d+)_(\d+)_(\w+)/', $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values['cg']{$matches[2]}['graph_template']{$matches[3]} = $val; }else{ /* this is a data query field */ $values['sg']{$matches[1]}{$matches[2]}['graph_template']{$matches[3]} = $val; } }elseif (preg_match('/^gi_(\d+)_(\d+)_(\d+)_(\w+)/', $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: graph_template_input_id, 4:field_name */ /* ================= input validation ================= */ input_validate_input_number($matches[3]); /* ==================================================== */ /* we need to find out which graph items will be affected by saving this particular item */ $item_list = db_fetch_assoc_prepared('SELECT graph_template_item_id FROM graph_template_input_defs WHERE graph_template_input_id = ?', array($matches[3])); /* loop through each item affected and update column data */ if (sizeof($item_list) > 0) { foreach ($item_list as $item) { if (empty($matches[1])) { /* this is a new graph from template field */ $values['cg']{$matches[2]}['graph_template_item']{$item['graph_template_item_id']}{$matches[4]} = $val; }else{ /* this is a data query field */ $values['sg']{$matches[1]}{$matches[2]}['graph_template_item']{$item['graph_template_item_id']}{$matches[4]} = $val; } } } }elseif (preg_match('/^d_(\d+)_(\d+)_(\d+)_(\w+)/', $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values['cg']{$matches[2]}['data_template']{$matches[3]}{$matches[4]} = $val; }else{ /* this is a data query field */ $values['sg']{$matches[1]}{$matches[2]}['data_template']{$matches[3]}{$matches[4]} = $val; } }elseif (preg_match('/^c_(\d+)_(\d+)_(\d+)_(\d+)/', $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:data_input_field_id */ if (empty($matches[1])) { /* this is a new graph from template field */ $values['cg']{$matches[2]}['custom_data']{$matches[3]}{$matches[4]} = $val; }else{ /* this is a data query field */ $values['sg']{$matches[1]}{$matches[2]}['custom_data']{$matches[3]}{$matches[4]} = $val; } }elseif (preg_match('/^di_(\d+)_(\d+)_(\d+)_(\d+)_(\w+)/', $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:local_data_template_rrd_id, 5:field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values['cg']{$matches[2]}['data_template_item']{$matches[4]}{$matches[5]} = $val; }else{ /* this is a data query field */ $values['sg']{$matches[1]}{$matches[2]}['data_template_item']{$matches[4]}{$matches[5]} = $val; } } } debug_log_clear('new_graphs'); while (list($form_type, $form_array) = each($selected_graphs_array)) { $current_form_type = $form_type; while (list($form_id1, $form_array2) = each($form_array)) { /* enumerate information from the arrays stored in post variables */ /* ================= input validation ================= */ input_validate_input_number($form_id1); /* ==================================================== */ if ($form_type == 'cg') { $graph_template_id = $form_id1; }elseif ($form_type == 'sg') { while (list($form_id2, $form_array3) = each($form_array2)) { /* ================= input validation ================= */ input_validate_input_number($form_id2); /* ==================================================== */ $snmp_index_array = $form_array3; $snmp_query_array['snmp_query_id'] = $form_id1; $snmp_query_array['snmp_index_on'] = get_best_data_query_index_type($host_id, $form_id1); $snmp_query_array['snmp_query_graph_id'] = $form_id2; } $graph_template_id = db_fetch_cell_prepared('SELECT graph_template_id FROM snmp_query_graph WHERE id = ?', array($snmp_query_array['snmp_query_graph_id'])); } if ($current_form_type == 'cg') { $return_array = create_complete_graph_from_template($graph_template_id, $host_id, '', $values['cg']); debug_log_insert('new_graphs', __('Created graph: %s', get_graph_title($return_array['local_graph_id']))); /* lastly push host-specific information to our data sources */ if (sizeof($return_array['local_data_id'])) { # we expect at least one data source associated foreach($return_array['local_data_id'] as $item) { push_out_host($host_id, $item); } } else { debug_log_insert('new_graphs', __('ERROR: no Data Source associated. Check Template')); } }elseif ($current_form_type == 'sg') { while (list($snmp_index, $true) = each($snmp_index_array)) { $snmp_query_array['snmp_index'] = decode_data_query_index($snmp_index, $snmp_query_array['snmp_query_id'], $host_id); $return_array = create_complete_graph_from_template($graph_template_id, $host_id, $snmp_query_array, $values['sg']{$snmp_query_array['snmp_query_id']}); debug_log_insert('new_graphs', __('Created graph: %s', get_graph_title($return_array['local_graph_id']))); /* lastly push host-specific information to our data sources */ if (sizeof($return_array['local_data_id'])) { # we expect at least one data source associated foreach($return_array['local_data_id'] as $item) { push_out_host($host_id, $item); } } else { debug_log_insert('new_graphs', __('ERROR: no Data Source associated. Check Template')); } } } } } } function host_new_graphs($host_id, $host_template_id, $selected_graphs_array) { /* we use object buffering on this page to allow redirection to another page if no fields are actually drawn */ ob_start(); top_header(); form_start('graphs_new.php'); $snmp_query_id = 0; $num_output_fields = array(); while (list($form_type, $form_array) = each($selected_graphs_array)) { while (list($form_id1, $form_array2) = each($form_array)) { /* ================= input validation ================= */ input_validate_input_number($form_id1); /* ==================================================== */ if ($form_type == 'cg') { $graph_template_id = $form_id1; html_start_box("Create Graph from '" . db_fetch_cell_prepared('SELECT name FROM graph_templates WHERE id = ?', array($graph_template_id)) . "'", '100%', '', '3', 'center', ''); }elseif ($form_type == 'sg') { while (list($form_id2, $form_array3) = each($form_array2)) { /* ================= input validation ================= */ input_validate_input_number($snmp_query_id); input_validate_input_number($form_id2); /* ==================================================== */ $snmp_query_id = $form_id1; $snmp_query_graph_id = $form_id2; $num_graphs = sizeof($form_array3); $snmp_query = db_fetch_row_prepared('SELECT snmp_query.name, snmp_query.xml_path FROM snmp_query WHERE snmp_query.id = ?', array($snmp_query_id)); $graph_template_id = db_fetch_cell_prepared('SELECT graph_template_id FROM snmp_query_graph WHERE id = ?', array($snmp_query_graph_id)); } if ($num_graphs > 1) { $header = __('Created %s Graphs from %s', $num_graphs, htmlspecialchars(db_fetch_cell_prepared('SELECT name FROM snmp_query WHERE id = ?', array($snmp_query_id)))); }else{ $header = __('Created 1 Graph from %s', htmlspecialchars(db_fetch_cell_prepared('SELECT name FROM snmp_query WHERE id = ?', array($snmp_query_id)))); } /* DRAW: Data Query */ html_start_box($header, '100%', '', '3', 'center', ''); } /* ================= input validation ================= */ input_validate_input_number($graph_template_id); /* ==================================================== */ $data_templates = db_fetch_assoc_prepared('SELECT data_template.name AS data_template_name, data_template_rrd.data_source_name, data_template_data.* FROM (data_template, data_template_rrd, data_template_data, graph_templates_item) WHERE graph_templates_item.task_item_id = data_template_rrd.id AND data_template_rrd.data_template_id = data_template.id AND data_template_data.data_template_id = data_template.id AND data_template_rrd.local_data_id = 0 AND data_template_data.local_data_id = 0 AND graph_templates_item.local_graph_id = 0 AND graph_templates_item.graph_template_id = ? GROUP BY data_template.id ORDER BY data_template.name', array($graph_template_id)); $graph_template = db_fetch_row_prepared('SELECT graph_templates.name AS graph_template_name, graph_templates_graph.* FROM (graph_templates, graph_templates_graph) WHERE graph_templates.id = graph_templates_graph.graph_template_id AND graph_templates.id = ? AND graph_templates_graph.local_graph_id = 0', array($graph_template_id)); $graph_template_name = db_fetch_cell_prepared('SELECT name FROM graph_templates WHERE id = ?', array($graph_template_id)); array_push($num_output_fields, draw_nontemplated_fields_graph($graph_template_id, $graph_template, "g_$snmp_query_id" . '_' . $graph_template_id . '_|field|', __('Graph [Template: %s]', htmlspecialchars($graph_template['graph_template_name'])), false, false, (isset($snmp_query_graph_id) ? $snmp_query_graph_id : 0))); array_push($num_output_fields, draw_nontemplated_fields_graph_item($graph_template_id, 0, 'gi_' . $snmp_query_id . '_' . $graph_template_id . '_|id|_|field|', __('Graph Items [Template: %s]', htmlspecialchars($graph_template_name)), false)); /* DRAW: Data Sources */ if (sizeof($data_templates)) { foreach ($data_templates as $data_template) { array_push($num_output_fields, draw_nontemplated_fields_data_source($data_template['data_template_id'], 0, $data_template, 'd_' . $snmp_query_id . '_' . $graph_template_id . '_' . $data_template['data_template_id'] . '_|field|', __('Data Source [Template: %s]', htmlspecialchars($data_template['data_template_name'])), false, false, (isset($snmp_query_graph_id) ? $snmp_query_graph_id : 0))); $data_template_items = db_fetch_assoc_prepared('SELECT data_template_rrd.* FROM data_template_rrd WHERE data_template_rrd.data_template_id = ? AND local_data_id = 0', array($data_template['data_template_id'])); array_push($num_output_fields, draw_nontemplated_fields_data_source_item($data_template['data_template_id'], $data_template_items, 'di_' . $snmp_query_id . '_' . $graph_template_id . '_' . $data_template['data_template_id'] . '_|id|_|field|', '', false, false, false, (isset($snmp_query_graph_id) ? $snmp_query_graph_id : 0))); array_push($num_output_fields, draw_nontemplated_fields_custom_data($data_template['id'], 'c_' . $snmp_query_id . '_' . $graph_template_id . '_' . $data_template['data_template_id'] . '_|id|', __('Custom Data [Template: %s]', htmlspecialchars($data_template['data_template_name'])), false, false, $snmp_query_id)); } } html_end_box(false); } } /* no fields were actually drawn on the form; just save without prompting the user */ if (array_sum($num_output_fields) == 0) { ob_end_clean(); /* since the user didn't actually click "Create" to POST the data; we have to pretend like they did here */ set_request_var('save_component_new_graphs', '1'); set_request_var('selected_graphs_array', serialize($selected_graphs_array)); host_new_graphs_save($host_id); header('Location: graphs_new.php?host_id=' . $host_id . '&header=false'); exit; } /* flush the current output buffer to the browser */ ob_end_flush(); form_hidden_box('host_template_id', $host_template_id, '0'); form_hidden_box('host_id', $host_id, '0'); form_hidden_box('save_component_new_graphs', '1', ''); print "\n"; if (!substr_count($_SERVER['HTTP_REFERER'], 'graphs_new')) { set_request_var('returnto', basename($_SERVER['HTTP_REFERER'])); } load_current_session_value('returnto', 'sess_grn_returnto', ''); form_save_button(get_nfilter_request_var('returnto')); bottom_footer(); } /* ------------------- Graph Functions ------------------- */ function graphs() { global $config, $item_rows; /* ================= input validation and session storage ================= */ $filters = array( 'rows' => array( 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' ), 'filter' => array( 'filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string') ), 'host_id' => array( 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => db_fetch_cell('SELECT id FROM host ORDER BY description, hostname LIMIT 1') ), 'graph_type' => array( 'filter' => FILTER_VALIDATE_INT, 'default' => read_config_option('default_graphs_new_dropdown') ) ); validate_store_request_vars($filters, 'sess_grn'); /* ================= input validation ================= */ if (get_request_var('rows') == '-1') { $rows = read_config_option('num_rows_table'); }else{ $rows = get_request_var('rows'); } if (!isempty_request_var('host_id')) { $host = db_fetch_row_prepared('SELECT id, description, hostname, host_template_id FROM host WHERE id = ?', array(get_request_var('host_id'))); $header = __('New Graphs for [ %s ]', htmlspecialchars($host['description']) . ' (' . htmlspecialchars($host['hostname']) . ') ' . (!empty($host['host_template_id']) ? htmlspecialchars(db_fetch_cell_prepared('SELECT name FROM host_template WHERE id = ?', array($host['host_template_id']))):'')); }else{ $host = array(); $header = __('New Graphs for None Host Type'); } html_start_box($header, '100%', '', '3', 'center', ''); form_alternate_row(); print ''; ?>
display:none;'>
*'>
*'>
'> ' title=''> ' title=''>
0) { load_current_session_value('page' . get_request_var('graph_type'), 'sess_grn_page' . get_request_var('graph_type'), '1'); }else if (get_request_var('graph_type') == -2) { foreach($snmp_queries as $query) { load_current_session_value('page' . $query['id'], 'sess_grn_page' . $query['id'], '1'); } } $script = "\n"; print $script; } form_hidden_box('save_component_graph', '1', ''); if (!isempty_request_var('host_id')) { form_hidden_box('host_id', $host['id'], '0'); form_hidden_box('host_template_id', $host['host_template_id'], '0'); } if (isset($_SERVER['HTTP_REFERER']) && !substr_count($_SERVER['HTTP_REFERER'], 'graphs_new')) { set_request_var('returnto', basename($_SERVER['HTTP_REFERER'])); } load_current_session_value('returnto', 'sess_grn_returnto', ''); if (substr_count(get_nfilter_request_var('returnto'), 'host.php') == 0) { set_request_var('returnto', ''); } form_save_button(get_nfilter_request_var('returnto'), 'create'); }