Announcement

Collapse
No announcement yet.

"SSH Connect" in Dashboard context menu - HOWTO

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    "SSH Connect" in Dashboard context menu - HOWTO

    Hi all,

    I want to tell you how to connect to hosts over SSH using context menu in Zabbix dashboard page.
    I really missed this feature so I made it single-handedly.

    As you know, scripts are executed on server side, there's no way to run "putty" on your PC that way.

    I used SSH java applet "MindTerm" which I installed on Zabbix PHP front-end server, here is download link:
    http://www.appgate.com/index/products/mindterm

    Download this applet and unpack to directory on server where is your Zabbix PHP front-end located.
    In my example it is /var/www/html/zabbix/mindterm

    After downloading and extracting, you must sign your applet with certificate.
    Proper tools are provided with Java JDK package.

    Here's the procedure:

    Generate key:
    Code:
    keytool -genkey -keyalg rsa -alias testkey
    Export key:
    Code:
    keytool -export -alias testkey -file testcert.crt
    Check JAR file:
    Code:
    jar tvf mindterm.jar
    Sign JAR file:
    Code:
    jarsigner mindterm.jar testkey
    Verify sign:
    Code:
    jarsigner -verify -verbose -certs mindterm.jar
    So, we have signed SSH applet.
    How to use it?

    First, create a script in Zabix Administration panel.
    The script doesn't need to do anything, you may use command that does nothing,
    eg.: /bin/echo "Hello world!" > /dev/null

    In my example I created (for testing) a little bash script that does nothing:



    And the script itself (/home/zabbix/bin/test):

    Code:
    #!/bin/sh
    exit 0

    We need the Zabbix "scriptid", you can find it in your browser status bar when you hover your script name on the list.

    It looks like this. My sriptid=6, as you can see:



    Then we need to modify Zabbix page "scripts_exec.php" in main directory of Zabbix PHP front-end.

    The concept:
    I want to run java applet in result message window, when I click "SSH Connect" in dashboard context menu, with specified destination host IP passed by applet parameter, without typing IP by hand.
    So we need to know IP of chosen host, and our scriptid.

    The modified file "scripts_exec.php" is attached to this post.
    You can replace this file (backup the old one first), changing scriptid and path to applet .jar file only.
    That's all.

    How it works?



    Do you like it?

    Final words:
    Remember, although applet is located on server, it runs on your desktop, so you need access to hosts you want connect to.
    I always need to connect to my VPN server when I'm out of office before I use this tool to connect to servers inside my company network.
    Of course your browser must support JAVA.

    If you want to use this feature in IE, you will need "mindterm_ie.cab" file,
    which is NOT included in MindTerm applet archive.
    But it's easy to find it with google, just up to 5 min. searching.


    In the same way you can add more features, eg. "VNC view" using this applet:
    http://www.tightvnc.com/download.html

    Any comments welcomed.
    Environment used in this example: Zabbix 1.6.4 on Linux server

    Have fun!
    Skygge.

    PS. This is my first post here. Sorry 4 my bad english. Zabbix is great!
    Attached Files
    Last edited by skygge; 18-06-2009, 12:31.

    #2
    Wow ! Excellent !

    I hope that this kind of functionality will be included in a future version of Zabbix.

    Alixen
    http://www.alixen.fr/zabbix.html

    Comment


      #3
      Thanks for the excellent HOWTO! Well done.
      Alexei Vladishev
      Creator of Zabbix, Product manager
      New York | Tokyo | Riga
      My Twitter

      Comment


        #4
        Open source applet

        Hi,

        mindterm applet is not open source.
        Does anybody know an SSH or a remote desktop client applet whose licencing is compatible with GPL ?

        Thanks,
        Alixen
        http://www.alixen.fr/zabbix.html

        Comment


          #5
          Originally posted by skygge View Post
          Remember, although applet is located on server, it runs on your desktop, so you need access to hosts you want connect to.
          It is possible to tunnel with SSH, so Zabbix server could make a connection to host, and client could make a connection to the Zabbix server.
          Code:
          ssh client ---> Zabbix server ---> hostB
          An alternative - when logging in with SSH, it is possible to specify a command to execute. So the client could log into the Zabbix server and specify a command of 'remotelogin.sh hostB'. remotelogin.sh would be a script created by Zabbix, containing the necessary details to get onto hostB without further intervention from the user.

          This isn't limited to SSH of course. The Zabbix server could presumably tunnel anything, turning Zabbix into a remote management gateway.

          Comment


            #6
            But it's not so secure, isn't it?

            Edit: BTW, I was looking for an GPL applet lately, but I found nothing interesting...
            Last edited by skygge; 22-06-2009, 16:20.

            Comment


              #7
              Which 'it' are you talking about?

              Comment


                #8
                Hi,

                It looks very nice but I have a problem with the new scripts_exec.php.

                When I put it, all my scripts work but I have an error message.



                Any ideas ?

                Cheers

                Comment


                  #9
                  Hi,

                  at first, thanks for the great job.

                  But on my side it won't work. I got two errors :

                  When i try to open an connection via ssh to the Server. I get following error in the server log.

                  [Fri Jun 26 10:09:48 2009] [error] [client 172.16.22.53] File does not exist: /var/www/zabbix/com.mindbright.application.MindTerm.class, referer: http://reamon2-vm.realan.de/zabbix/s...c30a52d2086f94
                  [Fri Jun 26 10:10:11 2009] [error] [client 172.16.22.53] File does not exist: /var/www/zabbix/com.mindbright.application.MindTerm.class, referer: http://reamon2-vm.realan.de/zabbix/s...c30a52d2086f94

                  And the secound is the same error like koska.


                  i use the last Version 1.6.5

                  cu Mario

                  Comment


                    #10
                    hmmm... hard for me to say what is wrong, I got it working with no errors... maybe you (both) can attach your scripts_exec.php so I could see the code and check it? Your scriptid is really 200200000000003? It's a quite big number...

                    Another, "file does not exists" mean that script couldn't find applet file, do you correctly replace the path to mindterm.jar in scripts_exec.php?

                    Cheers,
                    Skygge

                    ps. I upgraded my Zabbix server to 1.6.5 and it's working still without any changes.
                    Last edited by skygge; 26-06-2009, 13:50.

                    Comment


                      #11
                      HI skygge,

                      the big scriptid cames from the distributed Monitoring. We got ther an Master Zabbix, und an Satellit.

                      And i think that the path is correct. But ...

                      I have attached the file.

                      Thanks,

                      Mario
                      Attached Files

                      Comment


                        #12
                        And what about attributes? Make sure that directory and files of mindterm applet are accessible by user httpd. What is in Apache error.log?
                        Last edited by skygge; 26-06-2009, 14:15.

                        Comment


                          #13
                          Hi,

                          Everything is working now, at the first time i used your script, but now i modified my own script and it's all right !

                          I put my php file if you want to have a look.

                          Very good job !

                          See ya
                          Attached Files
                          Last edited by koska; 26-06-2009, 14:50.

                          Comment


                            #14
                            The Apache tells me the same like Zabbix_server :

                            [Fri Jun 26 14:54:52 2009] [error] [client 172.16.22.53] File does not exist: /var/www/zabbix/com.mindbright.application.MindTerm.class, referer: http://reamon2-vm.realan.de/zabbix/s...081fa4c8497898

                            And when i try to execute the mindterm.jar i got followin :

                            reamon2-vm:/var/www/zabbix# java /var/www/zabbix/mindterm/mindterm.jar
                            Exception in thread "main" java.lang.NoClassDefFoundError: /var/www/zabbix/mindterm/mindterm/jar
                            Caused by: java.lang.ClassNotFoundException: .var.www.zabbix.mindterm.mindterm.jar
                            at java.net.URLClassLoader$1.run(URLClassLoader.java: 217)
                            at java.security.AccessController.doPrivileged(Native Method)
                            at java.net.URLClassLoader.findClass(URLClassLoader.j ava:205)
                            at java.lang.ClassLoader.loadClass(ClassLoader.java:3 23)
                            at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:294)
                            at java.lang.ClassLoader.loadClass(ClassLoader.java:2 68)
                            at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:336)
                            Could not find the main class: /var/www/zabbix/mindterm/mindterm.jar. Program will exit.


                            I hope you can help me. This feature is cool.

                            Comment


                              #15
                              There is something wrong with the path to your mindterm.jar. Maybe you can try change path to relative to scripts_exec.php instead absolute?

                              EDIT:
                              I did an experiment. I executed the command:
                              Code:
                              java /var/www/zabbix/mindterm/mindterm.jar
                              but with no mindterm.jar on this path and got error exactly the same as yours.

                              Go to the directory where is your applet on the server and type
                              Code:
                              pwd
                              Then give us the output.
                              Last edited by skygge; 26-06-2009, 20:22.

                              Comment

                              Working...
                              X