Monitoring an Outlook Web Access site with Nagios

This is actually a really old post that I had done on another site and wanted to share it here in case it would help anyone. We have the code on GitHub should you want to fork it or collaborate to keep it updated to more recent versions of Nagios and Exchange.

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

Here is the content of the file:

#!/bin/sh
# Author: Computero
# 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.

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.sh $HOSTADDRESS$
        }

Setting up the checks

Checking from outside your network

Here is what you need in your owa_external.cfg for it to work:

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

Here is what you need in your owa_internal.cfg for it to work:

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
        }

The Nagios admins has their way to do it here.

Related articles
Advertisements

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s