Smartmon Disk Check

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Shivaramakrishnan
Posts: 71
Joined: Tue May 15, 2012 10:11 pm

Smartmon Disk Check

Post by Shivaramakrishnan »

Hello
I have a smartmon disk check that is working well ,It gives the required result.But the problem I am facing is the exit status.
Here is my script.I have 2 physical drives to which I am performing the test,I need to get notified when a drive fails.
though the script is executing,the exit status seems to be not working.

#!/bin/bash
ok='0'
warning='1'
critical='2'
unknown='3'

#smart='/usr/sbin/smartctl'
string1check=` sudo /usr/sbin/smartctl -H /dev/sda |grep -i PASSED`
string2check=` sudo /usr/sbin/smartctl -H /dev/sdb |grep -i PASSED`

string2catch='SMART overall-health self-assessment test result: PASSED'

if [ "$string2catch" = "$string1check" ]; then
echo 'OK : Drive 1 Good'
$status1=$ok
else
echo 'CRITICAL: Drive 1 Bad'
$status1=$critical
fi

if [ "$string2catch" = "$string2check" ]; then
echo 'OK : Drive 2 Good'
$status2=$ok
else
echo 'CRITICAL: Drive 2 Bad'
$status2=$critical
fi
exit $status1
exit $status2


Current Output :
OK : Drive 1 Good
./check_smart-test: line 15: =0: command not found
OK : Drive 2 Good
./check_smart-test: line 23: =0: command not found

Any help would be greatly appreciated.
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Smartmon Disk Check

Post by sreinhardt »

I would suggest changing

Code: Select all

if [ "$string2catch" = "$string1check" ]; then
echo 'OK : Drive 1 Good'
$status1=$ok
else
echo 'CRITICAL: Drive 1 Bad'
$status1=$critical
fi

if [ "$string2catch" = "$string2check" ]; then
echo 'OK : Drive 2 Good'
$status2=$ok
else
echo 'CRITICAL: Drive 2 Bad'
$status2=$critical
fi
To

Code: Select all

if [ "$string2catch" = "$string1check" ]; then
echo 'OK : Drive 1 Good'
status1=$ok
else
echo 'CRITICAL: Drive 1 Bad'
status1=$critical
fi

if [ "$string2catch" = "$string2check" ]; then
echo 'OK : Drive 2 Good'
status2=$ok
else
echo 'CRITICAL: Drive 2 Bad'
status2=$critical
fi
All I did was remove the leading $ from variables when you are setting them, so that they will set properly.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Shivaramakrishnan
Posts: 71
Joined: Tue May 15, 2012 10:11 pm

Re: Smartmon Disk Check

Post by Shivaramakrishnan »

My bad,I did not notice that.I thought my logic was wrong.
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Smartmon Disk Check

Post by sreinhardt »

Not a problem at all, let us know if there are any other issues with it!
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Locked