Hack 75. Send an Alert When Your SRP Is Down


Wrap some simple Perl code around bbsrptest.exe to create an automated alert when connectivity is lost.

You already realize the importance of you SRP connection. If connectivity is lost, all your devices are unable to send or receive email, view web sites via the BlackBerry Browser, or view attachments to email messages they've already received. If there are more than a few heavy BlackBerry users on your BlackBerry Enterprise Server, it won't take long for your phone to start ringing.

As with any service outage, it always makes your job a little easier when you already know about and are working on a problem when the CEO calls and asks about it. Use this hack to send an automated alert when bbsrptest fails.

7.5.1. The Code

 use Mail::Sendmail; use strict; my $BBSRPTEST = "bbsrptest.exe"; my $SMTP_SERVER = "smtp.server.com"; my $NO_OF_BES_SERVERS = 1; my $EMAIL_TO = 'email@domain.com,anotheremail@domain.com'; my $EMAIL_FROM = 'email@domain.com'; my $output = `$BBSRPTEST`; my $success_count = () = $output =~ /Successful/gs; if ($success_count < $NO_OF_BES_SERVERS) { my $failures = $NO_OF_BES_SERVERS - $success_count; my %mail_options = ( To => $EMAIL_TO, From => $EMAIL_FROM, Subject => "[$ENV{COMPUTERNAME}] BB SRP Down!", Body => "There was $failures SRP failures. Output was:\n$output\n", ); sendmail(%mail_options); } 

This Perl code uses the Mail::Sendmail Perl module, which doesn't come with the default distribution from ActiveState (which must be downloaded from http://www.activestate.com/store/languages/register.plex?id=ActivePerl). You'll need to install it by typing ppm install Mail::Sendmail from a command prompt. Type the following code into Notepad (or your favorite text editor) and save it as bbsrptest.pl. Of course, you will need to modify the variables at the top of the file.

7.5.2. Run the Code

To run the code, execute the following line from a command prompt in the directory where you saved the script.

 C:\temp>perl bbsrptest.pl 

The bbsrptest utility makes connection attempts for each BES you've configured on your server. This script counts the number of times the word "Successful" appears in the output of the bbsrptest command. If the count is less than the number of BES instances (which you've defined in the $NO_OF_BES_SERVERS variable), it will send an email to the address(es) you've specified in the $EMAIL_TO variable.

If you are a BlackBerry user and you've configured profiles on your device to receive alerts [Hack #24], you'll probably want to add another email address in addition to email that delivers through your BES. In the event that the bbsrptest does fail and the script sends an alert, your device won't receive it if your BES is not operational. Consider adding the SMS email address for your device, such as MOBILENUMBER@mycingular.com.




BlackBerry Hacks
Blackberry Hacks: Tips & Tools for Your Mobile Office
ISBN: 0596101155
EAN: 2147483647
Year: 2006
Pages: 164
Authors: Dave Mabe

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net