fix regexps

This commit is contained in:
Romain Bignon 2012-03-13 12:35:07 +01:00
commit db85b651d4

View file

@ -6,22 +6,22 @@
freemobile - Plugin to monitor a freemobile subscription freemobile - Plugin to monitor a freemobile subscription
copy this script to /etc/munin/plugins/freemobile copy this script to /etc/munin/plugins/freemobile
=note1 =note1
You have to manually create the folder: You have to manually create the folder:
$HOME/.config/weboob/munin/ $HOME/.config/weboob/munin/
=head1 CONFIGURATION =head1 CONFIGURATION
You need to configure the user and the home PATH like that: You need to configure the user and the home PATH like that:
[freemobile] [freemobile]
env.HOME /home/florent env.HOME /home/florent
user florent user florent
group florent group florent
You can configure the list of monitored data with the ligne: You can configure the list of monitored data with the ligne:
env.freemonitored voice sms mms data env.freemonitored voice sms mms data
Others monitored options: voicetoint voiceint smsint mmsint dataint Others monitored options: voicetoint voiceint smsint mmsint dataint
@ -32,13 +32,13 @@ use warnings;
my @monitored = split(/ /, $ENV{'freemonitored'} || 'voice sms'); my @monitored = split(/ /, $ENV{'freemonitored'} || 'voice sms');
my $cachefile = $ENV{'HOME'} . '/.config/weboob/munin/freemobile-munin'; my $cachefile = $ENV{'HOME'} . '/.config/weboob/munin/freemobile-munin';
my $weboob = "/usr/local/bin/weboob-cli ICapBill get_details coin -f table |"; my $weboob = "/usr/bin/env weboob-cli ICapBill get_details coin -f table |";
my %label = ( my %label = (
'voice' => "Voix en France (min)\n", 'voice' => "Voix en France (min)\n",
'voicetoint' => "Voix vers l'international (min)\n", 'voicetoint' => "Voix vers l'international (min)\n",
'sms' => "SMS en France\n", 'sms' => "SMS en France\n",
'mms' => "MMS en France", 'mms' => "MMS en France\n",
'data' => "Data en France\n", 'data' => "Data en France\n",
'voiceint' => "Voix à l\'international (min)\n", 'voiceint' => "Voix à l\'international (min)\n",
'smsint' => "SMS à l\'international\n", 'smsint' => "SMS à l\'international\n",
@ -50,24 +50,24 @@ my %linenum = (
'voice' => 3, 'voice' => 3,
'voicetoint' => 3, 'voicetoint' => 3,
'sms' => 5, 'sms' => 5,
'mms' => 6, 'mms' => 6,
'data' => 7, 'data' => 7,
'voiceint' => 8, 'voiceint' => 8,
'smsint' => 9, 'smsint' => 9,
'mmsint' => 10, 'mmsint' => 10,
'dataint' => 11 'dataint' => 11
); );
my %regexp = ( my %regexp = (
'voice' => 'Consommation : (\d+)h(\d+)min(\d+)s', 'voice' => 'Consommation : (\d+)h(\d+)min(\d+)s',
'voicetoint' => 'International : (\d+)h(\d+)min(\d+)s', 'voicetoint' => 'International : (\d+)h(\d+)min(\d+)s',
'sms' => 'Conso SMS \| (\d+) \/ (\d+)', 'sms' => 'Conso SMS \| (\d+) \/ (.*)',
'mms' => 'Vous avez consommé (\d+) MMS', 'mms' => 'Vous avez consommé (\d+) MMS',
'data' => 'Vous avez consommé (\d+) o', 'data' => 'Vous avez consommé ([\d\-]+) Mo',
'voiceint' => 'Appels émis (\d+)h(\d+)min(\d+)s', 'voiceint' => 'Appels émis (\d+)h(\d+)min(\d+)s',
'smsint' => 'Conso SMS (international) \| (\d+)', 'smsint' => 'Conso SMS (international) \| (\d+)',
'mmsint' => 'Vous avez consommé (\d+) MMS', 'mmsint' => 'Vous avez consommé (\d+) MMS',
'dataint' => 'Vous avez consommé (\d+) o' 'dataint' => 'Vous avez consommé ([\d\-]+) Mo'
); );
my %post = ( my %post = (
@ -86,7 +86,7 @@ my @lines;
my $cache; my $cache;
my $expr; my $expr;
if ($ARGV[0] and $ARGV[0] eq "config") { if ($ARGV[0] and $ARGV[0] eq "config") {
print "graph_title Conso Free\n"; print "graph_title Conso Free\n";
print "graph_vlabel Suivi conso du forfait 2 euros\n"; print "graph_vlabel Suivi conso du forfait 2 euros\n";
print "graph_category weboob\n"; print "graph_category weboob\n";
@ -97,14 +97,14 @@ if ($ARGV[0] and $ARGV[0] eq "config") {
} }
} }
else { else {
my $first = 1; my $first = 1;
my $time = time(); my $time = time();
# Check if cache exist and not older than 3 hours # Check if cache exist and not older than 3 hours
if (open(CACHE, "< " . $cachefile)) { if (open(CACHE, "< " . $cachefile)) {
$cache = 1; $cache = 1;
LOOP: while(<CACHE>) { LOOP: while(<CACHE>) {
if ($first) { if ($first) {
if ($time - $_ > 10800) { if ($time - $_ > 10800) {
$cache = 0; $cache = 0;
last; last;
} }
@ -122,7 +122,7 @@ else {
open(CACHE, "> " . $cachefile) or die "Failed to open file $cachefile"; open(CACHE, "> " . $cachefile) or die "Failed to open file $cachefile";
open(DATA, $weboob) or die "Couldn't execute program: $!"; open(DATA, $weboob) or die "Couldn't execute program: $!";
LOOP: while (<DATA>) { LOOP: while (<DATA>) {
push(@lines,$_); push(@lines,$_);
} }
close(DATA); close(DATA);
print CACHE time(). "\n"; print CACHE time(). "\n";