line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::DataDog::Search; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
13013
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use base qw( WebService::DataDog ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
324
|
|
7
|
1
|
|
|
1
|
|
6
|
use Carp qw( carp croak ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
8
|
1
|
|
|
1
|
|
4
|
use Data::Dumper; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
41
|
|
9
|
1
|
|
|
1
|
|
4
|
use Try::Tiny; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
195
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
WebService::DataDog::Search - Interface to Search functions in DataDog's API. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 VERSION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Version 1.0.1 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '1.0.1'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
This module allows you interact with the Search endpoint of the DataDog API. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Per DataDog: "This end point allows you to search for entities in Datadog. |
30
|
|
|
|
|
|
|
The currently searchable entities are: hosts, metrics" |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 METHODS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 retrieve() |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Return a list of search results for the specified term. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $search = $datadog->build('Search'); |
40
|
|
|
|
|
|
|
my $search_results = $search->retrieve( |
41
|
|
|
|
|
|
|
term => $search_term, |
42
|
|
|
|
|
|
|
facet => [ 'hosts', 'metrics' ] #optional |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Parameters: |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=over 4 |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item * term |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Search term you want to retrieve results for. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item * facet |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Limit search results to matches of the specified type |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=back |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub retrieve |
62
|
|
|
|
|
|
|
{ |
63
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
64
|
0
|
|
|
|
|
|
my $verbose = $self->verbose(); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Check for mandatory parameters |
67
|
0
|
|
|
|
|
|
foreach my $arg ( qw( term ) ) |
68
|
|
|
|
|
|
|
{ |
69
|
0
|
0
|
0
|
|
|
|
croak "ERROR - Argument '$arg' is required for retrieve()." |
70
|
|
|
|
|
|
|
if !defined( $args{$arg} ) || ( $args{$arg} eq '' ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $url = $WebService::DataDog::API_ENDPOINT . 'search'; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
0
|
|
|
|
if ( |
|
|
|
0
|
|
|
|
|
77
|
|
|
|
|
|
|
defined $args{'facet'} && |
78
|
|
|
|
|
|
|
$args{'facet'} ne 'hosts' && |
79
|
|
|
|
|
|
|
$args{'facet'} ne 'metrics' |
80
|
|
|
|
|
|
|
) |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
|
|
|
|
|
croak 'ERROR - Invalid facet type >' . $args{'facet'} . "<. Allowed values: 'hosts', 'metrics'"; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
if ( $args{'facet'} ) |
86
|
|
|
|
|
|
|
{ |
87
|
0
|
|
|
|
|
|
$url .= '?q=' . $args{'facet'} . ':' . $args{'term'}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
else |
90
|
|
|
|
|
|
|
{ |
91
|
0
|
|
|
|
|
|
$url .= '?q=' . $args{'term'}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $response = $self->_send_request( |
95
|
|
|
|
|
|
|
method => 'GET', |
96
|
|
|
|
|
|
|
url => $url, |
97
|
|
|
|
|
|
|
data => { '' => [] }, |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
0
|
|
|
|
if ( !defined($response) || !defined($response->{'results'}) ) |
101
|
|
|
|
|
|
|
{ |
102
|
0
|
|
|
|
|
|
croak "Fatal error. No response or 'results' missing from response."; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
return $response->{'results'}; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |