Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
New Nagios rc-script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
mozingod
n00b
n00b


Joined: 15 Jun 2003
Posts: 64
Location: Ohio

PostPosted: Fri Jan 23, 2004 9:28 pm    Post subject: New Nagios rc-script Reply with quote

I installed Nagios from source (cause, well, the ebuild sucks) and the startup script it comes with is a little lacking. I rewrote it using the rc-script standards before i saw the ebuild came with one. I liked it a little better, but I still wanted a little better error handling in there.

If Nagios is up and running, and you're working on the config files and misspell something, add in a service check and forget to add a definition for it, etc, when you go to restart it, it'll start but just show the [!!] when it fails, leaving the process dead. It was starting to tick me off so I added the ability to do a "nagios checkconfig" function to the rc-script. Cool, but I still had to remember to do it. So I thought I'd have it check the scripts for me before even stopping/starting/restarting it for me, making it pretty fool proof.

Let me know if you know of a better way to do this:

Code:

#!/sbin/runscript

opts="${opts} checkconfig checkcfg"

errors=`/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg | grep Error: | wc -l`

if [ $errors -gt 1 ]
then
        errorstring="$errors errors were found in the configuration files, please correct them before attempting to"
else
        errorstring="$errors error was found in the configuration files, please correct it before attempting to"
fi

depend() {
        need net
        use dns logger
}

checkcfg() {
        checkconfig
}

checkconfig() {
        /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
}

start() {
        if [ $errors -eq 0 ]
        then
                ebegin "Starting Nagios"
                        touch /usr/local/nagios/var/nagios.log /usr/local/nagios/var/status.sav
                        chown nagios:nagios /usr/local/nagios/var/nagios.log /usr/local/nagios/var/status.sav

                        rm -f /usr/local/nagios/var/rw/nagios.cmd

                        start-stop-daemon -o --quiet --start --startas /usr/local/nagios/bin/nagios \
                                --pidfile /usr/local/nagios/var/nagios.lock -- -d /usr/local/nagios/etc/nagios.cfg
                eend $?
        else
                checkconfig
                eerror "$errorstring start Nagios..."

                exit 1
        fi
}

stop() {
        if [ $errors -eq 0 ]
        then
                ebegin "Stopping Nagios"
                        start-stop-daemon -o --quiet --stop --pidfile /usr/local/nagios/var/nagios.lock

                        rm -f   /usr/local/nagios/var/status.log \
                                /usr/local/nagios/var/nagios.tmp \
                                /usr/local/nagios/var/nagios.lock \
                                /usr/local/nagios/var/rw/nagios.cmd
                eend $?
        else
                checkconfig
                eerror "$errorstring stop Nagios..."

                exit 1
        fi
}

restart() {
        if [ $errors -eq 0 ]
        then
                svc_stop
                svc_start
        else
                checkconfig
                eerror "$errorstring restart Nagios..."

                exit 1
        fi
}
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum