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