#!/usr/bin/perl # Detect Sprint PCS Minute Usage # Send a report if over $warning_threshold, or always if -f is passed # Best run through cron (I usually run it every day without -f, and once a week with -f). # by Chris Hardie - http://www.chrishardie.com/ # This is postcardware: if you find this script useful, please let me know! # History # 09/15/2005 - Reworked to accomodate sprint's new website code # 12/29/2004 - Initial release use WWW::Mechanize; use MIME::Lite; use Getopt::Std; use strict; ################################### # User Config Vars my $warning_threshold = 70; # Usage percentage at which you want to be notified my $email = 'your@addresss.com'; my $phone = 'yourphone'; # No dashes or spaces my $pass = 'yourpassword'; my $debug = 0; # End Configuration #################################### # Use -f to force a report, even if you're not over the threshold our ($opt_f); getopts("f"); my $a = WWW::Mechanize->new(); $a->agent_alias('Windows IE 6'); warn "Getting login screen..." if $debug; $a->get('https://manage.sprintpcs.com/Manage/portal/!ut/p/.scr/Login'); die "Couldn't get to login form, got return code $a->status\n" if $a->status != '200'; warn "Submitting form..." if $debug; $a->submit_form( form_name => 'loginForm', fields => { userid => $phone, password => $pass, } ); die "Couldn't log in, got return code $a->status\n" if $a->status != '200'; warn "Sleeping..." if $debug; sleep 2; warn "Getting Logged In screen..." if $debug; $a->get('https://manage.sprintpcs.com/Manage/myportal/!ut/p/.scr/LoggedIn'); die "Couldn't get to login form, got return code $a->status\n" if $a->status != '200'; warn "Getting minutes details page..." if $debug; $a->follow_link(text=>'Details...'); die "Couldn't fetch usage summary, got return code $a->status\n" if $a->status != '200'; my $raw_html = $a->content; $raw_html =~ s/^\s+//gm; $raw_html =~ s/\r\n//gm; my $invoice_period_end; if ($raw_html =~ s!Invoice period:.*class="right">.* - (.*?)!!m) { $invoice_period_end = $1; } else { die "Couldn't get invoice period, something's wrong, bailing out.\n"; } $raw_html =~ s!MINUTES IN PLAN.*?(\d+)(\d+)(\d+)!!m; my $peak_limit = $1; my $peak_usage = $2; my $peak_remaining = $3; $raw_html =~ s!OFF-PEAK OPTION.*?(.*?)(\d+)(.*?)-!!m; my $offpeak_limit = $1; my $offpeak_usage = $2; my $offpeak_remaining = $3; my $peak_percent = ($peak_usage / $peak_limit) * 100; if (($peak_percent >= $warning_threshold) || $opt_f) { my $status; $status .= "For Period Ending: $invoice_period_end\n"; $status .= "Peak: $peak_usage / $peak_limit ($peak_remaining remaining)\n"; $status .= "Off-Peak: $offpeak_usage / $offpeak_limit ($offpeak_remaining remaining)\n"; my $msg = MIME::Lite->new( From => $email, To => $email, Subject =>"Sprint PCS Status for $phone - $peak_percent% of Peak Used", Data => $status ); $msg->send(); } exit;