• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Simple Ping Monitor

    How-To
    2
    11
    2.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      Wingnut2.0
      last edited by

      Hello,

      I am looking for a simple way to monitor devices up-time. I found this thread https://forum.infiniteautomation.com/topic/3295/access-control-ip-monitor and was wondering if this is still the preferred method?

      The reason I am asking is that this seems like there must be a more efficient way to accomplish this than creating a Data source, Data point, Virtual Data point, and event handler for each individual device. Could this possibly be accomplished using a global script if it involved many devices?

      Thank you.

      1 Reply Last reply Reply Quote 0
      • phildunlapP
        phildunlap
        last edited by

        Hi Wingnut2.0,

        Of course! Scripts do enable pretty much anything. Can you say more about how you're going to monitor what sort of device's uptime? You could make HTTP requests through the HttpBuilder and check for timeouts. For that matter, in the referenced thread it is about pinging. You could do something like

        function ping(host) {
            return $EXEC('ping -c 1 ' + host + '; echo $?'); //returns 0 on successful ping
        }
        

        if you enabled shell access to your scripts: https://forum.infiniteautomation.com/topic/3818/invoke-shell-commands-from-a-scripting-environment

        So, yes, it's probably possible, but a specific answer will require knowing how you'll be monitoring it.

        1 Reply Last reply Reply Quote 0
        • W
          Wingnut2.0
          last edited by

          Thank you, Phillip.

          After your response, I am thinking about a binary meta point per device with timer update event and change detector to monitor the device(s) online status.

          1 Reply Last reply Reply Quote 0
          • phildunlapP
            phildunlap
            last edited by

            Certainly! Sounds like a good solution!

            Another option could be setting the information to a single alphanumeric point with a change detector if you're only looking for event active emails. Then you could do it all in a single scripting data source, and just edit the script when new hosts come around.

            1 Reply Last reply Reply Quote 0
            • W
              Wingnut2.0
              last edited by

              In the Alphanumeric approach, would the scripting data point hold the host info (IP) and pass it to the data source script? Or are you suggesting the hosts be part of the script and the alphanumeric point is the trigger for a general alarm for any return of 1?

              1 Reply Last reply Reply Quote 0
              • W
                Wingnut2.0
                last edited by

                Hello Phillip,

                I had a chance to try this out and I do not seem to get a response when running the ping command (this is on a MangoES). I have verified shell access is available via scripts by running commands like the ones below where I receive a response.

                var response = $EXEC("ls -l");
                print(response);
                
                var ip = $EXEC("ip a"); 
                print(ip);
                

                Can you confirm similar behavior? Is this a permissions issue?

                Thank you.

                1 Reply Last reply Reply Quote 0
                • phildunlapP
                  phildunlap
                  last edited by

                  Can you confirm similar behavior? Is this a permissions issue?

                  Yes, it is a Linux permission issue. One needs to give the ping a certain capability to be run with a lower privilege user, as java does to bind privileged ports. In this case, run,

                  sudo setcap 'cap_net_raw+ep' /bin/ping

                  1 Reply Last reply Reply Quote 0
                  • phildunlapP
                    phildunlap
                    last edited by phildunlap

                    I should have tested this, it doesn't look like echo $? works. Maybe something like,

                    function ping(host) {
                        return /1 received/.exec($EXEC("ping -c 1 " + host)) !== null;
                    }
                    
                    1 Reply Last reply Reply Quote 0
                    • phildunlapP
                      phildunlap
                      last edited by phildunlap

                      Ah, looks like there was an answer if only I had checked the documentation on enabling the shell scripting access: https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/shell.html

                      So, maybe,

                      function ping(host) {
                          $EXEC("ping -c 1 " + host);
                          return $EXIT //=== 0
                      }
                      
                      1 Reply Last reply Reply Quote 1
                      • W
                        Wingnut2.0
                        last edited by

                        As always, thank you.
                        Works perfectly and I appreciate the link to the documentation.

                        $EXIT
                        This global object is used to store the exit code of the process. If the exit code is not zero, then the process failed.
                        
                        1 Reply Last reply Reply Quote 0
                        • phildunlapP
                          phildunlap
                          last edited by

                          You're welcome!

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post