Hack 78. Create Alerts for Important Users


Start working on your CEO's BlackBerry problem before she realizes there is one.

It is amazing how important BlackBerry has become to some organizations. More and more executives now travel only with their BlackBerry, leaving their laptops behind. In many organizations, the BlackBerry has gone from nonexistent just a couple years ago to an absolutely mission-critical service today. With the high-profile users that are the typical users on a company's BlackBerry Enterprise Server, it is important that the administrators stay on their toes it is amazing how quickly BlackBerry users will notice even a short delay in message delivery.

If there are certain important executives who rely heavily on their BlackBerrys, it is a good idea to set up alerting to detect when there are problems with delivery of messages for these users. Use the code in this hack to send alerts when certain users reach specific pending count thresholds.

7.8.1. The Code

 use Text::CSV; use Mail::Sendmail; use strict; my %USERS_TO_CHECK = (    'email@domain.com' => -1, # pending count threshold for alerting ); my $ALERTS_GO_TO = 'admin@domain.com'; my $ALERTS_FROM = 'admin@domain.com'; my $ALERTS_SUBJECT = "User Pending Count Threshold Exceeded"; my $SMTP_SERVER = "smtp.server.com"; my $BES_USER_ADMIN_CLIENT =   "besuseradminclient.exe"; # change to your specific path my %BES_SERVERS = ( BES => "server.domain.com", # maps your BES name to the computer name ); my $PASSWORD = "password"; # change to the password for BESUserAdmin my $TEMP_DIR = "c:\\temp"; my $csv = Text::CSV->new; foreach my $bes (sort keys %BES_SERVERS) { my $output_file = "$TEMP_DIR\\bes.$bes.users.csv"; my $error_file = "$TEMP_DIR\\error.$bes.users.csv"; my $system_command = "\"$BES_USER_ADMIN_CLIENT\" -n " .   "$BES_SERVERS{$bes} -b $bes -p $PASSWORD -stats -users " .   "> $output_file 2> $error_file"; my $return_code = system $system_command; open OUTPUT, $output_file || die "Can't open output: $!\n"; my $count = 0; while (<OUTPUT>) { chomp; $csv->parse($_); my @fields = $csv->fields; my $email = $fields[17]; $email =~ s/^smtp://i; my $pending_count = $fields[9]; if ($USERS_TO_CHECK{$email}) { # "important" user to check my $pending_threshold = $USERS_TO_CHECK{$email}; if ($pending_count > $pending_threshold) { print "Sending alert for $email\n"; my %message_options = ( To => $ALERTS_GO_TO, From => $ALERTS_FROM, Subject => $ALERTS_SUBJECT, Body => "Alert threshold exceeded for $email " .    "($pending_count)\n", smtp => $SMTP_SERVER, ); sendmail(%message_options); } else { print "Pending count for $email was only $pending_count.\n"; } } } close OUTPUT; } 

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

7.8.2. Run the Code

Run the code by bringing up a command prompt and changing directory to the folder where you stored the file. Type the following code to run the script:

 C:\>perl user_alert.pl 

7.8.3. Output

In the event that the pending count threshold for any of the users you specified is reached, the script will fire off an email to the address specified in the $ALERTS_GO_TO variable. If the threshold is not met, you'll get console output similar to the following for each user you're checking:

 Pending count for dmabe@runningland.com was only 0. 

If you're testing, you can set the threshold to 1 so that the criteria will be met every time and the email will be fired off.




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