External ReportsOverviewIn addition to the "internal" reports available from KeyConfigure, you can also query K2 data tables using your favorite "external" SQL reporting tool. This capability lets you build your own reports with customized formatting and data summaries. Since most SQL reporting tools can query data from multiple data sources, this feature might also be used to build a custom report that joins any of K2's databases to other corporate databases. Regardless of what platform is hosting the K2 server process, there is no need to export K2 data in order to query the data using an external reporting tool. You can use any external reporting tool that can be configured to send SQL queries through ODBC - you must have set up a DSN (Data Source Name) that is configured to use the KeyServer Driver, ksODBC. Queries will be translated and conveyed to the K2 server through the ODBC driver. K2Admin.exe for Windows installs the KeyServer Driver by default - this installer can also be used to install just the ksODBC driver and external report examples without installing KeyConfigure. External Reports FolderThe K2Admin.exe installer creates an External Reports sub-folder within the Admin folder (available from the Start menu). Note: all of our external report examples are available only for reporting tools run on a Windows computer. Similar reports can be constructed using FileMaker on Macintosh (or Windows). The example reports are designed to demonstrate how to setup database joins using the various KeyServer data tables, and to show example summary calculations that may be useful. In general, there will be four files illustrating each example report:
These files are organized into four main folders (Documentation, Sample PDFs, MS Access Reports, Crystal Reports), and then subdirectories as follows:
The example reports are similar to some of the internal reports so unless you modify them, they are redundant and of little interest. However, they may serve as a valuable starting point for customization to suit your special reporting needs. In many of the example reports, there are very simple ways to change how the data is organized, what data is selected to be shown, etc. With Crystal Reports, this is accomplished through formula fields. In Microsoft Access, this is accomplished either with column aliases in the main query, or by field names in the report. In either type of file, the objects which are easy to change, and which will result in useful variations, have names which begin with underscores (e.g. “_threshhold”). This is to make it easy for you to find specific parts of the reports which you might want to change, while ignoring the parts which will probably remain the same. Assign a password to the External Report AccountBy default, the installer K2Admin.exe creates a DSN called “KeyServer Datasource”. It points to the local machine at address 127.0.0.1 and is configured with the default user name "External Report Account" and password "Sassafras". This DSN is setup to use the External Report Account that is automatically created by the KeyServer installation. However, before this account can be used, it must be given a matching password! Use the KeyConfigure Admin menu item "KeyConfigure Accounts..." to select the account "External Report Account" from the drop down menu and then set the password to "Sassafras" so it matches the DSN setup. For data privacy it is actually preferable to configure a custom password (instead of "Sassafras") for both the External Report Account and for the matching KeyServer Datasource.. When running external reports on a separate computer (e.g. not the KeyServer host), you will have to configure a DSN with the correct address of your KeyServer (instead of 127.0.0.1 created by the default install). After using k2admin.exe to install the ksODBC drivier, use the Windows administrative control panel "Data Sources (ODBC)" to modify the “KeyServer Datasource” DSN. Alternatively, you can create and configure a new DSN (with a different name but likewise based on the KeyServer Driver). Note: you will then also have to specify this new DSN name in the example reports. Changing reports to use a different DSNAll the example reports are setup to use the default DSN called “KeyServer Datasource”. You can create your own DSN using the Windows administrative control panel "Data Sources (ODBC)". Point it to the correct KeyServer address and use the "External Report Account" with the correct password (as configured in the "KeyConfigure Accounts..." dialog). To change the reports to use a different DSN:
If the K2 data tables have been exported to a dedicated database server (see exporting), then you can create a DSN that uses the corresponding ODBC driver, database server address, account name, and password - these same external reports will then use the dedicated database server as data source. Note: in Crystal Reports, when you change between a DSN using the KeyServer Driver and a DSN using some other ODBC driver, the reports may say that tables have changed. This is because many fields have different lengths if they have been exported. The reports will still work, so simply ignore the warning message. Performance NotesThe KeyServer ODBC driver has various optimizations to help reports run quickly. The most important optimization reformats original SQL queries, parsing out many common joins so they will be performed on the K2 server. Most reports take advantage of this optimization heavily. However, it is possible by adding more tables or changing how the SQL query is arranged, to prevent this optimization from occurring. This will result in a drastic slow down. You are more likely to end up with a slow report in Microsoft Access than you are in Crystal Reports. This is for a few reasons:
If your K2 server is tracking usage for hundreds of programs on many thousands of clients for dozens of months, the usage database will become very large and reports will slow in response. This is a situation that may benefit from export to a high performance, dedicated, database server. The DSN configuration details documented above explain how to continue using your custom external reports. You can also continue using internal reports (Windows KeyConfigure only) - use the Option button from the internal report interface to re-direct the data source using a properly configured DSN that points to the dedicated database server (instead of the default internal target, KeyServer). Display of ID fieldsAll of the ID fields in the KeyServer tables are of type SQL_C_BINARY. This type is used to store arbitrary data, which is not necessarily a string or a number. When Crystal Reports sees a column with this data type, it displays a string representation of the hex values contained in the field. This allows you to see the data in a readable format, and compare data from one field to another field. Microsoft Access, on the other hand, treats binary data as unicode, and simply displays whatever characters the data happens to encode. As a result, what you will see may be garbage characters (letters with accents, mixed with characters showing a square box), or it may be non-roman characters (Japanese, Russian, Arabic, etc). If you are using Access and want to be able to read the values in the ID fields, create a macro containing the function below:
Public Function DataToHex(udata As String) As String
Dim ByteData() As Byte
Dim i As Long
Dim ret As String
Dim htxt As String
ByteData = udata
ret = ""
For i = 0 to UBound(ByteData)
htxt = Hex(ByteData(i))
If Len(htxt) < 2 Then htxt = "0" & htx
ret = ret & htxt
Next
DataToHex = ret
End Function
Then, when you design your query, instead of including an ID field directly (e.g. “licenseID”), use an expression like “DataToHex(licenseID)”. Printing reports to A4Neither Crystal nor Access seem to have an easy, automatic way to convert reports from Letter size to A4 size. Here are instructions to make the borders slightly smaller, so the same content can fit on an A4 page without clipping. Microsoft Access:
Crystal Reports:
Example SQLIn case you are writing direct SQL queries, instead of using a “Builder” interface, here is an example of an SQL query. In this case, it is selecting quit events for logged and controlled programs within a certain time range, and selecting relevant fields that might be useful in a report: SELECT programVariantName,programVariant,programID,programPlatform,programVariantVersion,programFlags,programAction,usageUser,usageTime,usageWhen,usageOtherTime
FROM {oj KSUsage INNER JOIN KSPrograms ON KSUsage.usageProgramID=KSPrograms.programID AND KSUsage.usageServerID=KSPrograms.programServerID }
WHERE (usageEvent=4 OR usageEvent=9 OR usageEvent=11 OR usageEvent=13) AND programAction>1
AND usageWhen>={ts '2008-12-01 00:00:00'} AND usageOtherTime<={ts '2008-12-02 00:00:00'}
ORDER BY programVariantName,programVariant,usageUser
Note that this example is selecting any quits where the use of the program overlapped a certain day whatsoever. If you are dealing with the results in some sort of programming interface, such as php, then the code dealing with the results can adjust to only count the overlap, instead of the entire duration. Also, since the SQL is not doing grouping and summarization, the results may not be terribly interesting unless some summarization is done on them after the fact. You could use SQL's GROUP BY syntax to do some summarization, but you would be limited to a single level of summarization - unlike the internal reports which often have two levels of detail.
|
Related TopicsReportsReport Options Dialog Exporting KeyServer Tables Description Account Setup and Passwords Help Index |