mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
113 lines
5.0 KiB
PHP
113 lines
5.0 KiB
PHP
<?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 <[email protected]>
|
|
*/
|
|
|
|
if (is_admin() === false) {
|
|
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">
|
|
<div class="modal-dialog modal-lg">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
|
<h5 class="modal-title" id="search_rule">Alert rule collection</h5>
|
|
</div>
|
|
<div class="modal-body">
|
|
<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({
|
|
caseSensitive: false,
|
|
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";
|
|
}
|
|
},
|
|
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>"
|
|
}
|
|
}).on("loaded.rs.jquery.bootgrid", function()
|
|
{
|
|
grid.find(".rule_from_collection").on("click", function(e) {
|
|
var template_rule_id = $(this).data("rule_id");
|
|
$.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');
|
|
}
|
|
});
|
|
}).end();
|
|
});
|
|
</script>
|
|
</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>
|