2016-10-26 06:54:48 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* search_rule_collection.inc.php
|
|
|
|
*
|
|
|
|
* LibreNMS search_rule_collection modal
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
*/
|
|
|
|
|
2018-04-07 15:55:28 -05:00
|
|
|
use LibreNMS\Authentication\Auth;
|
|
|
|
|
|
|
|
if (!Auth::user()->hasGlobalAdmin()) {
|
2016-10-26 06:54:48 +00:00
|
|
|
die('ERROR: You need to be admin');
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<div class="modal fade" id="search_rule_modal" tabindex="-1" role="dialog" aria-labelledby="search_rule" aria-hidden="true">
|
2018-03-14 20:25:19 +00:00
|
|
|
<div class="modal-dialog modal-lg">
|
2016-10-26 06:54:48 +00:00
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
2017-09-29 21:12:22 +01:00
|
|
|
<h5 class="modal-title" id="search_rule">Alert rule collection</h5>
|
2016-10-26 06:54:48 +00:00
|
|
|
</div>
|
|
|
|
<div class="modal-body">
|
2017-09-29 21:12:22 +01:00
|
|
|
<div class="table-responsive">
|
|
|
|
<table id="rule_collection" class="table table-condensed table-hover">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th data-column-id="name" data-width="200px">Name</th>
|
|
|
|
<th data-column-id="rule">Rule</th>
|
|
|
|
<td data-column-id="action" data-formatter="action"></td>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<?php
|
|
|
|
$tmp_rule_id = 0;
|
|
|
|
foreach (get_rules_from_json() as $rule) {
|
|
|
|
$rule['rule_id'] = $tmp_rule_id;
|
|
|
|
echo "
|
|
|
|
<tr>
|
|
|
|
<td>{$rule['name']}</td>
|
|
|
|
<td>{$rule['rule']}</td>
|
|
|
|
<td>{$rule['rule_id']}</td>
|
|
|
|
</tr>
|
|
|
|
";
|
|
|
|
$tmp_rule_id++;
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</table>
|
|
|
|
<script>
|
|
|
|
var grid = $("#rule_collection").bootgrid({
|
2018-02-08 08:49:19 -06:00
|
|
|
caseSensitive: false,
|
2017-09-29 21:12:22 +01:00
|
|
|
formatters: {
|
|
|
|
"action": function (column, row) {
|
|
|
|
return "<button type=\"button\" id=\"rule_from_collection\" name=\"rule_from_collection\" data-rule_id=\"" + row.action + "\" class=\"btn btn-sm btn-primary rule_from_collection\">Select</button";
|
|
|
|
}
|
2018-03-14 20:25:19 +00:00
|
|
|
},
|
|
|
|
templates: {
|
|
|
|
footer: "<div id=\"{{ctx.id}}\" class=\"{{css.footer}}\"><div class=\"row\"><div class=\"col-sm-12\"><p class=\"{{css.pagination}}\"></p></div></div></div>"
|
2017-09-29 21:12:22 +01:00
|
|
|
}
|
|
|
|
}).on("loaded.rs.jquery.bootgrid", function()
|
|
|
|
{
|
2018-03-14 20:25:19 +00:00
|
|
|
grid.find(".rule_from_collection").on("click", function(e) {
|
2017-09-29 21:12:22 +01:00
|
|
|
var template_rule_id = $(this).data("rule_id");
|
2018-03-14 20:25:19 +00:00
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: "ajax_form.php",
|
|
|
|
data: {type: 'sql-from-alert-collection', template_id: template_rule_id},
|
|
|
|
dataType: "json",
|
|
|
|
success: function (data) {
|
|
|
|
if (data.status == 'ok') {
|
|
|
|
$("#search_rule_modal").modal('hide');
|
|
|
|
loadRule(data);
|
|
|
|
$('#create-alert').modal('show');
|
|
|
|
} else {
|
|
|
|
toastr.error(data.message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function () {
|
|
|
|
toastr.error('Failed to process template');
|
|
|
|
}
|
|
|
|
});
|
2017-09-29 21:12:22 +01:00
|
|
|
}).end();
|
|
|
|
});
|
|
|
|
</script>
|
2016-10-26 06:54:48 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
$("#search_rule_modal").on('hidden.bs.modal', function(e) {
|
|
|
|
$("#template_rule_id").val('');
|
|
|
|
$("#rule_suggest").val('');
|
|
|
|
$("#rule_display").html('');
|
|
|
|
});
|
|
|
|
</script>
|