line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Sentry::Client; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
133347
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
64
|
|
5
|
2
|
|
|
2
|
|
85
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
56
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
2183
|
use HTTP::Request::Common; |
|
2
|
|
|
|
|
92235
|
|
|
2
|
|
|
|
|
188
|
|
8
|
2
|
|
|
2
|
|
5218
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
71378
|
|
|
2
|
|
|
|
|
68
|
|
9
|
2
|
|
|
2
|
|
2155
|
use JSON (); |
|
2
|
|
|
|
|
25855
|
|
|
2
|
|
|
|
|
51
|
|
10
|
2
|
|
|
2
|
|
3123
|
use Data::UUID::MT (); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use MIME::Base64 'encode_base64'; |
12
|
|
|
|
|
|
|
use Compress::Zlib; |
13
|
|
|
|
|
|
|
use Time::HiRes (qw(gettimeofday)); |
14
|
|
|
|
|
|
|
use DateTime; |
15
|
|
|
|
|
|
|
use Digest::HMAC_SHA1 qw( hmac_sha1_hex ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use Carp; |
18
|
|
|
|
|
|
|
use Sys::Hostname; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Constructor |
21
|
|
|
|
|
|
|
sub new { |
22
|
|
|
|
|
|
|
my ( $class, %options ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if (! exists $options{sentry_key}) { |
25
|
|
|
|
|
|
|
die "Mandatory paramter 'sentry_key' not defined"; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
if (! exists $options{remote_url}) { |
29
|
|
|
|
|
|
|
die "Mandatory paramter 'remote_url' not defined"; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $self = { |
33
|
|
|
|
|
|
|
sentry_version => 0, |
34
|
|
|
|
|
|
|
ua => LWP::UserAgent->new(), |
35
|
|
|
|
|
|
|
%options, |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
bless $self, $class; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Send our message to the sentry server/servers |
42
|
|
|
|
|
|
|
sub send { |
43
|
|
|
|
|
|
|
my ( $self, $params ) = @_; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $ua = $self->{ua}; |
46
|
|
|
|
|
|
|
my $uri = $self->{remote_url}; |
47
|
|
|
|
|
|
|
my $message = $self->_getMessage( $params ); |
48
|
|
|
|
|
|
|
my $stamp = gettimeofday(); |
49
|
|
|
|
|
|
|
$stamp = sprintf ( "%.12g", $stamp ); |
50
|
|
|
|
|
|
|
my %header = $self->_getAuthHeader( $stamp, $message ); |
51
|
|
|
|
|
|
|
my $request = $ua->post( $uri, %header, Content => $message ); |
52
|
|
|
|
|
|
|
return $request; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# From outside message, we make a json message for server. |
56
|
|
|
|
|
|
|
sub _getMessage { |
57
|
|
|
|
|
|
|
my ( $self, $params ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $data = { |
60
|
|
|
|
|
|
|
message => $params->{message}, |
61
|
|
|
|
|
|
|
timestamp => time(), |
62
|
|
|
|
|
|
|
level => $params->{level}||20, |
63
|
|
|
|
|
|
|
message_id => Data::UUID::MT->new->create_hex(), |
64
|
|
|
|
|
|
|
logger => $params->{logger}||'root', |
65
|
|
|
|
|
|
|
view => $params->{view}||undef, |
66
|
|
|
|
|
|
|
server_name => $params->{server_name}||hostname, |
67
|
|
|
|
|
|
|
url => $params->{url}||undef, |
68
|
|
|
|
|
|
|
site => $params->{site}||undef, |
69
|
|
|
|
|
|
|
data => $params->{data}||undef, |
70
|
|
|
|
|
|
|
traceback => $params->{traceback}||undef, |
71
|
|
|
|
|
|
|
}; |
72
|
|
|
|
|
|
|
my $json = JSON->new->utf8(1)->pretty(1)->allow_nonref(1)->encode( $data ); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
return encode_base64(compress( $json )); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Make signature which is required for the sentry server |
78
|
|
|
|
|
|
|
sub _getSignature { |
79
|
|
|
|
|
|
|
my ( $self, $stamp, $message ) = @_; |
80
|
|
|
|
|
|
|
return hmac_sha1_hex( "$stamp $message", $self->{sentry_key} ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Make the specific header |
84
|
|
|
|
|
|
|
sub _getAuthHeader { |
85
|
|
|
|
|
|
|
my ( $self, $stamp, $message ) = @_; |
86
|
|
|
|
|
|
|
my $header_format = sprintf ( |
87
|
|
|
|
|
|
|
"Sentry sentry_signature=%s ,sentry_timestamp=%s ,sentry_client=%s", |
88
|
|
|
|
|
|
|
$self->_getSignature( $stamp, $message ), |
89
|
|
|
|
|
|
|
$stamp, |
90
|
|
|
|
|
|
|
$self->{sentry_version} |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
my %header = ( 'Authorization' => $header_format, 'Content-Type' => 'application/octet-stream' ); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
return %header; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |