Ad Widget

Collapse

Setting variables for Agent 2 under systemd

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • edisonguerra
    Junior Member
    • Feb 2021
    • 4

    #1

    Setting variables for Agent 2 under systemd

    Hi,

    I'm having an issue regarding environment variables for the agent 2 under systemd under Oracle Linux 7.9.

    I want to monitor an Oracle Database and I followed the instructions for the agent, placing the oracle binaries in the path for the zabbix user. So if I enable the zabbix user login, create a session, configure all of the variables needed and run the service in foreground the agent is able to find the Oracle Binaries and the tests work flawlessly.

    But whenever I start the service via systemd, I'll get the following error:

    "2021/09/21 13:03:14.682967 [Oracle] Connection failed: ORA-00000: DPI-1047: Cannot locate a 64-bit Oracle Client library: "$ORACLE_BASE/product/12/db_1//lib/libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/in...ion.html#linux for help."

    Using this documentation I found out that all I should need is to set the right variables so it can find the client libraries needed for the checks.

    Since the zabbix agent service runs via systemd, I tried creating overrides for the service.

    /etc/systemd/system/zabbix-agent2.service.d/override.conf
    [Service]
    EnvironmentFile=/etc/zabbix/env.conf
    PassEnvironment=ORACLE_BASE ORACLE_HOME PATH LD_LIBRARY_PATH CLASSPATH


    These are the contents of the "/etc/zabbix/env.conf":

    ORACLE_BASE=/opt/oracle
    ORACLE_HOME=$ORACLE_BASE/product/12/db_1/
    PATH=$PATH:$ORACLE_HOME/bin
    LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PAT H:}$ORACLE_HOME/lib:$ORACLE_HOME/ctx/lib
    CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlib


    If I check the service under systemd, it'll show me that the parameters have been imported to the daemon configuration:

    Environment=CONFFILE=/etc/zabbix/zabbix_agent2.conf
    EnvironmentFile=/etc/sysconfig/zabbix-agent2 (ignore_errors=yes)
    EnvironmentFile=/etc/zabbix/env.conf (ignore_errors=no)
    PassEnvironment=ORACLE_BASE ORACLE_HOME PATH LD_LIBRARY_PATH CLASSPATH


    But if I create a custom check to see the environment variables, I get only the default variables for the system:

    [root@xxxxxxx ~]# zabbix_agent2 -t test.env
    test.env [s|export HISTCONTROL="ignoredups"
    export HISTSIZE="1000"
    export HOME="/root"
    export HOSTNAME="aspora165"
    export LANG="en_US.UTF-8"
    export LESSOPEN="||/usr/bin/lesspipe.sh %s"
    export LOGNAME="root"
    export LS_COLORS="rs=0:di=01;34:ln=01;36:mh=00i=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01r=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30; 41:tw=30;42w=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31: *.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*. lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.t xz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=0 1;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:* .lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz= 01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01 ;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;3 1:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31: *.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.c ab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bm p=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga= 01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=0 1;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01 ;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01; 35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;3 5:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35 :*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*. rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fl i=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01 ;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;3 5:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35: *.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*. midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.o gg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga= 01;36:*.spx=01;36:*.xspf=01;36:"
    export MAIL="/var/spool/mail/root"
    export OLDPWD
    export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin"
    export PWD="/root"
    export SELINUX_LEVEL_REQUESTED=""
    export SELINUX_ROLE_REQUESTED=""
    export SELINUX_USE_CURRENT_RANGE=""
    export SHELL="/bin/bash"
    export SHLVL="2"
    export SSH_CLIENT="172.16.1.25 64510 22"
    export SSH_CONNECTION="172.16.1.25 64510 172.16.1.165 22"
    export SSH_TTY="/dev/pts/0"
    export TERM="xterm"
    export USER="root"
    export XDG_RUNTIME_DIR="/run/user/0"
    export XDG_SESSION_ID="10111"
    export _="/usr/sbin/zabbix_agent2"]


    Is there any other way to set the variables so the service will use them?

    I'm aware that the real issue here is related to systemd, not the zabbix daemon, but can anyone help me?
  • edisonguerra
    Junior Member
    • Feb 2021
    • 4

    #2
    It seems I've found the solution, so I'll post it in case anyone else faces this issue too.

    The systemd EnvironmentFile must be filled with real values that do not reference other variables. After some troubleshooting I was able to print the variables used by the agent and soon I've found out that I had a PATH variable with the content "PATH=\$PATH:\$ORACLE_HOME/bin".

    Then I edited the variables so it would match the real expected values for those variables:

    ORACLE_BASE=/opt/oracle
    ORACLE_HOME=/opt/oracle/product/12/db_1/
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/oracle/product/12/db_1/bin
    LD_LIBRARY_PATH=/opt/oracle/product/12/db_1/lib:/opt/oracle/product/12/db_1/ctx/lib
    CLASSPATH=/opt/oracle/product/12/db_1//JRE:/opt/oracle/product/12/db_1//jlib:/opt/oracle/product/12/db_1//rdbms/jlib:/opt/oracle/product/12/db_1//network/jlib


    I believe I don't need neither the base or home variables now since it's all correctly set in the $PATH and $LD_LIBRARY_PATH, but I just left it all there once I got it working.

    With this I was able to monitor both Oracle 12R2 and 19c, so I hope this helps someone else with as little experience as I on systemd.

    Comment

    Working...