I was using this perl script to generate an xml, but I've updated it and been trying to use the api via perl script to add hosts, but no luck so far. I can get the api to do a host.get and return successfully, so I believe that it's just my json object format. Could someone please look at this format and tell me if I'm missing required data or a bracket or brace.
Okay so this part works:
my $client = new JSON::RPC::Client;
my $url = 'http://localhost/zabbix/api_jsonrpc.php';
my $authID;
my $response;
my $json = {
jsonrpc => "2.0",
method => "user.login",
params => {
user => "admin",
password => "zabbix"
},
id => 1
};
$response = $client->call($url, $json);
# Check if response was successful
die "Authentication failed\n" unless $response->content->{'result'};
$authID = $response->content->{'result'};
print "Authentication successful. Auth ID: " . $authID . "\n";
I can get the authID and can pass it to the next step.
Next I try this
$json = {
jsonrpc => "2.0",
method => "host.create",
macros => [],
inventory_mode => 1,
inventory => {
notes => localtime(time)
},
params => {
host => "$results",
interfaces => [
{
type => 1,
main => 1,
useip => 1,
ip => "$ipaddress",
dns => "$results",
port => "10050"
}
],
groups => [
{
groupid => "9"
}
],
templates => [
{
templateid => "10089",
templateid => "10092"
}
],
},
auth => "$authID",
id => 2
};
$response = $client->call($url, $json);
# Check if response was successful
die "Host creation failed: Dumper($response);\n" unless $response->content->{'result'};
So I'm also wondering about the id part of the object, should it match the user.login id or should it be sequential?
Please let me know if you need more information.
Okay so this part works:
my $client = new JSON::RPC::Client;
my $url = 'http://localhost/zabbix/api_jsonrpc.php';
my $authID;
my $response;
my $json = {
jsonrpc => "2.0",
method => "user.login",
params => {
user => "admin",
password => "zabbix"
},
id => 1
};
$response = $client->call($url, $json);
# Check if response was successful
die "Authentication failed\n" unless $response->content->{'result'};
$authID = $response->content->{'result'};
print "Authentication successful. Auth ID: " . $authID . "\n";
I can get the authID and can pass it to the next step.
Next I try this
$json = {
jsonrpc => "2.0",
method => "host.create",
macros => [],
inventory_mode => 1,
inventory => {
notes => localtime(time)
},
params => {
host => "$results",
interfaces => [
{
type => 1,
main => 1,
useip => 1,
ip => "$ipaddress",
dns => "$results",
port => "10050"
}
],
groups => [
{
groupid => "9"
}
],
templates => [
{
templateid => "10089",
templateid => "10092"
}
],
},
auth => "$authID",
id => 2
};
$response = $client->call($url, $json);
# Check if response was successful
die "Host creation failed: Dumper($response);\n" unless $response->content->{'result'};
So I'm also wondering about the id part of the object, should it match the user.login id or should it be sequential?
Please let me know if you need more information.
Comment