Skip to content

Commit

Permalink
Merge pull request #768 from mountaindude/728
Browse files Browse the repository at this point in the history
feat(reload-alerts): Make app owner info available in reload failed a…
  • Loading branch information
mountaindude authored Aug 22, 2023
2 parents c8816fb + 1912d3e commit b254517
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 12 deletions.
12 changes: 12 additions & 0 deletions src/config/email_templates/aborted-reload.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@
<td class="tg-nalo">App ID</td>
<td class="tg-ipfp">{{appId}}</td>
</tr>
<tr>
<td class="tg-nalo">App owner</td>
<td class="tg-ipfp">{{appOwnerName}}</td>
</tr>
<tr>
<td class="tg-nalo">App owner user</td>
<td class="tg-ipfp">{{appOwnerUserDirectory}}/{{appOwnerUserId}}</td>
</tr>
<tr>
<td class="tg-nalo">App owner email</td>
<td class="tg-ipfp">{{appOwnerEmail}}</td>
</tr>
<tr>
<td class="tg-nalo"></td>
<td class="tg-ipfp"></td>
Expand Down
12 changes: 12 additions & 0 deletions src/config/email_templates/failed-reload.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@
<td class="tg-nalo">App ID</td>
<td class="tg-ipfp">{{appId}}</td>
</tr>
<tr>
<td class="tg-nalo">App owner</td>
<td class="tg-ipfp">{{appOwnerName}}</td>
</tr>
<tr>
<td class="tg-nalo">App owner user</td>
<td class="tg-ipfp">{{appOwnerUserDirectory}}/{{appOwnerUserId}}</td>
</tr>
<tr>
<td class="tg-nalo">App owner email</td>
<td class="tg-ipfp">{{appOwnerEmail}}</td>
</tr>
<tr>
<td class="tg-nalo"></td>
<td class="tg-ipfp"></td>
Expand Down
12 changes: 12 additions & 0 deletions src/config/slack_templates/aborted-reload.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
{
"type": "mrkdwn",
"text": "*App ID:*\n{{{appId}}}"
},
{
"type": "mrkdwn",
"text": "*App owner:*\n{{{appOwnerName}}}"
},
{
"type": "mrkdwn",
"text": "*App owner email:*\n{{{appOwnerEmail}}}"
},
{
"type": "mrkdwn",
"text": "*App owner user:*\n{{appOwnerUserDirectory}}/{{appOwnerUserId}}"
}
]
},
Expand Down
12 changes: 12 additions & 0 deletions src/config/slack_templates/failed-reload.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
{
"type": "mrkdwn",
"text": "*App ID:*\n{{{appId}}}"
},
{
"type": "mrkdwn",
"text": "*App owner:*\n{{{appOwnerName}}}"
},
{
"type": "mrkdwn",
"text": "*App owner email:*\n{{{appOwnerEmail}}}"
},
{
"type": "mrkdwn",
"text": "*App owner user:*\n{{appOwnerUserDirectory}}/{{appOwnerUserId}}"
}
]
},
Expand Down
9 changes: 9 additions & 0 deletions src/config/teams_templates/aborted-reload.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
},{
"name": "Task ID",
"value": "{{taskId}}"
},{
"name": "App owner",
"value": "{{appOwnerName}}"
},{
"name": "App owner user",
"value": "{{appOwnerUserDirectory}}/{{appOwnerUserId}}"
},{
"name": "App owner email",
"value": "{{appOwnerEmail}}"
}],
"markdown": true
}, {
Expand Down
9 changes: 9 additions & 0 deletions src/config/teams_templates/failed-reload.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
},{
"name": "Task ID",
"value": "{{taskId}}"
},{
"name": "App owner",
"value": "{{appOwnerName}}"
},{
"name": "App owner user",
"value": "{{appOwnerUserDirectory}}/{{appOwnerUserId}}"
},{
"name": "App owner email",
"value": "{{appOwnerEmail}}"
}],
"markdown": true
}, {
Expand Down
121 changes: 113 additions & 8 deletions src/lib/incident_mgmt/new_relic.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,19 @@ function getReloadFailedEventConfig() {

return cfg;
} catch (err) {
globals.logger.error(`NEWRELIC RELOADFAILEDEVENT: ${err}`);
if (err.message) {
globals.logger.error(`NEWRELIC RELOADFAILEDEVENT message: ${err.message}`);
}

if (err.stack) {
globals.logger.error(`NEWRELIC RELOADFAILEDEVENT stack: ${err.stack}`);
}

// If neither message nor stack is available, just log the error object
if (!err.message && !err.stack) {
globals.logger.error(`NEWRELIC RELOADFAILEDEVENT: ${JSON.stringify(err, null, 2)}`);
}

return false;
}
}
Expand Down Expand Up @@ -196,7 +208,19 @@ function getReloadFailedLogConfig() {

return cfg;
} catch (err) {
globals.logger.error(`NEWRELIC RELOADFAILEDLOG: ${err}`);
if (err.message) {
globals.logger.error(`NEWRELIC RELOADFAILEDLOG message: ${err.message}`);
}

if (err.stack) {
globals.logger.error(`NEWRELIC RELOADFAILEDLOG stack: ${err.stack}`);
}

// If neither message nor stack is available, just log the error object
if (!err.message && !err.stack) {
globals.logger.error(`NEWRELIC RELOADFAILEDLOG: ${JSON.stringify(err, null, 2)}`);
}

return false;
}
}
Expand Down Expand Up @@ -263,7 +287,19 @@ function getReloadAbortedEventConfig() {

return cfg;
} catch (err) {
globals.logger.error(`NEWRELIC RELOADABORTEDEVENT: ${err}`);
if (err.message) {
globals.logger.error(`NEWRELIC RELOADABORTEDEVENT message: ${err.message}`);
}

if (err.stack) {
globals.logger.error(`NEWRELIC RELOADABORTEDEVENT stack: ${err.stack}`);
}

// If neither message nor stack is available, just log the error object
if (!err.message && !err.stack) {
globals.logger.error(`NEWRELIC RELOADABORTEDEVENT: ${JSON.stringify(err, null, 2)}`);
}

return false;
}
}
Expand Down Expand Up @@ -327,7 +363,19 @@ function getReloadAbortedLogConfig() {

return cfg;
} catch (err) {
globals.logger.error(`NEWRELIC RELOADABORTEDLOG: ${err}`);
if (err.message) {
globals.logger.error(`NEWRELIC RELOADABORTEDLOG message: ${err.message}`);
}

if (err.stack) {
globals.logger.error(`NEWRELIC RELOADABORTEDLOG stack: ${err.stack}`);
}

// If neither message nor stack is available, just log the error object
if (!err.message && !err.stack) {
globals.logger.error(`NEWRELIC RELOADABORTEDLOG: ${JSON.stringify(err, null, 2)}`);
}

return false;
}
}
Expand Down Expand Up @@ -404,6 +452,11 @@ async function sendNewRelicEvent(incidentConfig, reloadParams, destNewRelicAccou
if (err.stack) {
globals.logger.error(`NEWRELIC 1 stack: ${err.stack}`);
}

// If neither message nor stack is available, just log the error object
if (!err.message && !err.stack) {
globals.logger.error(`NEWRELIC 1: ${JSON.stringify(err, null, 2)}`);
}
}
}

Expand Down Expand Up @@ -532,6 +585,10 @@ async function sendNewRelicLog(incidentConfig, reloadParams, destNewRelicAccount
globals.logger.error(`NEWRELIC 2 stack: ${err.stack}`);
}

// If neither message nor stack is available, just log the error object
if (!err.message && !err.stack) {
globals.logger.error(`NEWRELIC 2: ${JSON.stringify(err, null, 2)}`);
}
}
}

Expand Down Expand Up @@ -653,7 +710,19 @@ async function sendReloadTaskFailureEvent(reloadParams) {
sendNewRelicEvent(incidentConfig, params, destNewRelicAccounts);
return null;
} catch (err) {
globals.logger.error(`TASK FAILED NEWRELIC: ${err}`);
if (err.message) {
globals.logger.error(`TASK FAILED NEWRELIC 1 message: ${err.message}`);
}

if (err.stack) {
globals.logger.error(`TASK FAILED NEWRELIC 1 stack: ${err.stack}`);
}

// If neither message nor stack is available, just log the error object
if (!err.message && !err.stack) {
globals.logger.error(`TASK FAILED NEWRELIC 1: ${JSON.stringify(err, null, 2)}`);
}

return null;
}
})
Expand Down Expand Up @@ -781,7 +850,19 @@ async function sendReloadTaskFailureLog(reloadParams) {
sendNewRelicLog(incidentConfig, params, destNewRelicAccounts);
return null;
} catch (err) {
globals.logger.error(`TASK FAILED NEWRELIC: ${err}`);
if (err.message) {
globals.logger.error(`TASK FAILED NEWRELIC 2 message: ${err.message}`);
}

if (err.stack) {
globals.logger.error(`TASK FAILED NEWRELIC 2 stack: ${err.stack}`);
}

// If neither message nor stack is available, just log the error object
if (!err.message && !err.stack) {
globals.logger.error(`TASK FAILED NEWRELIC 2: ${JSON.stringify(err, null, 2)}`);
}

return null;
}
})
Expand Down Expand Up @@ -911,7 +992,19 @@ function sendReloadTaskAbortedEvent(reloadParams) {
sendNewRelicEvent(incidentConfig, params, destNewRelicAccounts);
return null;
} catch (err) {
globals.logger.error(`TASK ABORT NEWRELIC: ${err}`);
if (err.message) {
globals.logger.error(`TASK ABORT NEWRELIC 1 message: ${err.message}`);
}

if (err.stack) {
globals.logger.error(`TASK ABORT NEWRELIC 1 stack: ${err.stack}`);
}

// If neither message nor stack is available, just log the error object
if (!err.message && !err.stack) {
globals.logger.error(`TASK ABORT NEWRELIC 1: ${JSON.stringify(err, null, 2)}`);
}

return null;
}
})
Expand Down Expand Up @@ -1041,7 +1134,19 @@ function sendReloadTaskAbortedLog(reloadParams) {
sendNewRelicLog(incidentConfig, params, destNewRelicAccounts);
return null;
} catch (err) {
globals.logger.error(`TASK ABORT NEWRELIC: ${err}`);
if (err.message) {
globals.logger.error(`TASK ABORT NEWRELIC 2 message: ${err.message}`);
}

if (err.stack) {
globals.logger.error(`TASK ABORT NEWRELIC 2 stack: ${err.stack}`);
}

// If neither message nor stack is available, just log the error object
if (!err.message && !err.stack) {
globals.logger.error(`TASK ABORT NEWRELIC 2: ${JSON.stringify(err, null, 2)}`);
}

return null;
}
})
Expand Down
15 changes: 15 additions & 0 deletions src/lib/msteams_notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const handlebars = require('handlebars');
const { RateLimiterMemory } = require('rate-limiter-flexible');

const globals = require('../globals');
const { getAppOwner } = require('../qrs_util/get_app_owner');

let rateLimiterMemoryFailedReloads;
let rateLimiterMemoryAbortedReloads;
Expand Down Expand Up @@ -433,6 +434,9 @@ function sendReloadTaskFailureNotificationTeams(reloadParams) {
return 1;
}

// Get app owner
const appOwner = await getAppOwner(reloadParams.appId);

// Get script logs, if enabled in the config file
const scriptLogData = reloadParams.scriptLog;

Expand Down Expand Up @@ -491,6 +495,10 @@ function sendReloadTaskFailureNotificationTeams(reloadParams) {
scriptLogHeadCount: scriptLogData.scriptLogHeadCount,
qlikSenseQMC: senseUrls.qmcUrl,
qlikSenseHub: senseUrls.hubUrl,
appOwnerName: appOwner.userName,
appOwnerUserId: appOwner.userId,
appOwnerUserDirectory: appOwner.directory,
appOwnerEmail: appOwner.emails?.length > 0 ? appOwner.emails[0] : '',
};

// Check if script log is longer than 3000 characters. Truncate if so.
Expand Down Expand Up @@ -572,6 +580,9 @@ function sendReloadTaskAbortedNotificationTeams(reloadParams) {
return 1;
}

// Get app owner
const appOwner = await getAppOwner(reloadParams.appId);

// Get script logs, if enabled in the config file
const scriptLogData = reloadParams.scriptLog;

Expand Down Expand Up @@ -629,6 +640,10 @@ function sendReloadTaskAbortedNotificationTeams(reloadParams) {
scriptLogHeadCount: scriptLogData.scriptLogHeadCount,
qlikSenseQMC: senseUrls.qmcUrl,
qlikSenseHub: senseUrls.hubUrl,
appOwnerName: appOwner.userName,
appOwnerUserId: appOwner.userId,
appOwnerUserDirectory: appOwner.directory,
appOwnerEmail: appOwner.emails?.length > 0 ? appOwner.emails[0] : '',
};

// Check if script log is longer than 3000 characters. Truncate if so.
Expand Down
15 changes: 15 additions & 0 deletions src/lib/slack_notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { RateLimiterMemory } = require('rate-limiter-flexible');

const globals = require('../globals');
const slackApi = require('./slack_api');
const { getAppOwner } = require('../qrs_util/get_app_owner');

let rateLimiterMemoryFailedReloads;
let rateLimiterMemoryAbortedReloads;
Expand Down Expand Up @@ -475,6 +476,9 @@ function sendReloadTaskFailureNotificationSlack(reloadParams) {
return 1;
}

// Get app owner
const appOwner = await getAppOwner(reloadParams.appId);

// Get script logs, if enabled in the config file
const scriptLogData = reloadParams.scriptLog;

Expand Down Expand Up @@ -535,6 +539,10 @@ function sendReloadTaskFailureNotificationSlack(reloadParams) {
scriptLogHeadCount: scriptLogData.scriptLogHeadCount,
qlikSenseQMC: senseUrls.qmcUrl,
qlikSenseHub: senseUrls.hubUrl,
appOwnerName: appOwner.userName,
appOwnerUserId: appOwner.userId,
appOwnerUserDirectory: appOwner.directory,
appOwnerEmail: appOwner.emails?.length > 0 ? appOwner.emails[0] : '',
};

// Replace all single and dpouble quotes in scriptLogHead and scriptLogTail with escaped dittos
Expand Down Expand Up @@ -630,6 +638,9 @@ function sendReloadTaskAbortedNotificationSlack(reloadParams) {
return 1;
}

// Get app owner
const appOwner = await getAppOwner(reloadParams.appId);

// Get script logs, if enabled in the config file
const scriptLogData = reloadParams.scriptLog;

Expand Down Expand Up @@ -688,6 +699,10 @@ function sendReloadTaskAbortedNotificationSlack(reloadParams) {
scriptLogHeadCount: scriptLogData.scriptLogHeadCount,
qlikSenseQMC: senseUrls.qmcUrl,
qlikSenseHub: senseUrls.hubUrl,
appOwnerName: appOwner.userName,
appOwnerUserId: appOwner.userId,
appOwnerUserDirectory: appOwner.directory,
appOwnerEmail: appOwner.emails?.length > 0 ? appOwner.emails[0] : '',
};

// Check if script log is longer than 3000 characters, which is max for text fields sent to Slack API
Expand Down
Loading

0 comments on commit b254517

Please sign in to comment.