line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Dispatch::Slack; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
746
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.0004'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
804
|
use WebService::Slack::WebApi; |
|
1
|
|
|
|
|
100874
|
|
|
1
|
|
|
|
|
31
|
|
11
|
1
|
|
|
1
|
|
857
|
use Log::Dispatch::Output; |
|
1
|
|
|
|
|
10815
|
|
|
1
|
|
|
|
|
27
|
|
12
|
1
|
|
|
1
|
|
8
|
use Try::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
13
|
1
|
|
|
1
|
|
5
|
use JSON::XS qw/decode_json/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
5
|
use base qw( Log::Dispatch::Output ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
76
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
6
|
use Params::Validate qw(validate SCALAR BOOLEAN); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
497
|
|
18
|
|
|
|
|
|
|
Params::Validate::validation_options( allow_extra => 1 ); |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
0
|
0
|
|
sub APPEND {0} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
24
|
0
|
|
0
|
|
|
|
my $class = ref $proto || $proto; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my %p = @_; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
$self->_basic_init(%p); |
31
|
0
|
|
|
|
|
|
$self->_make_handle; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _basic_init { |
37
|
0
|
|
|
0
|
|
|
my $self = shift; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$self->SUPER::_basic_init(@_); |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my %p = validate( |
42
|
|
|
|
|
|
|
@_, { |
43
|
|
|
|
|
|
|
token => { type => SCALAR }, |
44
|
|
|
|
|
|
|
channel => { type => SCALAR }, |
45
|
|
|
|
|
|
|
icon => { type => SCALAR, optional => 1 }, |
46
|
|
|
|
|
|
|
username => { type => SCALAR, optional => 1 }, |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
$self->{channel} = $p{channel}; |
51
|
0
|
|
|
|
|
|
$self->{token} = $p{token}; |
52
|
0
|
|
|
|
|
|
$self->{username} = $p{username}; |
53
|
0
|
|
|
|
|
|
$self->{icon} = $p{icon}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _make_handle { |
57
|
0
|
|
|
0
|
|
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$self->{client} = WebService::Slack::WebApi->new( |
60
|
|
|
|
|
|
|
token => $self->{token}, |
61
|
0
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub log_message { |
65
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
66
|
0
|
|
|
|
|
|
my %p = @_; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my %post_params = ( |
69
|
|
|
|
|
|
|
text => $p{message}, |
70
|
|
|
|
|
|
|
channel => $p{channel} || $self->{channel}, |
71
|
0
|
|
0
|
|
|
|
); |
72
|
0
|
0
|
|
|
|
|
if( $p{icon} ){ |
|
|
0
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$post_params{icon_url} = $p{icon}; |
74
|
|
|
|
|
|
|
}elsif( $self->{icon} ){ |
75
|
0
|
|
|
|
|
|
$post_params{icon_url} = $self->{icon}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
if( $p{username} ){ |
|
|
0
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
$post_params{username} = $p{username}; |
80
|
|
|
|
|
|
|
}elsif( $self->{username} ){ |
81
|
0
|
|
|
|
|
|
$post_params{username} = $self->{username}; |
82
|
|
|
|
|
|
|
}else{ |
83
|
0
|
|
|
|
|
|
$post_params{as_user} = 1; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $response = $self->{client}->chat->post_message( %post_params ); |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
if( ! $response->{ok} ){ |
89
|
0
|
|
|
|
|
|
die( sprintf( "Failed to send message to channel (%s): %s", $self->{channel}, $response->{error} ) ); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 NAME |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Log::Dispatch::Slack |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 DESCRIPTION |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Send log messages to Slack |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SYNOPSIS |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
log4perl.appender.hipchat=Log::Dispatch::Slack |
107
|
|
|
|
|
|
|
log4perl.appender.hipchat.auth_token=your-auth-token |
108
|
|
|
|
|
|
|
log4perl.appender.hipchat.channel=channel-to-talk-to |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 COPYRIGHT |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Copyright 2016, Robin Clarke |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHOR |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Robin Clarke <robin@robinclarke.net> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|