Ad Widget

Collapse

userparameter give wrong value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tippexer
    Junior Member
    Zabbix Certified Specialist
    • Jan 2013
    • 3

    #1

    userparameter give wrong value

    Hello,


    i have a userparameter which is checking a process on a linux server.
    this is the code in my zabbix_agentd.conf
    Code:
    UserParameter=process.xyz,pgrep -lf "xyz" | wc -l
    when i run this command as zabbix user on the server i got an 1 and a when i run this command
    Code:
    zabbix_get -s 1.2.3.4 -k process.xyz
    on zabbix server i got the result 2
  • neogan
    Senior Member
    Zabbix Certified Trainer
    Zabbix Certified SpecialistZabbix Certified Professional
    • Sep 2011
    • 118

    #2
    Hmm really strange

    Because pgrep catch itself

    UserParameter:
    UserParameter=pgrep_test,pgrep -lf "apache2" >> /tmp/pgrep

    1063 /usr/sbin/apache2 -k start
    3174 sh -c pgrep -lf "apache2" >> /tmp/pgrep
    6710 /usr/sbin/apache2 -k start
    8103 /usr/sbin/apache2 -k start
    20359 /usr/sbin/apache2 -k start
    28517 /usr/sbin/apache2 -k start
    29203 /usr/sbin/apache2 -k start
    29964 /usr/sbin/apache2 -k start
    30459 /usr/sbin/apache2 -k start
    31201 /usr/sbin/apache2 -k start
    31319 /usr/sbin/apache2 -k start
    31828 /usr/sbin/apache2 -k start

    Comment

    • tippexer
      Junior Member
      Zabbix Certified Specialist
      • Jan 2013
      • 3

      #3
      Hello Neogan,

      and why i get the right result ("1") when i run the command manual on the bash?

      Comment

      • neogan
        Senior Member
        Zabbix Certified Trainer
        Zabbix Certified SpecialistZabbix Certified Professional
        • Sep 2011
        • 118

        #4
        pgrep -lf "apache"
        1063 /usr/sbin/apache2 -k start
        25794 /usr/sbin/apache2 -k start
        25796 /usr/sbin/apache2 -k start
        25829 /usr/sbin/apache2 -k start
        26032 /usr/sbin/apache2 -k start
        26301 /usr/sbin/apache2 -k start
        26447 /usr/sbin/apache2 -k start
        26655 /usr/sbin/apache2 -k start
        26727 /usr/sbin/apache2 -k start
        26729 /usr/sbin/apache2 -k start
        26862 /usr/sbin/apache2 -k start
        26863 /usr/sbin/apache2 -k start
        31828 /usr/sbin/apache2 -k start

        another example
        sudo pgrep -lf "apache2"
        1063 /usr/sbin/apache2 -k start
        25794 /usr/sbin/apache2 -k start
        25796 /usr/sbin/apache2 -k start
        25829 /usr/sbin/apache2 -k start
        26032 /usr/sbin/apache2 -k start
        26655 /usr/sbin/apache2 -k start
        26862 /usr/sbin/apache2 -k start
        27093 /usr/sbin/apache2 -k start
        27222 /usr/sbin/apache2 -k start
        27246 /usr/sbin/apache2 -k start
        27306 /usr/sbin/apache2 -k start
        27369 /usr/sbin/apache2 -k start
        27501 sudo pgrep -lf apache2
        31828 /usr/sbin/apache2 -k start

        It is pgrep or grep famous bug, it should ignore itself, but with another command it doesn't work


        Zabbix_agent as you can see execute pgrep with sh -c prep .... , it +1 process prep

        Comment

        • neogan
          Senior Member
          Zabbix Certified Trainer
          Zabbix Certified SpecialistZabbix Certified Professional
          • Sep 2011
          • 118

          #5
          also you can use this:

          pgrep -lf "apache2" | grep -v pgrep | wc -l

          it will be correct

          Comment

          • tippexer
            Junior Member
            Zabbix Certified Specialist
            • Jan 2013
            • 3

            #6
            Hello Neogan,

            I used your command and it works fine. Thanks for your help.

            I keep it in my mind

            Comment

            • Colttt
              Senior Member
              Zabbix Certified Specialist
              • Mar 2009
              • 878

              #7
              you dont need pgrep -lf, without that it worked too
              Debian-User

              Sorry for my bad english

              Comment

              Working...