Re: [Nagios-users] printing info from nagios db check script

2012-05-13 Thread Joerg Linge

Am 14.05.2012 um 00:27 schrieb Tim Dunphy:

> Hey list,
> 
> I'm having a small but important problem with a script I am writing in order 
> to monitor the tablespaces of an oracle database. This is probably more of a 
> bash programming issue, but as the ultimate purpose of the script is to be a 
> nagios check I am hoping that you won't mind me asking here. 
> 
> 
> Just to give you a brief overview of what I am experiencing, I'd like to 
> start by giving you the output of a couple runs of the script and a couple 
> snippets of code. 



Tim,
isn't it easier to use existing plugins?

http://labs.consol.de/lang/en/nagios/check_oracle_health/
--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Nagios-users mailing list
Nagios-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting 
any issue. 
::: Messages without supporting info will risk being sent to /dev/null


Re: [Nagios-users] printing info from nagios db check script

2012-05-13 Thread Tim Dunphy
hey guys,

 this was kind of interesting so I thought I might report it to anyone who 
might take an interest in this thread. But I just realized where the 
'additional' percentage that the tablespace check is reporting comes from.

 It comes from the fact that the check is attempting to report two tablespaces 
and that's why the formatting is falling apart. 

 I altered the print statement of the loop a little bit and saw the important 
difference:

 while i=$($sqlplus -s -l $USERNAME/$PASS@$SID  
@/opt/bin/ops/mlb_tablespace.sql | awk '{print $1}') j=$($sqlplus -s -l 
$USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql | awk '{print $3}') 
k=$($sqlplus -s -l $USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql | awk 
'{print $2}') l=$($sqlplus -s -l $USERNAME/$PASS@$SID  
@/opt/bin/ops/mlb_tablespace.sql | awk '{print $4}')
do
TBLSPACE=$i
PCT=$j
FREE=$k
TOTAL=$l
if [ "$TBLSPACE" ]
then
   echo "NOK"  $TBLSPACE " is at "  $PCT  $FREE/$TOTAL 
   exit 2
else
   echo "All OK"
exit 0
fi
done

Now outputs:

[db07-dc2:~] root% /opt/nagios/libexec/check_qaecom1_tablespace.sh 
NOK BAM_USER_INDX_LG MLBDATASM  is at  97.50% 95.85% 820 340/32764 8191


So what I need to try and figure out is how to print additional tablespaces 
that meet the threshold levels and have the output make sense visually. I will 
keep working on this, but would welcome any input you might have. 


Thanks
Tim

- Original Message -
From: "Tim Dunphy" 
To: nagios-users@lists.sourceforge.net
Sent: Sunday, May 13, 2012 6:27:36 PM
Subject: printing info from nagios db check script

Hey list,

 I'm having a small but important problem with a script I am writing in order 
to monitor the tablespaces of an oracle database. This is probably more of a 
bash programming issue, but as the ultimate purpose of the script is to be a 
nagios check I am hoping that you won't mind me asking here. 


Just to give you a brief overview of what I am experiencing, I'd like to start 
by giving you the output of a couple runs of the script and a couple snippets 
of code. 

First:

[db07-dc2:~] root% /opt/nagios/libexec/check_qaecom1_tablespace.sh 
/opt/nagios/libexec/check_qaecom1_tablespace.sh: line 60: [: BAM_USER_INDX_LG: 
unary operator expected
All OK


is mainly achieved through this loop:

while i=$($sqlplus -s -l $USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql 
| awk '{print $1}') j=$($sqlplus -s -l $USERNAME/$PASS@$SID  
@/opt/bin/ops/mlb_tablespace.sql | awk '{print $3}') k=$($sqlplus -s -l 
$USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql | awk '{print $2}') 
l=$($sqlplus -s -l $USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql | awk 
'{print $4}') 
do
TBLSPACE=$i
PCT=$j
FREE=$k
TOTAL=$l
if [  $TBLSPACE ]
then
   echo "NOK $TBLSPACE is at $PCT $FREE/$TOTAL " 
   exit 2
else
   echo "All OK"
exit 0
fi 
done

But as you can see a 'unary operator' error is produced by this code. As you 
can probably tell, all it does is execute a few sqlplus commands (with the SQL 
contained in a separate file) and assign them to a few variables. It 
incorrectly produces an 'OK' state.


But if I try to fix the 'unary operator' error by putting the TBLSPACE variable 
in quotes, the result changes from "ALL OK" to showing some output and 
(correctly) produces an error state: 

[db07-dc2:~] root% /opt/nagios/libexec/check_qaecom1_tablespace.sh 
NOK BAM_USER_INDX_LG
MLBDATASM is at 97.50%
95.85% 820
340/32764
8191 



while i=$($sqlplus -s -l $USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql 
| awk '{print $1}') j=$($sqlplus -s -l $USERNAME/$PASS@$SID  
@/opt/bin/ops/mlb_tablespace.sql | awk '{print $3}') k=$($sqlplus -s -l 
$USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql | awk '{print $2}') 
l=$($sqlplus -s -l $USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql | awk 
'{print $4}') 
do
TBLSPACE=$i
PCT=$j
FREE=$k
TOTAL=$l
if [  "$TBLSPACE" ]
then
   echo "NOK $TBLSPACE is at $PCT $FREE/$TOTAL " 
   exit 2
else
   echo "All OK"
exit 0
fi 
done

The SQL is designed to list any tablespaces that grow beyond a certain 
threshold. 


My question is this:

[db07-dc2:~] root% /opt/nagios/libexec/check_qaecom1_tablespace.sh 
NOK BAM_USER_INDX_LG # <-- this is correctly output from the script
MLBDATASM is at 97.50%   # <-- this is also correctly output from the 
scipt
95.85% 820   # <-- but where does this additional and 
different percentage come from?
340/32764# <-- and why are the two variables 
$FREE/$TOTAL broken up on different lines?
8191



I realize that this may not be an easy question, but I wanted to put this out 
there in case anyone has faced a similar situation before. 



Here is the entirety of the shell script:


#!/bin/bash

# exit codes
CRED_ERR=1  # if the credentials are not valid
NOARGS=2# if the required par

Re: [Nagios-users] Nagios 3.4.0 double quote in command bug (fixed)

2012-05-13 Thread Andreas Ericsson
On 05/13/2012 10:44 PM, Randal, Phil wrote:
> I've uploaded a patch to
> 
> http://tracker.nagios.org/view.php?id=332
> 
> Which fixes the double quote issue and my original compile problem.
> 

Thanks. The double-quote issue has been resolved by reverting the
faulty patch though. I'll see if I get time to take a look at the
compile problem tomorrow.

-- 
Andreas Ericsson   andreas.erics...@op5.se
OP5 AB www.op5.se
Tel: +46 8-230225  Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.

--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Nagios-users mailing list
Nagios-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting 
any issue. 
::: Messages without supporting info will risk being sent to /dev/null


[Nagios-users] printing info from nagios db check script

2012-05-13 Thread Tim Dunphy
Hey list,

 I'm having a small but important problem with a script I am writing in order 
to monitor the tablespaces of an oracle database. This is probably more of a 
bash programming issue, but as the ultimate purpose of the script is to be a 
nagios check I am hoping that you won't mind me asking here. 


Just to give you a brief overview of what I am experiencing, I'd like to start 
by giving you the output of a couple runs of the script and a couple snippets 
of code. 

First:

[db07-dc2:~] root% /opt/nagios/libexec/check_qaecom1_tablespace.sh 
/opt/nagios/libexec/check_qaecom1_tablespace.sh: line 60: [: BAM_USER_INDX_LG: 
unary operator expected
All OK


is mainly achieved through this loop:

while i=$($sqlplus -s -l $USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql 
| awk '{print $1}') j=$($sqlplus -s -l $USERNAME/$PASS@$SID  
@/opt/bin/ops/mlb_tablespace.sql | awk '{print $3}') k=$($sqlplus -s -l 
$USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql | awk '{print $2}') 
l=$($sqlplus -s -l $USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql | awk 
'{print $4}') 
do
TBLSPACE=$i
PCT=$j
FREE=$k
TOTAL=$l
if [  $TBLSPACE ]
then
   echo "NOK $TBLSPACE is at $PCT $FREE/$TOTAL " 
   exit 2
else
   echo "All OK"
exit 0
fi 
done

But as you can see a 'unary operator' error is produced by this code. As you 
can probably tell, all it does is execute a few sqlplus commands (with the SQL 
contained in a separate file) and assign them to a few variables. It 
incorrectly produces an 'OK' state.


But if I try to fix the 'unary operator' error by putting the TBLSPACE variable 
in quotes, the result changes from "ALL OK" to showing some output and 
(correctly) produces an error state: 

[db07-dc2:~] root% /opt/nagios/libexec/check_qaecom1_tablespace.sh 
NOK BAM_USER_INDX_LG
MLBDATASM is at 97.50%
95.85% 820
340/32764
8191 



while i=$($sqlplus -s -l $USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql 
| awk '{print $1}') j=$($sqlplus -s -l $USERNAME/$PASS@$SID  
@/opt/bin/ops/mlb_tablespace.sql | awk '{print $3}') k=$($sqlplus -s -l 
$USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql | awk '{print $2}') 
l=$($sqlplus -s -l $USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql | awk 
'{print $4}') 
do
TBLSPACE=$i
PCT=$j
FREE=$k
TOTAL=$l
if [  "$TBLSPACE" ]
then
   echo "NOK $TBLSPACE is at $PCT $FREE/$TOTAL " 
   exit 2
else
   echo "All OK"
exit 0
fi 
done

The SQL is designed to list any tablespaces that grow beyond a certain 
threshold. 


My question is this:

[db07-dc2:~] root% /opt/nagios/libexec/check_qaecom1_tablespace.sh 
NOK BAM_USER_INDX_LG # <-- this is correctly output from the script
MLBDATASM is at 97.50%   # <-- this is also correctly output from the 
scipt
95.85% 820   # <-- but where does this additional and 
different percentage come from?
340/32764# <-- and why are the two variables 
$FREE/$TOTAL broken up on different lines?
8191



I realize that this may not be an easy question, but I wanted to put this out 
there in case anyone has faced a similar situation before. 



Here is the entirety of the shell script:


#!/bin/bash

# exit codes
CRED_ERR=1  # if the credentials are not valid
NOARGS=2# if the required parameters were not supplied

# credentials / environment variables
ORACLE_HOME="/u01/app/oracle/product/10.2.0.4"
ORACLE_SID=qaecom1
sqlplus="/u01/app/oracle/product/10.2.0.4/bin/sqlplus"
USERNAME=mlbwatch
PASS=n3x1ch3q
SID=${ORACLE_SID}

if [ -z "${USERNAME}" ] || [ -z "${PASS}" ];   # Exit if no arguments were 
given.
then
echo "Error: Username or Password are empty"
exit $NOARGS
fi ;

PATH=$PATH:$ORACLE_HOME/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export ORACLE_HOME PATH LD_LIBRARY_PATH



while i=$($sqlplus -s -l $USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql 
| awk '{print $1}') j=$($sqlplus -s -l $USERNAME/$PASS@$SID  
@/opt/bin/ops/mlb_tablespace.sql | awk '{print $3}') k=$($sqlplus -s -l 
$USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql | awk '{print $2}') 
l=$($sqlplus -s -l $USERNAME/$PASS@$SID  @/opt/bin/ops/mlb_tablespace.sql | awk 
'{print $4}') 
do
TBLSPACE=$i
PCT=$j
FREE=$k
TOTAL=$l
if [  "$TBLSPACE" ]
then
   echo "NOK $TBLSPACE is at $PCT $FREE/$TOTAL " 
   exit 2
else
   echo "All OK"
exit 0
fi 
done


errorCode=$?# checks if the last operation (sqlplus) was completed 
successfully or not
if [ ${errorCode} -ne 0 ]
then
echo "Running sqlplus FAILED"
exit ${CRED_ERR}
echo
fi


And here's the SQL that the script calls.

--###
--###  THIS IS FOR TABLESPACE MONITORING with exclusion of TEMP and UNDO 
--##Tablespace Alert - A tablespace has reached a crital state!  #
--###  Checks for different pecentage thresholds by total size of the 

[Nagios-users] Nagios 3.4.0 double quote in command bug (fixed)

2012-05-13 Thread Randal, Phil
I've uploaded a patch to

http://tracker.nagios.org/view.php?id=332

Which fixes the double quote issue and my original compile problem.

Cheers,

Phil

"Any opinion expressed in this e-mail or any attached files are those of the 
individual and not necessarily those of Hoople Ltd. You should be aware that 
Hoople Ltd. monitors its email service. This e-mail and any attached files are 
confidential and intended solely for the use of the addressee. This 
communication may contain material protected by law from being passed on. If 
you are not the intended recipient and have received this e-mail in error, you 
are advised that any use, dissemination, forwarding, printing or copying of 
this e-mail is strictly prohibited. If you have received this e-mail in error 
please contact the sender immediately and destroy all copies of it.
--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___
Nagios-users mailing list
Nagios-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting 
any issue. 
::: Messages without supporting info will risk being sent to /dev/null