#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
use JSON::RPC::Client;
use Data:
umper;
my $client = new JSON::RPC::Client;
my $uri = 'http://*.*.*.*/zabbix/api_jsonrpc.php';
my $json_obj = {
jsonrpc => "2.0",
method => "user.login",
params => {
user => "root",
password => "password"
},
id => 1
};
my $response = $client->call($uri, $json_obj);
my $authHash;
if ($response->content->{'result'}) {
$authHash = $response->content->{'result'};
print "Auth successful - ID hash: " . $authHash . "\n";
}
else {
print "sorry, incorrect auth\n";
exit;
}
$client = new JSON::RPC::Client;
$json_obj = {
jsonrpc => '2.0',
method => 'host.create',
params =>
{
host => 'test_host',
interfaces =>
{
type => '1',
main => '1',
useip => 1,
ip => '1.2.3.4',
dns => 'teszt123',
port => '10050',
},
groups =>
{
groupid => '52',
}
},
id => 2,
auth => "$authHash"
};
$response = $client->call($uri, $json_obj);
print Dumper($response);
This was the response: "'data' => 'No permissions to referred object or it does not exist!',
'message' = > 'Application error.',
'code' => -32500
what's the problem?
The authentication part of the script is run as well.
The API access was enabled for root user.
use 5.010;
use strict;
use warnings;
use JSON::RPC::Client;
use Data:
umper;my $client = new JSON::RPC::Client;
my $uri = 'http://*.*.*.*/zabbix/api_jsonrpc.php';
my $json_obj = {
jsonrpc => "2.0",
method => "user.login",
params => {
user => "root",
password => "password"
},
id => 1
};
my $response = $client->call($uri, $json_obj);
my $authHash;
if ($response->content->{'result'}) {
$authHash = $response->content->{'result'};
print "Auth successful - ID hash: " . $authHash . "\n";
}
else {
print "sorry, incorrect auth\n";
exit;
}
$client = new JSON::RPC::Client;
$json_obj = {
jsonrpc => '2.0',
method => 'host.create',
params =>
{
host => 'test_host',
interfaces =>
{
type => '1',
main => '1',
useip => 1,
ip => '1.2.3.4',
dns => 'teszt123',
port => '10050',
},
groups =>
{
groupid => '52',
}
},
id => 2,
auth => "$authHash"
};
$response = $client->call($uri, $json_obj);
print Dumper($response);
This was the response: "'data' => 'No permissions to referred object or it does not exist!',
'message' = > 'Application error.',
'code' => -32500
what's the problem?
The authentication part of the script is run as well.
The API access was enabled for root user.

Comment