/** * Fetch RRDtool graph data for given switch/port * @param integer $switch Switch to look graph of. ID in host table * @param integer $port Port to look graph of. snmp_index in host_snmp_cache * @param string $from Date to collect data from (unix timestamp) * @param string $to Date to collect data to (unix timestamp) * @return array Output from rrdtool_function_xport * * @throws Exception * @see lib/rrd.php */ public function getGraphData($switch, $port, $from, $to) { //small sanitization $from = intval($from); $to = intval($to); $gid = $this->getGraphID($switch, $port); if (!$gid) { return false; } $xport_meta = array(); //2nd use rrdtool_function_xport on this graph return rrdtool_function_xport($gid, null, array("graph_start" => $from, "graph_end" => $to), $xport_meta); }
$graph_data_array["graph_nolegend"] = get_request_var("graph_nolegend"); } /* print RRDTool graph source? */ if (!empty($_GET["show_source"])) { $graph_data_array["print_source"] = get_request_var("show_source"); } $graph_info = db_fetch_row("SELECT * FROM graph_templates_graph WHERE local_graph_id='" . get_request_var("local_graph_id") . "'"); /* for bandwidth, NThPercentile */ $xport_meta = array(); /* Get graph export */ //echo "<pre>"; //echo $_GET["local_graph_id"]; //echo get_request_var("rra_id"); //print_r($graph_data_array); //print_r($xport_meta); $xport_array = @rrdtool_function_xport($_GET["local_graph_id"], get_request_var("rra_id"), $graph_data_array, $xport_meta); //echo "\n<br />"; //print_r($xport_array); //die; /* Make graph title the suggested file name */ if (is_array($xport_array["meta"])) { $filename = $xport_array["meta"]["title_cache"] . ".csv"; } else { $filename = "graph_export.csv"; } header("Content-type: application/vnd.ms-excel"); if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { header("Pragma: cache"); } header("Cache-Control: max-age=15"); if (!isset($_GET["stdout"])) {
function html_graph_thumbnail_area(&$graph_array, $no_graphs_message = "", $extra_url_args = "", $header = "", $columns = 0, $graphStart = 0, $graphEnd = 0) { global $config; $i = 0; $k = 0; $j = 0; $num_graphs = sizeof($graph_array); if ($columns == 0) { $columns = read_graph_config_option('num_columns'); } if ($num_graphs > 0) { if ($header != "") { print $header; } $start = true; foreach ($graph_array as $graph) { if (isset($graph["graph_template_name"])) { if (isset($prev_graph_template_name)) { if ($prev_graph_template_name != $graph["graph_template_name"]) { $prev_graph_template_name = $graph["graph_template_name"]; } } else { $prev_graph_template_name = $graph["graph_template_name"]; } } elseif (isset($graph["data_query_name"])) { if (isset($prev_data_query_name)) { if ($prev_data_query_name != $graph["data_query_name"]) { $print = true; $prev_data_query_name = $graph["data_query_name"]; } else { $print = false; } } else { $print = true; $prev_data_query_name = $graph["data_query_name"]; } if ($print) { if (!$start) { while ($i % $columns != 0) { print "<td align='center' width='" . ceil(100 / $columns) . "%'></td>"; $i++; } print "</tr>"; } print "<tr style='background-color:#a9b7cb;'>\n\t\t\t\t\t\t\t<td style='background-color:#a9b7cb;' colspan='{$columns}' class='textHeaderDark'><strong>Data Query:</strong> " . $graph["data_query_name"] . "</td>\n\t\t\t\t\t\t</tr>"; $i = 0; } } if ($i == 0) { print "<tr style='background-color: #" . ($j % 2 == 0 ? "F2F2F2" : "FFFFFF") . ";'>"; $start = false; } ?> <?php $graph_data_array = array("graph_start" => $graphStart, "graph_end" => $graphEnd); $xport_meta = array(); $data = @rrdtool_function_xport($graph["local_graph_id"], 0, $graph_data_array, $xport_meta); ?> <td align='center' width='<?php print ceil(100 / $columns); ?> %'> <table align='center' cellpadding='0'> <tr> <td align='center'> <div style="min-height: <?php echo 1.6 * read_graph_config_option("default_height") . "px"; ?> ;"><a href='<?php print htmlspecialchars($config['url_path'] . "graph.php?action=view&rra_id=all&local_graph_id=" . $graph["local_graph_id"]); ?> '><img class='graphimage' id='graph_<?php print $graph["local_graph_id"]; ?> ' src='<?php print htmlspecialchars($config['url_path'] . "graph_image.php?local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&graph_height=" . read_graph_config_option("default_height") . "&graph_width=" . read_graph_config_option("default_width") . "&graph_nolegend=true&title_font_size=" . (read_graph_config_option("custom_fonts") == "on" ? read_graph_config_option("title_size") : read_config_option("title_size")) . ($extra_url_args == "" ? "" : "&{$extra_url_args}")); ?> ' border='0' alt='<?php print htmlspecialchars($graph["title_cache"], ENT_QUOTES); ?> '></a></div> <?php print read_graph_config_option("show_graph_title") == "on" ? "<p style='font-size: 10;' align='center'><strong>" . htmlspecialchars($graph["title_cache"], ENT_QUOTES) . "</strong></p>" : ""; ?> </td> <td valign='top' style='align: left; padding: 3px;'> <a href='<?php print htmlspecialchars($config['url_path'] . "graph.php?action=zoom&local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&" . $extra_url_args); ?> '><img src='<?php print $config['url_path']; ?> images/graph_zoom.gif' border='0' alt='Zoom Graph' title='Zoom Graph' style='padding: 3px;'></a><br> <a href='<?php print htmlspecialchars($config['url_path'] . "graph_xport.php?local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&" . $extra_url_args); ?> '><img src='<?php print $config['url_path']; ?> images/graph_query.png' border='0' alt='CSV Export' title='CSV Export' style='padding: 3px;'></a><br> <a href='<?php print htmlspecialchars($config['url_path'] . "graph.php?action=properties&local_graph_id=" . $graph["local_graph_id"] . "&rra_id=0&" . $extra_url_args); ?> '><img src='<?php print $config['url_path']; ?> images/graph_properties.gif' border='0' alt='Graph Source/Properties' title='Graph Source/Properties' style='padding: 3px;'></a><br> <?php api_plugin_hook('graph_buttons_thumbnails', array('hook' => 'graphs_thumbnails', 'local_graph_id' => $graph['local_graph_id'], 'rra' => 0, 'view_type' => '')); ?> <a href='#page_top'><img src='<?php print $config['url_path'] . "images/graph_page_top.gif"; ?> ' border='0' alt='Page Top' title='Page Top' style='padding: 3px;'></a><br> </td> </tr> <tr> <td colspan="2" class="graph-detail"> <table id="graph-detail-<?php echo $graph["local_graph_id"]; ?> " class="datatable-display" cellspacing="0" width="100%"> <thead> <tr> <th>Time</th> <?php foreach ($data["meta"]["legend"] as $value) { ?> <th><?php echo $value; ?> </th> <?php } ?> </tr> </thead> <tbody> <?php // print_r($data) ?> <?php foreach ($data["data"] as $record) { ?> <tr> <?php $echoTime = false; ?> <?php foreach ($record as $key => $val) { ?> <?php if (!$echoTime) { echo "<td>"; if (array_key_exists("timestamp", $record)) { echo "<span title='" . date("Y-m-d H:i:s", $record['timestamp']) . "'>" . date("H:i:s", $record['timestamp']) . "</span>"; } $echoTime = true; echo "</td>"; ?> <?php } elseif ($key != "timestamp") { ?> <td><?php echo $val; ?> </td> <?php } ?> <?php } ?> </tr> <?php } ?> </tbody> </table> </td> </tr> </table> </td> <?php $i++; $k++; if ($i % $columns == 0 && $k < $num_graphs) { $i = 0; $j++; print "</tr>"; $start = true; } } if (!$start) { while ($i % $columns != 0) { print "<td align='center' width='" . ceil(100 / $columns) . "%'></td>"; $i++; } print "</tr>"; } } else { if ($no_graphs_message != "") { print "<td><em>{$no_graphs_message}</em></td>"; } } }
if (!empty($_GET["graph_width"]) && $_GET["graph_width"] < 3000) { $graph_data_array["graph_width"] = $_GET["graph_width"]; } /* override: skip drawing the legend? */ if (!empty($_GET["graph_nolegend"])) { $graph_data_array["graph_nolegend"] = $_GET["graph_nolegend"]; } /* print RRDTool graph source? */ if (!empty($_GET["show_source"])) { $graph_data_array["print_source"] = $_GET["show_source"]; } $graph_info = db_fetch_row("SELECT * FROM graph_templates_graph WHERE local_graph_id='" . $_REQUEST["local_graph_id"] . "'"); /* for bandwidth, NThPercentile */ $xport_meta = array(); /* Get graph export */ $xport_array = rrdtool_function_xport($_GET["local_graph_id"], $_GET["rra_id"], $graph_data_array, $xport_meta); /* Make graph title the suggested file name */ if (is_array($xport_array["meta"])) { $filename = $xport_array["meta"]["title_cache"] . ".csv"; } else { $filename = "graph_export.csv"; } header("Content-type: application/vnd.ms-excel"); header("Cache-Control: max-age=15"); header("Content-Disposition: attachment; filename=\"" . $filename . "\""); if (is_array($xport_array["meta"])) { print '"Title:","' . $xport_array["meta"]["title_cache"] . '"' . "\n"; print '"Vertical Label:","' . $xport_array["meta"]["vertical_label"] . '"' . "\n"; print '"Start Date:","' . date("Y-m-d H:i:s", $xport_array["meta"]["start"]) . '"' . "\n"; print '"End Date:","' . date("Y-m-d H:i:s", $xport_array["meta"]["end"]) . '"' . "\n"; print '"Step:","' . $xport_array["meta"]["step"] . '"' . "\n";
} /* override: skip drawing the legend? */ if (!empty($_REQUEST['graph_nolegend'])) { $graph_data_array['graph_nolegend'] = get_request_var_request('graph_nolegend'); } /* print RRDTool graph source? */ if (!empty($_REQUEST['show_source'])) { $graph_data_array['print_source'] = get_request_var_request('show_source'); } $graph_info = db_fetch_row_prepared('SELECT * FROM graph_templates_graph WHERE local_graph_id = ?', array(get_request_var_request('local_graph_id'))); /* for bandwidth, NThPercentile */ $xport_meta = array(); /* tell function we are csv */ $graph_data_array['export_csv'] = true; /* Get graph export */ $xport_array = rrdtool_function_xport($_REQUEST['local_graph_id'], get_request_var_request('rra_id'), $graph_data_array, $xport_meta); /* Make graph title the suggested file name */ if (is_array($xport_array['meta'])) { $filename = $xport_array['meta']['title_cache'] . '.csv'; } else { $filename = 'graph_export.csv'; } header('Content-type: application/vnd.ms-excel'); if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { header('Pragma: cache'); } header('Cache-Control: max-age=15'); if (!isset($_REQUEST['stdout'])) { header('Content-Disposition: attachment; filename="' . $filename . '"'); } if (is_array($xport_array['meta'])) {