Name
sn_em_ai.EvtMgmtProcessFeedback
Description
Process feedback for alerts. Currently applies to Log Analytics alerts only.
Script
var EvtMgmtProcessFeedback = Class.create();
EvtMgmtProcessFeedback.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
initialize: function(request, responseXML, gc) {
global.AbstractAjaxProcessor.prototype.initialize.call(this, request, responseXML, gc);
this.alertUtilsSnc = new global.EvtMgmtAlertUtilsSNC();
this.EXTRA_DATA_TABLE = "em_alert_extra_data";
this.OCCULTUS_USER_FEEDBACK_TABLE = "sn_occ_user_feedback";
this.ALERT_TABLE = "em_alert";
this.USER_TABLE = "sys_user";
this.USER_NAME = "user_name";
this.SIGNIFICANT = "2";
this.MUTED = "1";
this.RAISED = "Raised";
if (this.occultusScopedAppExists())
this.occultus = new sn_occ.OccultusAlertOperationHandler();
else {
gs.error(gs.getMessage("Health Log Analytics Core scoped app is not installed"));
this.occultus = null;
}
},
type: 'EvtMgmtProcessFeedback',
thumbUp: function() {
var alertGr = this.getAlert();
var userName = this.getUsername();
if (this.occultus) {
this.occultus.thumbUp(userName, alertGr);
this.setAppliedFeedback(alertGr, this.SIGNIFICANT);
this.updateWorkNotesOnAlert(alertGr, gs.getMessage("The alert was marked as significant"));
return alertGr.update();
}
return false;
},
unThumbUp: function() {
var alertGr = this.getAlert();
if (this.occultus) {
this.occultus.unThumbUp(alertGr);
this.setAppliedFeedback(alertGr, "");
this.updateWorkNotesOnAlert(alertGr, gs.getMessage("Feedback removed: the alert was unmarked as significant"));
return alertGr.update();
}
return false;
},
mute: function() {
var alertGr = this.getAlert();
if (this.occultus) {
if (this.occultus.mute(alertGr, this.getParameter('is_global_mute'))) {
this.setAppliedFeedback(alertGr, this.MUTED);
// close alert (its children will be closed automatically as well)
alertGr.state = "Closed";
this.updateWorkNotesOnAlert(alertGr, gs.getMessage("The alert was muted"));
return alertGr.update();
} else {
gs.addErrorMessage(gs.getMessage("Mute action failed. Please contact support."));
}
}
return false;
},
unMute: function() {
var alertGr = this.getAlert();
if (this.occultus) {
if (this.occultus.unMute(alertGr)) {
this.setAppliedFeedback(alertGr, "");
this.updateWorkNotesOnAlert(alertGr, gs.getMessage("Feedback removed: the alert was unmuted"));
return alertGr.update();
} else {
gs.addErrorMessage(gs.getMessage("Restore ML feedback failed. Please contact support."));
}
}
return false;
},
occultusScopedAppExists: function() {
var scopedAppGr = new GlideRecordSecure(this.OCCULTUS_USER_FEEDBACK_TABLE);
return scopedAppGr.isValid();
},
updateWorkNotesOnAlert: function(alertGr, message) {
// Calling global Java objects from scoped app via the SNC bridge script
this.alertUtilsSnc.updateWorkNotesOnAlert(alertGr, message);
},
setAppliedFeedback: function(alertGr, feedback) {
var gr = new GlideRecordSecure(this.EXTRA_DATA_TABLE);
gr.addQuery("alert", alertGr.getValue('sys_id'));
gr.query();
if (gr.next()) {
gr.setValue("applied_feedback", feedback);
gr.update();
}
},
getAlert: function() {
var alertSysId = this.getParameter('sysparm_alert');
var gr = new GlideRecordSecure(this.ALERT_TABLE);
gr.get(alertSysId);
return gr;
},
getUsername: function() {
var userNameSysId = this.getParameter('sysparm_user_name');
var gr = new GlideRecordSecure(this.USER_TABLE);
gr.get(userNameSysId);
return gr.getValue(this.USER_NAME);
},
raise: function() {
var alertGr = this.getAlert();
if (this.occultus) {
if (this.occultus.raise(alertGr)) {
this.setAppliedFeedback(alertGr, this.RAISED);
this.updateWorkNotesOnAlert(alertGr, gs.getMessage("The metric threshold was raised"));
return alertGr.update();
} else {
gs.addErrorMessage(gs.getMessage("Raise action failed. Please contact support."));
}
}
return false;
},
unRaise: function() {
var alertGr = this.getAlert();
if (this.occultus) {
if (this.occultus.unRaise(alertGr)) {
this.setAppliedFeedback(alertGr, "");
this.updateWorkNotesOnAlert(alertGr, gs.getMessage("Feedback removed: the alert was unraised"));
return alertGr.update();
} else {
gs.addErrorMessage(gs.getMessage("Restore ML feedback failed. Please contact support."));
}
}
return false;
},
});
Sys ID
12cca6205b4b101087bc47eeb681c793