Skip to content

Commit

Permalink
chore(deps): Upgrade ms-teams-webhook dependency
Browse files Browse the repository at this point in the history
Fixes #725
  • Loading branch information
Göran Sander committed Aug 17, 2023
1 parent 7a0f00d commit 6e7814a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"moment": "^2.29.4",
"moment-precise-range-plugin": "^1.3.0",
"mqtt": "^5.0.3",
"ms-teams-webhook": "^1.0.4",
"ms-teams-webhook": "^2.0.2",
"nodemailer": "^6.9.3",
"nodemailer-express-handlebars": "^6.1.0",
"npm": "^9.7.1",
Expand Down
6 changes: 3 additions & 3 deletions src/config/slack_templates/failed-reload.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"type": "section",
"text": {
"type": "mrkdwn",
"text": "```{{executionDetailsConcatenated}}```"
"text": "```{{ executionDetailsConcatenated }}```"
}
},
{
Expand All @@ -115,7 +115,7 @@
"type": "section",
"text": {
"type": "mrkdwn",
"text": "```{{scriptLogHead}}```"
"text": "```{{{ scriptLogHead }}}```"
}
},
{
Expand All @@ -129,7 +129,7 @@
"type": "section",
"text": {
"type": "mrkdwn",
"text": "```{{scriptLogTail}}```"
"text": "```{{{ scriptLogTail }}}```"
}
}
]
Expand Down
36 changes: 24 additions & 12 deletions src/lib/msteams_notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const handlebars = require('handlebars');
const { RateLimiterMemory } = require('rate-limiter-flexible');

const globals = require('../globals');
const scriptLog = require('./scriptlog');

let rateLimiterMemoryFailedReloads;
let rateLimiterMemoryAbortedReloads;
Expand Down Expand Up @@ -407,7 +406,8 @@ async function sendTeams(teamsWebhookObj, teamsConfig, templateContext, msgType)
}

if (msg !== null) {
const res = await teamsWebhookObj.send(JSON.stringify(msg));
// const res = await teamsWebhookObj.send(JSON.stringify(msg));
const res = await teamsWebhookObj.send(msg);
if (res !== undefined) {
globals.logger.debug(`TEAMSNOTIF: Result from calling TeamsApi.TeamsSend: ${res.statusText} (${res.status}): ${res.data}`);
}
Expand All @@ -434,11 +434,17 @@ function sendReloadTaskFailureNotificationTeams(reloadParams) {
}

// Get script logs, if enabled in the config file
const scriptLogData = await scriptLog.getScriptLog(
reloadParams.taskId,
globals.config.get('Butler.teamsNotification.reloadTaskFailure.headScriptLogLines'),
globals.config.get('Butler.teamsNotification.reloadTaskFailure.tailScriptLogLines')
);
const scriptLogData = reloadParams.scriptLog;

// Reduce script log lines to only the ones we want to send to Slack
scriptLogData.scriptLogHeadCount = globals.config.get('Butler.teamsNotification.reloadTaskFailure.headScriptLogLines');
scriptLogData.scriptLogTailCount = globals.config.get('Butler.teamsNotification.reloadTaskFailure.tailScriptLogLines');

scriptLogData.scriptLogHead = scriptLogData.scriptLogFull.slice(0, scriptLogData.scriptLogHeadCount).join('\r\n');;
scriptLogData.scriptLogTail = scriptLogData.scriptLogFull
.slice(Math.max(scriptLogData.scriptLogFull.length - scriptLogData.scriptLogTailCount, 0))
.join('\r\n');

globals.logger.debug(`TASK FAILED ALERT TEAMS: Script log data:\n${JSON.stringify(scriptLogData, null, 2)}`);

// Get Sense URLs from config file. Can be used as template fields.
Expand Down Expand Up @@ -561,11 +567,17 @@ function sendReloadTaskAbortedNotificationTeams(reloadParams) {
}

// Get script logs, if enabled in the config file
const scriptLogData = await scriptLog.getScriptLog(
reloadParams.taskId,
globals.config.get('Butler.teamsNotification.reloadTaskAborted.headScriptLogLines'),
globals.config.get('Butler.teamsNotification.reloadTaskAborted.tailScriptLogLines')
);
const scriptLogData = reloadParams.scriptLog;

// Reduce script log lines to only the ones we want to send to Slack
scriptLogData.scriptLogHeadCount = globals.config.get('Butler.teamsNotification.reloadTaskAborted.headScriptLogLines');
scriptLogData.scriptLogTailCount = globals.config.get('Butler.teamsNotification.reloadTaskAborted.tailScriptLogLines');

scriptLogData.scriptLogHead = scriptLogData.scriptLogFull.slice(0, scriptLogData.scriptLogHeadCount).join('\r\n');;
scriptLogData.scriptLogTail = scriptLogData.scriptLogFull
.slice(Math.max(scriptLogData.scriptLogFull.length - scriptLogData.scriptLogTailCount, 0))
.join('\r\n');

globals.logger.debug(`TASK ABORTED ALERT TEAMS: Script log data:\n${JSON.stringify(scriptLogData, null, 2)}`);

// Get Sense URLs from config file. Can be used as template fields.
Expand Down

0 comments on commit 6e7814a

Please sign in to comment.