mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Add procedure management
This commit is contained in:
@@ -26,6 +26,7 @@ if(defined('show_settings')) {
|
||||
$current_severity = isset($widget_settings['severity']) ? $widget_settings['severity'] : '';
|
||||
$current_state = isset($widget_settings['state']) ? $widget_settings['state'] : '';
|
||||
$current_group = isset($widget_settings['group']) ? $widget_settings['group'] : '';
|
||||
$current_proc = isset($widget_settings['proc']) ? $widget_settings['proc'] : '';
|
||||
|
||||
$common_output[] = '
|
||||
<form class="form" onsubmit="widget_settings(this); return false;">
|
||||
@@ -94,6 +95,20 @@ if(defined('show_settings')) {
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col-sm-4">
|
||||
<label for="proc" class="control-label">Show Doc field: </label>
|
||||
</div>
|
||||
<div class="col-sm-8">
|
||||
<select class="form-control" name="proc">';
|
||||
|
||||
$common_output[] = '<option value="1"'.($current_proc == '1' ? ' selected' : ' ').'>show</option>';
|
||||
$common_output[] = '<option value="0"'.($current_proc == '0' ? ' selected' : ' ').'>hide</option>';
|
||||
|
||||
$common_output[] = '
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-12">
|
||||
@@ -109,6 +124,7 @@ else {
|
||||
$state = $widget_settings['state'];
|
||||
$min_severity = $widget_settings['min_severity'];
|
||||
$group = $widget_settings['group'];
|
||||
$proc = $widget_settings['proc'];
|
||||
|
||||
$title = "Alerts";
|
||||
|
||||
@@ -165,7 +181,11 @@ else {
|
||||
<th data-column-id="hostname">Hostname</th>
|
||||
<th data-column-id="timestamp">Timestamp</th>
|
||||
<th data-column-id="severity">Severity</th>
|
||||
<th data-column-id="ack" data-formatter="ack" data-sortable="false">Acknowledge</th>
|
||||
<th data-column-id="ack" data-formatter="ack" data-sortable="false">Acknowledge</th>';
|
||||
if (is_numeric($proc)) {
|
||||
if ($proc) { $common_output[] = '<th data-column-id="proc" data-formatter="proc" data-sortable="false">Procedure</th>'; }
|
||||
}
|
||||
$common_output[] = '
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
@@ -192,6 +212,9 @@ var alerts_grid = $("#alerts_'.$unique_id.'").bootgrid({
|
||||
if (is_numeric($group)) {
|
||||
$common_output[]="group: '$group',\n";
|
||||
}
|
||||
if (is_numeric($proc)) {
|
||||
$common_output[]="proc: '$proc',\n";
|
||||
}
|
||||
|
||||
$common_output[]='
|
||||
device_id: \'' . $device['device_id'] .'\'
|
||||
@@ -204,7 +227,10 @@ var alerts_grid = $("#alerts_'.$unique_id.'").bootgrid({
|
||||
},
|
||||
"ack": function(column,row) {
|
||||
return "<button type=\'button\' class=\'btn btn-"+row.ack_col+" btn-sm command-ack-alert\' data-target=\'#ack-alert\' data-state=\'"+row.state+"\' data-alert_id=\'"+row.alert_id+"\' name=\'ack-alert\' id=\'ack-alert\' data-extra=\'"+row.extra+"\'><span class=\'glyphicon glyphicon-"+row.ack_ico+"\'aria-hidden=\'true\'></span></button>";
|
||||
}
|
||||
},
|
||||
"proc": function(column,row) {
|
||||
return "<button type=\'button\' class=\'btn command-open-proc\' data-alert_id=\'"+row.alert_id+"\' name=\'open-proc\' id=\'open-proc\'>Test</button>";
|
||||
}
|
||||
},
|
||||
templates: {
|
||||
}
|
||||
@@ -219,9 +245,9 @@ var alerts_grid = $("#alerts_'.$unique_id.'").bootgrid({
|
||||
alerts_grid.find(".incident").each( function() {
|
||||
$(this).parent().addClass(\'col-lg-4 col-md-4 col-sm-4 col-xs-4\');
|
||||
$(this).parent().parent().on("mouseenter", function() {
|
||||
$(this).find(".incident-toggle").fadeIn(200);
|
||||
$(this).find(".incident-toggle").fadeIn(400);
|
||||
}).on("mouseleave", function() {
|
||||
$(this).find(".incident-toggle").fadeOut(200);
|
||||
$(this).find(".incident-toggle").fadeOut(400);
|
||||
}).on("click", "td:not(.incident-toggle-td)", function() {
|
||||
var target = $(this).parent().find(".incident-toggle").data("target");
|
||||
if( $(this).parent().find(".incident-toggle").hasClass(\'glyphicon-plus\') ) {
|
||||
@@ -230,6 +256,22 @@ var alerts_grid = $("#alerts_'.$unique_id.'").bootgrid({
|
||||
}
|
||||
});
|
||||
});
|
||||
alerts_grid.find(".command-open-proc").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
var alert_id = $(this).data("alert_id");
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "ajax_form.php",
|
||||
data: { type: "open-proc", alert_id: alert_id },
|
||||
success: function(msg){
|
||||
window.open("procs/"+msg);
|
||||
// $("#message").html(\'<div class="alert alert-info">Opening \'+msg+\'</div>\');
|
||||
},
|
||||
error: function(){
|
||||
$("#message").html(\'<div class="alert alert-info">An error occurred opening procedure for this alert. Does the procedure exists ?</div>\');
|
||||
}
|
||||
});
|
||||
});
|
||||
alerts_grid.find(".command-ack-alert").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
var alert_id = $(this).data("alert_id");
|
||||
|
@@ -26,10 +26,15 @@ $interval = mres($_POST['interval']);
|
||||
$mute = mres($_POST['mute']);
|
||||
$invert = mres($_POST['invert']);
|
||||
$name = mres($_POST['name']);
|
||||
if ($_POST['proc'] != "") { $proc = $_POST['proc']; }
|
||||
else { $proc = "noproc.pdf"; }
|
||||
|
||||
if (empty($rule)) {
|
||||
$update_message = 'ERROR: No rule was generated - did you forget to click and / or?';
|
||||
}
|
||||
else if (! file_exists ("procs/".$proc)) {
|
||||
$update_message = 'ERROR: Procedure \''.$proc.'\' doesn\'t exists in procs directory';
|
||||
}
|
||||
else if (validate_device_id($_POST['device_id']) || $_POST['device_id'] == '-1' || $_POST['device_id'][0] == ':') {
|
||||
$device_id = $_POST['device_id'];
|
||||
if (!is_numeric($count)) {
|
||||
@@ -61,7 +66,7 @@ else if (validate_device_id($_POST['device_id']) || $_POST['device_id'] == '-1'
|
||||
);
|
||||
$extra_json = json_encode($extra);
|
||||
if (is_numeric($alert_id) && $alert_id > 0) {
|
||||
if (dbUpdate(array('rule' => $rule, 'severity' => mres($_POST['severity']), 'extra' => $extra_json, 'name' => $name), 'alert_rules', 'id=?', array($alert_id)) >= 0) {
|
||||
if (dbUpdate(array('rule' => $rule, 'severity' => mres($_POST['severity']), 'extra' => $extra_json, 'name' => $name, 'proc' => $proc), 'alert_rules', 'id=?', array($alert_id)) >= 0) {
|
||||
$update_message = "Edited Rule: <i>$name: $rule</i>";
|
||||
}
|
||||
else {
|
||||
@@ -73,7 +78,7 @@ else if (validate_device_id($_POST['device_id']) || $_POST['device_id'] == '-1'
|
||||
$device_id = ':'.$device_id;
|
||||
}
|
||||
|
||||
if (dbInsert(array('device_id' => $device_id, 'rule' => $rule, 'severity' => mres($_POST['severity']), 'extra' => $extra_json, 'disabled' => 0, 'name' => $name), 'alert_rules')) {
|
||||
if (dbInsert(array('device_id' => $device_id, 'rule' => $rule, 'severity' => mres($_POST['severity']), 'extra' => $extra_json, 'disabled' => 0, 'name' => $name, 'proc' => $proc), 'alert_rules')) {
|
||||
$update_message = "Added Rule: <i>$name: $rule</i>";
|
||||
if (is_array($_POST['maps'])) {
|
||||
foreach ($_POST['maps'] as $target) {
|
||||
|
@@ -28,6 +28,7 @@ if (is_numeric($alert_id) && $alert_id > 0) {
|
||||
'severity' => $rule['severity'],
|
||||
'extra' => $rule['extra'],
|
||||
'name' => $rule['name'],
|
||||
'proc' => $rule['proc'],
|
||||
'rules' => $rule_split,
|
||||
);
|
||||
header('Content-type: application/json');
|
||||
|
@@ -134,6 +134,12 @@ if(is_admin() !== false) {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<label for='proc' class='col-sm-3 control-label'>Doc name: </label>
|
||||
<div class='col-sm-9'>
|
||||
<input type='text' id='proc' name='proc' class='form-control' maxlength='30'>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-3 col-sm-3">
|
||||
<button class="btn btn-success btn-sm" type="submit" name="rule-submit" id="rule-submit" value="save">Save Rule</button>
|
||||
@@ -219,6 +225,7 @@ $('#create-alert').on('show.bs.modal', function (event) {
|
||||
$("[name='mute']").bootstrapSwitch('state',extra['mute']);
|
||||
$("[name='invert']").bootstrapSwitch('state',extra['invert']);
|
||||
$('#name').val(output['name']);
|
||||
$('#proc').val(output['proc']);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user