Skip to main content

Setting Up Qlik Sense to Send Email Notifications on Reload Task Failure

cancel
Showing results for 
Search instead for 
Did you mean: 
mdelvecchio
Contributor III
Contributor III

Setting Up Qlik Sense to Send Email Notifications on Reload Task Failure

Last Update:

Jul 1, 2022 8:00:32 AM

Updated By:

Sonja_Bauernfeind

Created date:

Oct 16, 2020 12:03:31 PM

Attachments

I spent a bunch of time on and off trying to figure how to generate an email alert when a reload fails. It's something I and I'm sure many others wish was built-in and worked out-of-the-box, but it's actually somewhat possible. There are some restrictions - for me, I sometimes get reloads that hang, even though I put in a max retry, and since they don't "fail," I never get the notification. And obviously, the email notification is generalized to the point where you have to log into the QMC to discover which app failed. But if you're a Qlik Sense admin, you're smart enough how to make customized email alerts for each reload task :).

 

Setting up Qlik Web Connectors

  1. If necessary, whitelist your Qlik Sense server’s IP in your mail relay.
  2. Download the QlikWebConnectors zip folder from the Qlik support site: https://us-d.demo.qlik.com/download/ 
    1. Filter down to "Qlik Connectors" and under the "Products" section, scroll down to find "Qlik Web Connectors."
    2. Find the most recent Initial Release and click on the name to download - March 2020 at time of writing.
  3. Extract that folder to the root of the C drive. Rename the folder to QlikWebConnectors if it is not already named so.
  4. You may notice no installation has ran yet. We will get back to that later. If you open the QlikWebConnectors folder, you can run QlikWebConnectors.exe to start the program. A window will appear in the bottom right of your screen.
     

    image.png

  5. Click "open in default browser" to begin setup. Accept the license agreement.
  6. While you can technically write out the script directly in a Qlik Sense app, a sanitized version of which I will provide below, the following is how to set up through the SMTP Connector.
  7. There are a lot of Connectors available. Browse to the "Standard" tab and open "Qlik SMTP Connector." Highlight SendEmail and click Parameters.
  8. Set up the fields according to how your mail server requires. Mine is set up to allow anonymous authentication but only whitelisted servers are allowed. Below is how mine is set up, but yours may be different.
    1. SMTP Server: FQDN of your mail relay
    2. Port: usually 25
    3. SSL Mode: depends on your setup - mine is anonymous so I set to "None"
    4. To: email you want to receive the email alerts
    5. Subject: email subject
    6. Message: email body
    7. HTML: check this box so you can use HTML tags in your Qlik script
    8. From name: display name the email is being sent from
    9. From email: email address the email is being sent from
  9. Click "Save Inputs & Run Table." On success, the To Email you entered above will receive the email.
  10. Click over to the "Qlik Sense (Standard Mode)" tab. You will see some instructions and some auto-generated code. Copy it to the clipboard.
    image.png
  11. Create a new Qlik Sense app titled something descriptive (e.g. "Send Email"), open the Data Load Editor, and paste the code into the Data Load Editor. You may get a warning that the app has no data, which is expected and can be safely ignored.
    image.pngimage.png
  12. Follow the instructions highlighted in red to set up the Web File connection. It should look as below. Give it a descriptive name as well. Make sure you create this as the Web Connector program is still running on the Qlik server.
    image.pngimage.pngimage.png
  13. Make sure the variable "vQwcConnectionName" matches the name of the email connection you just created.
    image.png
  14. Click "Load Data" to test the email and make sure it gets sent to the email you set above.
    image.png
  15. The obvious quirk of this set up is it requires the WebConnector program to be running constantly. Luckily, QlikWebConnectors can be set up to run as a service.
  16. On the Qlik Sense server, browse to C:\QlikWebConnectors\BatchFiles.
  17. Edit "Install Service.bat" and make sure the .NET and QlikWebConnectors_SVC.exe paths are valid.
    image.pngimage.png
  18. Close Notepad and run the "Install Service.bat" as an admin. When the script has completed after a few seconds, press any key to close.
    image.png
  19. Open Services.msc, find Qlik Web Connectors, and change the Log On to your Qlik service account. You may otherwise run into errors in the future if you try to re-setup any connectors.
  20. Start the service.
  21. Right-click, Properties, and switch to the Recovery tab. Change the "First Failure" dropdown to "Restart the service." Change "Restart service after" to zero minutes. Click Apply and OK.
    image.png
  22. If you try to run the QlikWebConnectors.exe program again, you will get an error that the program is already running.
    image.png

 

Setting up Task Failure Triggers

  1. Log into the QMC.
  2. Browse to Tasks either from the Dashboard or the sidebar.
    image.png
  3. Create a new task, name it something descriptive, and select the Send Email app you created above as the app. The email sends within seconds so it is recommended to lower the default timeout and increase the retries, though this depends on your environment.
    image.png
  4. Click the "Actions" dropdown and select "Create new task event trigger."
    image.png
  5. Name the trigger task something descriptive relative to the app, click "Add Task," change the dropdown to "Task Failed," and select the task you want to be alerted on a failure of. You can leave the time constraint as the default, it is not relevant when a task chain is only two tasks long, as is the case now. More information here: https://help.qlik.com/en-US/sense/June2019/Subsystems/ManagementConsole/Content/Sense_QMC/create-rel...

    image.png
  6. Repeat this process for each individual task you want to be alerted on. You can add a new Send Email app per app, new trigger event per Send email app, or new task per trigger event. I recommend the second for the sake of cleanliness and succinctness.
    image.png
     
  7. Make sure this trigger event process is repeated for each new app that is published in the future.
  8. When you go to the Tasks page in the QMC, you will notice little chain symbols for every app that is connected to the Send Email app and vice versa. You can click on this chain symbol to view the task chains from either direction.
    image.pngimage.png

 

Editing the Notification App

As written above, the actual script that runs the SMTP Connector is complete and already published to Qlik Sense. In other words, if you ever need to edit or re-publish the app or change the SMTP settings, there is little to do. Details below:

  1. When you set up the SMTP Connector and run the parameters, you will be given the below line of Qlik script. Notice how hard-coded the (unredacted) bold parameters are.
    image.png
  2. Of course, hard-coding is not best practice and the syntax is not obvious at first glance. The bold parameters are replaced by variables in the actual published Qlik Sense app.
    image.png
  3. Variables, when placed in the URL script line, must be in the form of $(variablename). If you look closely, every parameter is simply "parameter1=$(variable1)&parameter2=$(variable2)&..." The parameters from the original script block are untouched while the hard-coded values are now variables.
    image.png
  4. The script blocks are separated into sections, marked by comment sections. To go through them one-by-one:
    1. The first section is for script neatness. vQwcConnectionName pulls the webfile defined above into the script. vTimestamp is used for the email body.
      image.png
    2. These variables are the content that you will edit. The two "...Input" variables define the content of the email body and subject. More on them in the next section. The rest of the variables are what they sound like.
      image.png
    3. I would strongly recommend never touching these lines. The URL script line in Qlik Sense requires plus signs in the place of spaces for each value. These two lines replace the spaces with plus signs for you so editing the value is easier.
      image.png

 

[Redacted] QS Script for Send Email app

 

 

 

/**** you shouldn't have to modify these after setup ****/
let vQwcConnectionName = '[web file connector]';
let vTimestamp = timestamp(now());

/**** Edit these variables to change the email contents. ****/
let vMessageInput = 'Qlik Sense Task Failure at ' & '$(vTimestamp)' & '.<br><br>To Review, <a href="https://[Qlik Sense URL].com/qmc">go to the QMC.</a>';
let vSubjectInput = 'Qlik Sense Task Failure';
let vSMTPserver = ' ';
let vFromName = ' ';
let vSMTPPort = '25';
/**** use %40 in place of the @ symbol ****/
let vToEmail = '';
let vFromEmail = '';

/**** DO NOT EDIT ****/
/**** These variable text strings properly encode the text in the "input" variables ****/
/**** Replaces all spaces with plus signs in the message string above ****/
let vMessage = replace('$(vMessageInput)',' ','+');
let vSubject = replace('$(vSubjectInput)',' ','+');
/**** DO NOT EDIT ****/

SMTPConnector_SendEmail:
LOAD
    status as SendEmail_status,
    result as SendEmail_result,
    filesattached as SendEmail_filesattached
FROM [$(vQwcConnectionName)]
(URL IS [http://localhost:5555/data?connectorID=SMTPConnector&table=SendEmail&SMTPServer=$(vSMTPserver)&Port=$(vSMTPPort)&SSLmode=None&to=$(vToEmail)&subject=$(vSubject)&message=$(vMessage)&html=True&fromName=$(vFromName)&fromEmail=$(vFromEmail)&delayInSeconds=0&ignoreProxy=False&appID=], qvx);

// IMPORTANT: If, when loading the above script, you receive a 'Script Error' Dialog box with a 'Field Not Found'
// (or other) error, the first thing you should do is copy and paste the full request URL (i.e. the URL between the square [...]
// brackets IN THE QLIKVIEW / QLIK SENSE SCRIPT ERROR DIALOG) into a browser address bar and check the response.

 

 

 

Comments
jpjust
Specialist
Specialist

Hi,

Is it possible to get the specific task name that fails and the logs attached to the alert email?

Thanks

williejacobs
Creator
Creator

Hi @jpjust 

If you are still looking for a solution, we have been using this for just over 2 years now and it is still running without any issues.

Qliksense Automated Task Failure Email Alerts - Qlik Developer

 

 

JohannaR
Contributor II
Contributor II

Hello @williejacobs ,

we also use this extension, but sometimes mails about task cancellations are sent to wrong persons. Do you know this phenomenon and have you found a solution?

Best regards

luigi_nigro
Contributor
Contributor

Hi @mdelvecchio 

Thanks for that good explanation! That works well for me 🙂

I would like to send e-mail to multiple recipients using the blind carbon copy (bcc).

I thought I could simply change the "to" parameter into "bcc", but that doesn't work.

Is there a way to put recipients into the bcc field?

Best regards

Gino

gardenierbi
Creator II
Creator II

@luigi_nigro , you will always need to use the TO parameter. Use a dummy address or the service account in the TO parameter and the recipients in the BCC parameter. 

gardenierbi
Creator II
Creator II

@mdelvecchio you could use the QRS connection to read the repository database. In the database you will find all the tasks, the task results, the task names, the owner of the task, the owners of the connected app, etc. With these details you can create notifications with more specific details.  

Shrikant
Contributor III
Contributor III

I did this with very easy solution

https://www.youtube.com/watch?v=Px4pvSlqK0s

Version history
Last update:
‎2022-07-01 08:00 AM
Updated by: