In some of my earlier articles I have talked about managing the Task Audit information in HFM. The main point of these articles is that the Audit Extract Utility (AEU) no longer meets the requirements for a robust and complete task audit. The AEU is still fine for the extract of data audit information just not the task audit. To recap, the two main problems with the AEU is that the detailed logs of application changes (i.e. metadata, member list and rules loads) are not extracted and the last logon information is deleted. In this article I will go through an alternative to the AEU for managing the Task Audit data. It is customisable so that any application changes and logon information are preserved and you can ignore some events such as Logoff.
Process Overview
The key to this new Task Audit extract process is a SQL statement which selects and formats the data. This SQL statement is then automated by calling from a batch file or from a trigger/job in the relational database. The automation process collects the output from the SQL statement and writes it to a file.
Note: I have only tested this on SQL Server. For Oracle databases, the REPLACE function should work. You will need to use something like the to_date function instead of MONTH in the WHERE clause.
SQL Statement
This is a basic SQL statement to extract the data. If you look in the log file that the AEU creates, you will see something similar to this:
SELECT U.sUserName, a.ActivityCode, a.ServerName, a.AppName,
a.StartTime, a.EndTime, a.strModuleName
FROM @APPL@_TASK_AUDIT AS a INNER JOIN
HSV_ACTIVITY_USERS AS U WITH (NOLOCK) ON a.ActivityUserID = U.lUserID
Note: you need to change @APPL@ to the name of your HFM application.
This gives you data something like this:
While this has extracted the data, we need to make a few changes to make it more readable:
- change the ActivityCode to the activity description (e.g. Logon, Logoff)
- format the StartTime and/or EndTime to an actual date
- change the strModuleName to the module description.
There is a link at the bottom of the page to download the SQL statement.
StartTime/EndTime
The format of StartTime and EndTime is standard SQL so it depends on your database. For SQL Server you can use the DATEADD function:
DATEADD(day, -2, a.StartTime)
For some reason the display of dates in SQL Server needs to be adjusted by 2 days. This might not be the case for your server. For Oracle you use to_date. This will convert the numbers 42907.877962963 etc to something like 2017-07-10 15:10:43.000.
You can now play around with the display of the StartTime and EndTime to get the format you want. I prefer to split out the date and time. This will display the start time as YYYYMMDD (zero-padded):
CONVERT(VARCHAR(4), DATEPART(yyyy, DATEADD(dd, -2, a.StartTime)))
+ RIGHT('00' + CONVERT(VARCHAR(2), DATEPART(month, DATEADD(dd, -2, a.StartTime))), 2)
+ RIGHT('00' + CONVERT(VARCHAR(2), DATEPART(dd, DATEADD(dd, -2, a.StartTime))), 2)
And this displays the time element of the start time as HHMM:
RIGHT('00' + CONVERT(VARCHAR(2), DATEPART(hour, DATEADD(dd, -2, a.StartTime))), 2)
+ RIGHT('00' + CONVERT(VARCHAR(2), DATEPART(mi, DATEADD(dd, -2, a.StartTime))), 2)
ActivityCode
There is no table in the HFM database that contains the descriptions for the ActivityCode column so we will have to use a CASE function. You could create a table in your database to hold the activity codes and their descriptions if you preferred. So the CASE syntax is like this:
CASE a.ActivityCode
WHEN 0 THEN 'Idle'
WHEN 1 THEN 'Rules Load'
WHEN 2 THEN 'Rules Scan'
WHEN 3 THEN 'Rules Extract'
……
END AS Activity,
ModuleName
The module name is similar to ActivityCode in that there is no table containing the descriptions but has an extra complication. All of the records have #@RID@# at the beginning. We could keep that piece of text in the CASE statement but I prefer to remove it:
CASE REPLACE(a.strModuleName, '#@RID@#', '')
WHEN 0 THEN 'ADMINISTRATION'
WHEN 1 THEN 'CELL_HISTORY'
WHEN 2 THEN 'CLOSE_APPLICATION'
WHEN 3 THEN 'CONSOLIDATION'
……
ELSE a.strModuleName
END AS Module
WHERE clause
We don’t want to extract all the Task Audit data every month so we need a WHERE clause to restrict what data is extracted. This piece of code will only include data that has a start time within the month four calendar months ago. So if we are in November now, it will only include records for July.
WHERE DATEDIFF(MONTH, DATEADD(day, -2, a.StartTime), GETDATE()) = 4
You could also include exclusions on the ActivityCode (e.g. Logoff is 31) if you wanted.
Automation
Save your SQL statement to a file and call it using the sqlcmd statement e.g.:
sqlcmd -S %Server% -E -d %DB% -i %Script% -o "%Output%" -s "|" –W
The items between the % symbols are batch variables e.g.
set Script=getActivity.sql
That will extract the Task Audit data to a file. You will then probably add a statement to delete the records from Task Audit for the same month. And for the delete statement you will add some exceptions such as
WHERE ActivityCode NOT IN (1, 21, 23, 26, 29, 75)
This will keep all the application changes and logon information.
You can download the full SQL statement here. It has the extension .key and is a text file:Download GetActivity SQL statement
Conclusion
With this SQL statement, you can have an automated process to extract and manage the Task Audit data. The data that is extracted and deleted is customisable. This means that you can keep your Task Audit data to a minimum while keeping a full year’s data for the important audit records. Information on all application changes and are kept as well as the logon information for all users.