Is it possible to get alerted when monitoring database gets damaged?

I have had monitoring database damaged when power outage happened. Is there way I could immediately get notified when monitoring database requires fixing?

Q: I would prefer to get notified when monitoring database becomes inconsistent. How to spot that early?

A: Below are steps that allow you to check monitoring database for consistency, without stopping IPHost Network Monitor.

Prerequisites
  • Firebird 2.5 (32-bit version) installed on computer running IPHost. Download it from Firebird site; choose 2.5 version in sidebar menu, then download .exe from “32-bit Classic, Superclassic & Superserver” section; to install:
    • stop IPHost monitoring service (from Tools menu of IPHost GUI client) and use Task Manager to stop any fbserver.exe process still running
    • install downloaded Firebird distribution .exe; do not make it start on computer boot and do not enable Guardian service
    • start IPHost monitoring service again
  • select disk drive with enough disk space (should have free space at least 3 times as much as current monitoring database size).
Configuring the script

Select the text of script below, copy and paste it into text editor such as Notepad, check somewhere as check_db.cmd (you can choose whatever name you wish, just adjust the monitor settings, mentioned below, accordingly).

Alternately, you can download script archive and unpack the mentioned file from it.

@echo off

C:
cd \Firebird

SET errorlevel=
SET IPHOST_DATADIR=C:\ProgramData\IPHost Network Monitor\data
SET FIREBIRD_BIN=C:\Program Files (x86)\Firebird\Firebird_2_5\bin
SET BACKUP_DIR=D:\Backup\IPHost
SET ISC_USER=SYSDBA
SET ISC_PASSWORD=masterkey

rem Deleting files, if already exist
del /q /f nms-test.fdb nms-test.gbak nms-unchecked.gbak >nul 2>&1

rem Copy nms.gbak file, if present
if exist "%IPHOST_DATADIR%\nms.gbak" (
    copy /Y "%IPHOST_DATADIR%\nms.gbak" "%CD%\nms-unchecked.gbak" >nul 2>&1
) else (
    echo Database hot backup does not exist
    exit 1
)

rem File hasn't copied, aborting
if not exist "%CD%\nms-unchecked.gbak" (
    echo Hot backup could not be copied for processing
    exit 2
)

rem Attempt to get FDB database file from its hot backup
"%FIREBIRD_BIN%\nbackup.exe" -r "%CD%\nms-test.fdb" "%CD%\nms-unchecked.gbak" >nul 2>&1
if errorlevel 1 (
    echo Cannot restore database from hot backup
    del /q /f nms-test.fdb nms-unchecked.gbak >nul 2>&1
    exit 3
)

rem Attempt to make regular backup from this FDB file, thus checking for errors
"%FIREBIRD_BIN%\gbak.exe" -SE localhost/3055:service_mgr -b "%CD%\nms-test.fdb" "%CD%\nms-test.gbak" >nul 2>&1
if errorlevel 1 (
    echo Cannot create backup file from database
    del /q /f nms-test.fdb nms-test.gbak nms-unchecked.gbak >nul 2>&1
    exit 4
)

echo 0
rem Uncomment two lines below to enable backups
rem SET DOW=%date:~0,3%
rem copy /Y "%CD%\nms-test.gbak" "%BACKUP_DIR%\nms-checked-%DOW%.gbak" >nul 2>&1
del /q /f nms-test.fdb nms-test.gbak nms-unchecked.gbak >nul 2>&1
exit 0

Now open the script in text editor and adjust the lines mentioned below:

Lines 3,4

C:
cd \Firebird

The above is temporary directory used to perform database check. It should have at least 3 times as much free disk space, as monitoring database itself, at the moment. The script assumes it is C:\Firebird directory. If you create it elsewhere, adjust drive letter and path to the directory.

Line 7

SET IPHOST_DATADIR=C:\ProgramData\IPHost Network Monitor\data

The above is path where IPHost Network Monitor keeps its database file (nms.fdb) and its automatically made daily backup (nms.gbak).

You can find path to that file by opening “Settings -> System -> Path to the nms.fdb file”. The path should, as shown in the sample, end without slash. Important: make sure there are no extra white space in any part of the string, otherwise script won’t work.

Line 8

SET FIREBIRD_BIN=C:\Program Files (x86)\Firebird/Firebird_2_5\bin

The path to Firebird server binaries mentioned in prerequisites above. Adjust the path as required. Check, as well, that there are no extra white space.

Line 9

SET BACKUP_DIR=D:\Backups\IPHost

This is optional. If this is set and two lines below are uncommented, the script will copy the temporary backup it creates to the specified directory, using day of the week abbreviation (Mon, Tue etc) as suffix, to keep up to 7 weekly rotating backup files.

We strongly recommend to enable this feature and copy the mentioned files elsewhere. Make sure the backup directory specified above does exist and user, that has installed IPHost, can write to it.

Lines 48,49

rem SET DOW=%date:~0,3%
rem copy /Y "%CD%\nms-test.gbak" "%BACKUP_DIR%\nms-checked-%DOW%.gbak" >nul 2>&1

Uncomment the lines (remove ‘rem ‘ from their beginning) to enable backup feature.

After the file has been updated and all directories created, check it in action. Open cmd.exe command line window and type command:

cmd.exe /c C:\Scripts\check_db.cmd

Use actual script name, if you choose something different from check_db.cmd. Use actual directory name instead of C:\Scripts, where the script itself has been placed.

If everything is set up correctly, script will silently work for up to several minutes (depending on database size and disk I/O speed) and then print single digit 0. No new files should remain in the working directory (see lines 3,4) after that. If something else is printed, feel free to contact us for assistance. Please send us the exact copy of your check_db.cmd script and everything it prints.

Important: if you have upgraded your IPHost version less than 24 hours ago, the script may report that it can’t restore hot backup. This behavior is normal: the nms.gbak file created during IPHost upgrade, has different format. Please wait until IPHost creates first automated backup (which usually happens around 4:00am at the computer where IPHost monitoring service is running) and then proceed with the monitor setup below.

Create a monitor

Now that we have script and it has been tested, let’s create monitor to get alerts if database checks fail for some reason.

Click on “New Monitor” and create a new Script or Program monitor on the host where IPHost is running.

On step 3, define main parameters, so that would look like this:

Main parameters

Note: specify (in program arguments field) full path to the script, as in an example above.

Click on State conditions tab and define state conditions as on example. Make sure to disable (uncheck) spike filters. Also, remove Warning state conditions entirely.

Main parameters

Define alerts on Alerting tab as you see optimal, just keep in mind that monitor is set up to run daily.

Related topics