From a806da0b58a5bffd7a8e6331e3bc95eb2bc6abaa Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Thu, 18 Oct 2018 11:31:58 +0200 Subject: [PATCH] Add very basic script for PMG monitoring --- zabbix_conf/pmg.conf | 9 +++++++++ zabbix_scripts/check_pmg_sudo | 31 +++++++++++++++++++++++++++++++ zabbix_scripts/disco_pmg_sudo | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 zabbix_conf/pmg.conf create mode 100644 zabbix_scripts/check_pmg_sudo create mode 100644 zabbix_scripts/disco_pmg_sudo diff --git a/zabbix_conf/pmg.conf b/zabbix_conf/pmg.conf new file mode 100644 index 0000000..82f589d --- /dev/null +++ b/zabbix_conf/pmg.conf @@ -0,0 +1,9 @@ +# Discover PMG items +# $1 can be domains +UserParameter=pmg.discovery[*],/usr/bin/sudo /var/lib/zabbix/bin/disco_pmg_sudo --what $1 + +# Type: Agent or Agent (active) +# pmg.check.all[type,id] +# Where type is what to monitor (domain) +# id is the id of the item to monitor. Eg, the domain name +UserParameter=pmg.check.all[*],/usr/bin/sudo /var/lib/zabbix/bin/check_pmg_sudo --$1 $2 diff --git a/zabbix_scripts/check_pmg_sudo b/zabbix_scripts/check_pmg_sudo new file mode 100644 index 0000000..84bd0e9 --- /dev/null +++ b/zabbix_scripts/check_pmg_sudo @@ -0,0 +1,31 @@ +#!/usr/bin/perl -w + +use strict; +use warnings; +use JSON; +use Getopt::Long; +use File::Which; +use Data::Dumper; + +my $pmgsh = which('pmgsh'); +my $json = {}; +my $pretty = 0; +my ($domain) = undef; + +GetOptions( + 'domain=s' => \$domain, + 'pretty' => \$pretty +); + +if ($domain){ + my $stats = from_json(qx($pmgsh get /statistics/domains 2>/dev/null)); + foreach my $dom (@{$stats}){ + next unless ($dom->{domain} eq $domain); + $json->{$_} = $dom->{$_} foreach (qw/bytes_in bytes_out count_in count_out spamcount_in spamcount_out viruscount_in viruscount_out/); + } +} else{ + print 'ZBX_UNSUPORTED'; + exit 0; +} + +print to_json($json, { pretty => $pretty }) . "\n"; diff --git a/zabbix_scripts/disco_pmg_sudo b/zabbix_scripts/disco_pmg_sudo new file mode 100644 index 0000000..ec32ff8 --- /dev/null +++ b/zabbix_scripts/disco_pmg_sudo @@ -0,0 +1,35 @@ +#!/usr/bin/perl -w + +use strict; +use warnings; +use JSON; +use Getopt::Long; +use File::Which; + +my $what = 'nodes'; +my $pretty = 0; + +GetOptions( + 'what=s' => \$what, + 'pretty' => \$pretty +); + +my $pmgsh = which('pmgsh'); +my $json = {}; +@{$json->{data}} = (); + +unless($pmgsh){ + print to_json($json) . "\n"; + exit 0; +} + +if ($what eq 'domains'){ + my $domains = from_json(qx($pmgsh get /config/domains 2>/dev/null)); + foreach my $item (@{$domains}){ + push @{$json->{data}}, { + '{#PMG_RELAY_DOMAIN}' => $item->{domain}, + }; + } +} + +print to_json($json, { pretty => $pretty }) . "\n";