This article explains how to run a custom database query on a schedule, write the results to a log file, and surface that data in EventSentry's Web Reports.
The setup uses a Windows System DSN to connect to a database, which means it works with any ODBC-supported engine — including SQL Server, PostgreSQL, MySQL and others. The steps below use PostgreSQL (psqlODBC driver) as an example, but the EventSentry configuration is identical regardless of the backend. If you are connecting to a SQL Server database instead, create the System DSN using the ODBC Driver XX for SQL Server.
The example script queries all error events from the EventSentry database and writes them to a .log file. Each run produces a new timestamped file, so EventSentry treats every execution as a fresh log entry.
A – Set Up a System DSN
The PowerShell script connects to the database through an ODBC System DSN. This must be configured before the script can run.
B – Create and Test the PowerShell Script
The script connects to the database via the System DSN, runs a query, and writes the results to a timestamped log file. Remember to:
Reference the System DSN: Set the DSN variable to the name you created in section A.$dsn = "EventSentryPG"
Set the Output Directory: Define the folder where the script will write its output files.$outputDir = "C:\Scripts\Logs"
Create Timestamped Output Files: Each run generates a uniquely named file so EventSentry picks it up as a new log entry.$timestamp = Get-Date -Format "yyyy.MM.dd_HH.mm.ss"
$outputFile = Join-Path $outputDir "ESErrors_$timestamp.log"
Test the Script: Run the script manually and confirm that a new file appears in the output directory for each execution. The file name should reflect the current timestamp.
You can use the following PowerShell script as an example:
C – Set Up a User Embedded Script
Once the script is working, add it to EventSentry as a User Embedded Script so it can be called by an Action.
powershell.exe -inputformat none -executionpolicy bypass -fileD – Define the Log File to Monitor
Configure EventSentry to recognize the output files generated by the script.
C:\Scripts\Logs\ESErrors_*.log The * wildcard matches any timestamp in the file name, so every file the script creates will be picked up automatically. E – Create a Log Files & APIs Package
Note: Step 3 is required if you want the log data to appear in Web Reports.
F – Create an Application Scheduler Package
Set up the desired schedule for the script to run. You can use the Test option to ensure the script is working correctly, then click OK.
Assign the package to the desired host (the machine where the script will run).
G – Save the Configuration
Save the new configuration by clicking Save in the ribbon (Home > Save). EventSentry will deploy the changes to the assigned host and begin executing the script on the defined schedule.
Verifying the Results in the Web Reports
To confirm, go to the Web Reports > Features > Log Files. Use the summary view to locate the log, or search by the file name pattern defined in section D.
Each scheduled run should produce a new entry in the log file list, with the query results visible as individual log lines.
More information and related articles:
Defining Monitored Files
EventSentry Training [09-01]: Non-Delimited Logs / Log File Monitoring
EventSentry Training [09-02]: Delimited Logs / Log File Monitoring
How to monitor data in a SQL database
Manage your cookie preferences below:
To learn more about our use of cookies, please see our
Privacy Policy.