Sensu check-process.rb gives CheckProcess:OK for any -p pattern passed, which is not a current active process - sensu

There is no process named abc. I am pretty new to Sensu, please help is needed. The same check when executed on my sensu-client directly gives the following result:
root#pune-4755-col-stag-1:~# sudo check-process.rb -p /abc/ -W 1
CheckProcess CRITICAL: Found 0 matching processes; cmd //abc//
root#pune-4755-col-stag-1:~# sudo check-process.rb -p abc -W 1
CheckProcess CRITICAL: Found 0 matching processes; cmd /abc/

Related

What could cause tpm_unsealdata to be unable to write to a file?

I have successfully sealed a file to the tpm after having taking ownership of it using sudo tpm_sealdata -i inputfile -o encryptedfile -p 0 -p 1 -p 2 -p 3 -p 4 -p 5 -p 6 -z, however upon attempting to run sudo tpm_unsealdata -i encryptedfile -o newfile -z I simply recieve an error of "Unable to write to output file" however, the new file has been created and is simply empty. what could be causing tpm_unsealdata to successfully create the file, but then fail to write to it?

bashdb error after adding user to group listed via ls -l $(tty)

I see that this question has been posted and answered. However, the post answer does not work for me. The posted answer has 2 solutions:
1 - run bashdb as root
this does not work for me because the script I am trying to debug must be run as mqm. This script exits when it sees that it is being run (via bashdb) as root.
2 - Add the user to the group listed by ls -l $(tty)
I ran this command and got:
mqm#localhost.localdomain(/var/mqm/scripts): ls -l $(tty)
crw--w----. 1 root tty 136, 0 Jun 17 10:11 /dev/pts/0
I ran (as root) usermod -a -G root mqm
and verified that the root group contains mqm -
then logged in as mqm, I re-ran
bashdb myscript
and again received this error
/usr/share/bashdb/lib/setshow.sh: line 91: /dev/pts/0: Permission denied
Bashdb also has a --tty option.
By default, bashdb ... is the same as bashdb --tty $(tty). So try giving an explicit --tty argument with a name of a tty or psuedo tty that you know you can write to.
Here is how you might test having access to the tty before running bash. Suppose the tty is /dev/pts/2 then run
echo hi > /dev/pts/2
If that works, then try bashdb -tty /dev/pts/2 ...

How do I get pcp to automatically attach nodes to postgres pgpool?

I'm using postgres 9.4.9, pgpool 3.5.4 on centos 6.8.
I'm having a major hard time getting pgpool to automatically detect when nodes are up (it often detects the first node but rarely detects the secondary) but if I use pcp_attach_node to tell it what nodes are up, then everything is hunky dory.
So I figured until I could properly sort the issue out, I would write a little script to check the status of the nodes and attach them as appropriate, but I'm having trouble with the password prompt. According to the documentation, I should be able to issue commands like
pcp_attach_node 10 localhost 9898 pgpool mypass 1
but that just complains
pcp_attach_node: Warning: extra command-line argument "localhost" ignored
pcp_attach_node: Warning: extra command-line argument "9898" ignored
pcp_attach_node: Warning: extra command-line argument "pgpool" ignored
pcp_attach_node: Warning: extra command-line argument "mypass" ignored
pcp_attach_node: Warning: extra command-line argument "1" ignored
it'll only work when I use parameters like
pcp_attach_node -U pgpool -h localhost -p 9898 -n 1
and there's no parameter for the password, I have to manually enter it at the prompt.
Any suggestions for sorting this other than using Expect?
You have to create PCPPASSFILE. Search pgpool documentation for more info.
Example 1:
create PCPPASSFILE for logged user (vi ~/.pcppass), file content is 127.0.0.1:9897:user:pass (hostname:port:username:password), set file permissions 0600 (chmod 0600 ~/.pcppass)
command should run without asking for password
pcp_attach_node -h 127.0.0.1 -U user -p 9897 -w -n 1
Example 2:
create PCPPASSFILE (vi /usr/local/etc/.pcppass), file content is 127.0.0.1:9897:user:pass (hostname:port:username:password), set file permissions 0600 (chmod 0600 /usr/local/etc/.pcppass), set variable PCPPASSFILE (export PCPPASSFILE=/usr/local/etc/.pcppass)
command should run without asking for password
pcp_attach_node -h 127.0.0.1 -U user -p 9897 -w -n 1
Script for auto attach the node
You can schedule this script with for example crontab.
#!/bin/bash
#pgpool status
#0 - This state is only used during the initialization. PCP will never display it.
#1 - Node is up. No connections yet.
#2 - Node is up. Connections are pooled.
#3 - Node is down.
source $HOME/.bash_profile
export PCPPASSFILE=/appl/scripts/.pcppass
STATUS_0=$(/usr/local/bin/pcp_node_info -h 127.0.0.1 -U postgres -p 9897 -n 0 -w | cut -d " " -f 3)
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [INFO] NODE 0 status "$STATUS_0;
if (( $STATUS_0 == 3 ))
then
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [WARN] NODE 0 is down - attaching node"
TMP=$(/usr/local/bin/pcp_attach_node -h 127.0.0.1 -U postgres -p 9897 -n 0 -w -v)
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [INFO] "$TMP
fi
STATUS_1=$(/usr/local/bin/pcp_node_info -h 127.0.0.1 -U postgres -p 9897 -n 1 -w | cut -d " " -f 3)
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [INFO] NODE 1 status "$STATUS_1;
if (( $STATUS_1 == 3 ))
then
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [WARN] NODE 1 is down - attaching node"
TMP=$(/usr/local/bin/pcp_attach_node -h 127.0.0.1 -U postgres -p 9897 -n 1 -w -v)
echo $(date +%Y.%m.%d-%H:%M:%S.%3N)" [INFO] "$TMP
fi
exit 0
yes you can trigger execution of this command using a customised failover_command (failover.sh in your /etc/pgpool)
Automated way to up your pgpool down node:
copy this script into a file with execute permission to your desired location with postgres ownership into all nodes.
run crontab -e comamnd under postgres user
Finally set that script to run every minute at crontab . But to execute it for every second you may create your own
service and run it.
#!/bin/bash
# This script will up all pgpool down node
#************************
#******NODE STATUS*******
#************************
# 0 - This state is only used during the initialization.
# 1 - Node is up. No connection yet.
# 2 - Node is up and connection is pooled.
# 3 - Node is down
#************************
#******SCRIPT*******
#************************
server_node_list=(0 1 2)
for server_node in ${server_node_list[#]}
do
source $HOME/.bash_profile
export PCPPASSFILE=/var/lib/pgsql/.pcppass
node_status=$(pcp_node_info -p 9898 -h localhost -U pgpool -n $server_node -w | cut -d ' ' -f 3);
if [[ $node_status == 3 ]]
then
pcp_attach_node -n $server_node -U pgpool -p 9898 -w -v
fi
done

Perl Returning error for ls -l command

I am running a perl script from Nagios to check some files for certain characteristics on a windows machine. When I run the script from Nagios it responds with a result of:
UNKNOWN ERROR - execution of LANG=C ls -l resulted in an error 32512 -
My Code is from this GitHub with a single modification of line 168 so I can use it with windows:
use lib 'C$\Progra~1\Nagios\NRDS_Win\plugins';
The odd thing is the program actually outputs the expected result from the command line on the windows machine.
Here is the command:
check_files.pl -D c:\logs -F Health.log -a '~,300'
Here is an example:
CRITICAL - Health.log is 10703 (more than 300) seconds old - 1
Health.log files found
I modified line that defined LANG=C ls -l in the code but now i just get:
UNKNOWN ERROR - could not execute ls -l - No such file or directory
ls is unix command and by default there is no such command in windows.
If you need it, you can install it e.g. from GNU CoreUtils
You also need to change shell command on line 639 from LANG=C ls -l to just ls -l because in windows you can't set environment variables like that.

upstart script. shell arithmetic in script stanza producing incorrect values. equivalent /bin/sh script works

I have an upstart init script, but my dev/testing/production have different numbers of cpus/cores. I'd like to compute the number of worker processes to be 4 * number of cores within the init script
The upstart docs say that the script stanzas use /bin/sh syntax.
I created /bin/sh script to see what was going on. I'm getting drastically different results than my upstart script.
script stanza from my upstart script:
script
# get the number of cores
CORES=`lscpu | grep -v '#' | wc -l`
# set the number of worker processes to 4 * num cores
WORKERS=$(($CORES * 4))
echo exec gunicorn -b localhost:8000 --workers $WORKERS tutalk_site.wsgi > tmp/gunicorn.txt
end script
which outputs:
exec gunicorn -b localhost:8000 --workers 76 tutalk_site.wsgi
my equivalent /bin/sh script
#!/bin/sh
CORES=`lscpu -p | grep -v '#' | wc -l`
WORKERS=$(($CORES * 4))
echo exec gunicorn -b localhost:8000 --workers $WORKERS tutalk_site.wsgi
which outputs:
exec gunicorn -b localhost:8000 --workers 8 tutalk_site.wsgi
I'm hoping this is a rather simple problem and a few other pairs of eyes will locate the issue.
Any help would be appreciated.
I suppose I should have answered this several days ago. I first attempted using environment variables instead but didn't have any luck.
I solved the issue by replacing the computation with a python one-liner
WORKERS=$(python -c "import os; print os.sysconf('SC_NPROCESSORS_ONLN') * 2")
and that worked out just fine.
still curious why my bourne-shell script came up with the correct value while the upstart script, whose docs say use bourne-shell syntax didn't