Commit 145357c9 authored by CompileNix's avatar CompileNix

add: if subject or template callback function returns false, dismiss the whole message

parent 4ecddf5b
......@@ -69,8 +69,7 @@ class Config {
this.expressions = [
{
match: /" 503 /,
//filter: (/** @type {string} */ line) => { return line.match(/./); },
match: / status:503 /,
subject: (/** @type {any} */ match) => {
return `HTTP ${match[this.defaultMatchingGroupName.StatusCode]} (something we're already fixing...)\n`;
},
......@@ -89,9 +88,10 @@ class Config {
}
},
{
match: /" 5(?!03)\d{2} /, // matches all 5xx status codes, except a 503 (using regex negative lookahead)
//filter: (/** @type {string} */ line) => { return line.match(/./); },
match: / status:5(?!03)\d{2} /, // matches all 5xx status codes, except a 503 (using regex negative lookahead)
//filter: (/** @type {string} */ line) => { return line.match(/./); }, // use custom regex filter instead of this.defaultMatchingGroupName
subject: (/** @type {any} */ match) => {
if (match[this.defaultMatchingGroupName.Path].startsWith("/RequestToIgnore") return false; // return false to ignore/dismiss this message
return `HTTP ${match[this.defaultMatchingGroupName.StatusCode]}\n`;
},
template: (/** @type {any} */ match) => {
......
......@@ -49,19 +49,22 @@ async function notificationQueueWorker() {
message.expression.template = () => oldTemplateValue;
}
if (config.enableEmail) {
let subject = message.expression.subject(match);
let template = message.expression.template(match);
if (subject !== false && template !== false && config.enableEmail) {
await sendMail({
from: config.mailfrom,
to: config.mailto,
subject: `${config.subjectPrefix}${message.expression.subject(match)}`,
text: message.expression.template(match)
subject: `${config.subjectPrefix}${subject}`,
text: template
});
}
const oldSlackOptions = message.expression.slackOptions;
if (config.enableSlack) {
if (subject !== false && template !== false && config.enableSlack) {
let payload = message.expression.slackOptions;
payload.attachments[0].fallback = `${message.expression.subject(match)}${message.expression.template(match)}`;
payload.attachments[0].fallback = `${subject}${template}`;
payload.attachments[0].text = payload.attachments[0].fallback;
payload.attachments[0].ts = Date.now() / 1000;
slack.webhook(payload, (err, response) => {
......@@ -169,4 +172,4 @@ function sleep(/** @type {Number} */ ms) {
setupSlack();
await setupTail(config.filesToWatch);
setInterval(notificationQueueWorker, 1000);
})();
\ No newline at end of file
})();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment