/ qlik

Qlik Sense Mail Notifications

One feature that is missing in Qlik Sense is to send mail notifications when task is completed (fail or success). This feature is available in QlikView Server and I'm finding it very useful.

I've found 3 ways that this can be achieved in QS:

  • Log files scraping
  • QRS API
  • log4net

I'll cover the third option in details

Log files

Every QS service have it's own log folder where the activity is logged. Batch file can be written that monitor the Scheduler service log file and on change to scrap the content and mail the result.

QRS API

Ideally this is the most correct way to achieve mail notifications. Qlik Sense Repository Service (QRS) is a REST API service which can be consumed from any language. Notification end points can be set to visit specific url on specific event. Additional web server need to be set and running to handle the calls from QRS.
The downside of this approach is that the notification is session based. Which means that if you restart your web server or QRS service is restarted all notifications are gone and need to be created again. Of course this is not a blocker and with additional logic can be handled. Personally I like this approach and will build something in the future using it (already started it here)

log4net

Alex point few days back that QS have build in log4net functionality which can be used to trigger some events when the QRS log file is updated - send mail, append to another file, add event in windows events, write to database, send udp request etc (the full list is here).

Basically you just need to create LocalLogConfig.xml file in the service folder which you want to monitor - C:\ProgramData\Qlik\Sense\<ServiceName>

For example below is what the content of LocalLogConfig.xml looks like if you want to send UDP request to UDP server for the Scheduler service:

<?xml version="1.0"?>
<configuration>
    <appender name="NodeSchedulerLogger" type="log4net.Appender.UdpAppender">
        <param name="remoteAddress" value="localhost" />
        <param name="remotePort" value="9998" />
        <layout type="log4net.Layout.PatternLayout">
            <param name="conversionpattern" value="scheduler;%message;%property{ObjectId};%property{ObjectName};%property{Context};%property{Command};%property{Result};" />

        </layout>
    </appender>
   <logger name="AuditActivity.Scheduler">
      <appender-ref ref="NodeSchedulerLogger" />
   </logger>
</configuration>

The above xml define new appender NodeSchedulerLogger from log4net.Appender.UdpAppender type. On new log event log4net will send udp to remoteAddress and remotePort. layout section specify the format of the request and the fields you want (in my case I wanted message, ObjectId, ObjectName, Context, Command and Result fields.

After this is set I've build small NodeJs UDP server which parse the incoming messages and when the parser find event indicating that task is finished connection to QRS is established and using the API the script is getting the last execution script log and mail it as attachment.

Repo: qlik-sense-log4net

I'll try and move with the server part as quickly as possible. Also will include log4net "recepies" in the repo itself and probably will make separate blog post only for them.

Near Future

I'm having a bold plan to extend the NodeJs server part. This will include GUI part where different scenarios will be available to setup.

For example:

  • Setup mail recipients for all tasks
  • Setup mail recipients per single taks or group of tasks or for tasks with specific custom property
  • Custom mail messages based on the tasks
Somewhere in the future (just an ideas)
  • Setup notifications based not only on tasks but also on events from the other services
  • Setup notifications on new/updated documents. For example mail to users which can access a stream when app is added or updated in the stream
More log4net intergrations

Very good practical usage of log4net approach can be found here. Using Qlik Sense Proxy Service logs Alex has build this web site which show global Qlik Branch users acitivity using the logs from Qlik Sense Proxy Service (QPS).

Also you can check Alex's example for using log4net with QPS

Hope you like it!
Stefan