Page 1 of 1

NCPA 2.1.6 gives errors running shell scripts

Posted: Mon Mar 18, 2019 12:31 pm
by corkyman
After upgrading to NCPA 2.1.6 my .sh plugins started getting an error like this:

-bash-4.1$ /usr/local/nagios/libexec/check_ncpa.py -H sclppekbb003.tvlport.net -t wspwebfarm -M api/plugins/check_status_cassandra.sh -q "args=/apps02/tpworkdir/status.log,args= Cassandra_Cluster_Status"
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
OK: RTDP Cassandra_Cluster_Status is Up

Here is the execution of the test scrip and the script itself:
-bash-4.1$ /usr/local/nagios/libexec/check_ncpa.py -H shlgnwsad011.tvlport.net -t wspwebfarm -M api/plugins/check_test.sh
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
nagios
pwd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
pwd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
OK: Mounts are working
You have mail in /var/spool/mail/nagios
-bash-4.1$

test.sh
---------
#!/bin/bash
whoami
pwd
echo "OK: Mounts are working"
rc=0
exit $rc

Re: NCPA 2.1.6 gives errors running shell scripts

Posted: Mon Mar 18, 2019 2:56 pm
by tgriep
Can you post the ncpa.cfg file here so we can view it's settings?

What OS and Release is the NCPA agent running on?

Does /bin/bash exist?

If you change the first line of the script to

Code: Select all

#!/bin/sh
Does it pass?

Re: NCPA 2.1.6 gives errors running shell scripts

Posted: Mon Mar 18, 2019 4:00 pm
by corkyman
I uploaded the ncpa.cfg; there are no other cfg files that we have created so no custom changes to the plain vanilla cfg.

Here is the /bin/sh
[nagios@shlgnwsad011 bin]$ pwd
/bin
[nagios@shlgnwsad011 bin]$ ll sh
lrwxrwxrwx 1 root root 4 Nov 14 2017 sh -> bash
[nagios@shlgnwsad011 bin]$

I changed the first line of the script to #!/bin/sh and received the same result:
-bash-4.1$ /usr/local/nagios/libexec/check_ncpa.py -H SHLGNWSAD011.TVLPORT.NET -t wspwebfarm -M plugins/check_test.sh
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
nagios
pwd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
pwd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
OK: Mounts are working
-bash-4.1$

Linux version:
[nagios@shlgnwsad011 tmp]$ uname -a
Linux shlgnwsad011.tvlport.net 2.6.32-642.15.1.el6.x86_64 #1 SMP Mon Feb 20 02:26:38 EST 2017 x86_64 x86_64 x86_64 GNU/Linux

Re: NCPA 2.1.6 gives errors running shell scripts

Posted: Mon Mar 18, 2019 4:13 pm
by tgriep
When the NCPA agent runs plugins, it runs them as the nagios user.
If that account has issues it that the home folder is missing, that would be one cause for the error.

Can you login to the server that is running the NCAP agent, run the commands and post the output?

Code: Select all

grep nag /etc/group
grep nag /etc/passwd
su - nagios
echo $HOME
Thanks

Re: NCPA 2.1.6 gives errors running shell scripts

Posted: Tue Mar 19, 2019 7:44 am
by corkyman
[c601018@shlgnwsad011 ~]$ grep nag /etc/group
nagcmd:x:249:
nagios:x:248:nagios
[c601018@shlgnwsad011 ~]$ grep nag /etc/passwd
nagios:x:498:249::/home/nagios:/bin/bash
[c601018@shlgnwsad011 ~]$ su - nagios
Password:
[c601018@shlgnwsad011 ~]$ sudo su - nagios
[nagios@shlgnwsad011 ~]$ echo $HOME
/home/nagios
[nagios@shlgnwsad011 ~]$

Re: NCPA 2.1.6 gives errors running shell scripts

Posted: Tue Mar 19, 2019 11:54 am
by ssax
Did you restart the ncpa_listener and ncpa_passive services after upgrading?

Code: Select all

service ncpa_listener restart
service ncpa_passive restart

Re: NCPA 2.1.6 gives errors running shell scripts

Posted: Tue Mar 19, 2019 2:27 pm
by corkyman
i'll be damned, it helped! i was positive we did that during install so i need to talk to that person. thank you!

Re: NCPA 2.1.6 gives errors running shell scripts

Posted: Tue Mar 19, 2019 2:44 pm
by ssax
No problem, glad to help! Am I okay to mark this as resolved and lock the topic or do you have any other related questions?

Re: NCPA 2.1.6 gives errors running shell scripts

Posted: Wed Mar 20, 2019 10:42 am
by corkyman
yes, it is resolved for sure