Qlik Community

Qlik Sense Enterprise Documents & Videos

Documents & videos about Qlik Sense.

Sending e-mail alerts in Qlik Sense Enterprise Task Failures

Employee
Employee

Sending e-mail alerts in Qlik Sense Enterprise Task Failures

There´s a common request to any Qlik Sense Enterprise Administrator:

"Is there any way to be informed by e-mail when a reload task fails?"  Yes, there is!

Before that, let´s have some technical small talk (you can jump to session "Creating your config xml" if you want)

Qlik Sense Enterprise relies on log4Net a very mature Apache Project  that is very reliable and powerful. It, besides a lot of features  , has the concept of Appender. That concept means that the application being logged (Qlik Sense in our case) does not to take care where the log is being stored, log4net config files handles this.

You can change a config file and choose if your log are meant to be stored into a database, a flat file, a hadoop data lake and you can even send an e-mail for each error message.   Qlik Sense Enterprise help to Appenders

1 - Creating your config xml

Pick your favorite text editor and write your config file according this https://logging.apache.org/log4net/release/config-examples.html

No, wait!

I´m posting here a functional config file, you can copy and paste it.

I´m supposing you´re going to use Gmail as the SMTP but is up to you chose any working SMTP that you want

<?xml version="1.0"?>

<configuration>

    <!-- Mail appender-->

    <appender name="MailAppender" type="log4net.Appender.SmtpAppender">

        <filter type="log4net.Filter.LevelRangeFilter">

            <param name="levelMin" value="WARN" />

            <param name="levelMax" value="ERROR" />

        </filter>

        <filter type="log4net.Filter.DenyAllFilter" />

        <evaluator type="log4net.Core.LevelEvaluator">

            <param name="threshold" value="ERROR"/>

        </evaluator>

        <param name="to" value="admin@domain.com" /> <!-- please use your admin e-mail address here -->

        <param name="cc" value="someone.else@domain.com" />

        <param name="from" value="yourgmailaccount@gmail.com" /> <!-- you´re supposed to change this -->

        <param name="subject" value="Qlik Sense Task Fail!!!" />

        <param name="smtpHost" value="smtp.gmail.com" />

        <param name="port" value="587" />

        <param name="EnableSsl" value="true" />

        <param name="Authentication" value="Basic" />

        <param name="username" value="yourgmailaccount@gmail.com" /> <!-- you´re supposed to change this -->

        <param name="password" value="yourpasswordforGmail" /> <!-- you´re supposed to change this -->

        <param name="bufferSize" value="0" />

        <!-- Set this to 0 to make sure an email is sent on every error -->

        <param name="lossy" value="true" />

        <layout type="log4net.Layout.PatternLayout">7

<!-- You can change below code if you want to pretify your e-mail message -->

            <param name="conversionPattern" value="%newline%date %-5level %newline%property{TaskName}%newline%property{AppName}%newline%message%newline%newline%newline" />

        </layout>

    </appender>

    <!--Send mail on task failure-->

    <logger name="System.Scheduler.Scheduler.Slave.Tasks.ReloadTask"> <!-- Filter what kind of exceptionname is beeing captured -->

        <appender-ref ref="MailAppender" />

    </logger>

</configuration>

2 - Saving your config xml

You must save your file with LocalLogConfig.xml name and under C:\ProgramData\Qlik\Sense\Scheduler (at least until version April2018). Anything different from this will cause your configuration not work.

Capture.PNG


3 - Restarting your Scheduler Service


Check if any task is running before restarting the service!!

Capture.PNG



4 - Test

  • Create an app and create an very "silly always fail" script like Store notable into [lib://neverland/notable.qvd](qvd)
  • Schedule your app as usual (under QMC/Apps/[your app]/More options button/Create New Reload Task

    (https://help.qlik.com/en-US/sense/April2018/Subsystems/ManagementConsole/Content/create-reload-tasks...)

Get a cup of coffee and wait for your task fail and your alert e-mail arrives at your inbox.



This blog post was written with fundamental contribution of ile‌ that sent me a functional config file


Comments
Employee
Employee

If using gmail you may need to enable less secure applications in your Google mail settings:

Let less secure apps access your account - Google Account Help.

Employee
Employee

I also tested this in the Qlik Sense April 2018 release, using FakeSMTP for the mail server. This is useful to test and if you need to eliminate your mail service as having issues. Below is an example LocalLogConfig.xml config file.

Note that I used 2525 as the SMTP port and localhost for the smtpHost, as FakeSMTP was running on the Sense server. Fake SMTP can be run on a remote machine, as long a there's network connectivity and your chosen port is open.

<?xml version="1.0"?>

<configuration>

    <!-- Mail appender-->

    <appender name="MailAppender" type="log4net.Appender.SmtpAppender">

        <filter type="log4net.Filter.LevelRangeFilter">

            <param name="levelMin" value="WARN" />

            <param name="levelMax" value="ERROR" />

        </filter>

        <filter type="log4net.Filter.DenyAllFilter" />

        <evaluator type="log4net.Core.LevelEvaluator">

            <param name="threshold" value="ERROR"/>

        </evaluator>

<param name="to" value="senseadmins@yourcomapny.com" />

        <param name="cc" value="brian@yourcomapny.com,ted@yourcomapny.com" />

        <param name="bcc" value="sienna@yourcomapny.com,tony@yourcomapny.com" />

        <param name="from" value="sysadmin@yourcomapny.com" />

        <param name="subject" value="Qlik Sense Reload Error" />

        <param name="smtpHost" value="localhost" />

        <param name="port" value="2525" />

        <param name="bufferSize" value="0" />

        <!-- Set this to 0 to make sure an email is sent on every error -->

        <param name="lossy" value="true" />

        <layout type="log4net.Layout.PatternLayout">

            <param name="conversionPattern" value="%newline%date %-5level %newline%property{TaskName}%newline%property{AppName}%newline%message%newline%newline%newline" />

        </layout>

    </appender>

    <!--Send mail on task failure-->

    <logger name="System.Scheduler.Scheduler.Slave.Tasks.ReloadTask">

        <appender-ref ref="MailAppender" />

    </logger>

</configuration>

huangjing
Visitor

According to your method, we have succeeded in testing.

But what we need now is that only a part of task send wrong messages, what should i do?

For example, the prefix of the tasks is A , sending mail, others do not send.

Employee
Employee

You can use the StringToMatch filters in log4net, see Apache log4net™ SDK Documentation - Table of Content and look for StringMatchFilter

I don't have a working example of this, but if my understanding is correct it should work. As far as I know StringToMatch uses OR only, not AND, for multiple filters, and make sure <filter type="log4net.Filter.DenyAllFilter" /> is the last filter line used.

e.g.

<filter type="log4net.Filter.StringMatchFilter">

            <StringToMatch value="Your Text Here" />

   </filter>

<filter type="log4net.Filter.DenyAllFilter" />

millan123
Contributor

Thank you for the info Michael.

Could we use same for the June 2018 version ?

Br,

Clark

Employee
Employee

As far as I can see nothing has changed around this, so it should work as per previous releases - but I have not tested.

millan123
Contributor

Thank you , I tried using it about I am not getting any mails.

Where should I check Locallogconfig.xml log ? any troubleshooting idea will be helpful to us.

Thank you so much

Employee
Employee

Initially I recommend opening a support case with Qlik as I won't have time to test it anytime soon. I'm not sure where any errors would be logged; but probably either in the Logging service or the Schedule logs somewhere

millan123
Contributor

thank you sure , we will create a log in to Qlik support

miskin_m
Contributor

Hi Clark/ Mick

I am also trying to send gmail mails from June 18 but no luck. Did anyone of you found the solution.

Regards

Miskin

Version history
Revision #:
1 of 1
Last update:
‎04-26-2018 07:31 PM
Updated by:
Employee