1

I am in the process of developing a custom Nagios plugin to monitor the absolute path of a few running processes.

As a root user I have always used the command 'ls -l /proc/$pid/exe to find the path but when I get Nagios to run this command(as user nagios) it doesn't have permission to access the file in /proc/.

As a workaround I gave sudo access to user nagios to run the command pwdx and this seems to be working fine, but it is a pain to do this on all our servers. Without this sudo access the plugin would fail.

I was wondering if there is a cleaner way to do this? I basically need a way to provide user nagios read access to everything under /proc.

1
  • I have not tested this, but have you may want to try mount -o remount,hidepid=0,gid=${pgid} /proc pgid being the primary group id of the nrpe agent or nagios user. Obviously doing this to all your servers would also be a global change, but it might be worth testing.
    – Aaron
    Mar 17, 2016 at 15:36

2 Answers 2

0

How about combination with "sudo setting in central nagios server" and "Private key authorization"?

Assuming that you are accessing to your dest server by ssh,

  1. Set sudo access with NO Passwd option to nagios user to nagios user in your central nagios server

  2. Generate private and public key with root user and copy the pub key to your destination server.

DO below in root user

ssh-key-gen -t dsa -b 1024 ssh-copy-id -i [path to your .pub file] root@[dest server]

  1. Execute chec_by_ssh with sudo. sudo [path-to-nagiosplugin]/check_by_ssh -l root -C "ls -l /proc/[pid]/exe"

Below is sample result.

[nagios@dev plugins]$ sudo ./check_by_ssh -H localhost -l root "ls -l /proc/2027/exe"; echo $? lrwxrwxrwx. 1 root root 0 Mar 30 19:29 /proc/2027/exe -> /usr/libexec/postfix/master 0

0

We ended up continuing with pwdx with sudo access as other options were more or less 'complicated' as this one.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .