Monitoring an Outlook Web Access site with Nagios


I was tasked at work to devise a way to make our Exchange OWA site be monitored by our Nagios-3 servers. After several days and some hours of research, hoping that someone had already done it in hopes of making my life easier; I ended up with one script that basically combined php and curl. Being new to scripting it was most confusing and I ended up taking on the task to introduce myself to it.

Here goes…

At work we use Linux on all our servers so I had to get learning on something compatible and what better than Bash scripting.. So here is what I did so far:
Create a file called check_exchange.sh and made it executable:

sudo touch check_exchange.sh && sudo chmod +x check_exchange.sh

Here is the contents that go in check_exchange.sh:

#!/bin/sh
# Description: Nagios check command for Microsoft Exchange
# Date: 2009.05.06 
# Version: 1.0

if [ -z $1 ];
   then echo 'UNKNOWN: command is wrong'
exit 3 fi

curl -skIf -u 'user@domain.com:password' "https://${1}/owa/" >/dev/null 2>&1

if [ $? != 0 ];
   then echo 'CRITICAL: Exchange login failure' exit 2
fi

echo 'OK: Exchange login successful'
exit 0

Basically what the code does is use curl to log into the website and tell you if it was successful or not, if it was not able to it will provide and error code. The bash script then reads that output code and echo’s OK and exits with a code 0 if login was possible or echo’s critical and exits with a code 2 if not, the script then closes.

Hope this helps others that are trying to undertake the same task.

Update: Streamlined the script to make it more efficient.

Updated on 05/28/09

Getting Nagios3 configured

Once you have the above setup you can configure your Nagios server to start monitoring.

Setting up the command

This needs to be in the checkcommands.cfg

# 'check_exchange' command definition
define command{
        command_name            check_exchange
        command_line            /path/to/check_exchange $HOSTADDRESS$
        }

Setting up the checks

Here is what you need in your filename.cfg for it to work (change filename.cfg to whatever you want the name of these files to be):

Checking from outside your network

define host {
        use                     generic-host
        host_name               exchange-owa-ext
        alias                   Exchange OWA (External)
        address                 an.ipa.ddr.ess
        check_command           check-host-alive
        contacts                contact
        contact_groups          contact groups
        max_check_attempts      4
        notification_interval   60
        notification_period     24x7
        notification_options    d,u,r
        }

define service {
        use                     check-http
        host_name               exchange-owa-ext
        contacts                contact
        contact_groups          contact groups
        }define service {
        use                     check-exchange
        host_name               exchange-owa-ext
        contacts                contact
        contact_groups          contact groups
        }

Checking from inside your network

define host {
        use                     generic-host
        host_name               exchange-owa-int
        use                     generic-service
        alias                   Exchange OWA (Internal)
        address                 website url
        check_command           check-host-alive
        max_check_attempts      4
        notification_interval   60
        notification_period     24x7
        notification_options    d,u,r
        }define service {
        use                     check-http
        host_name               exchange-owa-int
        contacts                contact
        contact_groups          contact groups
        }define service {
        use                     check-exchange
        host_name               exchange-owa-int
        contacts                contact
        contact_groups          contact groups
        }

Here is the command that runs the script in nagios, this should be in the services.cfg file:

define service {
        name                    check-exchange
        use                     generic-service
        register                0
        service_description     Exchange Login
        is_volatile             0
        check_period            24x7
        max_check_attempts      5
        normal_check_interval   5
        retry_check_interval    1
        notification_interval   240
        notification_period     24x7
        notification_options    c,r
        check_command           check_exchange
        }

Update:

The Nagios admins recently posted their way to do it here.

 


About FiWeBelize

FiWeBelize is dedicated to providing quality information to our visitors. We aim to provide an open forum where people can have a voice without censorship while maintaining respect for the opinions of others. Find us on Google

Share your thoughts ...