While investigating intermittent "Odd number of elements in hash assignment"
noise from the diskstat_ plugin in munin-node.log, I noticed behaviour
hopefully demonstrated by this short example:
use Munin::Plugin;
$Munin::Plugin::statefile='./state';
my %test_state=(
'foo'=>'',
'bar'=>42,
'baz'=>''
);
save_state(time(), %test_state);
my ($prev_time, %new_state) = restore_state();
print(map {"before save: $_: ".(defined $test_state{$_}?$test_state{$_}:"undef")."\n"} sort keys %test_state);
print(map {"after restore: $_: ".(defined $new_state{$_}? $new_state{$_}:"undef")."\n"} sort keys %new_state);
Two thirds of the time, the generated state file will have an empty last
line. This breaks because by default, split() strips out trailing empty
fields (see manpage), resulting in an uneven-length list.
I offer the attached trivial patch against Munin::Plugin as a solution.
HTH,