Ad Widget

Collapse

[zabbix-1.6.1] UserParameter and ',' character.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zabbix_es
    Senior Member
    • Apr 2007
    • 153

    #1

    [zabbix-1.6.1] UserParameter and ',' character.

    Zabbix 1.6.1 agentd complains about that user parameter:

    UserParameter=mysql.version,mysql -V |cut -d " " -f 4,5,6

    I think that it works properly with 1.6 but I`m not sure.
    Maybe because ',' character in user command, but I think that must be allowed.

    zabbix_agentd fails to start with this parameter. Maybe it could ignore it and continue normal start ...
  • fmtaylor2
    Member
    • May 2006
    • 66

    #2
    Similar problem

    the following works fine in 1.4.x, 1.5.3, 1.6, but NOT in 1.6.1.

    UserParameter=lnx.io.disk_r,iostat | grep sd | awk '{sum += $ 5} END {printf( "%d\n",sum)}'

    I am stuck until I get a solution......

    Comment

    • fips
      Member
      • Sep 2005
      • 38

      #3
      I got the same problem and found out it is the second , in the UserParameter with triggers this problem. I think there are some new syntax test in the new 1.6 version of zabbix. Have not had time to verify this at the source code.

      Comment

      • fips
        Member
        • Sep 2005
        • 38

        #4
        I had a look at the source code and I found out, commas are not supported in UserParameters in version 1.6. The changelog is not right:

        Changelog
        - [ZBX-403] added support of commas in UserParameter's (Sasha)

        The problem is in the src/zabbix_agent/zbxconf.c file in the function: add_parameter. If you have a comma in your UserParameter num_param will give a value bigger then 2 and you will get the syntax_error. We have to change this function to re enable commas in UserParameters!

        Code:
        static int     add_parameter(const char *param)
        {
        	char	key[MAX_STRING_LEN], command[MAX_STRING_LEN];
        
        	assert(param);
        
        	if ([COLOR="Red"]num_param(param) != 2[/COLOR])
        		goto syntax_error;
        
        	if (0 != get_param(param, 1, key, sizeof(key)))
        		goto syntax_error;
        
                if (0 != get_param(param, [COLOR="Red"]2[/COLOR], command, sizeof(command)))
        		goto syntax_error;
        
        	if (*key == '\0' || *command == '\0')
        		goto syntax_error;
        
        	return add_user_parameter(key, command);
        syntax_error:
        	zabbix_log(LOG_LEVEL_WARNING, "UserParameter \"%s\" FAILED: Invalid format.",
        			param);
        
        	return FAIL;
        }
        Last edited by fips; 19-11-2008, 13:09.

        Comment

        • tore
          Junior Member
          • Feb 2008
          • 16

          #5
          I'm struggling with the same problem, help would be very welcome

          Comment

          • zabbix_es
            Senior Member
            • Apr 2007
            • 153

            #6
            Userparameter and ',' reminder.

            Any news about this issue?

            I think that this issue is quite important.

            Comment

            • wakko
              Junior Member
              • Dec 2008
              • 19

              #7
              If you dig a little deeper, you'll find the real problem:

              In libs/zbxcommon/str.c, the num_param() function is the problem:
              Code:
              int     num_param(const char *param)
              {
                      int     i;
                      int     ret = 1;
              
              /* 0 - init, 1 - inside quoted param, 2 - inside unquoted param */
                      int     state = 0;
                      char    c;
              
                      if(param == NULL)
                              return 0;
              
                      for(i=0;param[i]!='\0';i++)
                      {
                              c=param[i];
                              switch(state)
                              {
                                      case 0:
                                              if(c==',')
                                              {
                                                      ret++;
                                              }
                                              else if(c=='"')
                                              {
                                                      state=1;
                                              }
                                              else if(c=='\\' && param[i+1]=='"')
                                              {
                                                      state=2;
                                              }
                                              else if(c!=' ')
                                              {
                                                      state=2;
                                              }
                                              break;
                                      case 1:
                                              if(c=='"')
                                              {
                                                      state=0;
                                              }
                                              else if(c=='\\' && param[i+1]=='"')
                                              {
                                                      i++;
                                                      state=2;
                                              }
                                              break;
                                      case 2:
                                              if(c==',')
                                              {
                                                      ret++;
                                                      state=0;
                                              }
                                              break;
                              }
                      }
              
                      return ret;
              }
              As you can see, any comma is counted as an additional parameter.

              Unfortunately, the check for double-quotes, which should allow you a way around this behavior, doesn't appear to work as intended. In my testing, I haven't been able to get it to return a value of 2 if there is a comma anywhere in the command.

              Comment

              • wakko
                Junior Member
                • Dec 2008
                • 19

                #8
                By applying the patch below, I was able to get a mostly usable behavior. This simplifies the logic down to looking only for commas and double-quotes.

                Anything inside double-quotes is treated as a single parameter. Commas outside of double-quotes separate each parameter.

                This allows me to do UserParameter=foo,"some-command | using,commas" and have it succeed.

                This appears to confirm my suspicion that get_param() functions as intended, while num_param() is flawed.

                Code:
                --- str.c.orig  2008-12-28 17:39:46.000000000 -0800
                +++ str.c       2008-12-28 17:38:48.000000000 -0800
                @@ -1037,32 +1037,12 @@
                                                {
                                                        state=1;
                                                }
                -                               else if(c=='\\' && param[i+1]=='"')
                -                               {
                -                                       state=2;
                -                               }
                -                               else if(c!=' ')
                -                               {
                -                                       state=2;
                -                               }
                                                break;
                                        case 1:
                                                if(c=='"')
                                                {
                                                        state=0;
                                                }
                -                               else if(c=='\\' && param[i+1]=='"')
                -                               {
                -                                       i++;
                -                                       state=2;
                -                               }
                -                               break;
                -                       case 2:
                -                               if(c==',')
                -                               {
                -                                       ret++;
                -                                       state=0;
                -                               }
                                                break;
                                }
                        }

                Comment

                • vinny
                  Senior Member
                  • Jan 2008
                  • 145

                  #9
                  hi,
                  i am annoyed with this too.
                  do the zabbix team has foreseen to allow multiple commas ?

                  vinny
                  -------
                  Zabbix 1.8.3, 1200+ Hosts, 40 000+ Items...zabbix's everywhere

                  Comment

                  • zabbix_es
                    Senior Member
                    • Apr 2007
                    • 153

                    #10
                    [zabbix-1.6.2] UserParameter and ',' character.

                    This issue remains in version 1.6.2

                    Comment

                    • zabbix_es
                      Senior Member
                      • Apr 2007
                      • 153

                      #11
                      [zabbix-1.6.2] and character ',' in UserParameter.


                      What about this issue?
                      Is it fixed in pre-1.6.3?
                      (I am waiting until this issue was fixed before migrating all my agents from 1.6 to 1.6.x).

                      Comment

                      • Alexei
                        Founder, CEO
                        Zabbix Certified Trainer
                        Zabbix Certified SpecialistZabbix Certified Professional
                        • Sep 2004
                        • 5654

                        #12
                        Hmm, it is supposed to be fixed in 1.6.2. We will re-test it shortly.
                        Alexei Vladishev
                        Creator of Zabbix, Product manager
                        New York | Tokyo | Riga
                        My Twitter

                        Comment

                        • Alexei
                          Founder, CEO
                          Zabbix Certified Trainer
                          Zabbix Certified SpecialistZabbix Certified Professional
                          • Sep 2004
                          • 5654

                          #13
                          I confirm that the problem exists in 1.6.2, but it has been fixed in pre 1.6.3. Please download the latest pre-1.6.3 nightly build from http://www.zabbix.com/developers.php and report back if it works for you.

                          Thanks!
                          Alexei Vladishev
                          Creator of Zabbix, Product manager
                          New York | Tokyo | Riga
                          My Twitter

                          Comment

                          • zabbix_es
                            Senior Member
                            • Apr 2007
                            • 153

                            #14
                            It works fine.

                            Thank you!.

                            Originally posted by Alexei
                            I confirm that the problem exists in 1.6.2, but it has been fixed in pre 1.6.3. Please download the latest pre-1.6.3 nightly build from http://www.zabbix.com/developers.php and report back if it works for you.

                            Thanks!

                            Comment

                            • jez
                              Junior Member
                              • May 2013
                              • 1

                              #15
                              Seems, I've reproduced the issue.

                              i'm using Zabbix agent v1.8.13.0 on Win7.

                              for this option

                              UserParameter=t.test[*],echo ["$1"] [$2]

                              I get the next reply

                              C:\Program Files (x86)\Zabbix Agent> zabbix_get -s 127.0.0.1 -k t.test["select a, b from c",2]
                              > ["select a"] [b from c]

                              Is the issue still reproducible, or maybe i've made something wrong?
                              Thanks
                              Last edited by jez; 28-05-2013, 17:50.

                              Comment

                              Working...