OVH Community, your new community space.

Mit MRTG POP3/IMAP Logins etc. auflisten


eplay-tv
14.09.12, 11:36
hallo,

ich wollte in meinem MRTG die IMAP, POP3 Logins sowie den Mailausgang, der noch in der Warteschlange liegt, sowie die Mails, die noch durch den Postgrey laufen anzeigen.

Ich hab das mit folgen Code für IMAP schon mal probiert:

Code:
use Time::Local;

# Global Vars
$IntMins = "5";                     # Set this to your MRTG interval
$MailLogFile = "/var/log/mail.log";  # Change this if your maillog isn't here.
$SuccessCount = "0";
#$FailCount = "0";


# Exec
&Get_Time;
&Process_Log;
&Print_Totals;


# Subroutines
sub Get_Time {
  # Gets the start time and sets global variables.

  $timestart = time();
  my $date = localtime();
  my($day, $month, $num, $time, $year) = split(/\s+/,$date);
  $timeyear = $year;
}


sub Back_Time {
  # This is a debug mechanism for taking the seconds and converting them
  # back to human readable date format. (Not used in operation.)

  my $date = localtime($_[0]);
  my ($day, $month, $num, $time, $year) = split(/\s+/,$date);
  my $back = "[$month $num $time]";
  return $back;
}


sub Rec_Time {
  # Takes a date string on input and returns the universal second count
  # which is better for comparing intervals.
  #   input format is 'Sep 26 16:27:50' (syslog)
  
  my @DateString = split(/\ /,$_[0]);
  my @TimeString = split(/:/,$DateString[2]);
  my $month = $DateString[0];
  if ($month eq "Jan") { $month = "1"; }
  if ($month eq "Feb") { $month = "2"; }
  if ($month eq "Mar") { $month = "3"; }
  if ($month eq "Apr") { $month = "4"; }
  if ($month eq "May") { $month = "5"; }
  if ($month eq "Jun") { $month = "6"; }
  if ($month eq "Jul") { $month = "7"; }
  if ($month eq "Aug") { $month = "8"; }
  if ($month eq "Sep") { $month = "9"; }
  if ($month eq "Oct") { $month = "10"; }
  if ($month eq "Nov") { $month = "11"; }
  if ($month eq "Dec") { $month = "12"; }
  $month = int($month - 1);
  my $iseconds = timelocal($TimeString[2],$TimeString[1],$TimeString[0]
                            ,$DateString[1],$month,$timeyear);
  return $iseconds;
}


sub Process_Log {
  # Bulk of the processing occurs here.
  # 1. Mail Log is inputted and checked for 'score=2.0,' format entries.
  # 2. Only entries that fall within our program's interval are checked.
  # 3. A total is divided by a count producing an average.
  # 4. A global var is set with the average.
  
  my $int_secs = int($IntMins * 60);
  
  open (MAILLOG,$MailLogFile);
  while ($cline = ) {
    if ($cline =~ "imapd: Connection") {
      if ($cline =~ "imapd: Disconnected") {
        my @curline = split(/\ /,$cline);
        my $test = "$curline[1]";
        if ($test ne "") {
          $recsecs = Rec_Time("$curline[0] $curline[1] $curline[2]");
        } else {
          $recsecs = Rec_Time("$curline[0] $curline[2] $curline[3]");
        }

        my $distsecs = int($timestart - $recsecs);

        if ($int_secs > $distsecs && $distsecs > 0) {
          # Ok, count this one
          $SuccessCount++;
        }
      }
    }
  }
  close MAILLOG;

}


sub Print_Totals {
  # Output the total in MRTG format.

  print "$SuccessCount\n";
  print "$SuccessCount\n";
}


exit 0;
Aber leider klappt das nicht so wie ich mir das vorstellt habe, weil dort keine Daten angezeigt werden. Ich mit mit meinem Rechner auf ein IMAP-Konto angemeldet, es wird aber immer noch 0 angezeigt.

Wie kann ich das ändern?


PS: Die Codes für die anderen Befehle sehen fast genauso aus, nur dass im cline das verändert ist.