perling out to make some xml
I rarely code in PERL these days; but I wanted to aquire some experience with some flash based graphs that read XML, so I figured that I might as well take some standard text and run it through my perl scripts to generate XML which in turn can be fed into these flash graphs. For a simple test, I am taking pflogsumm.pl, running it and saving the output report to a text file and then parsing specific details in the report to feed into my scripts.
Some relevant sections of the code I was working on …
system("/usr/bin/pflogsumm.pl -u 0 --no_reject_detail -d yesterday /var/log/maillog > email_log.out");
open(EMAIL, "email_log.out");
open(TOP, ">top_out");
undef $/;
while () {
while ( /messages(.*?)Per-Hour/sgm ) {
#print “$1\n”;
print TOP “$1″;
}
}
close(EMAIL);
close(TOP);
$/ =”\n”;
open(TOP, “top_out”);
while () {
if ($_ =~ m/[0-9]\s+ received/) {$receivedStr= $_; print “$receivedStr”;}
if ($_ =~ m/[0-9]\s+ delivered/) {$deliveredStr= $_; print “$deliveredStr”; }
if ($_ =~ m/[0-9]\s+ forwarded/) {$forwardedStr= $_; print “$forwardedStr”;}
}
$receivedStr =~ s/[a-z]+//;
$receivedStr =~ s/^\s+//;
$receivedStr =~ s/\s+$//;
$deliveredStr =~ s/[a-z]+//;
$deliveredStr =~ s/^\s+//;
$deliveredStr =~ s/\s+$//;
$forwardedStr =~ s/[a-z]+//;
$forwardedStr =~ s/^\s+//;
$forwardedStr =~ s/\s+$//;
chomp($receivedStr, $deliveredStr, $forwardedStr);
Originally published on truman.net. See the archived copy.