line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Sysadmin::Log::Simple::UDP; |
2
|
4
|
|
|
4
|
|
6759
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
140
|
|
3
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
108
|
|
4
|
4
|
|
|
4
|
|
20
|
use Carp; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
308
|
|
5
|
4
|
|
|
4
|
|
5236
|
use IO::Socket::INET; |
|
4
|
|
|
|
|
79614
|
|
|
4
|
|
|
|
|
57
|
|
6
|
4
|
|
|
4
|
|
3131
|
use autodie qw(:socket); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
42
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: a UDP-logger for App::Sysadmin::Log::Simple |
9
|
|
|
|
|
|
|
our $VERSION = '0.009'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
5
|
|
|
5
|
1
|
2915
|
my $class = shift; |
14
|
5
|
|
|
|
|
17
|
my %opts = @_; |
15
|
5
|
|
|
|
|
16
|
my $app = $opts{app}; |
16
|
|
|
|
|
|
|
|
17
|
5
|
|
100
|
|
|
45
|
$app->{udp}->{host} ||= 'localhost'; |
18
|
5
|
|
100
|
|
|
33
|
$app->{udp}->{port} ||= 9002; |
19
|
|
|
|
|
|
|
|
20
|
5
|
|
|
|
|
44
|
return bless { |
21
|
|
|
|
|
|
|
do_udp => $app->{do_udp}, |
22
|
|
|
|
|
|
|
udp => $app->{udp}, |
23
|
|
|
|
|
|
|
user => $app->{user}, |
24
|
|
|
|
|
|
|
}, $class; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub log { |
29
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
30
|
2
|
|
|
|
|
4
|
my $logentry = shift; |
31
|
|
|
|
|
|
|
|
32
|
2
|
50
|
|
|
|
10
|
return unless $self->{do_udp}; |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
26
|
my $sock = IO::Socket::INET->new( |
35
|
|
|
|
|
|
|
Proto => 'udp', |
36
|
|
|
|
|
|
|
PeerAddr => $self->{udp}->{host}, |
37
|
|
|
|
|
|
|
PeerPort => $self->{udp}->{port}, |
38
|
|
|
|
|
|
|
); |
39
|
2
|
50
|
|
|
|
1458
|
carp "Couldn't get a socket: $!" unless $sock; |
40
|
|
|
|
|
|
|
|
41
|
2
|
50
|
|
|
|
12
|
if ($self->{udp}->{irc}) { |
42
|
0
|
|
|
|
|
0
|
my %irc = ( |
43
|
|
|
|
|
|
|
normal => "\x0F", |
44
|
|
|
|
|
|
|
bold => "\x02", |
45
|
|
|
|
|
|
|
underline => "\x1F", |
46
|
|
|
|
|
|
|
white => "\x0300", |
47
|
|
|
|
|
|
|
black => "\x0301", |
48
|
|
|
|
|
|
|
blue => "\x0302", |
49
|
|
|
|
|
|
|
green => "\x0303", |
50
|
|
|
|
|
|
|
lightred => "\x0304", |
51
|
|
|
|
|
|
|
red => "\x0305", |
52
|
|
|
|
|
|
|
purple => "\x0306", |
53
|
|
|
|
|
|
|
orange => "\x0307", |
54
|
|
|
|
|
|
|
yellow => "\x0308", |
55
|
|
|
|
|
|
|
lightgreen => "\x0309", |
56
|
|
|
|
|
|
|
cyan => "\x0310", |
57
|
|
|
|
|
|
|
lightcyan => "\x0311", |
58
|
|
|
|
|
|
|
lightblue => "\x0312", |
59
|
|
|
|
|
|
|
lightpurple => "\x0313", |
60
|
|
|
|
|
|
|
grey => "\x0314", |
61
|
|
|
|
|
|
|
lightgrey => "\x0315", |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
my $ircline = $irc{bold} . $irc{green} . '(LOG)' . $irc{normal} |
65
|
|
|
|
|
|
|
. ' ' . $irc{underline} . $irc{lightblue} . $self->{user} . $irc{normal} |
66
|
|
|
|
|
|
|
. ': ' . $logentry . "\r\n"; |
67
|
0
|
|
|
|
|
0
|
print $sock $ircline; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else { |
70
|
2
|
|
|
|
|
275
|
print $sock "(LOG) $self->{user}: $logentry\r\n"; |
71
|
|
|
|
|
|
|
} |
72
|
2
|
|
|
|
|
24
|
$sock->shutdown(2); |
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
77
|
return "Logged to $self->{udp}->{host}:$self->{udp}->{port}"; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |