Skip to content

Commit

Permalink
Fix storing script logs on disk for QSEoW and Cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
Göran Sander committed Oct 14, 2024
1 parent 206a713 commit 30e6a37
Show file tree
Hide file tree
Showing 8 changed files with 484 additions and 622 deletions.
2 changes: 1 addition & 1 deletion src/config/config-gen-api-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Butler:
enable: false
logDirectory: /path/to/scriptlogs/qseow
qsCloud:
apPReloadFailure:
appReloadFailure:
enable: false
logDirectory: /path/to/scriptlogs/qscloud

Expand Down
12 changes: 6 additions & 6 deletions src/config/production_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,13 @@ Butler:
enable: false
logDirectory: /path/to/scriptlogs/qscloud

# Qlik Sense related links used in notification messages
# Qlik Sense (client-managed) related links used in notification messages
qlikSenseUrls:
qmc: <URL to Qlik Sense QMC>
hub: <URL to Qlik Sense Hub>
appBaseUrl: <URL to Qlik Sense hub>/<virtual proxy, if any>/sense/app # Base URL for Qlik Sense apps, for example http://sense.mycompany.net/sense/app. App ID will be appended to this URL.

# Links available as template variables in notification messages
genericUrls:
- id: ptarmiganlabs_com
linkText: Ptarmigan Labs home page
Expand Down Expand Up @@ -370,7 +371,7 @@ Butler:
# These alerts will be sent irrespective of the alertEnableByCustomProperty.enable setting.
alertEnabledByEmailAddress:
customPropertyName: 'Butler_SuccessAlertSendToEmail'
rateLimit: 60 # Min seconds between emails for a given taskID. Defaults to 5 minutes.
rateLimit: 60 # Min seconds between emails for a given taskID/recipient combo. Defaults to 5 minutes.
headScriptLogLines: 15
tailScriptLogLines: 25
priority: high # high/normal/low
Expand Down Expand Up @@ -1003,10 +1004,9 @@ Butler:
tag: Butler - Send Teams alert if app reload fails
basicContentOnly: false
webhookURL: <URL to MS Teams webhook>

messageType: formatted # formatted / basic
basicMsgTemplate: 'Qlik Sense Cloud app reload failed: "{{appName}}"' # Only needed if message type = basic
rateLimit: 15 # Min seconds between emails for a given taskID. Defaults to 5 minutes.
rateLimit: 15 # Min seconds between emails for a given appId. Defaults to 5 minutes.
headScriptLogLines: 15
tailScriptLogLines: 15
templateFile: /path/to/teams_templates/failed-reload-qscloud-workflow.handlebars
Expand All @@ -1023,7 +1023,7 @@ Butler:
channel: sense-task-failure # Slack channel to which task failure notifications are sent
messageType: formatted # formatted / basic. Formatted means that template file below will be used to create the message.
basicMsgTemplate: 'Qlik Sense Cloud app reload failed: "{{appName}}"' # Only needed if message type = basic
rateLimit: 60 # Min seconds between emails for a given taskID. Defaults to 5 minutes.
rateLimit: 60 # Min seconds between emails for a given appId. Defaults to 5 minutes.
headScriptLogLines: 10
tailScriptLogLines: 20
templateFile: /path/to/slack_templates/failed-reload-qscloud.handlebars
Expand All @@ -1049,7 +1049,7 @@ Butler:
excludeOwner:
user:
# - email: [email protected]
rateLimit: 60 # Min seconds between emails for a given taskID. Defaults to 5 minutes.
rateLimit: 60 # Min seconds between emails for a given appId/recipient combo. Defaults to 5 minutes.
headScriptLogLines: 15
tailScriptLogLines: 25
priority: high # high/normal/low
Expand Down
50 changes: 31 additions & 19 deletions src/lib/qscloud/api/appreloadinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import globals from '../../../globals.js';
// Parameters:
// - appId: Qlik Sense Cloud app ID
// - reloadId: Qlik Sense Cloud reload ID
export async function getQlikSenseCloudAppReloadScriptLog(appId, reloadId, headLineCount, tailLineCount) {
export async function getQlikSenseCloudAppReloadScriptLog(appId, reloadId) {
try {
// Set up Qlik Sense Cloud API configuration
const axiosConfig = {
Expand All @@ -26,36 +26,48 @@ export async function getQlikSenseCloudAppReloadScriptLog(appId, reloadId, headL
// Get number of lines in scriptLogFull
const scriptLogLineCount = scriptLogFull.length;

let scriptLogHead = '';
let scriptLogTail = '';

if (headLineCount > 0) {
scriptLogHead = scriptLogFull.slice(0, headLineCount).join('\r\n');
}

if (tailLineCount > 0) {
scriptLogTail = scriptLogFull.slice(Math.max(scriptLogFull.length - tailLineCount, 0)).join('\r\n');
}

globals.logger.debug(`QLIK SENSE CLOUD GET SCRIPT LOG: Script log head:\n${scriptLogHead}`);
globals.logger.debug(`QLIK SENSE CLOUD GET SCRIPT LOG: Script log tails:\n${scriptLogTail}`);

globals.logger.verbose('QLIK SENSE CLOUD GET SCRIPT LOG: Done getting script log');

return {
scriptLogFull,
scriptLogSize: scriptLogLineCount,
scriptLogHead,
scriptLogHeadCount: headLineCount,
scriptLogTail,
scriptLogTailCount: tailLineCount,
};
} catch (err) {
globals.logger.error(`QLIK SENSE CLOUD GET SCRIPT LOG: ${err}`);
return false;
}
}

// Function to get script log head lines
// Parameters:
// - scriptLogFull: Full script log as array
// - headLineCount: Number of lines to get from head
export function getQlikSenseCloudAppReloadScriptLogHead(scriptLogFull, headLineCount) {
if (headLineCount > 0) {
const scriptLogHead = scriptLogFull.slice(0, headLineCount).join('\r\n');
globals.logger.debug(`QLIK SENSE CLOUD GET SCRIPT LOG: Script log head:\n${scriptLogHead}`);

return scriptLogHead;
} else {
return '';
}
}

// Function to get script log tail lines
// Parameters:
// - scriptLogFull: Full script log as array
// - tailLineCount: Number of lines to get from tail
export function getQlikSenseCloudAppReloadScriptLogTail(scriptLogFull, tailLineCount) {
if (tailLineCount > 0) {
const scriptLogTail = scriptLogFull.slice(Math.max(scriptLogFull.length - tailLineCount, 0)).join('\r\n');
globals.logger.debug(`QLIK SENSE CLOUD GET SCRIPT LOG: Script log tails:\n${scriptLogTail}`);

return scriptLogTail;
} else {
return '';
}
}

// Function to get general info/status/result for a specific Qlik Sense Cloud reload
// Parameters:
// - reloadId: Qlik Sense Cloud reload ID
Expand Down
Loading

0 comments on commit 30e6a37

Please sign in to comment.