Ssh – Zabbix ssh needs to force pseudo tty allocation

sshzabbix

I am currently trying to configure an item in zabbix to execute a check on a remote server via SSH. When I run the following command on the zabbix box it works

sudo -u zabbix ssh -t root@[remote_ip] 'sudo ls'

However when I run this

sudo -u zabbix ssh root@[remote_ip] 'sudo ls'

I get sudo: sorry, you must have a tty to run sudo. I understand this is because I have not forced tty. My question is, how can I get the zabbix ssh.run item 'key' to force tty? Preferably, we'd rather not be making any updates to the remote host.

Best Answer

Zabbix does not support sending parameters to ssh - because Zabbix server doesn't actually run 'ssh' binary per-se, but is linked against libssh2 library and it does the ssh calls from zabbix_server poller processes, on the Zabbix server machine.

I presume you could edit the src/zabbix_server/poller/checks_ssh.c, either adding "Force pseudo-tty allocation" config parameter or just plainly forcing it in code. I would advise you against the latter because you'll end up maintaining Zabbix fork for your own purposes. If you decide to do the former, you can apply the patch to Zabbix community, which would probably get accepted and maintained by the Zabbix devs in the future.

If you don't feel comfortable or don't have enough time to do it, the only clean solution thats left is to configure sudo on all of your "remote_ip" boxes with:

cat >> /etc/sudoers.d/zabbix_notty <<EOF
# Allow user zabbix to run sudo without tty
Defaults:zabbix !requiretty
EOF

I know you said you don't prefer that, but ...