| 1 | package WebService::Mackerel; | ||||||||||||
| 2 | 5 | ▶ | use 5.008001; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 5 | ▶ | use Carp qw/croak/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 5 | ▶ | use JSON; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 5 | ▶ | use HTTP::Tiny; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 5 | ▶ | use URI; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 5 | our $VERSION = "0.05"; | |||||||||||
| 11 | |||||||||||||
| 12 | 19 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||
| 13 | 19 | my ($class, %args) = @_; | |||||||||||
| 14 | 19 | ▶ | $args{api_key} or croak "api key is required"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 15 | 18 | ▶ | $args{service_name} or croak "service name is required"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 16 | my $self = { | ||||||||||||
| 17 | api_key => $args{api_key}, | ||||||||||||
| 18 | service_name => $args{service_name}, | ||||||||||||
| 19 | 17 | ▶ | mackerel_origin => $args{mackerel_origin} || 'https://api.mackerelio.com', | ||||||||||
|
Condition100%2/2
$args{'mackerel_origin'} || 'https://api.mackerelio.com'
MC/DC100%1/1
$args{'mackerel_origin'} || 'https://api.mackerelio.com'
$args{'mackerel_origin'}
Truth table100%2/2
A
A= $args{'mackerel_origin'}
| |||||||||||||
| 20 | agent => HTTP::Tiny->new( agent => "WebService::Mackerel agent $VERSION" ), | ||||||||||||
| 21 | }; | ||||||||||||
| 22 | 17 | bless $self, $class; | |||||||||||
| 23 | } | ||||||||||||
| 24 | |||||||||||||
| 25 | 1 | ▶ | sub get_service_metrics { | ||||||||||
|
Subroutine
get_service_metrics: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 26 | 1 | my ($self, $query_parameters) = @_; | |||||||||||
| 27 | 1 | my $uri = URI->new($self->{mackerel_origin}); | |||||||||||
| 28 | 1 | $uri->path("/api/v0/services/".$self->{service_name}."/metrics"); | |||||||||||
| 29 | 1 | $uri->query_form($query_parameters); | |||||||||||
| 30 | my $res = $self->{agent}->request('GET', $uri->as_string, { | ||||||||||||
| 31 | headers => { | ||||||||||||
| 32 | 'content-type' => 'application/json', | ||||||||||||
| 33 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 34 | }, | ||||||||||||
| 35 | 1 | }); | |||||||||||
| 36 | 1 | return $res->{content}; | |||||||||||
| 37 | } | ||||||||||||
| 38 | |||||||||||||
| 39 | 0 | ▶ | sub post_service_metrics { | ||||||||||
|
Subroutine
post_service_metrics: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 40 | 0 | my ($self, $args) = @_; | |||||||||||
| 41 | 0 | my $path = '/api/v0/services/' . $self->{service_name} . '/tsdb'; | |||||||||||
| 42 | my $res = $self->{agent}->request('POST', $self->{mackerel_origin} . $path, { | ||||||||||||
| 43 | content => encode_json $args, | ||||||||||||
| 44 | headers => { | ||||||||||||
| 45 | 'content-type' => 'application/json', | ||||||||||||
| 46 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 47 | }, | ||||||||||||
| 48 | 0 | }); | |||||||||||
| 49 | 0 | return $res->{content}; | |||||||||||
| 50 | } | ||||||||||||
| 51 | |||||||||||||
| 52 | 0 | ▶ | sub create_host { | ||||||||||
|
Subroutine
create_host: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 53 | 0 | my ($self, $args) = @_; | |||||||||||
| 54 | 0 | my $path = '/api/v0/hosts'; | |||||||||||
| 55 | my $res = $self->{agent}->request('POST', $self->{mackerel_origin} . $path, { | ||||||||||||
| 56 | content => encode_json $args, | ||||||||||||
| 57 | headers => { | ||||||||||||
| 58 | 'content-type' => 'application/json', | ||||||||||||
| 59 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 60 | }, | ||||||||||||
| 61 | 0 | }); | |||||||||||
| 62 | 0 | return $res->{content}; | |||||||||||
| 63 | } | ||||||||||||
| 64 | |||||||||||||
| 65 | 0 | ▶ | sub get_host { | ||||||||||
|
Subroutine
get_host: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 66 | 0 | my ($self, $hostId) = @_; | |||||||||||
| 67 | 0 | my $path = '/api/v0/hosts/' . $hostId; | |||||||||||
| 68 | my $res = $self->{agent}->request('GET', $self->{mackerel_origin} . $path, { | ||||||||||||
| 69 | headers => { | ||||||||||||
| 70 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 71 | }, | ||||||||||||
| 72 | 0 | }); | |||||||||||
| 73 | 0 | return $res->{content}; | |||||||||||
| 74 | } | ||||||||||||
| 75 | |||||||||||||
| 76 | 0 | ▶ | sub update_host { | ||||||||||
|
Subroutine
update_host: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 77 | 0 | my ($self, $args) = @_; | |||||||||||
| 78 | 0 | my $path = '/api/v0/hosts/' . $args->{hostId}; | |||||||||||
| 79 | my $res = $self->{agent}->request('PUT', $self->{mackerel_origin} . $path, { | ||||||||||||
| 80 | content => encode_json $args->{data}, | ||||||||||||
| 81 | headers => { | ||||||||||||
| 82 | 'content-type' => 'application/json', | ||||||||||||
| 83 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 84 | }, | ||||||||||||
| 85 | 0 | }); | |||||||||||
| 86 | 0 | return $res->{content}; | |||||||||||
| 87 | } | ||||||||||||
| 88 | |||||||||||||
| 89 | 0 | ▶ | sub update_host_status { | ||||||||||
|
Subroutine
update_host_status: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 90 | 0 | my ($self, $args) = @_; | |||||||||||
| 91 | 0 | my $path = '/api/v0/hosts/' . $args->{hostId} . '/status'; | |||||||||||
| 92 | my $res = $self->{agent}->request('POST', $self->{mackerel_origin} . $path, { | ||||||||||||
| 93 | content => encode_json $args->{data}, | ||||||||||||
| 94 | headers => { | ||||||||||||
| 95 | 'content-type' => 'application/json', | ||||||||||||
| 96 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 97 | }, | ||||||||||||
| 98 | 0 | }); | |||||||||||
| 99 | 0 | return $res->{content}; | |||||||||||
| 100 | } | ||||||||||||
| 101 | |||||||||||||
| 102 | 0 | ▶ | sub host_retire { | ||||||||||
|
Subroutine
host_retire: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 103 | 0 | my ($self, $hostId) = @_; | |||||||||||
| 104 | 0 | my $path = '/api/v0/hosts/' . $hostId . '/retire'; | |||||||||||
| 105 | my $res = $self->{agent}->request('POST', $self->{mackerel_origin} . $path, { | ||||||||||||
| 106 | content => encode_json +{}, | ||||||||||||
| 107 | headers => { | ||||||||||||
| 108 | 'content-type' => 'application/json', | ||||||||||||
| 109 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 110 | }, | ||||||||||||
| 111 | 0 | }); | |||||||||||
| 112 | 0 | return $res->{content}; | |||||||||||
| 113 | } | ||||||||||||
| 114 | |||||||||||||
| 115 | 0 | ▶ | sub post_host_metrics { | ||||||||||
|
Subroutine
post_host_metrics: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 116 | 0 | my ($self, $args) = @_; | |||||||||||
| 117 | 0 | my $path = '/api/v0/tsdb'; | |||||||||||
| 118 | my $res = $self->{agent}->request('POST', $self->{mackerel_origin} . $path, { | ||||||||||||
| 119 | content => encode_json $args, | ||||||||||||
| 120 | headers => { | ||||||||||||
| 121 | 'content-type' => 'application/json', | ||||||||||||
| 122 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 123 | }, | ||||||||||||
| 124 | 0 | }); | |||||||||||
| 125 | 0 | return $res->{content}; | |||||||||||
| 126 | } | ||||||||||||
| 127 | |||||||||||||
| 128 | 1 | ▶ | sub get_host_metrics { | ||||||||||
|
Subroutine
get_host_metrics: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 129 | 1 | my ($self, $host_id, $query_parameters) = @_; | |||||||||||
| 130 | 1 | my $uri = URI->new($self->{mackerel_origin}); | |||||||||||
| 131 | 1 | $uri->path("/api/v0/hosts/$host_id/metrics"); | |||||||||||
| 132 | 1 | $uri->query_form($query_parameters); | |||||||||||
| 133 | my $res = $self->{agent}->request('GET', $uri->as_string, { | ||||||||||||
| 134 | headers => { | ||||||||||||
| 135 | 'content-type' => 'application/json', | ||||||||||||
| 136 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 137 | }, | ||||||||||||
| 138 | 1 | }); | |||||||||||
| 139 | 1 | return $res->{content}; | |||||||||||
| 140 | } | ||||||||||||
| 141 | |||||||||||||
| 142 | 0 | ▶ | sub get_latest_host_metrics { | ||||||||||
|
Subroutine
get_latest_host_metrics: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 143 | 0 | my ($self, $args) = @_; | |||||||||||
| 144 | 0 | my $path = '/api/v0/tsdb/latest?hostId=' . $args->{hostId} . '&name=' . $args->{name}; | |||||||||||
| 145 | my $res = $self->{agent}->request('GET', $self->{mackerel_origin} . $path, { | ||||||||||||
| 146 | headers => { | ||||||||||||
| 147 | 'content-type' => 'application/json', | ||||||||||||
| 148 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 149 | }, | ||||||||||||
| 150 | 0 | }); | |||||||||||
| 151 | 0 | return $res->{content}; | |||||||||||
| 152 | } | ||||||||||||
| 153 | |||||||||||||
| 154 | 2 | ▶ | sub get_hosts { | ||||||||||
|
Subroutine
get_hosts: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 155 | 2 | my ($self, $query_parameters) = @_; | |||||||||||
| 156 | 2 | my $uri = URI->new($self->{mackerel_origin}); | |||||||||||
| 157 | 2 | $uri->path('/api/v0/hosts.json'); | |||||||||||
| 158 | 2 | $uri->query_form($query_parameters); | |||||||||||
| 159 | my $res = $self->{agent}->request('GET', $uri->as_string, { | ||||||||||||
| 160 | headers => { | ||||||||||||
| 161 | 'content-type' => 'application/json', | ||||||||||||
| 162 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 163 | }, | ||||||||||||
| 164 | 2 | }); | |||||||||||
| 165 | 2 | return $res->{content}; | |||||||||||
| 166 | } | ||||||||||||
| 167 | |||||||||||||
| 168 | 0 | ▶ | sub create_monitor { | ||||||||||
|
Subroutine
create_monitor: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 169 | 0 | my ($self, $args) = @_; | |||||||||||
| 170 | 0 | my $path = '/api/v0/monitors'; | |||||||||||
| 171 | my $res = $self->{agent}->request('POST', $self->{mackerel_origin} . $path, { | ||||||||||||
| 172 | content => encode_json $args, | ||||||||||||
| 173 | headers => { | ||||||||||||
| 174 | 'content-type' => 'application/json', | ||||||||||||
| 175 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 176 | }, | ||||||||||||
| 177 | 0 | }); | |||||||||||
| 178 | 0 | return $res->{content}; | |||||||||||
| 179 | } | ||||||||||||
| 180 | |||||||||||||
| 181 | 0 | ▶ | sub get_monitor { | ||||||||||
|
Subroutine
get_monitor: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 182 | 0 | my ($self, $args) = @_; | |||||||||||
| 183 | 0 | my $path = '/api/v0/monitors'; | |||||||||||
| 184 | my $res = $self->{agent}->request('GET', $self->{mackerel_origin} . $path, { | ||||||||||||
| 185 | headers => { | ||||||||||||
| 186 | 'content-type' => 'application/json', | ||||||||||||
| 187 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 188 | }, | ||||||||||||
| 189 | 0 | }); | |||||||||||
| 190 | 0 | return $res->{content}; | |||||||||||
| 191 | } | ||||||||||||
| 192 | |||||||||||||
| 193 | 0 | ▶ | sub update_monitor { | ||||||||||
|
Subroutine
update_monitor: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 194 | 0 | my ($self, $monitorId, $args) = @_; | |||||||||||
| 195 | 0 | my $path = '/api/v0/monitors/' . $monitorId; | |||||||||||
| 196 | my $res = $self->{agent}->request('PUT', $self->{mackerel_origin} . $path, { | ||||||||||||
| 197 | content => encode_json $args, | ||||||||||||
| 198 | headers => { | ||||||||||||
| 199 | 'content-type' => 'application/json', | ||||||||||||
| 200 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 201 | }, | ||||||||||||
| 202 | 0 | }); | |||||||||||
| 203 | 0 | return $res->{content}; | |||||||||||
| 204 | } | ||||||||||||
| 205 | |||||||||||||
| 206 | 0 | ▶ | sub delete_monitor { | ||||||||||
|
Subroutine
delete_monitor: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 207 | 0 | my ($self, $monitorId) = @_; | |||||||||||
| 208 | 0 | my $path = '/api/v0/monitors/' . $monitorId; | |||||||||||
| 209 | my $res = $self->{agent}->request('DELETE', $self->{mackerel_origin} . $path, { | ||||||||||||
| 210 | headers => { | ||||||||||||
| 211 | 'content-type' => 'application/json', | ||||||||||||
| 212 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 213 | }, | ||||||||||||
| 214 | 0 | }); | |||||||||||
| 215 | 0 | return $res->{content}; | |||||||||||
| 216 | } | ||||||||||||
| 217 | |||||||||||||
| 218 | 0 | ▶ | sub create_graph_annotation { | ||||||||||
|
Subroutine
create_graph_annotation: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 219 | 0 | my ($self, $args) = @_; | |||||||||||
| 220 | 0 | my $path = '/api/v0/graph-annotations'; | |||||||||||
| 221 | my $res = $self->{agent}->request('POST', $self->{mackerel_origin} . $path, { | ||||||||||||
| 222 | content => encode_json $args, | ||||||||||||
| 223 | headers => { | ||||||||||||
| 224 | 'content-type' => 'application/json', | ||||||||||||
| 225 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 226 | }, | ||||||||||||
| 227 | 0 | }); | |||||||||||
| 228 | 0 | return $res->{content}; | |||||||||||
| 229 | } | ||||||||||||
| 230 | |||||||||||||
| 231 | 0 | ▶ | sub get_graph_annotations { | ||||||||||
|
Subroutine
get_graph_annotations: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 232 | 0 | my ($self, $query_parameters) = @_; | |||||||||||
| 233 | 0 | my $uri = URI->new($self->{mackerel_origin}); | |||||||||||
| 234 | 0 | $uri->path('/api/v0/graph-annotations'); | |||||||||||
| 235 | 0 | $uri->query_form($query_parameters); | |||||||||||
| 236 | my $res = $self->{agent}->request('GET', $uri->as_string, { | ||||||||||||
| 237 | headers => { | ||||||||||||
| 238 | 'content-type' => 'application/json', | ||||||||||||
| 239 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 240 | }, | ||||||||||||
| 241 | 0 | }); | |||||||||||
| 242 | 0 | return $res->{content}; | |||||||||||
| 243 | } | ||||||||||||
| 244 | |||||||||||||
| 245 | 0 | ▶ | sub update_graph_annotation { | ||||||||||
|
Subroutine
update_graph_annotation: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 246 | 0 | my ($self, $graphAnnotationId, $args) = @_; | |||||||||||
| 247 | 0 | my $path = '/api/v0/graph-annotations/' . $graphAnnotationId; | |||||||||||
| 248 | my $res = $self->{agent}->request('PUT', $self->{mackerel_origin} . $path, { | ||||||||||||
| 249 | content => encode_json $args, | ||||||||||||
| 250 | headers => { | ||||||||||||
| 251 | 'content-type' => 'application/json', | ||||||||||||
| 252 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 253 | }, | ||||||||||||
| 254 | 0 | }); | |||||||||||
| 255 | 0 | return $res->{content}; | |||||||||||
| 256 | } | ||||||||||||
| 257 | |||||||||||||
| 258 | 0 | ▶ | sub delete_graph_annotation { | ||||||||||
|
Subroutine
delete_graph_annotation: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 259 | 0 | my ($self, $graphAnnotationId) = @_; | |||||||||||
| 260 | 0 | my $path = '/api/v0/graph-annotations/' . $graphAnnotationId; | |||||||||||
| 261 | my $res = $self->{agent}->request('DELETE', $self->{mackerel_origin} . $path, { | ||||||||||||
| 262 | headers => { | ||||||||||||
| 263 | 'content-type' => 'application/json', | ||||||||||||
| 264 | 'X-Api-Key' => $self->{api_key}, | ||||||||||||
| 265 | }, | ||||||||||||
| 266 | 0 | }); | |||||||||||
| 267 | 0 | return $res->{content}; | |||||||||||
| 268 | } | ||||||||||||
| 269 | |||||||||||||
| 270 | 5 | 1; | |||||||||||
| 271 | __END__ | ||||||||||||