Ad Widget

Collapse

Problems with zabbix_sender and cron

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • timuckun
    Junior Member
    • Oct 2008
    • 9

    #1

    Problems with zabbix_sender and cron

    I have the following line in my crontab.

    * * * * * root /usr/bin/zabbix_sender -z server.fqdn.com -s 'hostname' -k 'postgres.replication.lag' -o `/var/lib/postgresql/pg_standby_lag.rb` -vv


    This works but it sends weird values to zabbix. If run the command line from a shell it sends the value as output from pb_standby_lag.rb which is a positive integer (number of seconds).

    If I call the exact same line from cron the data comes in as a negative number.

    I can trace the number that comes in from the zabbix log so I know when the right and wrong number are sent.

    Why is the exact same script sending a different value from cron?
  • richlv
    Senior Member
    Zabbix Certified Trainer
    Zabbix Certified SpecialistZabbix Certified Professional
    • Oct 2005
    • 3112

    #2
    does the output of that ruby script depend in any way on environment variables and you are runing dcron ?
    if so, be aware that dcron does _not_ preserve most of the environment and you must take care of that yourself.
    to test this, you can just redirect script output to some file - like make it executed once every minute and do >>/tmp/somefile
    Zabbix 3.0 Network Monitoring book

    Comment

    • timuckun
      Junior Member
      • Oct 2008
      • 9

      #3
      env variables.

      Originally posted by richlv
      does the output of that ruby script depend in any way on environment variables and you are runing dcron ?
      if so, be aware that dcron does _not_ preserve most of the environment and you must take care of that yourself.
      to test this, you can just redirect script output to some file - like make it executed once every minute and do >>/tmp/somefile
      Well I am not sure if it does. It calls a postgres binary which might require some env variables though.

      I'll try your trick and see what happens

      Comment

      • timuckun
        Junior Member
        • Oct 2008
        • 9

        #4
        seems to be a locale issue?

        Originally posted by richlv
        does the output of that ruby script depend in any way on environment variables and you are runing dcron ?
        if so, be aware that dcron does _not_ preserve most of the environment and you must take care of that yourself.
        to test this, you can just redirect script output to some file - like make it executed once every minute and do >>/tmp/somefile
        I dug a little further and it does seem like it's a locale issue.

        When I run the command under the user account the locale is set to en_NZ.UTF8 under cron it seems to run as en_GB.UTF-8

        I tried various LANG= and LC_ALL= on the cron line but to no avail.

        How do I set the locale in a cron job? Do you know?

        Comment

        • richlv
          Senior Member
          Zabbix Certified Trainer
          Zabbix Certified SpecialistZabbix Certified Professional
          • Oct 2005
          • 3112

          #5
          you can pass it just before you execute the command that needs the variable, or you can set in a wrapper script.
          what exact syntax did you use ?
          Zabbix 3.0 Network Monitoring book

          Comment

          • timuckun
            Junior Member
            • Oct 2008
            • 9

            #6
            solved

            Originally posted by richlv
            you can pass it just before you execute the command that needs the variable, or you can set in a wrapper script.
            what exact syntax did you use ?
            The trick was to pass the "right" lang in.

            LANG=en_GB.UTF-8

            That's in the environment of the postgres user so it has to be in the environment of the cron job that calls any binary from the postgres install.

            Thanks for you help.

            Comment

            Working...