NCPA 2.1.6 gives errors running shell scripts

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
corkyman
Posts: 120
Joined: Wed Jul 13, 2016 12:58 pm

NCPA 2.1.6 gives errors running shell scripts

Post 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
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: NCPA 2.1.6 gives errors running shell scripts

Post 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?
Be sure to check out our Knowledgebase for helpful articles and solutions!
corkyman
Posts: 120
Joined: Wed Jul 13, 2016 12:58 pm

Re: NCPA 2.1.6 gives errors running shell scripts

Post 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
You do not have the required permissions to view the files attached to this post.
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: NCPA 2.1.6 gives errors running shell scripts

Post 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
Be sure to check out our Knowledgebase for helpful articles and solutions!
corkyman
Posts: 120
Joined: Wed Jul 13, 2016 12:58 pm

Re: NCPA 2.1.6 gives errors running shell scripts

Post 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 ~]$
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: NCPA 2.1.6 gives errors running shell scripts

Post 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
corkyman
Posts: 120
Joined: Wed Jul 13, 2016 12:58 pm

Re: NCPA 2.1.6 gives errors running shell scripts

Post 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!
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: NCPA 2.1.6 gives errors running shell scripts

Post 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?
corkyman
Posts: 120
Joined: Wed Jul 13, 2016 12:58 pm

Re: NCPA 2.1.6 gives errors running shell scripts

Post by corkyman »

yes, it is resolved for sure
Locked