Ad Widget

Collapse

problem with item with ssh agent

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jgironda
    Junior Member
    • Apr 2010
    • 14

    #1

    problem with item with ssh agent

    Hello,

    I had created a item for check Memory size, with the following data:

    Description: Memory
    Type SSH Agent
    Key ssh.run[memoria]
    Authentication method Password
    User name xxx
    Password xxx
    Executed script LANG= free | grep Mem | awk "{print $3 * 100 / $2}"
    Type of information Numeric(Float)
    Units %
    Use multiplier
    Update interval (in sec) 30


    The problem is that the item does not work in all host, in one host the result it is correct and the other host the "lastest data" is not updated.

    Why??

    In the host with the problem, I can execute the scritp and work fine.

    I would like know how Zabbix execute the script, for example:

    ssh user@ip 'LANG= free | grep Mem | awk "{print $3 * 100 / $2}"'

    Thank you for your time.
  • jgironda
    Junior Member
    • Apr 2010
    • 14

    #2
    Hello,

    Nobody has this problem??????

    Comment

    • bashman
      Senior Member
      • Dec 2009
      • 432

      #3
      Have you tried to write ip and port?

      Code:
      ssh.run[<unique short description>,<ip>,<port>,<encoding>]
      978 Hosts / 16.901 Items / 8.703 Triggers / 44 usr / 90,59 nvps / v1.8.15

      Comment

      • alixen
        Senior Member
        • Apr 2006
        • 474

        #4
        Hi,

        Are you sure that your command is working ?

        On Debian Lenny, I get:
        Code:
        # LANG= free | grep Mem | awk "{print $3 * 100 / $2}"
        awk: line 1: syntax error at or near *
        If I replace double quotes by single quotes, it works:
        Code:
        # LANG= free | grep Mem | awk '{print $3 * 100 / $2}'
        93.8524
        Regards,
        Alixen
        http://www.alixen.fr/zabbix.html

        Comment

        • bashman
          Senior Member
          • Dec 2009
          • 432

          #5
          On RedHat 5:

          Code:
          free | grep Mem | awk "{print $3 * 100 / $2}"
          awk: {print  * 100 / }
          awk:         ^ syntax error
          Code:
          free | grep Mem | awk '{print $3 * 100 / $2}'
          54.5354
          The same problem, try to change double quotes for simple quotes.
          978 Hosts / 16.901 Items / 8.703 Triggers / 44 usr / 90,59 nvps / v1.8.15

          Comment

          • jgironda
            Junior Member
            • Apr 2010
            • 14

            #6
            Originally posted by bashman
            Have you tried to write ip and port?

            Code:
            ssh.run[<unique short description>,<ip>,<port>,<encoding>]

            Hello,

            I do not try this becouse I had defined my item in a template, and I think that I can not put one ip.

            Thank you.

            Comment

            • bashman
              Senior Member
              • Dec 2009
              • 432

              #7
              Originally posted by jgironda
              Hello,

              I do not try this becouse I had defined my item in a template, and I think that I can not put one ip.

              Thank you.
              Ok, you can use macros when you're using templates.
              978 Hosts / 16.901 Items / 8.703 Triggers / 44 usr / 90,59 nvps / v1.8.15

              Comment

              • jgironda
                Junior Member
                • Apr 2010
                • 14

                #8
                Originally posted by alixen
                Hi,

                Are you sure that your command is working ?

                On Debian Lenny, I get:
                Code:
                # LANG= free | grep Mem | awk "{print $3 * 100 / $2}"
                awk: line 1: syntax error at or near *
                If I replace double quotes by single quotes, it works:
                Code:
                # LANG= free | grep Mem | awk '{print $3 * 100 / $2}'
                93.8524
                Regards,
                Alixen

                Hello,

                The command no it is the problem, but thank very much you for the interest.


                I would like know as Zabbix Launch the scritp, for example:

                ssh user@host "command;command"

                Comment

                • jgironda
                  Junior Member
                  • Apr 2010
                  • 14

                  #9
                  Originally posted by bashman
                  Ok, you can use macros when you're using templates.
                  I go to investigated using macros... I never user macros.

                  and do you now as Zabbix launch the command with ssh agent.


                  Thank you very much!!!

                  Comment

                  • alixen
                    Senior Member
                    • Apr 2006
                    • 474

                    #10
                    Hi,

                    Originally posted by jgironda
                    Hello,

                    The command no it is the problem, but thank very much you for the interest.
                    I really think that it IS the problem since $ meta character is interpreted by the shell within double quotes, which is not the case with single quotes.
                    However, if you are convinced that bashman and myself are wrong, so be it ...

                    Originally posted by jgironda
                    I would like know as Zabbix Launch the scritp, for example:

                    ssh user@host "command;command"
                    Zabbix uses libssh2 internally, so I think that it does not use ssh command.

                    Hope this helps
                    Alixen
                    http://www.alixen.fr/zabbix.html

                    Comment

                    • jgironda
                      Junior Member
                      • Apr 2010
                      • 14

                      #11
                      Originally posted by alixen
                      Hi,



                      I really think that it IS the problem since $ meta character is interpreted by the shell within double quotes, which is not the case with single quotes.
                      However, if you are convinced that bashman and myself are wrong, so be it ...



                      Zabbix uses libssh2 internally, so I think that it does not use ssh command.

                      Hope this helps
                      Alixen

                      Hello Alixen,

                      I are not convinced that you are wrong, I change the "" by '' 1000 time, and other change, but mi error es very stange:


                      I define the item (as up) but I change the "" by ''


                      I probe the script from zabbix server to monitoring server (4 server):

                      [root@smaxxxx01 html]# ssh operacion@smxxx20 LANG= free | grep Mem | awk '{print $3 * 100 / $2}'
                      Password:
                      96.4913
                      [root@smaxx01 html]# ssh operacion@smxxx24 LANG= free | grep Mem | awk '{print $3 * 100 / $2}'
                      Password:
                      98.0885
                      [root@smaxxx01 html]# ssh operacion@smxxx48 LANG= free | grep Mem | awk '{print $3 * 100 / $2}'
                      Password:
                      99.7297
                      [root@smaxxx01 html]# ssh operacion@smxxxx75 LANG= free | grep Mem | awk '{print $3 * 100 / $2}'
                      operacion@smxxx75's password:
                      96.4011
                      [root@smaxxxx01 html]# ssh operacion@smaxxx61 LANG= free | grep Mem | awk '{print $3 * 100 / $2}'
                      operacion@smxxx61's password:
                      85.8811

                      but in the last date, the host 48 show 0% evertime, and the 61, no show any result!!



                      Host image Description Last check down Last value Change History
                      20 image - other - (1 Items)
                      memoria 04 May 2010 14:51:47 96.58 % -0.01 % Graph
                      24 image - other - (1 Items)
                      memoria 04 May 2010 14:51:46 98.08 % +0.05 % Graph
                      48 image - other - (1 Items)
                      memoria 28 Apr 2010 13:04:15 0 % - Graph
                      75 image - other - (1 Items)
                      memoria 04 May 2010 14:51:47 96.32 % 0 % Graph


                      The correct value of smaxxx48 it is 99% and the smaxxx61 is 85%

                      Comment

                      • alixen
                        Senior Member
                        • Apr 2006
                        • 474

                        #12
                        Hi,

                        Originally posted by jgironda
                        Hello Alixen,

                        I probe the script from zabbix server to monitoring server (4 server):

                        [root@smaxxxx01 html]# ssh operacion@smxxx20 LANG= free | grep Mem | awk '{print $3 * 100 / $2}'
                        Password:
                        96.4913
                        Your test is not valid, only 'free' command is run through ssh, remaining commands after first pipe are run locally on your zabbix server.
                        If you want to run all commands through ssh, you have to carefully quote them:

                        Code:
                        ssh operacion@smxxx20 "LANG= free | grep Mem | awk '{print $3 * 100 / $2}'"
                        Sorry to bother you with all these shell syntax details but if you want to check your commands, you have to be sure that they are run remotely.

                        Hope this helps
                        Alixen
                        http://www.alixen.fr/zabbix.html

                        Comment

                        • jgironda
                          Junior Member
                          • Apr 2010
                          • 14

                          #13
                          Ok.... my mistake


                          I had checked with your command:

                          [root@smxxxx01 ~]# ssh operacion@smaxxx48 "LANG= free | grep Mem | awk '{print \$3 * 100 / \$2}'"
                          Password:
                          99,7495
                          [root@sxxxx01 ~]# ssh operacion@smaxxxx24 "LANG= free | grep Mem | awk '{print \$3 * 100 / \$2}'"
                          Password:
                          99.5417
                          [root@smaxxxx01 ~]# ssh operacion@smadxxx75 "LANG= free | grep Mem | awk '{print \$3 * 100 / \$2}'"
                          operacion@smadava75's password:
                          96.3551

                          And the check by ssh it is correct, but in zabbix not work fine.


                          I do not know that put in "Excecuted script" field in the Item.

                          Now, I write this:

                          "LANG= free | grep Mem | awk '{print \$3 * 100 / \$2}'"


                          And the Lastes date is not updated....

                          And In the zabbix logs, I do not see error...

                          23539:20100504:173346.813 Get value from agent result: '239265727'
                          23539:20100504:173346.813 End of get_value():SUCCEED
                          23539:20100504:173346.813 In calculate_item_nextcheck (18441,5,"",1272987226)
                          23539:20100504:173346.813 End calculate_item_nextcheck (result:1272987231)
                          23539:20100504:173346.813 In substitute_simple_macros (data:'ssh.run[memoria,{IPADDRESS},22,UTF8]')
                          23539:20100504:173346.813 End substitute_simple_macros (result:'ssh.run[memoria,10.xx.xx.16,22,UTF8]')
                          23539:20100504:173346.813 In substitute_simple_macros (data:'operacion')
                          23539:20100504:173346.813 In substitute_simple_macros(data:NULL)
                          23539:20100504:173346.813 In substitute_simple_macros(data:NULL)
                          23539:20100504:173346.814 In substitute_simple_macros (data:'XXXX')
                          23539:20100504:173346.814 In substitute_simple_macros (data:'"LANG= free | grep Mem | awk '{print \$3 * 100 / \$2}'"')
                          23539:20100504:173346.814 End substitute_simple_macros (result:'"LANG= free | grep Mem | awk '{print \$3 * 100 / \$2}'"')
                          23539:20100504:173346.814 In get_value() key:'ssh.run[memoria,{IPADDRESS},22,UTF8]'
                          23539:20100504:173346.814 In ssh_run()
                          23539:20100504:173346.994 ssh_run() Supported authentication methods:'publickey,password,keyboard-interactive'

                          Thank for your help

                          Comment

                          • jgironda
                            Junior Member
                            • Apr 2010
                            • 14

                            #14
                            Hello,

                            The issue is solve

                            The problem was in the item result, the separator decimal was different, one host with "." and other with ","

                            for this, in the scripts I put this:

                            sed -e 's/,/./'

                            And now Zabbix obtain the value correctly, becouse zabbix in my case work with "." separator for numeric type.


                            In other scripts the problem was the number format, becouse the result of the script was in cientific format, for example:

                            8.76575e+11

                            for this, in the awk, I had changed the command print by printf, for add a format:

                            printf "%15.0f\n", SUM


                            Thank you

                            Comment

                            • jangel
                              Junior Member
                              • Apr 2024
                              • 1

                              #15
                              Hello, try using '' in the key ssh.run['memory']

                              Comment

                              Working...