line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# client::splunk Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Client::Splunk; |
7
|
1
|
|
|
1
|
|
808
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
74
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
9
|
use base qw(Metabrik::Api::Splunk); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
551
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable rest) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
attributes => { |
19
|
|
|
|
|
|
|
uri => [ qw(uri) ], # Inherited |
20
|
|
|
|
|
|
|
username => [ qw(username) ], # Inherited |
21
|
|
|
|
|
|
|
password => [ qw(password) ], # Inherited |
22
|
|
|
|
|
|
|
ssl_verify => [ qw(0|1) ], # Inherited |
23
|
|
|
|
|
|
|
output_mode => [ qw(json|xml|csv) ], |
24
|
|
|
|
|
|
|
count => [ qw(number) ], |
25
|
|
|
|
|
|
|
offset => [ qw(number) ], |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
attributes_default => { |
28
|
|
|
|
|
|
|
uri => 'https://localhost:8089', |
29
|
|
|
|
|
|
|
username => 'admin', |
30
|
|
|
|
|
|
|
ssl_verify => 0, |
31
|
|
|
|
|
|
|
output_mode => 'json', |
32
|
|
|
|
|
|
|
count => 1000, |
33
|
|
|
|
|
|
|
offset => 0, |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
commands => { |
36
|
|
|
|
|
|
|
search => [ qw(string) ], |
37
|
|
|
|
|
|
|
is_job_done => [ qw(sid) ], |
38
|
|
|
|
|
|
|
get_results => [ qw(sid) ], |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# |
44
|
|
|
|
|
|
|
# Example: |
45
|
|
|
|
|
|
|
# run client::splunk search "index=main" |
46
|
|
|
|
|
|
|
# |
47
|
|
|
|
|
|
|
sub search { |
48
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
49
|
0
|
|
|
|
|
|
my ($search) = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('search', $search) or return; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
my $r = $self->search_jobs({ search => "search $search" }) or return; |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if (! exists($r->{sid})) { |
56
|
0
|
|
|
|
|
|
return $self->log->error("search: sid not found in response"); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return $r->{sid}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub is_job_done { |
63
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
64
|
0
|
|
|
|
|
|
my ($sid) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('is_job_done', $sid) or return; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my $r = $self->search_jobs_sid($sid); |
69
|
0
|
0
|
|
|
|
|
if (! defined($r)) { |
|
|
0
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
elsif ($r == 0) { |
73
|
0
|
|
|
|
|
|
return 0; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
0
|
|
|
|
if (exists($r->{content}) |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
77
|
|
|
|
|
|
|
&& exists($r->{content}{'s:dict'}) |
78
|
|
|
|
|
|
|
&& exists($r->{content}{'s:dict'}{'s:key'}) |
79
|
|
|
|
|
|
|
&& exists($r->{content}{'s:dict'}{'s:key'}{dispatchState}) |
80
|
|
|
|
|
|
|
&& exists($r->{content}{'s:dict'}{'s:key'}{dispatchState}{content})) { |
81
|
0
|
|
|
|
|
|
my $status = $r->{content}{'s:dict'}{'s:key'}{dispatchState}{content}; |
82
|
0
|
|
|
|
|
|
return $status eq 'DONE'; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return $self->log->error("is_job_done: invalid response"); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub get_results { |
89
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
90
|
0
|
|
|
|
|
|
my ($sid, $count, $offset) = @_; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
0
|
|
|
|
$count ||= $self->count; |
93
|
0
|
|
0
|
|
|
|
$offset ||= $self->offset; |
94
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('get_results', $sid) or return; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $output_mode = $self->output_mode; |
97
|
0
|
0
|
0
|
|
|
|
if ($output_mode ne 'xml' |
|
|
|
0
|
|
|
|
|
98
|
|
|
|
|
|
|
&& $output_mode ne 'json' |
99
|
|
|
|
|
|
|
&& $output_mode ne 'csv') { |
100
|
0
|
|
|
|
|
|
return $self->log->error("get_results: output_mode not supported [$output_mode]"); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $r = $self->search_jobs_sid_results($sid, $count, $offset); |
104
|
0
|
0
|
|
|
|
|
if (! defined($r)) { |
105
|
0
|
|
|
|
|
|
return; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# No results from this search |
109
|
0
|
0
|
|
|
|
|
if (! length($r)) { |
110
|
0
|
|
|
|
|
|
return []; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
return $r; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |