Page 2 of 4

Re: Unable to execute a application specific cmd using check

Posted: Wed Apr 26, 2017 12:07 pm
by diwakar0304
Thanks for patience and response.

/tmp/watchqueue_1.txt itself not generating. Which suppose to be generated after running "watchqueue 1" command.

How ever I feel it is something related to tty session.
As I have shown output from check_by_ssh, if tty is unknown then /tmp/watchqueue_1.txt file is not generated. If there any tty assigned then script works perfectly.

Re: Unable to execute a application specific cmd using check

Posted: Wed Apr 26, 2017 1:51 pm
by tgriep
Did you add the following line to the /etc/sudoers file?

Code: Select all

Defaults:nagios !requiretty
Also, uncomment this option in the sudoers file as well.

Code: Select all

Defaults   !visiblepw
Try that and see if that works for you.

Re: Unable to execute a application specific cmd using check

Posted: Wed Apr 26, 2017 10:41 pm
by diwakar0304
sudoer file:

Code: Select all

Defaults:nagios    !requiretty
Defaults   !visiblepw
Defaults    always_set_home
Defaults    env_reset
Defaults    env_keep =  "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS"
Defaults    env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"
Defaults    env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"
Defaults    env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"
Defaults    env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:
root    ALL=(ALL)       ALL
nagios  ALL=(ALL)       NOPASSWD:ALL
command executed:

Code: Select all

Logapp nagios:~ 0$ /usr/local/nagios/libexec/check_nrpe -H localhost -c check_watchque
Critical: File /tmp/watchqueue_1.txt is not generated with current time
Logs:

Code: Select all

<31>Apr 27 09:06:21 localhost nrpe[24192]: Connection from 127.0.0.1 port 28582
<31>Apr 27 09:06:21 localhost nrpe[24192]: Host address is in allowed_hosts
<31>Apr 27 09:06:21 localhost nrpe[24192]: Host 127.0.0.1 is asking for command 'check_watchque' to be run...
<31>Apr 27 09:06:21 localhost nrpe[24192]: Running command: /usr/local/nagios/libexec/check_watchque
<85>Apr 27 09:06:21 localhost sudo:   nagios : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/<path to command>/watchqueue 1
<31>Apr 27 09:06:21 localhost nrpe[24192]: Command completed with return code 2 and output: Critical: File /tmp/watchqueue_1.txt is not generated with current time
<31>Apr 27 09:06:21 localhost nrpe[24192]: Return Code: 2, Output: Critical: File /tmp/watchqueue_1.txt is not generated with current time
<31>Apr 27 09:06:21 localhost nrpe[24192]: Connection from 127.0.0.1 closed.

Re: Unable to execute a application specific cmd using check

Posted: Thu Apr 27, 2017 9:32 am
by tgriep
If the path to the watchqueue command is an environment variable and not actually in the check_watchque script, that could be the issue because the environment variable it not available when the command it run by NRPE.
Can you put in the full path to the command and see if that works?

Re: Unable to execute a application specific cmd using check

Posted: Thu Apr 27, 2017 10:28 pm
by diwakar0304
In my all post I always mention /<path to cmd>/watchqueue is actually complete path with command in all instance. Same is mentioned in script since starting. I had tried to pass command with path or without path in both

Re: Unable to execute a application specific cmd using check

Posted: Fri Apr 28, 2017 7:43 am
by tacolover101
jumping in late, but what i would do is debug your variables before exiting so you can see what they're equal to so you can check the internal logic of your script.

Code: Select all

`/bin/cat /tmp/watchqueue_1.txt | /bin/grep shm | /usr/bin/head -1 | /bin/awk '{print $7}' | /bin/sed 's/(//g;s/)//g'` -ge `/bin/date +%s`

Re: Unable to execute a application specific cmd using check

Posted: Fri Apr 28, 2017 9:27 am
by tgriep
Without knowing what the requirements are for running the watchqueue command, it is hard to guess how to fix it.

Another thing to try is to add this line to your /etc/sudoers file and see if this helps.

Code: Select all

nagios ALL=NOPASSWD: /usr/local/nagios/libexec/check_watchque
Also, can you run the following commands on your remote server and post the output?

Code: Select all

change -l nagios
grep nag /etc/passwd
grep nag /etc/group

Re: Unable to execute a application specific cmd using check

Posted: Sun Apr 30, 2017 1:47 am
by diwakar0304
@tacolover101 : If you want further debug than on bash shell, strace output attached with my previous post.

Logapp nagios:~/libexec 0$ bash -xxx /usr/local/nagios/libexec/check_watchque

Code: Select all

+ sudo /<Path to command>/watchqueue 1
++ /bin/cat /tmp/watchqueue_1.txt
++ /bin/grep shm
++ /usr/bin/head -1
++ /bin/awk '{print $7}'
++ /bin/sed 's/(//g;s/)//g1'
+ EPOC2=1493533427
++ /bin/cat /tmp/watchqueue_1.txt
++ /bin/grep shm
++ /usr/bin/head -1
++ /bin/awk '{print $7}'
++ /bin/sed 's/(//g;s/)//g'
++ /bin/date +%s
+ '[' 1493533427 -ge 1493533427 ']'
++ /bin/cat /tmp/watchqueue_1.txt
++ /bin/grep 'Total UDP Messages'
++ /bin/awk '{print $9}'
++ /bin/sed 's/(//g'
+ MsgRate=7
+ /bin/echo 'Ok: Message rate is 7 | 7'
Ok: Message rate is 7 | 7
+ exit 0
@tgriep :

Same result, no success for below attempt:

Code: Select all

nagios ALL=NOPASSWD: /usr/local/nagios/libexec/check_watchque
as per your required output:
users details.GIF
users details.GIF (11.04 KiB) Viewed 5509 times
Now to understand, I am uploading the watchqueue 1 command strace output.
I hope this will help you to understand the requirement to run this command.
strace_watchqueue_1.txt
(35.78 KiB) Downloaded 338 times
BR//

Re: Unable to execute a application specific cmd using check

Posted: Mon May 01, 2017 10:07 am
by tgriep
I am seeing a lot of "ENOENT (No such file or directory" errors for the libraries the application is trying to use.
Make sure the paths for your libraries are in the ld.so.conf file and that the ld.so.cache file is rebuilt by running ldconfig on the server as root.


Also, does that script try and open/run xterm?

Code: Select all

access("/usr/local/nagios/.terminfo/x/xterm", R_OK) = -1 ENOENT (No such file or directory)
access("/<Path to application directory>/share/terminfo/x/xterm", R_OK) = 0
open("/<Path to application directory>/share/terminfo/x/xterm", O_RDONLY) = 3
read(3, "\32\0010\0&\0\17\0\235\1&\5", 12) = 12
read(3, "xterm|xterm terminal emulator (X"..., 48) = 48
That could be another issue as NRPE is running without a terminal and it cannot execute it.

Re: Unable to execute a application specific cmd using check

Posted: Mon May 01, 2017 10:45 am
by diwakar0304
Strace output shared was for successful execution only, you can see it's opens a file /tmp/watchqueue_1.txt.
No issue for ENOENT in strace.

Since starting I am trying to point out on terminal issue while executing check_script. To achieve same I switch to check_by_ssh with force tty option.

Post implementing the check_by_ssh in nagios, it's not pulling correct value. I have attached output for same in my previous post too.