-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharpwlog.pl
More file actions
executable file
·61 lines (50 loc) · 2.14 KB
/
Copy patharpwlog.pl
File metadata and controls
executable file
·61 lines (50 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl
# Konrad Cempura 2009
# GNU GPL 2.0
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
use warnings;
use strict;
my @wiersze;
chomp (@wiersze = <STDIN>);
open (OUT , ">>/var/log/arpwatch/arpwatch_mail.log")
or die "Nie moglem zapisac danych!";
my %wpis;
foreach ( @wiersze ) {
chomp;
if (/^\s*(hostname|ip address|interface|ethernet address|ethernet vendor|old ethernet address|old ethernet vendor|timestamp|previous timestamp|delta):\s(.*)/) {
$wpis{$1} = $2 if ($2 ne '<unknown>');
} elsif (/^Subject:\s+(.*)/) {
# $wpis{'subject'} = '<b>' . $1 . '</b>';
$wpis{'subject'} = $1;
} elsif (/^\s*$/ || /^From: / || /^To: /) {
# skip
} else {
if (not defined $wpis{other}) {
$wpis{'other'} = $_
} else {
$wpis{'other'} = ", " . $wpis{'other'} . $_
}
}
}
my @tmp;
@tmp = split (/,?\s/, $wpis{'timestamp'});
$wpis{'timestamp'} = $tmp[2] . " " . substr($tmp[1], 0, 3) . " " . $tmp[3] . " " . $tmp[4];
if (defined $wpis{'previous timestamp'}) {
@tmp = split (/,?\s/, $wpis{'previous timestamp'});
$wpis{'previous timestamp'} = $tmp[2] . " " . substr($tmp[1], 0, 3) . " " . $tmp[3] . " " . $tmp[4];
}
undef @tmp;
my $result = $wpis{'timestamp'};
$result = $result . "; " . $wpis{'interface'} if defined $wpis{'interface'};
$result = $result . "; " . $wpis{'subject'} if defined $wpis{'subject'};
$result = $result . "; " . $wpis{'ip address'} if defined $wpis{'ip address'};
$result = $result . " (" . $wpis{'hostname'} . ")" if defined $wpis{'hostname'};
$result = $result . "; " . $wpis{'ethernet address'} if defined $wpis{'ethernet address'};
$result = $result . " (" . $wpis{'ethernet vendor'} . ")" if defined $wpis{'ethernet vendor'};
$result = $result . "; " . $wpis{'old ethernet address'} if defined $wpis{'old ethernet address'};
$result = $result . " (" . $wpis{'old ethernet vendor'} . ")" if defined $wpis{'old ethernet vendor'};
$result = $result . "; " . $wpis{'previous timestamp'} if defined $wpis{'previous timestamp'};
$result = $result . " (" . $wpis{'delta'} . ")" if defined $wpis{'delta'};
$result = $result . " nie rozpoznane opcje: " . $wpis{'other'} if defined $wpis{'other'};
print OUT $result . "\n";
close OUT;