Page 1 of 2

Command return OK when check but Unkonwn on nagios

Posted: Mon Nov 11, 2013 4:00 am
by amitdaniel
Hey ,

i created a script that check if some process is running .

Code: Select all

#!/bin/bash

# Nagios return codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3


while getopts H:u:p:L: OPT
do
  case $OPT in
    "H" ) FLAGH="TRUE" ; HOST="$OPTARG" ;;
    "p" ) FLAGu="TRUE" ; PEM="$OPTARG" ;;
      * ) echo "Usage: $CMDNAME [-H HOST] [-pem /pem/file/location.pem ]. Example: -H 10.0.3.101  -pem /root/x.pem" 1>&2
          exit $STATE_UNKNOWN ;;
  esac
done


# Commands
RESULT=`ssh -i $PEM $HOST 'ps -ef | grep logstash | grep -v grep | wc -l'`


case $RESULT in
[1-2]*)
echo "OK - $RESULT proc found ."
exit $STATE_OK
;;
[0]*)
echo "CRITICAL - $RESULT proc found ."
exit $STATE_CRITICAL
;;
*)
echo "UNKNOWN - $RESULT proc found ."
exit $STATE_UNKNOWN
;;
esac

When i ran this command on /usr/local/nagios/libexec

Code: Select all

./check_logstash.sh -H openx-dist1d -p /root/x.pem
the result is : " OK - 1 proc found . "

i created command like this :

Code: Select all

define command{
command_name check_logstash_virginia
command_line /usr/local/nagios/libexec/check_logstash.sh -H $HOSTADDRESS$ -p /root/x.pem
}
and on nagios UI i get this warning - Status Information: UNKNOWN - proc found .

Some can help me ?

Thanks !!!

Re: Command return OK when check but Unkonwn on nagios

Posted: Mon Nov 11, 2013 12:05 pm
by abrist
Can you try running the command as user nagios?

Code: Select all

su nagios
./check_logstash.sh -H openx-dist1d -p /root/x.pem

Re: Command return OK when check but Unkonwn on nagios

Posted: Mon Nov 11, 2013 12:16 pm
by amitdaniel
Hey

Thanks for your quick replay

when i tried to run the command with nagios user it's looks like the command ignore my pem file

./check_logstash.sh -H openx-dist1d -p /usr/local/nagios/x.pem

nagios@openx-dist1d's password:


But i don't have password.

what should i do ?

Thanks !!!!

Re: Command return OK when check but Unkonwn on nagios

Posted: Mon Nov 11, 2013 12:36 pm
by scottwilkerson
amitdaniel wrote: ./check_logstash.sh -H openx-dist1d -p /usr/local/nagios/x.pem

nagios@openx-dist1d's password:

What are the permissions on /usr/local/nagios/x.pem ?

Code: Select all

ls -l /usr/local/nagios/x.pem
and is /usr/local/nagios/x.pem the same as /root/x.pem that you said was working?

Re: Command return OK when check but Unkonwn on nagios

Posted: Mon Nov 11, 2013 12:40 pm
by amitdaniel
Hey

Thanks again for you very quick response.

Yes the x.pem is the same.

permission are :

-rw------- 1 nagios nagios 1679 Nov 11 17:12 /usr/local/nagios/x.pem

Thanks !

Re: Command return OK when check but Unkonwn on nagios

Posted: Mon Nov 11, 2013 1:22 pm
by abrist
Change the permissions to include the nagios group:

Code: Select all

chmod g+xr /usr/local/nagios/x.pem

Re: Command return OK when check but Unkonwn on nagios

Posted: Mon Nov 11, 2013 1:28 pm
by amitdaniel
Done but now i have other issue

-rw-r-x--- 1 nagios nagios 1679 Nov 11 17:12 /usr/local/nagios/x.pem

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0650 for '/usr/local/nagios/x.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /usr/local/nagios/x.pem

Thanks !

Re: Command return OK when check but Unkonwn on nagios

Posted: Mon Nov 11, 2013 1:42 pm
by abrist
Well, heck. Remove the permission:

Code: Select all

chmod g-xr /usr/local/nagios/x.pem
amitdaniel wrote:But i don't have password.

what should i do ?

Thanks !!!!
Are you sure your pem is not password protected?

Re: Command return OK when check but Unkonwn on nagios

Posted: Mon Nov 11, 2013 2:34 pm
by amitdaniel
i succeed to run the command using
su nagios

if i ran the command like this

./check_logstash.sh -H root@openx-dist1d -p /usr/local/nagios/x.pem

Re: Command return OK when check but Unkonwn on nagios

Posted: Mon Nov 11, 2013 2:39 pm
by amitdaniel
but still i config the command :

define command{
command_name check_logstash_virginia
command_line /usr/local/nagios/libexec/check_logstash.sh -H $HOSTADDRESS$ -p /usr/local/nagios/x.pem
}



RETURN : UNKNOWN - proc found .