package Splunk::HEC;
use Carp;
use JSON::XS;
use HTTP::Tiny;
use Splunk::Base -base;
use Splunk::HEC::Request;
use Splunk::HEC::Response;
use strict;
our $VERSION = '1.02';
has url => sub { return
meout => $args{timeout} || $self->timeout,
default_headers => {'Content-Type' => 'application/json'}
);
Carp::croak('A valid Splunk HEC token is required for authentication') unless $self->to
if the token has the indexes parameter set.
# "fields" (Not applicable to raw data.) Specifies a JSON object that contains explicit custom fields to be defined at index time. Requests containing the
eturn !$self->success;
}
sub is_success {
my $self = shift;
return $self->success;
}
sub TO_JSON {
my $self = shift;
my %res = map { $_ => $self->{$_} } keys %$self;
return \%res;
}
1;
=
>content({text => 'Success', code => 0});
The contents of a successful HEC request (decoded from JSON)
=head2 is_error
my $is_error = $res->is_error;
Returns true if the response was an error.
r a hash reference with attribute values.
=head2 TO_JSON
my $hash = $res->TO_JSON;
Returns a JSON encoding friendly hashref for use with L<JSON::XS>
=head1 SEE ALSO
L<Splunk::HEC::Request>, L<S
if the token has the indexes parameter set.
# "fields" (Not applicable to raw data.) Specifies a JSON object that contains explicit custom fields to be defined at index time. Requests containing the
;
has sourcetype => '';
has index => '';
has fields => '';
has event => '';
sub TO_JSON {
my $self = shift;
Carp::croak('Splunk HEC requests must contain a valid event') unless $sel
sourcetype('custom-sourcetype');
The sourcetype value to assign to the event data.
e.g. Use _json for JSON-based events (not required)
=head2 index
my $index = $req->index;
$index = $req->index