function generate_device_link($device, $text = null, $vars = array(), $start = 0, $end = 0, $escape_text = 1, $overlib = 1) { global $config; if (!$start) { $start = $config['time']['day']; } if (!$end) { $end = $config['time']['now']; } $class = devclass($device); if (!$text) { $text = $device['hostname']; } if (isset($config['os'][$device['os']]['over'])) { $graphs = $config['os'][$device['os']]['over']; } else { if (isset($device['os_group']) && isset($config['os'][$device['os_group']]['over'])) { $graphs = $config['os'][$device['os_group']]['over']; } else { $graphs = $config['os']['default']['over']; } } $url = generate_device_url($device, $vars); // beginning of overlib box contains large hostname followed by hardware & OS details $contents = '<div><span class="list-large">' . $device['hostname'] . '</span>'; if ($device['hardware']) { $contents .= ' - ' . $device['hardware']; } if ($device['os']) { $contents .= ' - ' . mres($config['os'][$device['os']]['text']); } if ($device['version']) { $contents .= ' ' . mres($device['version']); } if ($device['features']) { $contents .= ' (' . mres($device['features']) . ')'; } if (isset($device['location'])) { $contents .= ' - ' . htmlentities($device['location']); } $contents .= '</div>'; foreach ($graphs as $entry) { $graph = $entry['graph']; $graphhead = $entry['text']; $contents .= '<div class="overlib-box">'; $contents .= '<span class="overlib-title">' . $graphhead . '</span><br />'; $contents .= generate_minigraph_image($device, $start, $end, $graph); $contents .= generate_minigraph_image($device, $config['time']['week'], $end, $graph); $contents .= '</div>'; } if ($escape_text) { $text = htmlentities($text); } if ($overlib == 0) { $link = $contents; } else { $link = overlib_link($url, $text, escape_quotes($contents), $class); } if (device_permitted($device['device_id'])) { return $link; } else { return $device['hostname']; } }
<?php /* * LibreNMS front page top devices graph * - Find most utilised devices that have been polled in the last N minutes * * Author: Paul Gear * Copyright (c) 2013 Gear Consulting Pty Ltd <http://libertysys.com.au/> * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. Please see LICENSE.txt at the top level of * the source code distribution for details. */ $minutes = 15; $seconds = $minutes * 60; $top = $config['front_page_settings']['top']['devices']; if (is_admin() === true || is_read() === true) { $query = "\n SELECT *, sum(p.ifInOctets_rate + p.ifOutOctets_rate) as total\n FROM ports as p, devices as d\n WHERE d.device_id = p.device_id\n AND unix_timestamp() - p.poll_time < {$seconds}\n AND ( p.ifInOctets_rate > 0\n OR p.ifOutOctets_rate > 0 )\n GROUP BY d.device_id\n ORDER BY total desc\n LIMIT {$top}\n "; } else { $query = "\n SELECT *, sum(p.ifInOctets_rate + p.ifOutOctets_rate) as total\n FROM ports as p, devices as d, `devices_perms` AS `P`\n WHERE `P`.`user_id` = ? AND `P`.`device_id` = `d`.`device_id` AND\n d.device_id = p.device_id\n AND unix_timestamp() - p.poll_time < {$seconds}\n AND ( p.ifInOctets_rate > 0\n OR p.ifOutOctets_rate > 0 )\n GROUP BY d.device_id\n ORDER BY total desc\n LIMIT {$top}\n "; $param[] = array($_SESSION['user_id']); } //end if echo "<strong>Top {$top} devices (last {$minutes} minutes)</strong>\n"; echo "<table class='simple'>\n"; foreach (dbFetchRows($query, $param) as $result) { echo '<tr class=top10>' . '<td class=top10>' . generate_device_link($result, shorthost($result['hostname'])) . '</td>' . '<td class=top10>' . generate_device_link($result, generate_minigraph_image($result, $config['time']['day'], $config['time']['now'], 'device_bits', 'no', 150, 21, '&', 'top10'), array(), 0, 0, 0) . '</td>' . "</tr>\n"; } echo "</table>\n";
GROUP BY d.device_id ORDER BY total desc LIMIT :count '; } $common_output[] = ' <div class="table-responsive"> <table class="table table-hover table-condensed table-striped bootgrid-table"> <thead> <tr> <th class="text-left">Device</th> <th class="text-left">Total traffic</a></th> </tr> </thead> <tbody> '; foreach (dbFetchRows($query, $params) as $result) { $common_output[] = ' <tr> <td class="text-left">' . generate_device_link($result, shorthost($result['hostname'])) . '</td> <td class="text-left">' . generate_device_link($result, generate_minigraph_image($result, $config['time']['day'], $config['time']['now'], 'device_bits', 'no', 150, 21), array(), 0, 0, 0) . ' </td> </tr> '; } $common_output[] = ' </tbody> </table> </div> '; }
<?php /* * LibreNMS front page top devices graph * - Find most utilised devices that have been polled in the last N minutes * * Copyright (c) 2013 Gear Consulting Pty Ltd <http://libertysys.com.au/> * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. Please see LICENSE.txt at the top level of * the source code distribution for details. */ $minutes = 15; $seconds = $minutes * 60; $top = $config['front_page_settings']['top']['devices']; $query = "\n SELECT *, sum(p.ifInOctets_rate + p.ifOutOctets_rate) as total\n FROM ports as p, devices as d\n WHERE d.device_id = p.device_id\n AND unix_timestamp() - p.poll_time < {$seconds}\n AND ( p.ifInOctets_rate > 0\n OR p.ifOutOctets_rate > 0 )\n GROUP BY d.device_id\n ORDER BY total desc\n LIMIT {$top}\n"; echo "<strong>Top {$top} devices (last {$minutes} minutes)</strong>\n"; echo "<table class='simple'>\n"; foreach (dbFetchRows($query) as $result) { echo "<tr class=top10>" . "<td class=top10>" . generate_device_link($result, shorthost($result['hostname'])) . "</td>" . "<td class=top10>" . generate_device_link($result, generate_minigraph_image($result, $config['time']['day'], $config['time']['now'], "device_bits", "no", 150, 21, '&', "top10"), array(), 0, 0, 0) . "</td>" . "</tr>\n"; } echo "</table>\n";
$query = 'SELECT `last_polled_timetaken`, `hostname`, `last_polled`, `d`.`device_id` FROM `devices` as `d`, `devices_perms` AS `P` WHERE `P`.`user_id` = :user AND `P`.`device_id` = `d`.`device_id` AND unix_timestamp() - UNIX_TIMESTAMP(`last_polled`) < :interval ORDER BY `last_polled_timetaken` ' . $sort_order . ' LIMIT :count'; } } $common_output[] = ' <div class="table-responsive"> <table class="table table-hover table-condensed table-striped bootgrid-table"> <thead> <tr> <th class="text-left">Device</th> <th class="text-left">' . $table_header . '</a></th> </tr> </thead> <tbody>'; foreach (dbFetchRows($query, $params) as $result) { $common_output[] = ' <tr> <td class="text-left">' . generate_device_link($result, shorthost($result['hostname'])) . '</td> <td class="text-left">' . generate_device_link($result, generate_minigraph_image($result, $config['time']['day'], $config['time']['now'], $graph_type, 'no', 150, 21), $graph_params, 0, 0, 0) . '</td> </tr>'; } $common_output[] = ' </tbody> </table> </div>'; }