[Utility] Powershell watchdog script for monitoring the Blue Iris logfile and sending notifications

jaydeel

BIT Beta Team
Nov 9, 2016
1,466
1,479
SF Bay Area
I've created a PowerShell watchdog script to monitor the Blue Iris logfile and send push notifications (via Pushover or Telegram) when entries are found that match specified values (key words). You can specify any or all of the logfile entry columns: 'severity level', 'object', and 'message'. A batch mode is also supported for multiple queries (see post #3). Additionally, a test mode is supported for experimenting with queries (see post #4).

Typically, the script would be executed every 30 minutes or so from Windows Task Scheduler. The script is very fast and is not resource intensive because it inspects only the newest logfile entries since the script's previous execution. The entire logfile is loaded into memory only on the very first execution.

This utility may be for you if you have ever discovered LONG AFTER-THE-FACT that your Blue Iris system has issues that you wish you had known about sooner, for example:
  • Database corruption
  • Server issues
  • Drive issues (overallocated)
  • Clip issues, (e.g., 'Disk can't write fast enough', 'Cannot append')
  • Camera issues ('Failed to connect', 'Socket error', 'FORCE quitting camthread')
  • AI issues ('AI: error', 'AI Faces: Error -1')
  • MQTT 'publish' failures
  • Action Set errors ('Push: failed', Write action 'error 32')
  • Software update failures
In addition to the core functions of finding logfile entries with issues, this script also has these features:
  • It saves timestamped results from each execution to a CSV file in the script's folder.
  • It can log results to the Blue Iris logfile (optional).
  • It has a convenient help guide BI_logfile_wdog.ps1 -Help
  • It has a convenient examples guide BI_logfile_wdog.ps1 -Examples

HOW TO GUIDE...

STEP #1:


Install the script and its companion 'user settings file'

  1. Extract all the files from the attached zip file to your desktop, or scripts folder.
  2. Please note that the folder used must be in your PC's environment path.
  3. Create a working folder for this script - it will be used to process the attachments files; to hold the script's log file, etc.
  4. To use the folder, you must edit a user setting $app_path in the user-settings script file (see STEP #2)

NOTE: If you've never used PowerShell on your Blue Iris PC, you may first to need to change its default security policy.
Open PowerShell in Administrator mode, and type the following, then hit the Enter key: Set-ExecutionPolicy RemoteSigned
(click here for a nice beginner's tutorial to using PowerShell).


STEP #2:

Edit the user settings file
The user settings file is named 'BI_logfile_wdog_user_settings.ps1'
  1. Open the file in a text editor (a code text editor is recommended; I use Notepad++)
  2. Edit the REQUIRED SETTINGS section (see screenshot)
  3. Ignore the remaining settings for now. They provide customizations that you may want to explore later.
user_settings_reqd.png

STEP #3:

Test the script from the PowerShell console

Open an Admin PowerShell window, or Powershell-ISE window​

3.1 - Select and copy the following command and paste it into the console.
BI_logfile_wdog.ps1
Hit the Enter key.
  1. The first execution will show a count of all entries the active logfile.
  2. Wait a few seconds (maybe longer), then repeat the command.
  3. Now it will show the number of new entries in the logfile.
The response should look like following 2 screenshots:

execute_1st_time.png


execute_2nd_time.png


3.2 - Select and copy the following command and paste it into the console.
BI_logfile_wdog.ps1 -Examples
Hit the Enter key.
  1. Look at the bottom 'TIP' section.
  2. Select and copy the URL.
    The URL should be like, http://<ip_adress and port>/admin?log=demo%20message&level=2
  3. Paste the URL to the address bar in your Internet Browser
  4. Hit the Enter key.
This will add a new error entry to your Blue Iris logfile that we can test in the next step (3.3).
Note that you can edit the URL as desired to create ANY demo issue you want to test.

3.3 - Select and copy the following command and paste it into the console.
BI_alert_protect.ps1 -FilterLevels 2
Hit the Enter key.

The response should look like following screenshot:
execute_filterlevels_2.png


And the command should send a notification to your Pushover or Telegram device that looks like one of these 2 screenshots:

push_pushover_1.jpg push_telegram_1.jpg

STEP #4

Automate the script from Task Scheduler.

task_scheduler.png


USAGE GUIDE Screenshots:
usage_guide_help.png usage_guide_examples.png

SCRIPT ZIP FILE:
EDIT (2024-10-26): Script updated to V2 - added file 'batch_mode_template.txt' (see post #3); minor output summary formatting fix
EDIT (2025-02-22): Script updated to V3 - new argument -PushService; improved the formatting pf notification messages; updated 'batch_mode_template.txt' (see post #6)
PLEASE NOTE: if you are updating, you must edit & use the new user-settings-file
tip: to facilitate editing, rename the existing settings file before unzipping the update.
 

Attachments

Last edited:
This post contains some usage examples for Powershell script 'BI_logfile_wdog.ps1'.

Note: A default notification uses the settings specified in the script's user-settings-file.

1. Send a default notification if the Blue Iris logfile has recently added a drive(s) overallocated error:
BI_logfile_wdog.ps1 -FilterLevels 2 -FilterMsgs "free","-"

Note: Argument -FilterMsgs is using the AND logical operator (the comma ",")
Example of the logfile entry we are looking for...​
2 9/23/2024 9:54:11.611 AM D: 9635 items, 6505/8405GB (731.6GB/7.27TB free, -1.14TB)
Note: The "-" term is not strictly needed to detect this error, but it makes it more precise (in case another error contains the keyword "free")
example_1.png example_1_push.jpg

2. Send a default notification if the Blue Iris logfile has recently added any error:
BI_logfile_wdog.ps1 -FilterLevels 2 -ShowMatches

Note: Argument -ShowMatches applies only when the command is executed in the console. The argument is ignored when the script is executed from the background, e.g. via Task Scheduler, or a Blue Iris Action.
example_2.png example_2_push.jpg

3. Send a default notification if the Blue Iris logfile has recently added any error entries that involve storage folders 'Alerts' OR 'Aux 1':
BI_logfile_wdog.ps1 -FilterLevels 2 -FilterObjects 'Alerts|Aux 1'

Note: Argument -FilterObjects is using the OR logical operator (pipe character '|')

4. Send a priority 1 Pushover notification if the Blue Iris logfile has recently added any of the specified common issues keywords:
BI_logfile_wdog.ps1 -FilterMsgs "err|fail|died|debug|missing|undefined|quit|corrupt" -PushService "pushover"-Priority 1 -Title "Common logfile issue(s)"

Note: Argument -FilterMsgs is using OR logical operators (pipe character '|')
example_4.png example_4_push.jpg

5. Send a default notification if the Blue Iris logfile has recently added any of the specified less common issues keywords:
BI_logfile_wdog.ps1 -FilterMsgs "keep up|force|fast enough|cannot|can't|unexpected|not responding|file exists" -Title "Less common logfile issue(s)" -ShowMatches

Note: Argument -ShowMatches shows ALL matches, while the Push notification only shows only 1 logfile entry per match when the filter argument has only OR logical operators. This is done to avoid an excessively long notification message.
example_5.png example_5_push.jpg

6. Send a default notification if the Blue Iris logfile has recently added error entries with warning or error keywords:
BI_logfile_wdog.ps1 -FilterLevels 2 -FilterMsgs "error","!warning" -ShowMatches

Note: Argument -FilterMsgs is using both AND and NOT logical operators
The tested logfile contained these entries...​
2 10/25/2024 3:01:06.556 PM External (demo) warning message
2 10/25/2024 3:01:00.686 PM External (demo) error message
But the script command matched only the 2nd (as expected).​
example_6.png example_6_push.jpg
 
Last edited:
  • Like
Reactions: jrbeddow
This post describes the 'batch mode' for Powershell script 'BI_logfile_wdog.ps1'

The zip file in post #1 has been updated to
V2 and now includes a 3rd file named batch_mode_template.txt.
You can make a copy of this file and edit it as you desire.

Instead of creating multiple Task Scheduler tasks for notification of different logfile issues, the script supports using a batch file, for example:
BI_logfile_wdog.ps1 -BatchFile "my_filters.txt"

Where file 'my_filters.txt' contains actionable lines like:
Code:
-FilterLevels=2;-Title=Logfile level '2' errors;-Priority=1
-FilterLevels=2;-FilterMsgs="free","-";-Title=Drive(s) Overallocated!;-Priority=2
-FilterLevels=2;-FilterMsgs="live.sem stuck";-Title=Possible Memory Leak pending;-Priority=2

KEY POINTS:
  • The path for -BatchFile is not required if the file is located in the script's working folder ($app_path in the user-settings-file).
  • The actionable line syntax has some differences compared to commands used in the Powershell console:
    • each argument is delimited by a semicolon instead of a space
    • arguments and values are separated by '=' instead of a space
    • quotes are not required for argument values EXCEPT when using a comma as an AND logical operator (2nd example above).
  • The -BatchFile may contain comment lines (start with '#' or '//').
  • Each actionable line can have individualized push notification titles (and for Pushover: priority, sound, and devices).
Another feature is that the default notification service and parameters in the -BatchFile can be superceded by specifying them in the command line, e.g.:
BI_logfile_wdog.ps1 -BatchFile "my_filters.txt" -PushService "telegram"

UNDER THE HOOD:

The script's "batch mode" works by recursively calling the script. This method uses several .txt files to track progress. These files are located in a subfolder under the script's working folder (\script_files\batchfile_arg*.txt).

On occasion these files may get out of sync (e.g., if the script does not run to completion).
If the script is not running as you expect, try using this command:
BI_logfile_wdog.ps1 -Reset
 
Last edited:
This post describes the 'test mode' for Powershell script 'BI_logfile_wdog.ps1'

Instead of inspecting the Blue Iris active logfile, the script supports using a test file, for example:
BI_logfile_wdog.ps1 -TestFile "test.txt" -FilterMsgs "xxx"
BI_logfile_wdog.ps1 -TestFile "test.txt" -BatchFile "my_filters.txt"

Why use?
Using a test file provides a more convenient way to test a filter set or batch file. You don't need to wait for an event to happen. Nor do you need to insert mock entries into the active logfile, as described in step #3.2 in post #1.

The file specified via argument -TestFile should have rows exactly like the Blue Iris logfile, for example:
Code:
level    time    object    message
2    8/22/2024 12:01:43.615 AM    DW1    Clip: Disk can't write fast enough (0 2594 30010 74024)
2    8/22/2024 12:02:06.131 AM    FD    Clip: Disk can't write fast enough (0 1918 30005 95802)
2    9/23/2024 9:50:48.051 AM    D:    9636 items, 6505/12405GB (731.4GB/7.27TB free, -5.04TB)
2    10/20/2024 10:47:22.607 AM    DW1    AI: not responding
2    10/20/2024 10:47:23.022 AM    DW2    AI: not responding
2    10/20/2024 10:47:23.544 AM    DW2    AI: not responding
2    10/20/2024 10:47:24.044 AM    DW2    AI: not responding
2    10/20/2024 10:47:24.777 AM    DW2    AI: not responding
2    10/20/2024 12:47:25.007 PM    BY    Clip: Disk can't write fast enough (0 1920 30010 0)
2    10/23/2024 2:50:51.154 PM    D:    8826 items, 6503/7405GB (733.0GB/7.27TB free, -168.5GB)

KEY POINTS:
  • The path for -TestFile is not required if the file is located in the script's working folder ($app_path in the user-settings-file).
  • If -TestFile does not have a header (level, time, object, message), it will be automatically inserted.
  • Each line in -TestFile must have 4 tab-delimited columns.
  • Once you have finished experimenting with a test file, you should run the following commands:
    BI_logfile_wdog.ps1 -Reset
    BI_logfile_wdog.ps1 -Renew
 
Last edited:
Here's my current my_filters.txt file.

It's intended to be used for commands like:
BI_logfile_wdog.ps1 -BatchFile "my_filters.txt"

You might find this batch file to be useful while developing notifications for issues you wish to discover and receive notifications.

Feel free to comment out the lines that you are not interested in using.

And if you encounter potentially problematic logfile entries that I've not included in the file, please share them.
 

Attachments

  • Like
Reactions: looney2ns
Script updated to V3. See post #1 to download the file.

Why you might want to use this new version:
  • To specify a non-default push service (or both Pushover AND Telegram) for specific notifications
Changelog:
  1. BREAKING CHANGE: must replace old user-settings file
  2. ADDED: argument -PushService (and user-setting $push_service) may now be 'all' as well as 'Pushover' or 'Telegram'
  3. FIXED: highlighted found terms in the notification message now preserves the logfile entry's original capitalization
  4. CHANGED: user setting $use_bi_creds_flg to $post_w_creds_flg
 
Last edited:
  • Like
Reactions: looney2ns