| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Sensu::API::Client; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Perl client for the Sensu API |
|
3
|
|
|
|
|
|
|
$Sensu::API::Client::VERSION = '0.02'; |
|
4
|
8
|
|
|
8
|
|
219160
|
use 5.010; |
|
|
8
|
|
|
|
|
63
|
|
|
|
8
|
|
|
|
|
306
|
|
|
5
|
8
|
|
|
8
|
|
9225
|
use JSON; |
|
|
8
|
|
|
|
|
149119
|
|
|
|
8
|
|
|
|
|
47
|
|
|
6
|
8
|
|
|
8
|
|
1319
|
use Carp; |
|
|
8
|
|
|
|
|
23
|
|
|
|
8
|
|
|
|
|
858
|
|
|
7
|
8
|
|
|
8
|
|
8088
|
use Try::Tiny; |
|
|
8
|
|
|
|
|
12427
|
|
|
|
8
|
|
|
|
|
462
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
7242
|
use Moo; |
|
|
8
|
|
|
|
|
148104
|
|
|
|
8
|
|
|
|
|
55
|
|
|
10
|
8
|
|
|
8
|
|
22529
|
use namespace::clean; |
|
|
8
|
|
|
|
|
111515
|
|
|
|
8
|
|
|
|
|
57
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Sensu::API::Client::APICaller'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has url => ( |
|
15
|
|
|
|
|
|
|
is => 'ro', |
|
16
|
|
|
|
|
|
|
required => 1, |
|
17
|
|
|
|
|
|
|
); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub events { |
|
20
|
0
|
|
|
0
|
1
|
|
my ($self, $client) = @_; |
|
21
|
0
|
|
|
|
|
|
my $path = '/events'; |
|
22
|
0
|
0
|
|
|
|
|
$path .= "/$client" if $client; |
|
23
|
0
|
|
|
|
|
|
return $self->get($path); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub event { |
|
27
|
0
|
|
|
0
|
1
|
|
my ($self, $client, $check) = @_; |
|
28
|
0
|
0
|
0
|
|
|
|
croak 'Client and check required' unless ($client and $check); |
|
29
|
0
|
|
|
|
|
|
return $self->get(sprintf('/events/%s/%s', $client, $check)); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub resolve { |
|
33
|
0
|
|
|
0
|
1
|
|
my ($self, $client, $check) = @_; |
|
34
|
0
|
0
|
0
|
|
|
|
croak "Client and check required" unless ($client and $check); |
|
35
|
0
|
|
|
|
|
|
return $self->post('/resolve', { client => $client, check => $check }); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub info { |
|
39
|
0
|
|
|
0
|
1
|
|
return shift->get('/info'); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub stash { |
|
43
|
0
|
|
|
0
|
1
|
|
my ($self, $path) = @_; |
|
44
|
0
|
0
|
|
|
|
|
croak 'Path required' unless $path; |
|
45
|
0
|
|
|
|
|
|
return $self->get('/stashes/' . $path); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub stashes { |
|
49
|
0
|
|
|
0
|
1
|
|
return shift->get('/stashes'); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub create_stash { |
|
53
|
0
|
|
|
0
|
1
|
|
my ($self, @args) = @_; |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $hash = { @args }; |
|
56
|
0
|
|
|
|
|
|
my %valid_keys = ( path => 1, content => 1, expire => 1 ); |
|
57
|
0
|
|
|
|
|
|
my @not_valid = grep { not defined $valid_keys{$_} } keys %$hash; |
|
|
0
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
die 'Unexpected keys: ' . join(',', @not_valid) if (scalar @not_valid); |
|
60
|
0
|
0
|
|
|
|
|
die 'Path required' unless $hash->{path}; |
|
61
|
0
|
0
|
|
|
|
|
die 'Content required' unless $hash->{content}; |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return $self->post('/stashes', {@args}); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub delete_stash { |
|
67
|
0
|
|
|
0
|
1
|
|
my ($self, $path) = @_; |
|
68
|
0
|
0
|
|
|
|
|
croak 'Path required' unless defined $path; |
|
69
|
0
|
|
|
|
|
|
return $self->delete('/stashes/' . $path); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub health { |
|
73
|
0
|
|
|
0
|
1
|
|
my ($self, %args) = @_; |
|
74
|
0
|
|
|
|
|
|
my ($c, $m, $r) = ($args{consumers}, $args{messages}, undef); |
|
75
|
0
|
0
|
0
|
|
|
|
croak "Consumers and Messages required" unless ($c and $m); |
|
76
|
|
|
|
|
|
|
try { |
|
77
|
0
|
|
|
0
|
|
|
$r = $self->get(sprintf('/health?consumers=%d&messages=%d', $c, $m)); |
|
78
|
|
|
|
|
|
|
} catch { |
|
79
|
0
|
0
|
|
0
|
|
|
if ($_ =~ qw/503/) { |
|
80
|
0
|
|
|
|
|
|
$r = 0; |
|
81
|
|
|
|
|
|
|
} else { |
|
82
|
0
|
|
|
|
|
|
croak $_; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
0
|
|
|
|
|
|
}; |
|
85
|
0
|
|
|
|
|
|
return $r; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub client { |
|
89
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
|
90
|
0
|
0
|
|
|
|
|
croak 'Client name required' unless defined $name; |
|
91
|
0
|
|
|
|
|
|
return $self->get(sprintf('/clients/%s', $name)); |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub clients { |
|
95
|
0
|
|
|
0
|
1
|
|
return shift->get('/clients'); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub delete_client { |
|
99
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
|
100
|
0
|
0
|
|
|
|
|
croak 'Client name required' unless defined $name; |
|
101
|
0
|
|
|
|
|
|
return $self->delete(sprintf('/clients/%s', $name)); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub client_history { |
|
105
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
|
106
|
0
|
0
|
|
|
|
|
croak 'Client name required' unless defined $name; |
|
107
|
0
|
|
|
|
|
|
return $self->get(sprintf('/clients/%s/history', $name)); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub checks { |
|
111
|
0
|
|
|
0
|
1
|
|
return shift->get('/checks'); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub check { |
|
115
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
|
116
|
0
|
0
|
|
|
|
|
croak 'Check name required' unless defined $name; |
|
117
|
0
|
|
|
|
|
|
return $self->get(sprintf('/checks/%s', $name)); |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub request { |
|
121
|
0
|
|
|
0
|
1
|
|
my ($self, $name, $subs) = @_; |
|
122
|
0
|
0
|
0
|
|
|
|
croak 'Name and subscribers required' unless ($name and $subs); |
|
123
|
0
|
0
|
|
|
|
|
croak 'Subscribers must be an arrayref' unless (ref $subs eq 'ARRAY'); |
|
124
|
0
|
|
|
|
|
|
return $self->post('/request', { check => $name, subscribers => $subs }); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |