Kaseya Community

Script generated emails at certain times of Day

  • Am looking for a script the will run after an alert , e.g."Agent Offline" , and will test for the current time of day ( or the time the alert was created ).
    If it is after hours ( say 6pm - 7am ) it will send an email to an after hours call centre who will then contact a support technician

    I've tried

    1) reading the current time system variable
    2) or writing a file them testing for its last midified date/time
    3) or looked at ways to find the alarm entry in the script log

    None of which I could get to work
    Any ideas ?


    Legacy Forum Name: Script generated emails at certain times of Day,
    Legacy Posted By Username: Paul Haaker
  • This is a very good question Paul. Please let me know if anyone else replies to you with an answer on this as it may prove very useful for other users on this forum.

    Legacy Forum Name: Script Requests,
    Legacy Posted By Username: knightmare
  • You could use the "Run script after alert" option in the alert config to run a script on your monitoring server.

    To get the time you could write a basic VB script that uses the Timer function. The Timer function returns the number of seconds past midnight. You could take that, shave off the decimal with the CInt function to make things easier and do some simple IF statements to determine if it's after hours or not and write the output to a text file in the agent's temp directory on the monitoring server. The output could be something as simple as "Day" for business hours or "Night" for after business hours. From there you can have your kaseya script read the txt file into a variable and call another script that does whatever you want based on what's in the text file your VB script created.


    Legacy Forum Name: Script Requests,
    Legacy Posted By Username: brad.g

  • I've created 2 scripts ( one calls the other )

    1st script writes the current time a text file

    "echo %time% > c:\currenttime.txt"

    It then reads the file content into the variable #currenttime#
    and then rights the variable to a temp registry key on the machine runnig the script

    i.e. "HKEY_LOCAL_MACHINE\SOFTWARE\kaseya\alert_time\alert_time"

    I then write 2 other temp keys withfixed time values to indicate the start time & end for "After Hours"

    I write "18:00:00:00" to HKEY_LOCAL_MACHINE\SOFTWARE\kaseya\alert_time\ah_start
    and write "08:00:00:00" to HKEY_LOCAL_MACHINE\SOFTWARE\kaseya\alert_time\ah_end

    Next I call my second script that compares the registry values with the IF statement

    HKEY_LOCAL_MACHINE\SOFTWARE\\kaseya\alert_time\alert_time > HKEY_LOCAL_MACHINE\SOFTWARE\\kaseya\alert_time\ah_start

    ......create approriate action for after hrs....

    ......create approriate action for working hrs....

    Still need to refine for weekends , holidays etc but this bit seems to work OK


    Legacy Forum Name: Script Requests,
    Legacy Posted By Username: Paul Haaker