Netscaler monitor for MS Exchange 2013(, and higher???)

I was recently involved in creating a custom Netscaler monitor for MS Exchange servers that are in maintenance mode. It seems that on newer versions of exchange that port 25 is still open and accessible when put into maintenance mode. Apparently in older versions the port was closed. So using a simple port monitor on Netscaler would no longer cut it. Since I have used Perl as my primary scripting language for years, I was enlisted to help out. The scripting was simple. And if I was the Netscaler admin, I would have wrote the script differently. But needless to say, we found that via telnet, you can make a connection to port 25, but you could see the connection close once you did a MAIL FROM: line. So using Net::SMTP, I wrote a script that will connect to the server, and runs the mail method on an smtp object. If the command is successful, return 0, else return 1. The admins tested it and it worked! So I decided I would share it in case someone else would find it useful. 

#!/usr/bin/perl -w
## By: Court Campbell
## MS Exchange smtp monitor.

use strict;
use Netscaler::KAS;

## This function is a handler for performing smtp probe in KAS mode
sub smtp_probe {
    use Net::SMTP;
     my $host = ""; 
     my $mailer = '"; 

     my $smtp = Net::SMTP->new($host, Timeout => 10) || die "Error: $!";

     if ($smtp->mail($mailer)) { 
         return 0; 
     } else { 
         return 1; 
     } 
}

## Register smtp probe handler, to the KAS module.
probe(\&smtp_probe);

Comments