From cdfe518d363b9555c9adbb09841bfd54867fb7c6 Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Fri, 19 Jul 2013 10:59:36 +0200 Subject: [PATCH] use Munin::Plugin for statefiles --- plugins/dovecot/dovecot | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/plugins/dovecot/dovecot b/plugins/dovecot/dovecot index 4236279b..3452a071 100644 --- a/plugins/dovecot/dovecot +++ b/plugins/dovecot/dovecot @@ -3,8 +3,8 @@ #%# family=auto #%# capabilities=autoconf +use Munin::Plugin; -$statefile = "/var/lib/munin-node/plugin-state/root/plugin-dovecot.state"; $pos = undef; $connected = 0; $connectedimap = 0; @@ -24,7 +24,6 @@ $aborted = 0; $logfile = $ENV{'LOGFILE'} || '/var/log/mail.log'; $DOVEADM = "/usr/bin/doveadm"; - if ( $ARGV[0] and $ARGV[0] eq "autoconf" ) { if (! -x $DOVEADM) { @@ -161,17 +160,7 @@ $connectionspop3 =~ s/\s+$//; $connected = $connectedimap + $connectedpop3; $connections = $connectionsimap + $connectionspop3; -if (-f "$statefile") { - if (!open (IN, "$statefile")) { - print "Cannot open statefile $statefile for reading: $!\n"; - exit 4; - } - my $in = ; - if ($in =~ /^(\d+)$/) { - ($pos) = ($1); - } - close IN; -} +my ($pos) = restore_state(); $startsize = (stat $logfile)[7]; @@ -189,16 +178,7 @@ if ($startsize < $pos) { parseDovecotfile ($logfile, $pos, $startsize); $pos = $startsize; -if (-l $statefile) { - die("$statefile is a symbolic link, refusing to touch it."); -} - -if (!open (OUT, ">$statefile")) { - print "Cannot open statefile $statefile for writing: $!\n"; - exit 4; -} -print OUT "$pos\n"; -close OUT; +save_state($pos); print "multigraph dovecot_connections\n"; print "connections.value $connections\n";