Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 5.010;
- use strict;
- use warnings;
- use JSON::RPC::Client;
- use Data::Dumper;
- # Authenticate yourself
- my $client = new JSON::RPC::Client;
- my $url = 'http://10.10.10.108/zabbix/api_jsonrpc.php';
- my $authID;
- my $response;
- my $json = {
- jsonrpc => "2.0",
- method => "user.login",
- params => {
- user => "zapper",
- password => "zapper"
- },
- 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";
- # # Get list of all hosts using authID
- $json = {
- jsonrpc=> '2.0',
- method => 'usergroup.get',
- params =>
- {
- output => ['userids', 'name'],# get only host id and host name # sort by host name
- sortfield => 'name',
- },
- id => 2,
- auth => "$authID",
- };
- $response = $client->call($url, $json);
- # Check if response was successful
- die "usergroup.get failed\n" unless $response->content->{result};
- print "List of hosts\n-----------------------------\n";
- foreach my $host (@{$response->content->{result}}) {
- print "Host ID: ".$host->{userid}." Host: ".$host->{name}."\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement