Page 1 of 2

Need setting up service

Posted: Tue Apr 25, 2017 12:42 pm
by bosecorp
I'm trying to run script on remote host and show the output in Nagios, scripts are as per Nagios standards.
So when i run it from Nagios host, it gives me correct results.

[nagios@nagmonus1 ~]$ /usr/bin/sudo /usr/bin/ssh -l root sftp /nagios-scripts/check_disk_sol.sh -p / -w 80 -c 90
Unauthorized access to or use of this system is prohibited. All access and use may be monitored or recorded.
OK- / : Total Space= 1.9G, Used Space= 91M, Available Space= 1.8G i.e. 5% Usage | 'Usage'=5;80;90;0;100

I basically want to show this output in Nagios for the remote host (sftp)

I have configured the command in Command definition already and then i have created a service and associated the appropriate check command to it.

After saving and restarting nagios core, i see below warning message on this host
[sudo: no tty present and no askpass program specified]

Need quick assistance here.

Re: Need setting up service

Posted: Tue Apr 25, 2017 12:50 pm
by mcapra
Does the sudoers file on your Nagios XI machine grant permissions for /usr/bin/ssh to the nagios user/group? Does the script itself have the appropriate permissions to be executed by the nagios user/group?

Re: Need setting up service

Posted: Tue Apr 25, 2017 1:14 pm
by bosecorp
[nagios@nagmonus1 ~]$ /usr/bin/sudo /usr/bin/ssh -l root sftp /nagios-scripts/check_disk_sol.sh -p / -w 80 -c 90
Unauthorized access to or use of this system is prohibited. All access and use may be monitored or recorded.
OK- / : Total Space= 1.9G, Used Space= 91M, Available Space= 1.8G i.e. 5% Usage | 'Usage'=5;80;90;0;100

[nagios@nagmonus1 ~]$ id
uid=59991(nagios) gid=59991(nagios) groups=59991(nagios),59016(nagcmd)

I'm running this as nagios user

Re: Need setting up service

Posted: Tue Apr 25, 2017 1:48 pm
by bosecorp
I have checked other posts, and the parameter !requiretty does not exists in sudoers file.

Tried reading https://support.nagios.com/forum/viewto ... 7&start=10
but no luck..

Re: Need setting up service

Posted: Tue Apr 25, 2017 2:38 pm
by ssax
You'll likely need to use check_by_ssh so that you can get rid of the MOTD, try this and send the full output:

Code: Select all

su - nagios
/usr/local/nagios/libexec/check_by_ssh -H sftp -l root -S 1 -C "/nagios-scripts/check_disk_sol.sh -p / -w 80 -c 90"
echo $?
Thank you

Re: Need setting up service

Posted: Tue Apr 25, 2017 3:03 pm
by bosecorp
# su - nagios
[nagios@nagmonus1 ~]$ /usr/local/nagios/libexec/check_by_ssh -H sftp -l root -S 1 -C "/nagios-scripts/check_disk_sol.sh -p / -w 80 -c 90"
Remote command execution failed: Unauthorized access to or use of this system is prohibited. All access and use may be monitored or recorded.
[nagios@nagmonus1 ~]$ echo $?
3

Note: I need to run this command as root, as i have configured password less ssh from nagiosxi server to remote host.

Re: Need setting up service

Posted: Tue Apr 25, 2017 3:05 pm
by bosecorp
When i run the check command from the nagios console, it works fine. PFA

Re: Need setting up service

Posted: Tue Apr 25, 2017 3:25 pm
by ssax
Please run these commands from the CLI and send the entire output (including the commands run):

Code: Select all

su - nagios
/usr/local/nagios/libexec/check_by_ssh -H sftp -l root -C "/nagios-scripts/check_disk_sol.sh -p / -w 80 -c 90"
echo $?
/usr/local/nagios/libexec/check_by_ssh -H sftp -l root -S -C "/nagios-scripts/check_disk_sol.sh -p / -w 80 -c 90"
echo $?
/usr/local/nagios/libexec/check_by_ssh -H sftp -l root -E -C "/nagios-scripts/check_disk_sol.sh -p / -w 80 -c 90"
echo $?
/usr/local/nagios/libexec/check_by_ssh -H sftp -l root -S 2 -C "/nagios-scripts/check_disk_sol.sh -p / -w 80 -c 90"
echo $?
/usr/local/nagios/libexec/check_by_ssh -H sftp -l root -E 1 -C "/nagios-scripts/check_disk_sol.sh -p / -w 80 -c 90"
echo $?
/usr/local/nagios/libexec/check_by_ssh -H sftp -l root -E 2 -C "/nagios-scripts/check_disk_sol.sh -p / -w 80 -c 90"
echo $?

Re: Need setting up service

Posted: Tue Apr 25, 2017 4:05 pm
by bosecorp
i got a workaround, thanks.

Re: Need setting up service

Posted: Tue Apr 25, 2017 4:07 pm
by dwhitfield
It sounds like this issue has been resolved. Is it okay if we lock this thread? Thanks for choosing the Nagios forums!