Skip to content

Instantly share code, notes, and snippets.

@jrelo
Created February 26, 2019 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrelo/6aa3ea6c0c6fadf28380a3b7c07aaf21 to your computer and use it in GitHub Desktop.
Save jrelo/6aa3ea6c0c6fadf28380a3b7c07aaf21 to your computer and use it in GitHub Desktop.
zabbix pull
#!/usr/bin/env perl
use strict;
use warnings;
use Zabbix::Tiny;
$|++;
my %hostgroups = (
'Test' => "42",
);
my $zabbix = Zabbix::Tiny->new(
server => 'https://myzabbix.something.com/api_jsonrpc.php',
user => 'user',
password => 'pass',
);
my @entries;
foreach my $group ( keys %hostgroups ) {
print "Checking: $group\n";
my $hosts = $zabbix->do('host.get',
{
groupids => $hostgroups{$group},
monitored => 1,
output => [qw(
hostid
name
host
)],
}
);
foreach my $host ( @$hosts ) {
push @entries, sprintf("%s\t%s\t%s", $host->{hostid}, $host->{name}, $host->{host});
}
}
print(join "\n", sort @entries);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment