forked from librenms/librenms
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
alert: Added ability to make notes for acking alerts + record who did…
… so (librenms#8433) * alert: Added ability to make notes for acking alerts + record who did so * Updated schema * moved sql file * Updated from comments in PR * warning changed to blue * reset notes + keep notes on ack
- Loading branch information
1 parent
c26a13d
commit b7c92ee
Showing
12 changed files
with
229 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* alert-notes.inc.php | ||
* | ||
* LibreNMS alert-notes.inc.php | ||
* | ||
* 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 2018 Neil Lathwood | ||
* @author Neil Lathwood <gh+n@laf.io> | ||
*/ | ||
|
||
header('Content-type: application/json'); | ||
|
||
$alert_id = $vars['alert_id']; | ||
$sub_type = $vars['sub_type']; | ||
$note = $vars['note'] ?: ''; | ||
$status = 'error'; | ||
|
||
if (is_numeric($alert_id)) { | ||
if ($sub_type === 'get_note') { | ||
$note = dbFetchCell("SELECT `note` FROM `alerts` WHERE `id` = ?", [$alert_id]); | ||
$message = 'Alert note retrieved'; | ||
$status = 'ok'; | ||
} else { | ||
if (dbUpdate(['note' => $note], 'alerts', '`id` = ?', [$alert_id])) { | ||
$status = 'ok'; | ||
$message = 'Note updated'; | ||
} else { | ||
$message = 'Could not update note'; | ||
} | ||
} | ||
} else { | ||
$message = 'Invalid alert id'; | ||
} | ||
die(json_encode([ | ||
'status' => $status, | ||
'message' => $message, | ||
'note' => $note, | ||
])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<form> | ||
<div class="modal fade" id="alert_notes_modal" tabindex="-1" role="dialog" aria-labelledby="alert_notes" 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="alert_notes">Alert notes</h5> | ||
</div> | ||
<div class="modal-body"> | ||
<div class="row"> | ||
<div class='col-sm-12'> | ||
<div class="form-group"> | ||
<textarea class="form-control" id="note" name="note" rows="15"></textarea> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class='col-sm-12'> | ||
<div class="form-group"> | ||
<input type="hidden" id="alert_id" name="alert_id" value=""> | ||
<button class="btn btn-success" id="save-alert-notes" name="save-alert-notes">Save notes</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
<script> | ||
$('#alert_notes_modal').on('show.bs.modal', function (event) { | ||
var alert_id = $("#alert_id").val(); | ||
$.ajax({ | ||
type: "POST", | ||
url: "ajax_form.php", | ||
data: { type: "alert-notes", alert_id: alert_id, sub_type: 'get_note'}, | ||
dataType: "json", | ||
success: function (data) { | ||
$("#note").val(data.note); | ||
} | ||
}); | ||
}); | ||
$("#save-alert-notes").click('', function(event) { | ||
event.preventDefault(); | ||
var alert_id = $("#alert_id").val(); | ||
var note = $("#note").val(); | ||
$.ajax({ | ||
type: "POST", | ||
url: "ajax_form.php", | ||
data: { type: "alert-notes", alert_id: alert_id, sub_type: 'set_note', note: note}, | ||
dataType: "json", | ||
success: function (data) { | ||
if (data.status == 'ok') { | ||
toastr.success(data.message); | ||
$("#alert_notes_modal").modal('hide'); | ||
} else { | ||
toastr.error(data.message); | ||
} | ||
}, | ||
error: function() { | ||
toastr.error(data.message); | ||
} | ||
}); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE `alerts` ADD `note` TEXT NOT NULL AFTER `open`; |