Kaseya Community

Duplicate Question: Machine Variable

  • This was posted in the Monitor forum but I know some people look at the Scripts forum and not Monitor so wanted to throw this out where everybody can see it.

    The script runs from our Kserver when the monitor (agent offline) is triggered

    Code:
    Script Name: Gateway
    Script Description: Pings machine gateway to check for connectivity

    IF True
    THEN
    Execute Shell Command
    Parameter 1 : ping %client_Firewall%>>C:\utility\ping.txt
    Parameter 2 : 0
    OS Type : 0
    Execute Script
    Parameter 1 : Ping Email (NOTE: Script reference is NOT imported. Correct manually in script editor.
    Parameter 2 :
    Parameter 3 : 0
    OS Type : 0
    ELSEScript that is called upon

    Code:
    Script Name: Ping Email
    Script Description:

    IF Test File
    Parameter 1 : C:\utility\ping.txt
    Contains :bytes=
    THEN
    Send Email
    Parameter 1 : support@domain.com, pagernumber@domain.net
    Parameter 2 : Server offline
    Parameter 3 : The client gateway is pinging but a server is offline. This needs checked immediately.
    OS Type : 0
    ELSE
    Send Email
    Parameter 1 : support@domain.com
    Parameter 2 : Server offline and no ping
    Parameter 3 : The server is offline, and the gateway is unreachable. This is probably an internet down situation.
    OS Type : 0

    What I need is a variable that will pull the machineid.groupid of the machine that triggers the Monitor and passes that variable to the script so that we know which machine is offline. I can use the MachineID variable, but it pulls the Kserver id since that is where the script runs. Ideas?

    Legacy Forum Name: Duplicate Question: Machine Variable,
    Legacy Posted By Username: JonJohnston
  • Hey Jon, just sent you a PM asking this same question! That'l teach me to not read further down my search results....

    Anyway, wondering if you or anyone found a resolution for this? Or a different way of checking it?

    thanks in advance!

    Rick J

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: rbjsea
  • So far it is working great for us. It is not fully in production yet however.
    What I had to do was hardcode the live IP into the script, therefore 1 script per client per site.
    My latest version of this script includes another step, so 3 scripts total. But now the second one checks the alert time and last checkin time of the machine that triggered the alert, and sends an email or continues to the third script accordingly. This prevented the emails saying the server is offline when it came back online. Let me know if you would like to see the latest version. We are having a meeting tomorrow to decide if we are going to fully implement this, but as mentioned with the limited rollouts it has worked wonderful.
    I have been able to trigger an alert and have our pager going off that a server was down in as little as 3 minutes. However, for practical purposes this time period is going to be expanded.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: JonJohnston
  • You can't use #vMachine.ConnectionGatewayIp# for this? That would ping the agents connection gateway (external IP address of the firewall).

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Lmhansen
  • Lmhansen
    You can't use #vMachine.ConnectionGatewayIp# for this? That would ping the agents connection gateway (external IP address of the firewall).


    That is exactly what I thought at first, except that this script runs from our Kserver, so it pings the Kserver live IP which fails. I looked for a variable that would take the connection gateway of the machine that triggers the alert, but I have not been able to find one.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: JonJohnston
  • JonJohnston
    That is exactly what I thought at first, except that this script runs from our Kserver, so it pings the Kserver live IP which fails. I looked for a variable that would take the connection gateway of the machine that triggers the alert, but I have not been able to find one.


    Ah ... why not use the "system check" under "external monitoring" on the Monitor tab? You can have it ping anything, anywhere from anywhere (as long as there's an agent somewhere...)

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Lmhansen
  • Lmhansen
    Ah ... why not use the "system check" under "external monitoring" on the Monitor tab? You can have it ping anything, anywhere from anywhere (as long as there's an agent somewhere...)


    Let me explain what we are trying to do, because while the system check is a good idea I do not beleive it will work.

    We are trying to devise a plan that when an agent goes offline, we get alerted. Well that's simple, except my boss wants to know if it is the server down, or an internet/power outage. Therefore, I came up with the idea f triggering a script to run from the Kserver that pings the client firewall. If ping is successfull, but server is down, an email is sent out to everybody, including our on-call pager that a server is down. If ping fails, we assume the internet or power is down and just send an email.

    I have this setup so if a server does not checkin for 1.5 minutes we get alerted. At 20 minutes the pager goes off if the internet is up but agent offline.

    We considered SNMP traps but at this time have decided against implementation; the script check is simpler even though we must have 1 script per client.

    If you have any other ideas though I would be glad to hear them or if you would like to review the script I can post it.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: JonJohnston
  • If you are using a group per customer and they only have one gateway you could setup a group variable for the internet ip, a bit of a pain to configure initially, but you can call it from the script and only have to maintain one script overall, not one per client?

    I assume this fits with what you are trying to achieve.
    Also keep in mind some firewall devices wont respond unless configured Smile

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: philipj@itwest.biz
  • philipj@itwest.biz
    If you are using a group per customer and they only have one gateway you could setup a group variable for the internet ip, a bit of a pain to configure initially, but you can call it from the script and only have to maintain one script overall, not one per client?

    I assume this fits with what you are trying to achieve.
    Also keep in mind some firewall devices wont respond unless configured Smile


    Not a bad idea, and I might go ahead and do the custom variable. We have started implementing this, and it's been very simple to just create a new script with the client's specific IP, and then still call upon the other two scripts.

    As for the firewalls, this gave us yet another reason to hurry up and finish some configurations we have been meaning to do, including allowing ICMP from our IP.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: JonJohnston
  • JonJohnston
    So far it is working great for us. It is not fully in production yet however.
    What I had to do was hardcode the live IP into the script, therefore 1 script per client per site.
    My latest version of this script includes another step, so 3 scripts total. But now the second one checks the alert time and last checkin time of the machine that triggered the alert, and sends an email or continues to the third script accordingly. This prevented the emails saying the server is offline when it came back online. Let me know if you would like to see the latest version. We are having a meeting tomorrow to decide if we are going to fully implement this, but as mentioned with the limited rollouts it has worked wonderful.
    I have been able to trigger an alert and have our pager going off that a server was down in as little as 3 minutes. However, for practical purposes this time period is going to be expanded.



    Jon, I'd love to see the scripts as you have them now (including the 3rd you mentioned). It would be cool to pass a variable (or two) between scripts, or to a script directly from the alerts screen...

    Did you all decide to roll this out to everyone?

    thanks for the work!

    rj

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: rbjsea
  • rbjsea
    Jon, I'd love to see the scripts as you have them now (including the 3rd you mentioned). It would be cool to pass a variable (or two) between scripts, or to a script directly from the alerts screen...



    Did you all decide to roll this out to everyone?



    thanks for the work!



    rj




    Sure, I don't mind sharing them. See this thread, about halfway down the first page. http://community.kaseya.com/xsp/f/28/t/6172.aspx.



    I am stillhaving some trouble with the script. In testing and limited roll-outs everything worked great. As we have started implementing this on more client servers, my variable in the second script has not been working the way it should. The second script compares the last checkin time with the alert time (agent online or offline) and sends an email if the agent has checked in since the alert.



    Now part of this could be an easy fix: by default agent checkin time is 45 seconds. We have changed a few servers to lower periods, I think I need to change all of the servers to a lower time period.

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