zabbix-agent-addons/zabbix_scripts/disco_zimbra_sudo
Daniel Berteaud 285d61c51c Set info in the data element for Zimbra discovery
Because when the response is empty, Zabbix will mark the item as unsupported if it can find the data element
2019-09-19 18:38:39 +02:00

65 lines
1.3 KiB
Perl

#!/usr/bin/perl -w
use JSON;
use POSIX;
use Getopt::Long;
use Net::Domain qw(hostfqdn);
use Data::Dumper;
my $json;
@{$json->{data}} = ();
my $pretty = 0;
my $services = 1;
my $servers = 0;
GetOptions(
"pretty" => \$pretty,
"services" => \$services,
"servers" => \$servers
);
if ($servers) {
$services = 0;
}
my $uid = getuid();
my $gid = getgid();
my (undef,undef,$zimuid,$zimgid) = getpwnam('zimbra');
my $zmprov = '/opt/zimbra/bin/zmprov';
my $hostname = hostfqdn();
# If there's no zimbra user or no zmcontrol, just return an empty list
if (not defined $zimuid or not defined $zimgid or not -e $zmprov){
print to_json({});
exit;
}
# Switch to Zimbra user
setuid($zimuid) if ($uid ne $zimuid);
setgid($zimgid) if ($gid ne $zimgid);
if ($services){
# zmconfigd is always enabled and should be running
push @{$json}, {
'{#ZM_SERVICE}' => 'zmconfigd'
};
foreach my $service (qx($zmprov getServer $hostname zimbraServiceEnabled)){
if ($service =~ m/^zimbraServiceEnabled:\s+(\w+)/){
push @{$json->{data}}, {
'{#ZM_SERVICE}' => $1
};
}
}
} elsif ($servers){
foreach my $server (qx($zmprov getAllServers)){
chomp $server;
push @{$json->{data}}, {
'{#ZM_SERVER}' => $server
};
}
}
print to_json($json, { pretty => $pretty });