diff --git a/html/ajax_dash.php b/html/ajax_dash.php index e25994282..3b4c56e46 100644 --- a/html/ajax_dash.php +++ b/html/ajax_dash.php @@ -33,6 +33,8 @@ if ($type == 'placeholder') { } elseif (is_file('includes/common/'.$type.'.inc.php')) { + $results_limit = 10; + $no_form = true; include 'includes/common/'.$type.'.inc.php'; $output = implode('', $common_output); $status = 'ok'; diff --git a/html/includes/common/graylog.inc.php b/html/includes/common/graylog.inc.php new file mode 100644 index 000000000..0d24e8406 --- /dev/null +++ b/html/includes/common/graylog.inc.php @@ -0,0 +1,125 @@ + + * + * 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. + */ + +if (empty($results_limit)) { + $results_limit = 25; +} +$tmp_output = '

Graylog

+ +
+ + + + + + + + + + +
TimestampSourceMessageFacilityLevel
+
+ + + +'; + +$common_output[] = $tmp_output; diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 54b51213f..14aa08ca8 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -77,9 +77,17 @@ if ($_SESSION['userlevel'] >= '10') {
  • Eventlog
  • - Syslog'); -} ?> + Syslog'; +} + +if (isset($config['graylog']['server']) && isset($config['graylog']['port'])) { + echo '
  • Graylog
  • '; +} + +?>
  • Inventory
  • diff --git a/html/includes/table/graylog.inc.php b/html/includes/table/graylog.inc.php new file mode 100644 index 000000000..88165e9fe --- /dev/null +++ b/html/includes/table/graylog.inc.php @@ -0,0 +1,64 @@ + + * + * 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.'"'; +} +else { + $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 .= ' && '; + } + $query .= 'source:"'.$filter_hostname.'"'; +} + +$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( + 'header' => "Authorization: Basic " . base64_encode($config['graylog']['username'].':'.$config['graylog']['password']) + ) +)); + +$messages = json_decode(file_get_contents($graylog_url, false, $context),true); + +foreach ($messages['messages'] as $message) { + $response[] = array( + 'timestamp' => $message['message']['timestamp'], + 'source' => $message['message']['source'], + 'message' => $message['message']['message'], + 'facility' => $message['message']['facility'], + 'level' => $message['message']['level'], + ); +} + +$total = $messages['total_results']; + +$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total); +echo _json_encode($output); diff --git a/html/pages/device/logs.inc.php b/html/pages/device/logs.inc.php index 11fd6914b..81fea25a1 100644 --- a/html/pages/device/logs.inc.php +++ b/html/pages/device/logs.inc.php @@ -30,9 +30,21 @@ if (isset($config['enable_syslog']) && $config['enable_syslog'] == 1) { } } +if (isset($config['graylog']['server']) && isset($config['graylog']['port'])) { + echo ' | '; + if ($vars['section'] == 'graylog') { + echo ''; + } + echo generate_link('Graylog', $vars, array('section' => 'graylog')); + if ($vars['section'] == 'graylog') { + echo ''; + } +} + switch ($vars['section']) { case 'syslog': case 'eventlog': + case 'graylog': include 'pages/device/logs/'.$vars['section'].'.inc.php'; break; diff --git a/html/pages/graylog.inc.php b/html/pages/graylog.inc.php new file mode 100644 index 000000000..78d59ec64 --- /dev/null +++ b/html/pages/graylog.inc.php @@ -0,0 +1,4 @@ +