Ad Widget

Collapse

net.tcp.service items fail with default macro host=localhost but works with 127.0.0.1

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • H25E
    Junior Member
    • Aug 2022
    • 6

    #1

    net.tcp.service items fail with default macro host=localhost but works with 127.0.0.1

    Hello,

    I'm using the default Nginx template for C zabbix agent (Nginx by Zabbix Agent). The agent it's properly configured on the nginx host and the zabbix server is properly configured too. Most of the items are working properly:

    ​​


    But two of the items aren't. The ones that work through "net.tcp.service" (or "net.tcp.service.perf"), which are "Nginx: Service status" and "Nginx: Service response time". The default value of the macro "{$NGINX.STUB_STATUS.HOST}" for the nginx template is "localhost". But if I enter on one of these two items and test replacing localhost with 127.0.0.1 it works:

    ​​

    Of course I could modify the value on the template and that's all, but I wanted to know what's going on, since if that's the default behavior of the official template a lot of people should have this error. So I don't know if I'm doing something stupid.
  • Answer selected by H25E at 17-01-2023, 15:40.
    cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    web.page.get uses curl as intermediate, so there is probably a reason, why it works. curl does its own things (maybe defaults to IPv4??) and then you get a page... net.tcp.service is a direct, so to say... item and depends on environment, what, where and how resolves and then .. how your nginx actually serves pages... might aswell be that it only serves over IPV4 and v6 will not answer for you ... Just as Hamardaban said above... "localhost" is not always "127.0.0.1"

    I start more and more lean towards the nginx config issues here, not zabbix issues..

    Comment

    • Hamardaban
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • May 2019
      • 2713

      #2
      Check in which IP the localhost name is resolved to .
      If there is IPv6 on the host, you may get an address where no one listens at the port.

      "localhost" is not always equal to "127.0.0.1"
      Last edited by Hamardaban; 17-01-2023, 11:17.

      Comment

      • cyber
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Dec 2006
        • 4807

        #3
        I am not too sure, but seems like a issue with resolving localhost to 127.0.0.1... something in /etc/hosts missing?
        Google will give you hints, if you look for "Nginx works on 127.0.01 but not localhost".

        Comment

        • H25E
          Junior Member
          • Aug 2022
          • 6

          #4
          The other items that work on "web.page.get" work with localhost without problem:

          ​​Click image for larger version

Name:	image.png
Views:	467
Size:	29.9 KB
ID:	457687

          Also "telnet localhost 80" inside the nginx host returns the following when somethig is sent through it:
          Code:
          HTTP/1.1 400 Bad Request
          Server: nginx
          Date: Tue, 17 Jan 2023 09:22:11 GMT
          Content-Type: text/html
          Content-Length: 150
          Connection: close
          
          <html>
          <head><title>400 Bad Request</title></head>
          <body>
          <center><h1>400 Bad Request</h1></center>
          <hr><center>nginx</center>
          </body>
          </html>
          Connection closed by foreign host.
          ​So localhost is resolving correctly. But ping localhost seems to be working through IPV6. Could be that?
          Code:
          root@nginx:/# ping localhost
          PING localhost(localhost (::1)) 56 data bytes
          64 bytes from localhost (::1): icmp_seq=1 ttl=64 time=0.014 ms

          Comment

          • cyber
            Senior Member
            Zabbix Certified SpecialistZabbix Certified Professional
            • Dec 2006
            • 4807

            #5
            web.page.get uses curl as intermediate, so there is probably a reason, why it works. curl does its own things (maybe defaults to IPv4??) and then you get a page... net.tcp.service is a direct, so to say... item and depends on environment, what, where and how resolves and then .. how your nginx actually serves pages... might aswell be that it only serves over IPV4 and v6 will not answer for you ... Just as Hamardaban said above... "localhost" is not always "127.0.0.1"

            I start more and more lean towards the nginx config issues here, not zabbix issues..

            Comment

            • H25E
              Junior Member
              • Aug 2022
              • 6

              #6
              Yea, both of you are right.

              Enabling ipv6 on the default nginx virtual host made it.
              Code:
              listen [::]:80
              It was very confusing that it was working through web page but not through raw tcp, but I understand it's not zabbix fault.

              Thanks!

              Comment

              Working...