Added bootgrid support for storage page

This commit is contained in:
laf
2015-05-16 16:30:25 +01:00
parent 7e757efb2d
commit 7c5087bacb
3 changed files with 146 additions and 86 deletions

View File

@ -27,7 +27,11 @@ foreach ($periods as $period)
unset($link_array['height'], $link_array['width']);
$link = generate_url($link_array);
if ($return_data === TRUE) {
$graph_data[] = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL);
} else {
echo(overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL));
}
}
?>

View File

@ -0,0 +1,102 @@
<?php
$sql = " FROM `storage` AS `S`, `devices` AS `D` WHERE `S`.`device_id` = `D`.`device_id`";
$count_sql = "SELECT COUNT(`storage_id`) $sql";
$total = dbFetchCell($count_sql,$param);
if (empty($total)) {
$total = 0;
}
if (!isset($sort) || empty($sort)) {
$sort = '`D`.`hostname`, `S`.`storage_descr`';
}
$sql .= " ORDER BY $sort";
if (isset($current)) {
$limit_low = ($current * $rowCount) - ($rowCount);
$limit_high = $rowCount;
}
if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
$sql = "SELECT * $sql";
system("echo '$sql' >> /tmp/testing");
foreach (dbFetchRows($sql,$param) as $drive) {
if (device_permitted($drive['device_id'])) {
$skipdrive = 0;
if ($drive["os"] == "junos") {
foreach ($config['ignore_junos_os_drives'] as $jdrive) {
if (preg_match($jdrive, $drive["storage_descr"])) {
$skipdrive = 1;
}
}
$drive["storage_descr"] = preg_replace("/.*mounted on: (.*)/", "\\1", $drive["storage_descr"]);
}
if ($drive['os'] == "freebsd") {
foreach ($config['ignore_bsd_os_drives'] as $jdrive) {
if (preg_match($jdrive, $drive["storage_descr"])) {
$skipdrive = 1;
}
}
}
if ($skipdrive) {
continue;
}
$perc = round($drive['storage_perc'], 0);
$total = formatStorage($drive['storage_size']);
$free = formatStorage($drive['storage_free']);
$used = formatStorage($drive['storage_used']);
$graph_array['type'] = $graph_type;
$graph_array['id'] = $drive['storage_id'];
$graph_array['from'] = $config['time']['day'];
$graph_array['to'] = $config['time']['now'];
$graph_array['height'] = "20";
$graph_array['width'] = "80";
$graph_array_zoom = $graph_array;
$graph_array_zoom['height'] = "150";
$graph_array_zoom['width'] = "400";
$link = "graphs/id=" . $graph_array['id'] . "/type=" . $graph_array['type'] . "/from=" . $graph_array['from'] . "/to=" . $graph_array['to'] . "/";
$mini_graph = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL);
$bar_link = overlib_link($link, print_percentage_bar (400, 20, $perc, "$used / $total", "ffffff", $background['left'], $free, "ffffff", $background['right']), generate_graph_tag($graph_array_zoom), NULL);
$background = get_percentage_colours($perc);
$response[] = array('device_id' => generate_device_link($drive),
'storage_descr' => $drive['storage_descr'],
'graph' => $mini_graph,
'usage' => $bar_link,
'storage_used' => $perc . "%");
if ($_POST['view'] == "graphs") {
system("echo 'test' >> /tmp/testing");
$graph_array['height'] = "100";
$graph_array['width'] = "216";
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $drive['storage_id'];
$graph_array['type'] = $graph_type;
$return_data = true;
include("includes/print-graphrow.inc.php");
unset($return_data);
$response[] = array('device_id' => $graph_data[0],
'storage_descr' => $graph_data[1],
'graph' => $graph_data[2],
'usage' => $graph_data[3],
'storage_used' => '');
} # endif graphs
}
}
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
echo _json_encode($output);

View File

