LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-20-2014, 05:46 PM   #1
LiNuXMaN31509
LQ Newbie
 
Registered: Jun 2009
Location: Houston Texas (Born in Brooklyn NY)
Distribution: CentOS
Posts: 25

Rep: Reputation: 0
Nagios Check - No Output


Hello,

So I have a Nagios server which monitors a cPanel server. One of the checks I wanted to make is to check the cPanel service and make sure it's running. Custom nagios checks can be done in bash like I have. When I run the check, I don't get any errors BUT it does not produce any output:

Code:
#!/bin/bash

SERVICE=$(service cpanel status | head -1);

if [ "$SERVICE" = running ] ; then
        status=0
        echo "OK - cPanel is running."
        elif [ "$SERVICE" = stopped ] ; then
                status=2
                echo "CRITICAL - cPanel is NOT running!!"
        else
                status=1
                statustxt=WARNING
fi
As you can see, I want to run the
Code:
service cpanel status | head -1
command and take that output and pass it so depending on the output it will determine the exit code and output. I'm new to bash scripting so I'm at a lost as to what I'm doing wrong.

Thank you SO MUCH in advance for any and all help!!
 
Old 06-23-2014, 03:28 AM   #2
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,307
Blog Entries: 2

Rep: Reputation: Disabled
Why don't you add a line in the final else that just echos the variable and see if the reason is it doesn't exactly match (including case) the options "running" or "stopped"?
Another suggestion, since your using escapes (brackets) in your if statements, I'd set two variables (on/off) and then match them like this

ON='running'
OFF='stopped'

so when you do the evaluations it looks more like if["$SERVICE"="$ON"] and if["$SERVICE"="$OFF"]. The reason is the behavior of bald strings inside of escapes can be... frustrating.
 
Old 06-24-2014, 12:25 AM   #3
LiNuXMaN31509
LQ Newbie
 
Registered: Jun 2009
Location: Houston Texas (Born in Brooklyn NY)
Distribution: CentOS
Posts: 25

Original Poster
Rep: Reputation: 0
Hello,

After doing a bunch more reading and research I figured out the following and it seems to be working correctly:

Quote:
#!/bin/bash

##############################################################################
# Constants

cpanelstate="running"

ALERT_OK="OK - cPanel is running"
ALERT_CRITICAL="CRITICAL - cPanel is NOT running"
###############################################################################

cpanel=$(service cpanel status | head -1)
echo CPANEL $cpanel
if [[ $cpanel == *$cpanelstate* ]]; then

echo $ALERT_OK
exit 0
else
echo $ALERT_CRITICAL
exit 2

fi
I will look into your suggestion as well and see if it makes it better or I can use it for other instances.

Thank you!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
check postgresql with Nagios ,!!!! sarah allali Linux - Newbie 6 03-17-2013 11:05 AM
webpage contains check through nagios ratotopi Linux - Software 4 05-16-2012 07:35 PM
Nagios Check_nrpe returns no output in Nagios but works in terminal dave0821 Linux - Software 1 04-18-2012 07:26 PM
nagios check resource djackbloodshed Ubuntu 2 03-30-2011 11:26 AM
Nagios and Check.cgi kopite2012 Linux - Newbie 1 04-08-2004 05:42 AM


All times are GMT -5. The time now is 05:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration