Hi guys,
I have configured testing IT services so I can prepare sth. for a real environment...
I'm trying to obtain IT services via API (currently, via Perl script). It "works", but in the GUI, there is a "TREE" structure such as:
Now, I can read all relevant/configured SLAs, but I do not know how to read them following this tree structure, because I get the output where I do not know what is dependent on what...
If I run API for services.get, there is "dependencies" field, but it's gonna be horrible to somehow generate this tree topology somehow in Perl and so on...
Isn't here anything to make it simple? So that I can read it one by one following this tree structure?
My script is as follows for now;
Btw using Zabbix 3.0.15... CentOS7, MySQL, ...
I have configured testing IT services so I can prepare sth. for a real environment...
I'm trying to obtain IT services via API (currently, via Perl script). It "works", but in the GUI, there is a "TREE" structure such as:
Code:
Network
- Routers
- Router-A
- Router-B
- Switches
- Switch-1
- Switch-2
If I run API for services.get, there is "dependencies" field, but it's gonna be horrible to somehow generate this tree topology somehow in Perl and so on...
Isn't here anything to make it simple? So that I can read it one by one following this tree structure?
My script is as follows for now;
Code:
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
use JSON::RPC::Legacy::Client;
use Data::Dumper;
# Authenticate yourself
my $client = new JSON::RPC::Legacy::Client;
my $url = 'http://X.Y.Z.W/zabbix/api_jsonrpc.php';
my $authID;
my $response;
my $json = {
jsonrpc => "2.0",
method => "user.login",
params => {
user => "Admin",
password => "PASSWORD"
},
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\n";
$json = {
jsonrpc => '2.0',
method => 'service.get',
params => {
output => 'extend',
selectDependencies => 'extend',
sortfield => 'name',
},
id => 2,
auth => "$authID",
};
$response = $client->call($url, $json);
# Check if response was successful
die "service.get failed\n" unless $response->content->{'result'};
print Dumper($response);
my $slaID=1;
my $json2;
my $response2;
print "List of IT Services (current 30 days SLA)\n--------------------------------------------------------------------------\n";
foreach my $service (@{$response->content->{result}}) {
$slaID = $service->{serviceid};
$json2 = {
jsonrpc => '2.0',
method => 'service.getsla',
params => {
serviceids => $slaID,
intervals => {
from => time()-2592000,
to => time(),
},
},
id => 2,
auth => "$authID",
};
$response2 = $client->call($url, $json2);
# Check if response was successful
die "service.getsla failed\n" unless $response2->content->{'result'};
foreach my $slaLevel (@{$response2->content->{result}->{$slaID}->{sla}}) {
print "IT service ID: ".$service->{serviceid}."\tName: ".$service->{name}."\t\tSLA: ".$slaLevel->{sla}."\n";
}
}
# Logout
$json = {
jsonrpc => '2.0',
method => 'user.logout',
params => [],
id => 3,
auth => "$authID",
};
$response = $client->call($url, $json);
# Check if response was successful
die "user.logout failed\n" unless $response->content->{'result'};
print "\nLogout successful\n"

Comment