mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Feature: Added alerts output to capture system (#4574)
* Feature: Added alerts output to capture system * Renamed $output to $content * removed duplicate functions
This commit is contained in:
committed by
Tony Murray
parent
601074606d
commit
9936aa77ff
@@ -18,6 +18,7 @@ require_once '../includes/definitions.inc.php';
|
||||
require_once 'includes/functions.inc.php';
|
||||
require_once '../includes/functions.php';
|
||||
require_once 'includes/authenticate.inc.php';
|
||||
require_once '../includes/alerts.inc.php';
|
||||
|
||||
set_debug($_REQUEST['debug']);
|
||||
$id = mres($_REQUEST['id']);
|
||||
|
@@ -1343,3 +1343,21 @@ function ipmiSensorName($hardwareId, $sensorIpmi, $rewriteArray)
|
||||
return $sensorIpmi;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filename
|
||||
* @param $content
|
||||
*/
|
||||
function file_download($filename, $content)
|
||||
{
|
||||
$length = strlen($content);
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: text/plain');
|
||||
header("Content-Disposition: attachment; filename=$filename");
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Content-Length: ' . $length);
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Expires: 0');
|
||||
header('Pragma: public');
|
||||
echo $content;
|
||||
}
|
||||
|
@@ -78,16 +78,5 @@ if ($_GET['format'] == 'text') {
|
||||
|
||||
$output = preg_replace('/\033\[[\d;]+m/', '', $output);
|
||||
|
||||
$length = strlen($output);
|
||||
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: text/plain');
|
||||
header("Content-Disposition: attachment; filename=$filename");
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Content-Length: ' . $length);
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Expires: 0');
|
||||
header('Pragma: public');
|
||||
|
||||
echo $output;
|
||||
file_download($filename, $output);
|
||||
}
|
||||
|
68
html/includes/output/query.inc.php
Normal file
68
html/includes/output/query.inc.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* output.php
|
||||
*
|
||||
* runs the requested query and outputs as a file or text
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2016 Neil Lathwood
|
||||
* @author Neil Lathwood <neil@lathwood.co.uk>
|
||||
*/
|
||||
|
||||
if (!is_admin()) {
|
||||
echo("Insufficient Privileges");
|
||||
exit();
|
||||
}
|
||||
|
||||
$hostname = escapeshellcmd($_REQUEST['hostname']);
|
||||
$type = $_REQUEST['type'];
|
||||
|
||||
switch ($type) {
|
||||
case 'alerts':
|
||||
$filename = "alerts-$hostname.txt";
|
||||
$device_id = getidbyname($hostname);
|
||||
$device = device_by_id_cache($device_id);
|
||||
$rules = GetRules($device_id);
|
||||
$output = '';
|
||||
foreach ($rules as $rule) {
|
||||
$sql = GenSQL($rule['rule']);
|
||||
$qry = dbFetchRow($sql, array($device_id));
|
||||
if (is_array($qry)) {
|
||||
$response = 'matches';
|
||||
} else {
|
||||
$response = 'no match';
|
||||
}
|
||||
$output .= 'Rule name: ' . $rule['name'] . PHP_EOL;
|
||||
$output .= 'Alert rule: ' . $rule['rule'] . PHP_EOL;
|
||||
$output .= 'Rule match: ' . $response . PHP_EOL . PHP_EOL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
echo 'You must specify a valid type';
|
||||
exit();
|
||||
}
|
||||
|
||||
// ---- Output ----
|
||||
|
||||
if ($_GET['format'] == 'text') {
|
||||
header("Content-type: text/plain");
|
||||
header('X-Accel-Buffering: no');
|
||||
|
||||
echo $output;
|
||||
} elseif ($_GET['format'] == 'download') {
|
||||
file_download($filename, $output);
|
||||
}
|
@@ -36,6 +36,7 @@ if (!is_admin()) {
|
||||
<li role="presentation" class="active"><a data-toggle="tab" href="#discovery">Discovery</a></li>
|
||||
<li role="presentation"><a data-toggle="tab" href="#poller">Poller</a></li>
|
||||
<li role="presentation"><a data-toggle="tab" href="#snmp">SNMP</a></li>
|
||||
<li role="presentation"><a data-toggle="tab" href="#alerts">Alerts</a></li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<?php
|
||||
@@ -43,6 +44,7 @@ if (!is_admin()) {
|
||||
'discovery' => 'ajax_output.php?id=capture&format=text&type=discovery&hostname='.$device['hostname'],
|
||||
'poller' => 'ajax_output.php?id=capture&format=text&type=poller&hostname='.$device['hostname'],
|
||||
'snmp' => 'ajax_output.php?id=capture&format=text&type=snmpwalk&hostname='.$device['hostname'],
|
||||
'alerts' => 'ajax_output.php?id=query&format=text&type=alerts&hostname='.$device['hostname'],
|
||||
);
|
||||
|
||||
foreach ($tabs as $tab => $url) {
|
||||
|
Reference in New Issue
Block a user