Ad Widget

Collapse

Ping an external IP-address from a Zabbix agent.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johnusa
    Junior Member
    • Jul 2009
    • 12

    #1

    Ping an external IP-address from a Zabbix agent.

    Hi, We are running a Zabbix server (1.6.5) monitoring, amongst many, a Linux server (with the Zabbix agent installed). We have established a VPN-tunnel between an external IP-address (172.20.184.240) to the Linux agent server ONLY (for security reasons). We would like to monitor the VPN-tunnel. The Zabbix server can not ping the external address so we would like the agent server to ping it and report it back to the Zabbix server. Does anyone have an idea how to create an item and trigger to do this for that host ??
  • ruswold
    Senior Member
    • Mar 2010
    • 210

    #2
    Originally posted by johnusa
    Hi, We are running a Zabbix server (1.6.5) monitoring, amongst many, a Linux server (with the Zabbix agent installed). We have established a VPN-tunnel between an external IP-address (172.20.184.240) to the Linux agent server ONLY (for security reasons). We would like to monitor the VPN-tunnel. The Zabbix server can not ping the external address so we would like the agent server to ping it and report it back to the Zabbix server. Does anyone have an idea how to create an item and trigger to do this for that host ??
    Add to zabbix_agentd.conf on linux server
    UserParameter=CheckVPN,fping x.x.x.x | grep alive | wc -l

    where x.x.x.x internal IP address of second end of VPN-tunnel

    Create item with type zabbix agent(active), key CheckVPN, value type integer. Create trigger, if value = 0 - vpn down

    Comment

    • johnusa
      Junior Member
      • Jul 2009
      • 12

      #3
      Thank you. Worked perfectly.

      Comment

      • Alexei
        Founder, CEO
        Zabbix Certified Trainer
        Zabbix Certified SpecialistZabbix Certified Professional
        • Sep 2004
        • 5654

        #4
        Another alternative:

        UserParameter=CheckIP[],fping $1 | grep -c alive
        Alexei Vladishev
        Creator of Zabbix, Product manager
        New York | Tokyo | Riga
        My Twitter

        Comment

        • atran
          Junior Member
          • May 2008
          • 8

          #5
          anyone knows how to do this from a Windows agent?

          Comment

          • atran
            Junior Member
            • May 2008
            • 8

            #6
            i have a solution for Windows agents

            create a pingcheck.vbs script (i found this on internet):

            Code:
            'Use a remote computer to ping another remote computer
            
            Option Explicit 
            'Change the SourceServer and RemoteServer Strings below to servernames or IP addresses for you.
            'wscript.Echo RemotePing("SourceComputer", "DestinationComputer")
            wscript.Echo RemotePing(".", WScript.Arguments(0))
            
            Function RemotePing( SourceComputer, DestinationComputer)
            
             Dim strComputer1, strComputer2
             Dim objWMIService, colItems, objItem
            
             strComputer1 = SourceComputer
             strComputer2 = DestinationComputer
            
             On Error Resume Next
              ' error control block
              Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}//" & strComputer1 & "\root\cimv2")
              Set colItems = objWMIService.ExecQuery ("Select * from Win32_PingStatus " & "Where Address = '" & strComputer2 & "'")
              For Each objItem in colItems
                  If objItem.StatusCode = 0 Then
                      RemotePing = 1         
                  Else
                   RemotePing = 0
                  End If
              Next
             On Error GoTo 0
            End function
            add a UserParameter in zabbix_agentd.conf like this:

            Code:
            UserParameter=PingCheck[*],cscript.exe c:\scripts\pingcheck.vbs $1 //NoLogo
            restart the windows agent.

            create a new item for the host from where you want to ping from in zabbix:

            type: zabbix agent
            key: PingCheck[10.0.0.1]
            type of information: Numeric (unsigned)
            data type: decimal

            remember to change the pingcheck ip-address to your needs!

            Comment

            • thmix
              Junior Member
              • Mar 2012
              • 5

              #7
              Here is a one liner for the Windows agent.

              Code:
              UserParameter=CheckVPN,@echo off && for /f "tokens=3 delims==" %A IN ('ping -w 200 -n 1 192.168.15.101 ^| find "Received"') do for /f "tokens=1 delims=^, " %B IN ("%A") do echo %B

              Comment

              • Stephen Wood
                Member
                • Feb 2012
                • 43

                #8
                Watch out for the catcha here. If the agent is behind a VPN and that VPN goes down, it won't be able to report a ping value other than the last value reported.

                You'll need to add something like {vpn.ping}.nodata(300)=1 to trigger an alert if it doesn't receive data for 5 minutes.

                Comment

                • arucard
                  Junior Member
                  • Jul 2012
                  • 10

                  #9
                  Sorry... it's working, stupid me :\


                  Hi,

                  i've got similar problem - i need to monitor vpn connections and where is possible i use:

                  UserParameter=VPN_check[*],/usr/local/sbin/fping $1 | grep alive | wc -l

                  but, sometimes other side doesn't allow ICMP, so the only way to monitor is to do telnet to "their" server to some port.
                  But don't how to do such thing, does anybody has some glue for this?

                  ps. i can't do net.tcp.service from zabbix server (it's in different part of network and NAT is not possible), it must be done from AS (application server).

                  Regards,
                  Last edited by arucard; 01-08-2012, 14:18.

                  Comment

                  • ghoz
                    Senior Member
                    • May 2011
                    • 204

                    #10
                    Originally posted by arucard
                    ps. i can't do net.tcp.service from zabbix server (it's in different part of network and NAT is not possible), it must be done from AS (application server).
                    you can simply use the net.tcp.service as an agent item on your AS. that way the AS will check the port for you from the agent.

                    yay!

                    Ghoz

                    Comment

                    • louis-m
                      Member
                      • Nov 2013
                      • 70

                      #11
                      I've mananged to hobble a vbs script together that will return the response times for a remote host from a windows agent.
                      Couple with a few posts from above, this can return TTL, RESPONSE rather than just if a host is alive.

                      Code:
                      Function Ping(strHost)
                          Dim oPing, oRetStatus, bReturn
                          Set oPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address='" & strHost & "'")
                       
                          For Each oRetStatus In oPing
                              If IsNull(oRetStatus.StatusCode) Or oRetStatus.StatusCode <> 0 Then
                                  bReturn = False
                       
                                   WScript.Echo "Status code is " & oRetStatus.StatusCode
                              Else
                                  bReturn = True
                                    
                                   ' UNCOMMENT BELOW WHAT RESPONSE YOU WANT RETURNED eg oRetStatus.ResponseTime
                                   'Wscript.Echo oRetStatus.BufferSize
                                   Wscript.Echo oRetStatus.ResponseTime
                                   'Wscript.Echo oRetStatus.ResponseTimeToLive
                      		 
                      		 
                              End If
                              Set oRetStatus = Nothing
                          Next
                          Set oPing = Nothing
                       
                          Ping = bReturn
                      End Function
                      1. Call the file whatever you want but in this example pingcheck.vbs and place in C:\scripts\pingcheck.vbs

                      And then exactly like ATRAN (thank you) posted above:

                      2. add a UserParameter in zabbix_agentd.conf like this:

                      Code:
                      UserParameter=[B]PingCheck[*][/B],cscript.exe c:\scripts\pingcheck.vbs $1 //NoLogo
                      3. restart the windows agent.

                      4. create a new item for the host from where you want to ping from in zabbix:

                      type: zabbix agent
                      key: PingCheck[10.0.0.1] <<< this must match the UserParameter in zabbix_agentd.conf
                      type of information: Numeric (unsigned)
                      data type: decimal

                      NB: remember to change the PingCheck[<ip-address>] above to your needs!

                      5. wait for the results to roll in!
                      Last edited by louis-m; 13-05-2014, 14:40.

                      Comment

                      • Terminator-T800
                        Junior Member
                        • Aug 2015
                        • 1

                        #12
                        In my case fping does not work on Windows. in Debug logging writes that values, received drom agent cannot be accepted, or something like that.
                        Thus i have a questons about.

                        1. Can you, please, give us exact example how can i write UserParameter in .conf file.

                        For example
                        UserParameter=ping_ReoteServer,icmpping[10.20.30.40]
                        UserParameter=fping_RemoteServer,fping 10.20.30.40 | grep alive | wc -l

                        2. Do i need add something after icmppin[10.20.30.40]? like echo something...?

                        Thanx

                        Comment

                        • Zabbixtrainee
                          Junior Member
                          • Mar 2016
                          • 20

                          #13
                          I am aware that this is an old post, but I am trying to ping from host to another host by using this script posted here earlier. Both machines are running on windows environment and there are configured agents up and running

                          Function Ping(strHost)
                          Dim oPing, oRetStatus, bReturn
                          Set oPing = GetObject("winmgmts:{impersonationLevel=impersonat e}").ExecQuery("select * from Win32_PingStatus where address='" & strHost & "'")

                          For Each oRetStatus In oPing
                          If IsNull(oRetStatus.StatusCode) Or oRetStatus.StatusCode <> 0 Then
                          bReturn = False

                          WScript.Echo "Status code is " & oRetStatus.StatusCode
                          Else
                          bReturn = True

                          ' UNCOMMENT BELOW WHAT RESPONSE YOU WANT RETURNED eg oRetStatus.ResponseTime
                          'Wscript.Echo oRetStatus.BufferSize
                          Wscript.Echo oRetStatus.ResponseTime
                          'Wscript.Echo oRetStatus.ResponseTimeToLive


                          End If
                          Set oRetStatus = Nothing
                          Next
                          Set oPing = Nothing

                          Ping = bReturn
                          End Function

                          I have followed the instructions louis-m told, but I get no results from this. In latest data it shows empty values when I choose the type of information as "text", otherwise I get error telling me that numeric values are not supported
                          My knowledge about this topic is relatively low.
                          If anybody could help me out on this and tell me is there any steps I need to do before using this or am I just shooting blanks here?
                          Last edited by Zabbixtrainee; 29-04-2016, 13:27.

                          Comment

                          Working...