No valid device specified // A valid device was not specified in the URL. Please retype and try again.'); // break; //} // Print the device header if (isset($device) && is_array($device)) { $args = []; if ($type === 'device') { // device have own panel, hide on xl $args['div-class'] = 'hidden-xl'; } print_device_header($device, $args); } if (isset($config['graph_types'][$type][$subtype]['descr'])) { $title .= " :: ".$config['graph_types'][$type][$subtype]['descr']; } else { $title .= " :: ".nicecase($subtype); } // Generate navbar with subtypes $graph_array = $vars; $graph_array['height'] = "60"; $graph_array['width'] = $thumb_width; // Clear collectd argument forcing axis rendering if (isset($graph_array['draw_all'])) { unset($graph_array['draw_all']); } //$graph_array['legend'] = "no"; //$graph_array['to'] = $config['time']['now']; $navbar = array('brand' => "Graph", 'class' => "navbar-narrow"); switch ($type) { case 'device': case 'sensor': case 'cefswitching': case 'munin': $navbar['options']['graph'] = array('text' => nicecase($type).' ('.$subtype.')', 'url' => generate_url($vars, array('type' => $type."_".$subtype, 'page' => "graphs"))); break; default: # Load our list of available graphtypes for this object /// FIXME not all of these are going to be valid /// This is terrible. --mike /// The future solution is to keep a 'registry' of which graphtypes apply to which entities and devices. /// I'm not quite sure if this is going to be too slow. --adama 2013-11-11 $types = []; if ($handle = opendir($config['html_dir'] . "/includes/graphs/".$type."/")) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != "auth.inc.php" && $file != "graph.inc.php" && $file != ".auth.swp" && strstr($file, ".inc.php")) { $types[] = str_replace(".inc.php", "", $file); } } closedir($handle); } foreach ($title_array as $key => $element) { $navbar['options'][$key] = $element; } $navbar['options']['graph'] = array('text' => 'Graph'); sort($types); foreach ($types as $avail_type) { if ($subtype == $avail_type) { $navbar['options']['graph']['suboptions'][$avail_type]['class'] = 'active'; $navbar['options']['graph']['text'] .= ' ('.$avail_type.')'; } $navbar['options']['graph']['suboptions'][$avail_type]['text'] = nicecase($avail_type); $navbar['options']['graph']['suboptions'][$avail_type]['url'] = generate_url($vars, array('type' => $type."_".$avail_type, 'page' => "graphs")); } } // Adding to the dashboard if ($_SESSION['userlevel'] > 7) { $dashboards = dbFetchRows("SELECT * FROM `dashboards`"); // FIXME - widget_exists() dashboard_exists(), widget_permitted(), dashboard_permitted(), etc. // FIXME - convert this to ajax call, maybe make the code usable on other pages too $valid = array('id', 'device', 'c_plugin', 'c_plugin_instance', 'c_type', 'c_type_instance'); $add_array = [ 'type' => $vars['type'] ]; if (isset($vars['period']) && is_numeric($vars['period'])) { $add_array['period'] = $vars['period']; } foreach($vars as $var => $value) { if(in_array($var, $valid)) { $add_array[$var] = $value; } } if (isset($vars['dash_add']) && dashboard_exists($vars['dash_add'])) { $widget_id = dbInsert(array('dash_id' => $vars['dash_add'], 'widget_config' => json_encode($add_array), 'widget_type' => 'graph', 'x' => 0, 'y' => 99, 'width' => 3, 'height' => 2), 'dash_widgets'); print_message('Graph widget added to dashboard.', 'info'); unset($vars['dash_add']); } if (isset($vars['dash_add_widget'])) { dbUpdate(array('widget_config' => json_encode($add_array)), 'dash_widgets', '`widget_id` = ?', array($vars['dash_add_widget'])); if (dbAffectedRows() == 1) { print_message("Widget updated.", 'info'); } unset($vars['dash_add_widget']); } $navbar['options_right']['export']['text'] = "Export Data"; foreach($config['graph_formats'] as $format => $entry) { $export_array = $graph_array; $export_array['format'] = $format; $navbar['options_right']['export']['suboptions'][$format]['text'] = $entry['descr']; $navbar['options_right']['export']['suboptions'][$format]['url'] = generate_graph_url($export_array); $navbar['options_right']['export']['suboptions'][$format]['link_opts'] = 'target="_blank"'; } if (safe_count($dashboards)) { $navbar['options_right']['dash']['text'] = "Add to Dashboard"; foreach($dashboards as $dash) { $navbar['options_right']['dash']['suboptions'][$dash['dash_id']]['text'] = "Add to " . $dash['dash_name']; $navbar['options_right']['dash']['suboptions'][$dash['dash_id']]['url'] = generate_url($vars, array('page' => "graphs", 'dash_add' => $dash['dash_id'])); /* Disable adding to specific widgets, the menu doesn't expand. $widgets = dbFetchRows("SELECT * FROM `dash_widgets` WHERE `dash_id` = ? AND widget_type = 'graph' AND `widget_config` = ?", array($dash['dash_id'], '[]')); foreach($widgets as $widget) { $navbar['options_right']['dash']['suboptions'][$dash['dash_id']]['entries'][$widget['widget_id']]['text'] = "Add to Widget #".$widget['widget_id'].""; $navbar['options_right']['dash']['suboptions'][$dash['dash_id']]['entries'][$widget['widget_id']]['url'] = generate_url($vars, array('page' => "graphs", 'dash_add_widget' => $widget['widget_id'])); } */ } } } print_navbar($navbar); // Start form for the custom range. echo generate_box_open(array('box-style' => 'padding-bottom: 5px;')); $thumb_array = array('sixhour' => '6 Hours', 'day' => '24 Hours', 'twoday' => '48 Hours', 'week' => 'One Week', //'twoweek' => 'Two Weeks', 'month' => 'One Month', 'threemonth' => 'Three Months', 'year' => 'One Year', 'threeyear' => 'Three Years' ); $periods = ['21600' => '6 Hours', '86400' => '1 Day', '172800' => '2 Days', '604800' => 'One Week', //'1209600' => 'Two Weeks', '2628000' => 'One Month', '7884000' => 'Three Months', '31536000' => 'One Year', '94608000' => 'Three Years']; echo(''); foreach ($periods as $period => $text) { //$graph_array['from'] = $config['time'][$period]; $graph_array['period'] = $period; $remove_vars = ['from', 'to']; foreach($remove_vars as $remove_var) { if (isset($graph_array[$remove_var])) { unset($graph_array[$remove_var]); } } $link_array = $graph_array; //$link_array['from'] = $graph_array['from']; //$link_array['to'] = $graph_array['to']; $link_array['page'] = "graphs"; $link = generate_url($link_array); echo(''); } echo('
'); echo(''.$text.'
'); echo(''); echo(generate_graph_tag($graph_array)); echo(''); echo('
'); $graph_array = $vars; $graph_array['height'] = "300"; $graph_array['width'] = $graph_width; echo generate_box_close(); $form_vars = $vars; unset($form_vars['from']); unset($form_vars['to']); unset($form_vars['period']); $form = array('type' => 'rows', 'space' => '5px', 'submit_by_key' => TRUE, 'url' => 'graphs'.generate_url($form_vars)); if (is_numeric($vars['from']) && $vars['from'] < 0) { $text_from = time() + $vars['from']; } elseif(is_numeric($vars['from'])) { $text_from = date('Y-m-d H:i:s', $vars['from']); } if (is_numeric($vars['to']) && $vars['to'] < 0) { $text_to = time() + $vars['to']; } elseif ($vars['to'] === 'now' || $vars['to'] === "NOW") { $text_to = time(); } elseif(is_numeric($vars['to'])) { $text_to = date('Y-m-d H:i:s', $vars['to']); } if (isset($vars['period']) && (!isset($vars['from']) || !isset($vars['to']))) { $text_to = date('Y-m-d H:i:s', time()); $text_from = date('Y-m-d H:i:s', time() - $vars['period']); } // Datetime Field $form['row'][0]['timestamp'] = array( 'type' => 'datetime', 'grid' => 10, 'grid_xs' => 10, //'width' => '70%', //'div_class' => 'text-nowrap col-sm-push-0', // Too hard, will fix later //'div_class' => 'col-lg-10 col-md-10 col-sm-10 col-xs-10', 'presets' => TRUE, 'min' => '2007-04-03 16:06:59', // Hehe, who will guess what this date/time means? --mike // First commit! Though Observium was already 7 months old by that point. --adama 'max' => date('Y-m-d 23:59:59'), // Today 'from' => $text_from, 'to' => $text_to); $search_grid = 2; if ($type == "port") { if ($subtype == "bits") { $speed_list = array('auto' => 'Autoscale', 'speed' => 'Interface Speed ('.formatRates($port['ifSpeed'], 4, 4).')'); foreach ($config['graphs']['ports_scale_list'] as $entry) { $speed = intval(unit_string_to_numeric($entry, 1000)); $speed_list[$entry] = formatRates($speed, 4, 4); } $form['row'][0]['scale'] = array( 'type' => 'select', // Type 'name' => 'Scale', // Displayed title for item 'grid' => 2, 'width' => '100%', 'value' => (isset($vars['scale']) ? $vars['scale'] : $config['graphs']['ports_scale_default']), 'values' => $speed_list); //reduce timestamp element grid sizes $form['row'][0]['timestamp']['grid'] -= 2; } if (in_array($subtype, array('bits', 'percent', 'upkts', 'pktsize'))) { $form['row'][0]['style'] = array( 'type' => 'select', 'name' => 'Graph style', 'grid' => 2, 'width' => '100%', 'value' => (isset($vars['style']) ? $vars['style'] : $config['graphs']['style']), 'values' => array('default' => 'Default', 'mrtg' => 'MRTG')); //reduce timestamp element grid sizes $form['row'][0]['timestamp']['grid'] -= 1; unset($form['row'][0]['timestamp']['grid_xs']); $search_grid = 1; } } // Update button $form['row'][0]['update'] = [ 'type' => 'submit', //'name' => 'Search', //'icon' => 'icon-search', //'div_class' => 'col-lg-2 col-md-2 col-sm-2 col-xs-2', 'grid' => $search_grid, 'grid_xs' => ($search_grid > 1 ? $search_grid : 12), 'right' => TRUE ]; print_form($form); unset($form, $speed_list, $speed, $search_grid); // Run the graph to get data array out of it $vars = array_merge($vars, $graph_array); $vars['command_only'] = 1; include($config['html_dir']."/includes/graphs/graph.inc.php"); unset($vars['command_only']); // Print options navbar $navbar = array(); $navbar['brand'] = "Options"; $navbar['class'] = "navbar-narrow"; $navbar['options']['legend'] = array('text' => 'Show Legend', 'inverse' => TRUE); $navbar['options']['previous'] = array('text' => 'Graph Previous'); if (in_array('trend', $graph_return['valid_options'])) { $navbar['options']['trend'] = array('text' => 'Graph Trend'); } //$navbar['options']['max'] = array('text' => 'Graph Maximum'); if (in_array('inverse', $graph_return['valid_options'])) { $navbar['options']['inverse'] = array('text' => 'Invert Graph'); } if (in_array('line_graph', $graph_return['valid_options'])) { $navbar['options']['line_graph'] = array('text' => 'Line Graph'); } $navbar['options_right']['showcommand'] = array('text' => 'RRD Command'); foreach (array('options' => $navbar['options'], 'options_right' => $navbar['options_right'] ) as $side => $options) { foreach ($options AS $option => $array) { if ($array['inverse'] == TRUE) { if ($vars[$option] == "no") { $navbar[$side][$option]['url'] = generate_url($vars, array('page' => "graphs", $option => NULL)); } else { $navbar[$side][$option]['url'] = generate_url($vars, array('page' => "graphs", $option => 'no')); $navbar[$side][$option]['class'] .= " active"; } } else { if ($vars[$option] == "yes") { $navbar[$side][$option]['url'] = generate_url($vars, array('page' => "graphs", $option => NULL)); $navbar[$side][$option]['class'] .= " active"; } else { $navbar[$side][$option]['url'] = generate_url($vars, array('page' => "graphs", $option => 'yes')); } } } } $navbar['options_right']['graph_link'] = array('text' => 'Link to Graph', 'url' => generate_graph_url($graph_array), 'link_opts' => 'target="_blank"'); print_navbar($navbar); unset($navbar); /* ?>

'Description', 'padding' => TRUE)); echo($graph_return['descr']); echo generate_box_close(); } #print_vars($graph_return); if (isset($vars['showcommand'])) { echo generate_box_open(array('title' => 'Performance & Output', 'padding' => TRUE)); echo("RRDTool Output: " . escape_html($graph_return['output'])."
RRDtool Runtime: ".number_format($graph_return['runtime'], 3)."s | Total time: " .number_format($graph_return['total'], 3)."s"); echo generate_box_close(); echo generate_box_open(array('title' => 'RRDTool Command', 'padding' => TRUE)); echo escape_html($graph_return['command']); echo generate_box_close(); echo generate_box_open(array('title' => 'RRDTool Files Used', 'padding' => TRUE)); if (is_array($graph_return['rrds'])) { foreach ($graph_return['rrds'] as $rrd) { echo "$rrd
"; } } else { echo "No RRD information returned. This may be because the graph module doesn't yet return this data.
"; } echo generate_box_close(); } // EOF