@ -2,90 +2,44 @@
$graph_type = "storage_usage";
echo("<div style='padding: 5px;'>
<table class='table table-condensed'>");
echo("<tr>
<th>Device</th>
<th>Storage</th>
<th></th>
<th>Usage</th>
<th>Used</th>
</tr>");
foreach (dbFetchRows("SELECT * FROM `storage` AS S, `devices` AS D WHERE S.device_id = D.device_id ORDER BY D.hostname, S.storage_descr") as $drive)
{
if (device_permitted($drive['device_id']))
{
$skipdrive = 0;
if ($drive["os"] == "junos")
{
foreach ($config['ignore_junos_os_drives'] as $jdrive)
{
if (preg_match($jdrive, $drive["storage_descr"]))
{
$skipdrive = 1;
}
}
$drive["storage_descr"] = preg_replace("/.*mounted on: (.*)/", "\\1", $drive["storage_descr"]);
}
if ($drive['os'] == "freebsd")
{
foreach ($config['ignore_bsd_os_drives'] as $jdrive)
{
if (preg_match($jdrive, $drive["storage_descr"]))
{
$skipdrive = 1;
}
}
}
if ($skipdrive) { continue; }
$perc = round($drive['storage_perc'], 0);
$total = formatStorage($drive['storage_size']);
$free = formatStorage($drive['storage_free']);
$used = formatStorage($drive['storage_used']);
$graph_array['type'] = $graph_type;
$graph_array['id'] = $drive['storage_id'];
$graph_array['from'] = $config['time']['day'];
$graph_array['to'] = $config['time']['now'];
$graph_array['height'] = "20";
$graph_array['width'] = "80";
$graph_array_zoom = $graph_array;
$graph_array_zoom['height'] = "150";
$graph_array_zoom['width'] = "400";
$link = "graphs/id=" . $graph_array['id'] . "/type=" . $graph_array['type'] . "/from=" . $graph_array['from'] . "/to=" . $graph_array['to'] . "/";
$mini_graph = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL);
$bar_link = overlib_link($link, print_percentage_bar (400, 20, $perc, "$used / $total", "ffffff", $background['left'], $free, "ffffff", $background['right']), generate_graph_tag($graph_array_zoom), NULL);
$background = get_percentage_colours($perc);
echo("<tr class='health'><td>" . generate_device_link($drive) . "</td><td class=tablehead>" . $drive['storage_descr'] . "</td>
<td>$mini_graph</td>
<td>$bar_link</td><td>$perc"."%</td></tr>");
if ($vars['view'] == "graphs")
{
echo("<tr></tr><tr class='health'><td colspan=5>");
$graph_array['height'] = "100";
$graph_array['width'] = "216";
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $drive['storage_id'];
$graph_array['type'] = $graph_type;
include("includes/print-graphrow.inc.php");
echo("</td></tr>");
} # endif graphs
}
}
echo("</table></div>");
echo $vars['view'];
?>
<div class="table-responsive">
<table id="storage" class="table table-hover table-condensed storage">
<thead>
<tr>
<th data-column-id="device_id">Device</th>
<th data-column-id="storage_descr">Storage</th>
<th data-column-id="graph" data-sortable="false"></th>
<th data-column-id="usage">Usage</th>
<th data-column-id="storage_used">Used</th>
</tr>
</thead>
</table>
</div>
<script>
var grid = $("#storage").bootgrid({
ajax: true,
post: function ()
{
return {
id: "storage",
view: '<?php echo $vars['view']; ?>'
};
},
url: "/ajax_table.php",
formatters: {
"status": function(column,row) {
return "<h4><span class='label label-"+row.extra+" threeqtr-width'>" + row.msg + "</span></h4>";
},
"ack": function(column,row) {
return "<button type='button' class='btn btn-"+row.ack_col+" btn-sm command-ack-alert' data-target='#ack-alert' data-state='"+row.state+"' data-alert_id='"+row.alert_id+"' name='ack-alert' id='ack-alert' data-extra='"+row.extra+"'><span class='glyphicon glyphicon-"+row.ack_ico+"'aria-hidden='true'></span></button>";
}
},
templates: {
}
});
</script>