Add environment variable to check_by_ssh

I need to run something like this LANG=C ls via check_by_ssh and I’m struggling how to define by_ssh_command and/or by_ssh_arguments. Could anyone provide the correct syntax?

Hallo @rsx , here are a few examples how to do it right, you can have a look.

I hope this helps you further!

Best,
Yonas

Hi, thanks for that blog entry. However, it does not contain any hints regarding additional environment variables.

Hi.

You can add the environment variable as prefix to the ssh-command.

Example:

vars.by_ssh_command = "LC_ALL=en_US.utf8 /usr/lib/nagios/plugins/your_script"
# Would set LC_ALL to en_US.utf8

Additional notes:

  1. If you use the LC_ALL, it has to exist on the target system, otherwise it fails
  2. SSH-daemon: On the target system (ssh-Daemon), the environment variable has to be accepted.
    Example:
AcceptEnv LANG LC_* FOO BAR

This would accept environment variables named LANG, FOO and BAR and additionally those starting with LC_


Hope this helps

vars.by_ssh_command = "NLS_LANG=AMERICAN_AMERICA.AL32UTF8 /usr/lib/nagios/plugins/your_script"

result in

Remote command execution failed: sh: NLS_LANG=AMERICAN_AMERICA.AL32UTF8 /usr/lib/nagios/plugins/your_script: No such file or directory

Running the same command directly work as expected:

ssh 192.168.188.153 -C 'NLS_LANG=AMERICAN_AMERICA.AL32UTF8 /usr/lib/nagios/plugins/your_script'
OK

Any other idea?

Hi again.

Sorry that it didn’t help.

I tried it with your required environment-variable and it worked:

vars.by_ssh_command = "NLS_LANG=AMERICAN_AMERICA.AL32UTF8 /usr/lib/nagios/plugins/whatever_your_scriptname_is.sh"

My example script outputs all environment-variables, also:
NLS_LANG=AMERICAN_AMERICA.AL32UTF8

Edit:
Maybe you could check what arrives at the target-host.
I captured the executed ssh command and it should look like this:

NLS_LANG=AMERICAN_AMERICA.AL32UTF8 /usr/lib/nagios/plugins/show_env.sh

(But with the correct scriptname and path)


Greetings.