Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Oxidized basic config search #5333

Merged
merged 3 commits into from Jan 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions html/includes/forms/search-oxidized-config.inc.php
@@ -0,0 +1,31 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2017 Søren Friis Rosiak <sorenrosiak@gmail.com>
* 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.
*/
header('Content-type: application/json');

$status = 'error';
$message = 'unknown error';
$parameters = clean($_POST['search_in_conf_textbox']);
if (isset($parameters)) {
$status = 'ok';
$message = 'Queried';
$output = clean(search_oxidized_config($parameters));
} else {
$status = 'error';
$message = 'ERROR: Could not query';
}

echo _json_encode(array(
'status' => $status,
'message' => $message,
'search_in_conf_textbox' => $parameters,
'output' => $output
));
20 changes: 20 additions & 0 deletions html/includes/functions.inc.php
Expand Up @@ -1362,3 +1362,23 @@ function get_rules_from_json()
global $config;
return json_decode(file_get_contents($config['install_dir'] . '/misc/alert_rules.json'), true);
}

function search_oxidized_config($search_in_conf_textbox)
{
global $config;
$oxidized_search_url = $config['oxidized']['url'] . '/nodes/conf_search?format=json';
$postdata = http_build_query(
array(
'search_in_conf_textbox' => $search_in_conf_textbox,
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
return json_decode(file_get_contents($oxidized_search_url, false, $context), true);
}
6 changes: 6 additions & 0 deletions html/includes/print-menubar.php
Expand Up @@ -89,6 +89,12 @@
<a href="<?php echo(generate_url(array('page'=>'overview'))); ?>"><i class="fa fa-wrench fa-fw fa-lg" aria-hidden="true"></i> Tools</a>
<ul class="dropdown-menu scrollable-menu">
<li><a href="<?php echo(generate_url(array('page'=>'ripenccapi'))); ?>"><i class="fa fa-arrow-circle-up fa-fw fa-lg" aria-hidden="true"></i> RIPE NCC API</a></li>
<?php
if ($config['oxidized']['enabled'] === true && isset($config['oxidized']['url'])) {
echo '<li><a href="'.generate_url(array('page'=>'oxidized')).'"><i class="fa fa-arrow-circle-up fa-fw fa-lg" aria-hidden="true"></i> Oxidized</a></li>';
}

?>
</ul>
</li>
<li role="presentation" class="divider"></li>
Expand Down
55 changes: 55 additions & 0 deletions html/pages/oxidized.inc.php
@@ -0,0 +1,55 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2017 Søren Friis Rosiak <sorenrosiak@gmail.com>
* 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.
*/
$pagetitle[] = 'Oxidized';
?>
<h3> Oxidized - Config Search </h3>
<hr>
<form class="form-horizontal" action="" method="post">
<br />
<div class="input-group">
<input type="text" class="form-control" id="input-parameter" placeholder="service password-encryption etc.">
<span class="input-group-btn">
<button type="submit" name="btn-search" id="btn-search" class="btn btn-primary">Search</button>
</span>
</div>
</form>
<br />
<div id="search-output" class="alert alert-success" style="display: none;"></div>
<br />
<script>
$("[name='btn-search']").on('click', function(event) {
event.preventDefault();
var $this = $(this);
var search_in_conf_textbox = $("#input-parameter").val();
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: {
type: "oxidized-search-config",
search_in_conf_textbox: search_in_conf_textbox
},
dataType: "json",
success: function(data) {
$('#search-output').empty();
$("#search-output").show();
if (data.output)
$('#search-output').append('Config appears on the folllowing device(s):<br />');
$.each(data.output, function(row, value) {
$('#search-output').append(value['full_name'] + '<br />');
});
},
error: function() {
toastr.error('Error');
}
});
});
</script>