Ad Widget

Collapse

Monitoring SSH tunnel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mindas
    Junior Member
    • Oct 2007
    • 19

    #1

    Monitoring SSH tunnel

    Hi,

    I am trying to set up a monitor of SSH tunnel I have created. Basically the remote end of this tunnel has an endless loop with

    echo "pong" | nc -l 13307

    whereas I do "nc localhost 13307" on the other end of the tunnel to see if the tunnel is still functioning. This all works, but I want to hook this to Zabbix.

    So I have following in my zabbix_agentd.conf on the monitored machine:

    ...
    UserParameter=tunping,nc 127.0.0.1 13307
    UserParameter=ping,echo 1
    ...

    If I run "nc 127.0.0.1 13307" on the monitored machine, I get "pong".
    But if I do the same from Zabbix server, I get the following:

    user@zabbix:$ zabbix_get -s monitored_machine -k tunping
    ZBX_NOTSUPPORTED
    user@zabbix:$ zabbix_get -s monitored_machine -k ping
    1

    Is there any reason why tunping fails bug ping works? I am using 1.8.1 version of Zabbix, as it comes by default with Ubuntu lucid.

    Excerpt from /var/log/zabbix-agent/zabbix_agentd.log:
    22268:20101229:235836.631 Processing request.
    22268:20101229:235836.632 Requested [tunping]
    22268:20101229:235836.635 Before
    22268:20101229:235836.635 Sending back [ZBX_NOTSUPPORTED]

    Is there any other way to ask zabbix agent to telnet to a port on localhost and retrieve whatever comes back?
  • dima_dm
    Senior Member
    • Dec 2009
    • 2697

    #2
    Originally posted by mindas
    Is there any other way to ask zabbix agent to telnet to a port on localhost and retrieve whatever comes back?
    Write script that return single line as output.
    Example:
    Write Perl script with module Net::Telnet

    Comment

    • mindas
      Junior Member
      • Oct 2007
      • 19

      #3
      Originally posted by dima_dm
      Write script that return single line as output.
      Example:
      Write Perl script with module Net::Telnet
      The thing is, I already have a custom script that does what I need (using netcat), but for some strange reason Zabbix does not pick it up. So I don't really mind how this problem is solved - either with getting it to work using custom script, or using some standard Zabbix functionality, I just want to get things done!

      Comment

      • dima_dm
        Senior Member
        • Dec 2009
        • 2697

        #4
        Run script from zabbix user
        nc 127.0.0.1 13307
        and show output of a script

        Comment

        • mindas
          Junior Member
          • Oct 2007
          • 19

          #5
          Ghm...

          root@zabbix #: nc localhost 13307
          pong
          root@zabbix:# su -c "nc localhost 13307" zabbix
          root@zabbix:#

          Researching further I found that zabbix user has shell set to /bin/false (it comes like this as a default in Ubuntu). Changing it to /bin/bash fixed the issue locally (su -c ... command works now), but remote zabbix_get still returns ZBX_NOTSUPPORTED. Zabbix agent logs do not contain any more information than before.

          Огpомное спасибо Dima for your help.

          Comment

          • dima_dm
            Senior Member
            • Dec 2009
            • 2697

            #6
            May by problem in SELinux policy?
            Use
            sudo -u zabbix nc localhost 13307
            for testing purpose
            Last edited by dima_dm; 30-12-2010, 13:49.

            Comment

            • mindas
              Junior Member
              • Oct 2007
              • 19

              #7
              Both this and su'ing to zabbix user and executing the command by hand works, it's just Zabbix agent that is not picking it up. I will investigate further to see if there is anything else I can think of. Thanks again.

              Comment

              • dima_dm
                Senior Member
                • Dec 2009
                • 2697

                #8
                Do you restart zabbix_agentd then you change zabbix_agentd.conf file?
                restart zabbix_agentd and try again.

                Comment

                • mindas
                  Junior Member
                  • Oct 2007
                  • 19

                  #9
                  Yes I did - I restarted the daemon after every change (should have mentioned this, sorry!)

                  Comment

                  • dima_dm
                    Senior Member
                    • Dec 2009
                    • 2697

                    #10
                    Originally posted by mindas
                    Yes I did - I restarted the daemon after every change (should have mentioned this, sorry!)
                    Write full path for nc script
                    UserParameter=tunping,/path/nc 127.0.0.1 13307

                    Comment

                    • mindas
                      Junior Member
                      • Oct 2007
                      • 19

                      #11
                      Tried that as well - same result

                      Comment

                      • dima_dm
                        Senior Member
                        • Dec 2009
                        • 2697

                        #12
                        Originally posted by mindas
                        Tried that as well - same result
                        You can add debug code in script ns, and log in file /tmp/ns.debug each action in script.
                        You can use Telnet checks from zabbix server
                        http://www.zabbix.com/documentation/...l/config/items -> 19.11. Telnet checks

                        Comment

                        • mindas
                          Junior Member
                          • Oct 2007
                          • 19

                          #13
                          I have solved this differently by apt-get installing netpipes.

                          For some strange reason

                          UserParameter=tunping,/bin/nc 127.0.0.1 13307

                          doesn't work from Zabbix, but the following does:

                          UserParameter=tunping2,/usr/bin/hose 127.0.0.1 13307 --in cat

                          Must be something to do with combination of Zabbix/Netcat.
                          Hopefully this will be useful for somebody.

                          Thanks again Дима for your help!

                          Comment

                          Working...