Hello:
I am just starting to explore some basic remote information gathering from our zbx 1.8.10 host.
I found an example on the blog at Getting started with Zabbix API and I can authenticate fine.
so I move on to Getting list of hosts on the same page but it returns no hosts.
I do get
Can someone help me out and show me the error of my ways?
Thank you.
Edit: The topic is not accurate, it does NOT fail, it simply returns no hosts.
Sorry about that.
I am just starting to explore some basic remote information gathering from our zbx 1.8.10 host.
I found an example on the blog at Getting started with Zabbix API and I can authenticate fine.
so I move on to Getting list of hosts on the same page but it returns no hosts.
PHP Code:
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
use JSON::RPC::Client;
use Data::Dumper;
# Authenticate yourself
my $client = new JSON::RPC::Client;
my $url = 'http://some.ip.address/zabbix/api_jsonrpc.php';
my $authID;
my $response;
my $json = {
jsonrpc => "2.0",
method => "user.login",
params => {
user => "user",
password => "secret"
},
id => 1
};
$response = $client->call($url, $json);
# Check if response was successful
die "Authentication failed.\n" unless $response->content->{'result'};
$authID = $response->content->{'result'};
# Get list of all hosts using authID
$json = {
jsonrpc=> '2.0',
method => 'host.get',
params =>
{
output => ['hostid','name'],# get only host id and host name
sortfield => 'name', # sort by host name
},
id => 2,
auth => "$authID",
};
$response = $client->call($url, $json);
# Check if response was successful
die "host.get failed\n" unless $response->content->{result};
print "List of hosts\n-----------------------------\n";
foreach my $host (@{$response->content->{result}}) {
print "Host ID: ".$host->{hostid}." Host: ".$host->{name}."\n";
}
Code:
List of hosts -----------------------------
Thank you.
Edit: The topic is not accurate, it does NOT fail, it simply returns no hosts.
Sorry about that.
Comment