parent
9de059cdd2
commit
ec110483dd
3 changed files with 130 additions and 0 deletions
@ -0,0 +1,11 @@ |
||||
# Discovery of configured host |
||||
# Key: zimbra.discovery[services] or zimbra.discovery[servers] |
||||
# Macro: {#ZM_SERVICE} |
||||
# Other available macros: |
||||
UserParameter=zimbra.discovery[*],/usr/bin/sudo /var/lib/zabbix/bin/disco_zimbra_sudo --$1 |
||||
|
||||
# Item prototypes |
||||
# key: zimbra.check[*] |
||||
# or |
||||
# Returns a JSON object, use dependent item to split it |
||||
UserParameter=zimbra.status[*],/usr/bin/sudo /var/lib/zabbix/bin/check_zimbra_sudo --status=$2 |
@ -0,0 +1,59 @@ |
||||
#!/usr/bin/perl -w |
||||
|
||||
use JSON; |
||||
use POSIX; |
||||
use Getopt::Long; |
||||
use Net::Domain qw(hostfqdn); |
||||
use Data::Dumper; |
||||
|
||||
my $pretty = 0; |
||||
my $status = 'all'; |
||||
|
||||
GetOptions( |
||||
"pretty" => \$pretty, |
||||
"status=s" => \$status |
||||
); |
||||
|
||||
if (defined $service and $service !~ m/^\w+$/){ |
||||
die "Invelid service name\n"; |
||||
} |
||||
|
||||
my $zmprov = '/opt/zimbra/bin/zmprov'; |
||||
my $zmcontrol = '/opt/zimbra/bin/zmcontrol'; |
||||
my $hostname = hostfqdn(); |
||||
|
||||
# We need to switch to zimbra |
||||
my $uid = getuid(); |
||||
my $gid = getgid(); |
||||
my (undef,undef,$zimuid,$zimgid) = getpwnam('zimbra'); |
||||
|
||||
if (not defined $zimuid or not defined $zimgid or not -e $zmprov){ |
||||
print 'ZBX_NOTSUPPOTED'; |
||||
exit; |
||||
} |
||||
|
||||
setuid($zimuid) if ($uid ne $zimuid); |
||||
setgid($zimgid) if ($gid ne $zimgid); |
||||
|
||||
# If there's no zimbra user or no zmcontrol, return unsupported item |
||||
if (not defined $zimuid or not defined $zimgid or not -e $zmprov){ |
||||
print 'ZBX_NOTSUPPOTED'; |
||||
exit 0; |
||||
} |
||||
|
||||
my $output = {}; |
||||
|
||||
if (defined $status){ |
||||
foreach my $line (qx($zmcontrol status)){ |
||||
if ($line =~ m/^\s+(\w+)\s+(Running|Stopped)/){ |
||||
$output->{$1} = ($2 eq 'Running') ? 1 : 0; |
||||
} |
||||
} |
||||
if ($service eq 'all'){ |
||||
print to_json($output, { pretty => $pretty }); |
||||
} elsif (defined $output->{$status}){ |
||||
print $output->{$status} |
||||
} else { |
||||
print 'ZBX_NOTSUPPORTED'; |
||||
} |
||||
} |
@ -0,0 +1,60 @@ |
||||
#!/usr/bin/perl -w |
||||
|
||||
use JSON; |
||||
use POSIX; |
||||
use Getopt::Long; |
||||
use Net::Domain qw(hostfqdn); |
||||
use Data::Dumper; |
||||
|
||||
my $json; |
||||
@{$json} = (); |
||||
|
||||
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){ |
||||
foreach my $service (qx($zmprov getServer $hostname zimbraServiceEnabled)){ |
||||
if ($service =~ m/^zimbraServiceEnabled:\s+(\w+)/){ |
||||
push @{$json}, { |
||||
'{#ZM_SERVICE}' => $1 |
||||
}; |
||||
} |
||||
} |
||||
} elsif ($servers){ |
||||
foreach my $server (qx($zmprov getAllServers)){ |
||||
chomp $server; |
||||
push @{$json}, { |
||||
'{#ZM_SERVER}' => $server |
||||
}; |
||||
} |
||||
} |
||||
|
||||
print to_json($json, { pretty => $pretty }); |
Loading…
Reference in new issue