Ad Widget

Collapse

Public ip address - agent active

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kamilalek1
    Junior Member
    • Jul 2016
    • 16

    #1

    Public ip address - agent active


    How can you use zabbix to check what public ip address the active agent has?

    The pubic ip address of the active agent changes every 24-48 hours
  • ripperSK
    Member
    • Jul 2019
    • 42

    #2
    Of course you can

    Code:
    # cat /etc/zabbix/zabbix_agentd.d/userparameter_WAN.IP.address.conf
    # get current WAN IP address
    UserParameter=WAN.IP.address,curl -s ipinfo.io/ip
    and add the item:

    Attached Files

    Comment

    • av123412
      Junior Member
      • Mar 2021
      • 1

      #3
      This works very well thank you, just stumbled across this. I know this thread is old but how would we build a trigger to alert us on if the IP changes? Would the trigger just look at a simple diff then if true alert?

      Comment

      • rtime
        Junior Member
        • Aug 2022
        • 3

        #4
        Hello, how can you do the same with a windows active client?

        Comment

        • rtime
          Junior Member
          • Aug 2022
          • 3

          #5
          (Invoke-WebRequest -uri "http://ifconfig.me/ip" -UseBasicParsing).Content;

          ps command gives me what I want, but how can I make a zabbix item out of this

          Comment

          • ripperSK
            Member
            • Jul 2019
            • 42

            #6
            rtime you just need to replicate the same thing under Windows as I advised to do under Linux - of course with PowerShell ...

            create a file

            Code:
            C:\zabbix\zabbix_agentd.d\userparameter_WAN.IP.add ress.conf
            or with similar path in your zabbix agent installation.

            userparameter_WAN.IP.address.conf file contents would be:

            Code:
            UserParameter=WAN.IP.address,C:\zabbix\get_wan_IP.ps1
            C:\zabbix\get_wan_IP.ps1 file contents would be:

            Code:
            (Invoke-WebRequest -uri "http://ifconfig.me/ip" -UseBasicParsing).Content
            if that does not work - try to wrap it up with CMD / BAT file - but I think it should.

            PowerShell execution policy needs to be adjusted for the execution of that .ps1 file to work correctly.

            Item creation in zabbix Web interface should be the same as posted above.

            Comment

            • rtime
              Junior Member
              • Aug 2022
              • 3

              #7
              only the cmd/bat file worked with the following content:

              Code:
              Powershell.exe -executionpolicy remotesigned -File  "c:\Program Files\Zabbix Agent 2\get_wan_IP.ps1"
              on the other hand made such an ugly entry in zabbix:

              Code:
              C:\Windows\system32>Powershell.exe -executionpolicy remotesigned -File "c:\Program Files\Zabbix Agent 2\get_wan_IP.ps1"
              
              XX.XXX.X.XX(wan_ip)
              could this be niced somehow so that only the ip address is visible?

              Comment

              • ripperSK
                Member
                • Jul 2019
                • 42

                #8
                I think you forgot to put something into that PowerShell script as my test case works OK by echoing only the WAN IP:

                Code:
                C:\tmp>type get_wan_ip.ps1
                (Invoke-WebRequest -uri "http://ifconfig.me/ip" -UseBasicParsing).Content
                
                C:\tmp>type get_wan_ip.bat
                @echo off
                powershell.exe -executionpolicy remotesigned -File C:\tmp\get_wan_ip.ps1
                
                C:\tmp>get_wan_ip.bat
                1xx.2xx.1xx.7x
                note1: command type works like Linux cat - echoes content of that file to the console
                note2: my WAN IP is redacted - you don't need to know that

                also.. you're asking Linux Sysadmin to help out with PowerShell - I'm not good with that scripting language

                Comment

                Working...