From 5bb432cb9aff0f681e36d85af1a7a8b8e3767d85 Mon Sep 17 00:00:00 2001 From: Florent Date: Wed, 28 Mar 2012 14:36:05 +0200 Subject: [PATCH] Print cache if empty output of plugin Bad news : in case of site change, connection to the website every 5min Good news : The graph will be good --- contrib/freemobile-munin | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/contrib/freemobile-munin b/contrib/freemobile-munin index a680183a..6e1101d4 100755 --- a/contrib/freemobile-munin +++ b/contrib/freemobile-munin @@ -142,10 +142,10 @@ EOF } sub fetch { - + my @cache_data; # Check if cache exist and not older than the refresh threshold. if ( open $cache_fh, '<', $cachefile ) { - my @cache_data = <$cache_fh>; + @cache_data = <$cache_fh>; close $cache_fh or croak "unable to close: $ERRNO"; # File not empty? @@ -158,13 +158,22 @@ sub fetch { } } } - - # Open cache for writing and execute weboob - open $cache_fh, '>', $cachefile - or croak "Failed to open file $cachefile"; + # execute weboob open my $data, q(-|), $weboob or croak "Couldn't execute program: $ERRNO"; my @lines = <$data>; close $data or carp "unable to close: $ERRNO"; + # If error output, print the cache (if exist) and exit + if ( @cache_data > 0 ) { + if ( @cache_data > 0 ) { + print join q{}, @cache_data[ 1 .. $#cache_data ]; + exit 0; + } + exit 1; + } + + # Open cache for writing + open $cache_fh, '>', $cachefile + or croak "Failed to open file $cachefile"; print {$cache_fh} time . "\n"; foreach my $monit (@monitored) {