Ad Widget

Collapse

Test port from one host with agent to another without

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fabioctba
    Junior Member
    • Jun 2010
    • 6

    #1

    Test port from one host with agent to another without

    Hello,

    I need to run a test, where the HOST_1 must be able to connect at HOST_2 specific port, but i only have access to HOST_1, where there's a zabbix agent installed. If i were testing from the server to a monitored host, i could simply create an item with the key 'tcp,port'. But the server won't have access to that port on HOST_2, so i must test from HOST_1. Any ideas?

    Regards,

    Fabio
  • Inc0
    Member
    • Dec 2010
    • 36

    #2
    You can use a bash script like the following one to check if the port is open or closed.
    Code:
    #!/bin/bash
    
    HOSTIP='127.0.0.1'
    PORT=21
    TIMEOUT=30
    if
      nc -zv -w$TIMEOUT $HOSTIP $PORT &>/dev/null
    then
      echo 'Port is open'
    else
      echo 'Port is closed'
    fi
    In zabbix_agentd.conf you can add a new user-defined minitored parameter that executes the script and then you check the result from zabbix in a trigger.

    I suggest you to change the echo to 0/1 instead of "port is open" and "port is closed".

    Moreover you can modify it to accept parameter so you can specifiry ip, port and timeout in the item instead of having those parameter inside the script.

    Comment

    • fabioctba
      Junior Member
      • Jun 2010
      • 6

      #3
      Inc0 thanks for your answer, this solves the problem for linux hosts, i had tried with nc before and i've made a script similar to yours. But i forgot to mention that in my case both hosts are running Windows.

      Comment

      • Inc0
        Member
        • Dec 2010
        • 36

        #4
        nc for windows: http://www.hackosis.com/wp-content/u...12/nc111nt.zip

        I have no idea if it works or not.

        If you don't trust the link, I suggest you to find a script for windows that do the same

        Comment

        • wizard-ict
          Junior Member
          • Feb 2012
          • 18

          #5
          On Windows you can use portqry, don't worry that it says Windows 2000, it runs fine on Windows 7, Server 2008 etc too.



          It doesn't require any install, so you can just drop it in your zabbix folder or whereever you want it, add a UserParameter to your agent config to call it and you're good to go.

          Comment

          • fabioctba
            Junior Member
            • Jun 2010
            • 6

            #6
            Originally posted by wodanbrlam


            I appreciate your self-confidence a lot.
            i don't understand.

            Comment

            • fabioctba
              Junior Member
              • Jun 2010
              • 6

              #7
              Originally posted by wizard-ict
              On Windows you can use portqry, don't worry that it says Windows 2000, it runs fine on Windows 7, Server 2008 etc too.



              It doesn't require any install, so you can just drop it in your zabbix folder or whereever you want it, add a UserParameter to your agent config to call it and you're good to go.
              Thanks wizard-ict, i'm going to give it a try and then i'll post the results!

              Comment

              Working...