check_disk: Permission denied

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Zendan
Posts: 10
Joined: Wed Jan 29, 2020 7:03 am

check_disk: Permission denied

Post by Zendan »

I've added a command to check the disk space for my hard drives. I edited /etc/nagios/objects/localhost.cfg and added the following:

Code: Select all

define command{
    command_name check_hard_disks
    command_line /usr/lib/monitoring-plugins/check_disk -w '$ARG1$' -c '$ARG2$' -e -r '^/media/.*' --exclude-type=tracefs --exclude-type=cgroup
}

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       localhost
        service_description             Disk Space for Hard disks
        check_command                   check_hard_disks!204800!102400
 }
However, I'm getting the following error in the GUI

Code: Select all

DISK CRITICAL - /media/Morlock is not accessible: Permission denied
Nagios is in the correct group with the correct permissions, and the command seems to work when I run it manually

Code: Select all

$ ls -ld /media/Morlock
drwxr-x--- 5 pi media 4096 Jul 27  2019 /media/Morlock
$ sudo runuser -u nagios -- groups
nagios media
$ sudo runuser -u nagios -- /usr/lib/monitoring-plugins/check_disk -w '204800' -c '102400' -e -r '^/media/.*' --exclude-type=tracefs --exclude-type=cgroup
DISK OK| /media/Morlock=1480562MB;2610828;2713228;0;2815628 /media/PiBuHDD=3496481MB;3549720;3652120;0;3754520 /media/PiHDD=1832964MB;2561328;2663728;0;2766128 /media/PiHDD2=2818985MB;5472216;5574616;0;5677016
How can I fix these permissions?
User avatar
mbellerue
Posts: 1403
Joined: Fri Jul 12, 2019 11:10 am

Re: check_disk: Permission denied

Post by mbellerue »

Welcome to the forum!

All of that looks good. Can you try executing the command as nagios one more time, except this time use su - nagios to get to the nagios user. From what I can tell, the runuser application should do this properly, but it's the only unknown I'm seeing right off the bat.

Also, it looks like you've installed the distribution's Nagios Core package, which means you're probably on Nagios Core v3.something. We're on 4.4.5. We'll still help out, of course. It's all Nagios after all. But sometimes it's good to know that there are updated versions out there.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
Zendan
Posts: 10
Joined: Wed Jan 29, 2020 7:03 am

Re: check_disk: Permission denied

Post by Zendan »

Thank you for the quick reply mbellerue.
mbellerue wrote: this time use su - nagios to get to the nagios user.
This fails, but doesn't su - require nagios to open a login shell?

Code: Select all

$ sudo su - nagios -- /usr/lib/monitoring-plugins/check_disk -w '204800' -c '102400' -e -r '^/media/.*' --exclude-type=tracefs --exclude-type=cgroup
su: warning: cannot change directory to /dev/null: Not a directory
I also tried without -, but that produced no output

Code: Select all

$ sudo su nagios -- /usr/lib/monitoring-plugins/check_disk -w '204800' -c '102400' -e -r '^/media/.*' --exclude-type=tracefs --exclude-type=cgroup
mbellerue wrote:Also, it looks like you've installed the distribution's Nagios Core package, which means you're probably on Nagios Core v3.something. We're on 4.4.5. We'll still help out, of course. It's all Nagios after all. But sometimes it's good to know that there are updated versions out there.
Sorry, I actually should have mentioned that. Yes, I installed the distro package. However, I'm using Arch Linux, so it's actually running Nagios 4.4.5.
User avatar
mbellerue
Posts: 1403
Joined: Fri Jul 12, 2019 11:10 am

Re: check_disk: Permission denied

Post by mbellerue »

Sorry, I wasn't very clear there. What I meant was, you should become root, and then su - nagios, and then run the command. Then it should give us some decent output. Unless the core of the problem is that nagios just doesn't have a home directory.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
Zendan
Posts: 10
Joined: Wed Jan 29, 2020 7:03 am

Re: check_disk: Permission denied

Post by Zendan »

No worries, but su - nagios still doesn't work, presumably because it's still not a login shell?

Code: Select all

$ sudo su - nagios
su: warning: cannot change directory to /dev/null: Not a directory
$ sudo su
# su - nagios
su: warning: cannot change directory to /dev/null: Not a directory
Yes, nagios doesn't have a home directory.

Code: Select all

$ grep nagios /etc/passwd
nagios:x:30:30::/dev/null:/bin/false
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: check_disk: Permission denied

Post by Box293 »

I would recommend creating a home directory for the Nagios user, we've seen this cause many issues in the past.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Zendan
Posts: 10
Joined: Wed Jan 29, 2020 7:03 am

Re: check_disk: Permission denied

Post by Zendan »

Thank you again for the suggestion.
Box293 wrote:I would recommend creating a home directory for the Nagios user, we've seen this cause many issues in the past.
This didn't seem to help. I tried creating a home directory:

Code: Select all

sudo mkdir /home/nagios
sudo chown nagios: /home/nagios
sudo chmod 700 /home/nagios
Then restarted nagios.service. It still failed.

I then tried actually letting the system know the location of the home directory by editing /etc/passwd, changing /dev/null to /home/nagios, then restarting, but it still fails. FWIW there was nothing created in the home directory byt the service.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: check_disk: Permission denied

Post by scottwilkerson »

You also need to change the /bin/false to /bin/bash
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Zendan
Posts: 10
Joined: Wed Jan 29, 2020 7:03 am

Re: check_disk: Permission denied

Post by Zendan »

Thanks scottwilkerson. I changed the shell, so that the full line is now

Code: Select all

nagios:x:30:30::/home/nagios:/bin/bash
I rebooted then re-ran the service, but unfortunately the problem still persists.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: check_disk: Permission denied

Post by scottwilkerson »

and what does the following show?

Code: Select all

sudo su nagios
/usr/lib/monitoring-plugins/check_disk -w '204800' -c '102400' -e -r '^/media/.*' --exclude-type=tracefs --exclude-type=cgroup
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked