наваял простенький скрипт:
#!/usr/bin/perl -w
use strict;
use JSON::RPC::Client;
use JSON;
my $client = new JSON::RPC::Client;
my $url = 'http://hostname/api_jsonrpc.php';
my ($user, $password) = ('user', 'pass');
my $object1 = {
jsonrpc => '2.0',
method => 'user.authenticate',
id => 1,
params => { 'user' => $user, 'password' => $password }
};
my $result = $client->call( $url, $object1);
my $sessionid = $result->result unless $result->is_error;
print "Result: ", $sessionid, "\n";
my $object2 = {
jsonrpc => '2.0',
method => 'Host.getById',
id => 2,
auth => $sessionid,
params => { 'hostid' => '10047' }
};
$result = $client->call( $url, $object2);
print "Error: ", to_json( $result->error_message), "\n";
Результат выглядит как-то так:
Result: 9e085beb7e87d0910fc1d00b62c619e4
Error: {"data":"Action does not exists","message":"Invalid params.","code":-32602}
Вопрос: что я делаю неправильно во втором вызове? Хочу получить информацию о хосте.
#!/usr/bin/perl -w
use strict;
use JSON::RPC::Client;
use JSON;
my $client = new JSON::RPC::Client;
my $url = 'http://hostname/api_jsonrpc.php';
my ($user, $password) = ('user', 'pass');
my $object1 = {
jsonrpc => '2.0',
method => 'user.authenticate',
id => 1,
params => { 'user' => $user, 'password' => $password }
};
my $result = $client->call( $url, $object1);
my $sessionid = $result->result unless $result->is_error;
print "Result: ", $sessionid, "\n";
my $object2 = {
jsonrpc => '2.0',
method => 'Host.getById',
id => 2,
auth => $sessionid,
params => { 'hostid' => '10047' }
};
$result = $client->call( $url, $object2);
print "Error: ", to_json( $result->error_message), "\n";
Результат выглядит как-то так:
Result: 9e085beb7e87d0910fc1d00b62c619e4
Error: {"data":"Action does not exists","message":"Invalid params.","code":-32602}
Вопрос: что я делаю неправильно во втором вызове? Хочу получить информацию о хосте.
Comment