Trying to use perl to query influxdb ! Any help is appreciated.
My Perl Code snippet :
use warnings;
use strict;
use Hijk ();
use URI::Escape qw(uri_escape);
use Data::Dumper;
# Source influxdb
my $ihost = "cricket" ;
my $iport = 8086;
my $idb = "telegraf" ;
my $iuser = "myuser" ;
my $ipass = "pass" ;
my $epoch = "ms" ;
my $iprecision = "rfc3339" ;
my $iquery = "SELECT usage_idle FROM cpu WHERE cpu = 'cpu-total' LIMIT 5" ;
my $res = Hijk::request({
method => "GET",
host => $ihost,
port => $iport,
path => "/query",
query_string => "db=$idb&user=$ipass&password=$ipass&precision=$iprecision&query=$iquery" ,
body => ""
});
if ($res->{status} != 200) {
print Dumper($res);
}
die "Expecting an 'OK' response " unless $res->{status} == 200;
say $res->{body};
exit;
$ perl conn_influxdb.pl
Useless use of hash element in void context at ./conn_influxdb.pl line 61.
$VAR1 = {
‘body’ => ‘400 Bad Request’,
‘head’ => {
‘Connection’ => ‘close’,
‘Content-Type’ => ‘text/plain; charset=utf-8’
},
‘proto’ => ‘HTTP/1.1’,
‘status’ => 400
};
Expecting an ‘OK’ response at ./conn_influxdb.pl line 59.
I was basically trying to use InfluxDB::Lineprotocol the perl module and it needs hijk ( heard its the simplest and fastest ) to do the calls! I see lots of “Write” examples with LineProocol and hijk but no "get " so any help is appreciated.