Kaseya Community

Monitor Log File & Alert if Unchanged & Restart Service

  • I have an issue where a service stops working and I can tell this by the fact that it stops logging to a file. It's easy enough to fix by restarting the service.

    I have setup a script that performs a Get File and alerts if the file is unchanged (see below). But to make this 'self-healing' I would like Kaseya to let me know when it stops logging to this file and also restart the service for me. Any ideas on how to do this?


    Script Name: Service-ClientLogFile-Alert
    Script Description: Get Log file and alert if it's unchanged

    IF Test File
    Parameter 1 : %userprofile%\log\log.txt
    Exists :
    THEN
    Get File
    Parameter 1 : %userprofile%\log\log.txt
    Parameter 2 : ..\Docs\log.txt
    Parameter 3 : 4
    OS Type : 0
    ELSE



    Legacy Forum Name: Monitor Log File & Alert if Unchanged & Restart Service,
    Legacy Posted By Username: jeffryer
  • i would have thought i would be easier to monitor the service, not the file, provided it actually stops rather than just not responding.

    I.E Monitoring, Monitor Sets, Create a new monitor set, go to the Services Check and add the service in there ( Update lsit by scan if not) and then set your actions on the monitor set.

    from that you can check if the service is running.
    Restart it if its not and alert on it.
    Report on the service history

    Pretty much everything you would want.

    If the service is still running, but not working, then i would be writing a script to check the file hasnt changed as you suggested, and then call another script to restart the service using a command line.

    Should be reasonably straight forward.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Commander
  • The service stops responding but still shows that it is running; that's why I want to monitor the log file. It's the only reliable way I know of to know that the service stopped working. So the trigger would be that there are no changes to the log file and the action would be to alert, email, and restart the service.

    So I guess the question is how to make a script that checks if the file hasn't changed. Any examples of how to do this?

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: jeffryer
  • One strategy would be making a copy of the log (for example, once an hour) and comparing it to the original. Here is a free command line utility to compare:

    http://www.gammadyne.com/cmdline.htm#fcmp

    In Kaseya, schedule a script like this:

    1. fcmp /nologo log1.txt log2.txt > compare.txt
    2. copy /y log1.txt log2.txt
    3. Execute another script like this:

    Script Name: File Compare Example
    Script Description:

    IF Test File
    Parameter 1 : compare.txt
    Contains :Files are identical.
    THEN
    Execute Shell Command
    Parameter 1 : net stop service
    Parameter 2 : 1
    OS Type : 0
    Execute Shell Command
    Parameter 1 : net start service
    Parameter 2 : 1
    OS Type : 0
    ELSE


    Hopefully this helps.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: SMason
  • Keep in mind if you schedule the script to run once per hour, it could be up to two hours before the service is restarted.

    Let's say the log file stops changing right after the script runs. It will then be another hour before the script runs again to compare. The files will still be different at this time. The script will then copy the log and an hour later discover they are the same.

    I don't know how critical this service is to your client, but you might want to run the script at smaller intervals.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: SMason