Page 1 of 2
check_disk: Permission denied
Posted: Thu Jan 30, 2020 4:24 am
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?
Re: check_disk: Permission denied
Posted: Thu Jan 30, 2020 4:45 pm
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.
Re: check_disk: Permission denied
Posted: Fri Jan 31, 2020 2:15 am
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.
Re: check_disk: Permission denied
Posted: Mon Feb 03, 2020 3:05 pm
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.
Re: check_disk: Permission denied
Posted: Mon Feb 03, 2020 4:01 pm
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
Re: check_disk: Permission denied
Posted: Tue Feb 04, 2020 7:12 pm
by Box293
I would recommend creating a home directory for the Nagios user, we've seen this cause many issues in the past.
Re: check_disk: Permission denied
Posted: Sat Feb 08, 2020 2:24 am
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.
Re: check_disk: Permission denied
Posted: Mon Feb 10, 2020 9:05 am
by scottwilkerson
You also need to change the /bin/false to /bin/bash
Re: check_disk: Permission denied
Posted: Mon Feb 10, 2020 3:51 pm
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.
Re: check_disk: Permission denied
Posted: Mon Feb 10, 2020 4:17 pm
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