mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
feature: Added new alert rule builder UI and rule mapping UI (#8293)
* 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.
This commit is contained in:
@@ -29,6 +29,14 @@ echo '<div class="panel panel-default panel-condensed">
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
if (isset($_POST['device_id'])) {
|
||||
$default_option = '<option value="' . (int)$_POST['device_id'] . '" selected="selected">';
|
||||
$default_option .= htmlentities($_POST['hostname']) . '</option>';
|
||||
} else {
|
||||
$default_option = '';
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="table-responsive">
|
||||
@@ -55,12 +63,13 @@ echo '<div class="panel panel-default panel-condensed">
|
||||
header: '<div id="{{ctx.id}}" class="{{css.header}}"><div class="row"> \
|
||||
<div class="col-sm-8 actionBar"><span class="pull-left"> \
|
||||
<form method="post" action="" class="form-inline" role="form" id="result_form"> \
|
||||
<input type=hidden name="hostname" id="hostname"> \
|
||||
<div class="form-group"> \
|
||||
<label> \
|
||||
<strong>Device </strong> \
|
||||
</label> \
|
||||
<select name="device_id" id="device_id" class="form-control input-sm" style="min-width: 175px;"> \
|
||||
<option value="">All Devices</option> \
|
||||
<?php echo $default_option; ?> \
|
||||
</select> \
|
||||
</div> \
|
||||
<div class="form-group"> \
|
||||
@@ -118,5 +127,22 @@ echo '<div class="panel panel-default panel-condensed">
|
||||
});
|
||||
});
|
||||
|
||||
<?php echo generate_fill_select_js('hostnames', '#device_id', $_POST['device_id']); ?>
|
||||
$("#device_id").select2({
|
||||
allowClear: true,
|
||||
placeholder: "All Devices",
|
||||
ajax: {
|
||||
url: 'ajax_list.php',
|
||||
delay: 250,
|
||||
data: function (params) {
|
||||
return {
|
||||
type: 'devices',
|
||||
search: params.term,
|
||||
limit: 8,
|
||||
page: params.page || 1
|
||||
};
|
||||
}
|
||||
}
|
||||
}).on('select2:select', function (e) {
|
||||
$('#hostname').val(e.params.data.text);
|
||||
});
|
||||
</script>
|
||||
|
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
require_once 'includes/modal/new_alert_map.inc.php';
|
||||
require_once 'includes/modal/delete_alert_map.inc.php';
|
||||
|
||||
$no_refresh = true;
|
||||
|
||||
echo '<div class="row"><div class="col-sm-12"><span id="message"></span></div></div>';
|
||||
echo '<div class="table-responsive">';
|
||||
echo '<table class="table table-condensed table-hover"><thead><tr>';
|
||||
echo '<th>Rule</th><th>Target</th><th>Actions</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
foreach (dbFetchRows('SELECT alert_map.target,alert_map.id,alert_rules.name FROM alert_map,alert_rules WHERE alert_map.rule=alert_rules.id ORDER BY alert_map.rule ASC') as $link) {
|
||||
if ($link['target'][0] == 'g') {
|
||||
$link['target'] = substr($link['target'], 1);
|
||||
$link['target'] = '<a href="'.generate_url(array('page' => 'devices', 'group' => $link['target'])).'">'.ucfirst(dbFetchCell('SELECT name FROM device_groups WHERE id = ?', array($link['target']))).'</a>';
|
||||
} elseif (is_numeric($link['target'])) {
|
||||
$link['target'] = '<a href="'.generate_url(array('page' => 'device', 'device' => $link['target'])).'">'.dbFetchCell('SELECT hostname FROM devices WHERE device_id = ?', array($link['target'])).'</a>';
|
||||
}
|
||||
|
||||
echo '<tr id="row_'.$link['id'].'">';
|
||||
echo '<td>'.$link['name'].'</td>';
|
||||
echo '<td>'.$link['target'].'</td>';
|
||||
echo '<td>';
|
||||
echo "<button type='button' class='btn btn-primary btn-sm' aria-label='Edit' data-toggle='modal' data-target='#create-map' data-map_id='".$link['id']."' name='edit-alert-map'><i class='fa fa-pencil' aria-hidden='true'></i></button> ";
|
||||
echo "<button type='button' class='btn btn-danger btn-sm' aria-label='Delete' data-toggle='modal' data-target='#confirm-delete' data-map_id='".$link['id']."' name='delete-alert-map'><span class='fa fa-trash' aria-hidden='true'></i></button>";
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
echo '</tbody></table></div>';
|
||||
echo "<button type='button' class='btn btn-primary btn-sm' aria-label='Add' data-toggle='modal' data-target='#create-map' data-map_id='' name='create-alert-map'>Create new Map</button> ";
|
@@ -12,6 +12,4 @@
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
$device['device_id'] = '-1';
|
||||
require_once 'includes/print-alert-rules.php';
|
||||
unset($device['device_id']);
|
||||
|
Reference in New Issue
Block a user