2015-08-10 13:36:55 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LibreNMS
|
|
|
|
*
|
|
|
|
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
$filter_hostname = mres($_POST['hostname']);
|
|
|
|
$filter_range = mres($_POST['range']);
|
|
|
|
|
|
|
|
if (isset($searchPhrase) && !empty($searchPhrase)) {
|
|
|
|
$query = 'message:"'.$searchPhrase.'"';
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2015-08-10 13:36:55 -07:00
|
|
|
$query = '*';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($current)) {
|
|
|
|
$offset = ($current * $rowCount) - ($rowCount);
|
|
|
|
$limit = $rowCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($rowCount != -1) {
|
|
|
|
$extra_query = "&limit=$limit&offset=$offset";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($filter_hostname)) {
|
|
|
|
if (!empty($query)) {
|
|
|
|
$query .= ' && ';
|
|
|
|
}
|
2015-08-17 10:46:40 +00:00
|
|
|
$ip = gethostbyname($filter_hostname);
|
2016-06-21 20:45:03 +01:00
|
|
|
$device = device_by_name($filter_hostname);
|
2015-08-17 10:46:40 +00:00
|
|
|
$query .= 'source:"'.$filter_hostname.'" || source:"'.$ip.'"';
|
2016-06-22 19:39:47 +01:00
|
|
|
if (isset($device['ip']) && $ip != $device['ip']) {
|
2016-06-21 20:45:03 +01:00
|
|
|
$query .= ' || source:"'.$device['ip'].'"';
|
|
|
|
}
|
2015-08-10 13:36:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$graylog_url = $config['graylog']['server'] . ':' . $config['graylog']['port'] . '/search/universal/relative?query=' . urlencode($query) . '&range='. $filter_range . $extra_query;
|
|
|
|
|
|
|
|
$context = stream_context_create(array(
|
|
|
|
'http' => array(
|
2015-08-11 14:50:05 -07:00
|
|
|
'header' => "Authorization: Basic " . base64_encode($config['graylog']['username'].':'.$config['graylog']['password']) . "\r\n" .
|
|
|
|
"Accept: application/json",
|
2015-08-10 13:36:55 -07:00
|
|
|
)
|
|
|
|
));
|
|
|
|
|
2016-08-18 20:28:22 -05:00
|
|
|
$messages = json_decode(file_get_contents($graylog_url, false, $context), true);
|
2015-08-10 13:36:55 -07:00
|
|
|
|
|
|
|
foreach ($messages['messages'] as $message) {
|
|
|
|
$response[] = array(
|
|
|
|
'timestamp' => $message['message']['timestamp'],
|
2015-08-18 16:52:25 +00:00
|
|
|
'source' => '<a href="'.generate_url(array('page'=>'device', 'device'=>$message['message']['source'])).'">'.$message['message']['source'].'</a>',
|
2015-08-10 13:36:55 -07:00
|
|
|
'message' => $message['message']['message'],
|
|
|
|
'facility' => $message['message']['facility'],
|
|
|
|
'level' => $message['message']['level'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-08-17 10:46:40 +00:00
|
|
|
if (empty($messages['total_results'])) {
|
|
|
|
$total = 0;
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2015-08-17 10:46:40 +00:00
|
|
|
$total = $messages['total_results'];
|
|
|
|
}
|
2015-08-10 13:36:55 -07:00
|
|
|
|
|
|
|
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
|
|
|
|
echo _json_encode($output);
|