Ad Widget

Collapse

Issue running remote python script that is in a VENV environment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • The-Tech
    Junior Member
    • Jan 2022
    • 29

    #1

    Issue running remote python script that is in a VENV environment

    I am having issues on my Zabbix Server with running remote Python scripts on a Rasp Pi 5 Running Trixie 64 Bit. I need to run DHT22 temp logs using Adafruit libraries running in a VENV environment. I can run the scripts fine locally on the PI but when I trigger from zabbix it keeps reporting Timeout while executing a shell script.

    Below is my Item Key command
    system.run[sudo "/dht22/env/bin/python" "/dht22/humidity.py"]

    I thought it it was a permission issue but root has rwx permissions

    I am sure there is a simple way to get Zabbix server to run VENV python scripts but I just can't figure out what I am doing wrong.


    zabbix_agentd.conf includes AllowKey=system.run[*]
    visudo includes

    # user privilege specification
    root ALL=(ALL:ALL) ALL
    pi ALL=(ALL:ALL) ALL
    zabbix ALL=(ALL:ALL) ALL


    I have includes some screen images if anyone has a suggestion.
    Attached Files
    Last edited by The-Tech; 10-12-2025, 22:07.
  • tim.mooney
    Senior Member
    • Dec 2012
    • 1427

    #2
    Are you sure it's not because you're not including NOPASSWD for your zabbix sudo entry?

    Does your sudo config allow execution without a pseudo terminal? The default config on many modern platforms requires it, and that's almost certainly not going to work for zabbix agent.

    Probably not the source of your problem, but in general you're better off defining a custom item key than using system.run[].

    Comment


    • The-Tech
      The-Tech commented
      Editing a comment
      Tim, sorry I am still new to zabbix and Pi. Are you referring to the sudo visudo config ? What am I missing or needed?


      Here is my current setup.

      # User privilege specification
      root ALL=(ALL:ALL) ALL
      pi ALL=(ALL:ALL) ALL
      zabbix ALL=(ALL:ALL) ALL


      # Allow members of group sudo to execute any command
      %sudo ALL=(ALL:ALL) ALL

      # See sudoers(5) for more information on "@include" directives:

      @includedir /etc/sudoers.d

      pi ALL=(ALL) NOPASSWD: ALL
      zabbix ALL=(ALL) NOPASSWD: ALL
  • tim.mooney
    Senior Member
    • Dec 2012
    • 1427

    #3
    'visudo' is just the name of the standard tool for interactively editing sudoers entries. It's a wrapper around an editor that does some basic syntax checking before putting the entry into place. A broken entry in sudoers can cause a lot of problems.

    It appears you do have the "NOPASSWD" setting for one of your entries for zabbix, but you have an earlier entry that doesn't have it. That's confusing at a minimum. I would probably comment out or delete the 'zabbix' entry that does NOT have the NOPASSWD config.

    Regarding the terminal, a lot of modern Linux distros set "requiretty" to true, meaning that sudo will fail if it doesn't have an associated terminal. See sudoers(5) for more info. If the distro you're using on the pi sets "requiretty" to true, you need to disable either just for the 'zabbix' user or globally. The zabbix agent will never have an associated terminal when it runs commands.

    Comment

    Working...