AnyEvent-InfluxDB
view release on metacpan or search on metacpan
Source code for a work means the preferred form of the work for making
modifications to it. For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.
4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License. However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.
5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.
jwt => 'JWT_TOKEN_BLOB'
);
Returns object representing given InfluDB "server" connected using
optionally provided username "username" and password "password".
Default value of "server" is "http://localhost:8086".
If the server protocol is "https" then by default no validation of
remote host certificate is performed. This can be changed by setting
"ssl_options" parameter with any options accepted by AnyEvent::TLS.
my $db = AnyEvent::InfluxDB->new(
...
ssl_options => {
verify => 1,
verify_peername => 'https',
ca_file => '/path/to/cacert.pem',
}
);
As an debugging aid the "on_request" code reference may also be
provided. It will be executed before each request with the method name,
url and POST data if set.
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
$AnyEvent::InfluxDB::VERSION = '1.0.2.0';
use AnyEvent;
use AnyEvent::HTTP;
use URI;
use URI::QueryParam;
use JSON qw(decode_json);
use List::MoreUtils qw(zip);
use URI::Encode::XS qw( uri_encode );
use Moo;
has [qw( ssl_options username password jwt on_request )] => (
is => 'ro',
predicate => 1,
);
has 'server' => (
is => 'rw',
default => 'http://localhost:8086',
);
has '_is_ssl' => (
is => 'lazy',
);
has '_tls_ctx' => (
is => 'lazy',
);
has '_server_uri' => (
is => 'lazy',
);
sub _build__tls_ctx {
my ($self) = @_;
# no ca/hostname checks
return 'low' unless $self->has_ssl_options;
# create ctx
require AnyEvent::TLS;
return AnyEvent::TLS->new( %{ $self->ssl_options } );
}
sub _build__is_ssl {
my ($self) = @_;
return $self->server =~ /^https/;
}
sub _build__server_uri {
my ($self) = @_;
my $url = URI->new( $self->server, 'http' );
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
if ( $method eq 'POST' ) {
if ( defined $post_data ) {
$args{'body'} = $post_data;
} else {
if ( my $q = $url->query_param_delete('q') ) {
$args{headers}{'content-type'} = 'application/x-www-form-urlencoded';
$args{body} = 'q='. uri_encode($q);
}
}
}
if ( $self->_is_ssl ) {
$args{tls_ctx} = $self->_tls_ctx;
}
my $guard;
$guard = http_request
$method => $url->as_string,
%args,
sub {
$cb->(@_);
undef $guard;
lib/AnyEvent/InfluxDB.pm view on Meta::CPAN
# or use JWT token
jwt => 'JWT_TOKEN_BLOB'
);
Returns object representing given InfluDB C<server> connected using optionally
provided username C<username> and password C<password>.
Default value of C<server> is C<http://localhost:8086>.
If the server protocol is C<https> then by default no validation of remote
host certificate is performed. This can be changed by setting C<ssl_options>
parameter with any options accepted by L<AnyEvent::TLS>.
my $db = AnyEvent::InfluxDB->new(
...
ssl_options => {
verify => 1,
verify_peername => 'https',
ca_file => '/path/to/cacert.pem',
}
);
As an debugging aid the C<on_request> code reference may also be provided. It will
be executed before each request with the method name, url and POST data if set.
my $db = AnyEvent::InfluxDB->new(
...
on_request => sub {
my ($method, $url, $post_data) = @_;
print "$method $url\n";
print "$post_data\n" if $post_data;
}
);
=for Pod::Coverage has_jwt jwt has_on_request has_password has_ssl_options has_username on_request password server ssl_options username
=head2 ping
$cv = AE::cv;
$db->ping(
wait_for_leader => 2,
on_success => $cv,
on_error => sub {
$cv->croak("Failed to ping cluster leader: @_");
( run in 1.479 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )