Modernize lvm monitoring scripts

support getting all the value at once in a JSON structure, support VG monitoring, and various other cleanups

GLPI #47654
tags/zabbix-agent-addons-0.2.142-1
Daniel Berteaud 4 years ago
parent b95cca848c
commit bf190465bf
  1. 3
      zabbix_conf/lvm.conf
  2. 77
      zabbix_scripts/check_lvm_sudo

@ -5,4 +5,5 @@ UserParameter=vfs.lvm.discovery[*],/usr/bin/sudo /var/lib/zabbix/bin/disco_lvm_s
# Type: Agent or Agent (active) # Type: Agent or Agent (active)
# Key: vfs.lvm.lv[volume,key] where volume is the path to a logical volume and # Key: vfs.lvm.lv[volume,key] where volume is the path to a logical volume and
# key can be size, allocation (for snapshots only) or status # key can be size, allocation (for snapshots only) or status
UserParameter=vfs.lvm.lv[*],/usr/bin/sudo /var/lib/zabbix/bin/check_lvm_sudo $1 $2 UserParameter=vfs.lvm.lv[*],/usr/bin/sudo /var/lib/zabbix/bin/check_lvm_sudo --lv='$1' --what='$2'
UserParameter=vfs.lvm.vg[*],/usr/bin/sudo /var/lib/zabbix/bin/check_lvm_sudo --vg='$1' --what='$2'

@ -1,49 +1,72 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
use Zabbix::Agent::Addons::LVM; use Zabbix::Agent::Addons::LVM;
use Getopt::Long;
use JSON;
Zabbix::Agent::Addons::LVM->units(B); Zabbix::Agent::Addons::LVM->units(B);
if (@ARGV < 2){ my $vg = undef;
usage(); my $lv = undef;
exit(1); my $what = undef;
my $pretty = 0;
GetOptions(
'vg=s' => \$vg,
'lv=s' => \$lv,
'what:s' => \$what,
"pretty" => \$pretty
);
if (not defined $lv and not defined $vg){
$lv ||= $ARGV[0];
$what ||= $ARGV[1];
} }
my $vol = $ARGV[0]; if (not defined $lv and not defined $vg){
my $what = $ARGV[1]; usage();
exit 1;
}
sub usage { sub usage {
print<<"EOF"; print<<"EOF";
Usage: $0 <logical volume> [size|allocation|allocation_pool_data|allocation_metadata|status] Usage: $0 <logical volume> [size|allocation|allocation_pool_data|allocation_metadata|status]
$0 --lv=<logical volume>
$0 --lv=<logical volume> --what=<size|allocation|allocation_pool_data|allocation_metadata|status|etc.>
$0 --vg=<volume group>
$0 --vg=<volume group> --what=<alloc_pe_size|vg_size|etc.>
EOF EOF
} }
my %info = get_lv_info($vol); my $json;
if (defined $vg){
if ($what eq 'size'){ %{$json} = get_volume_group_information($vg);
print $info{size}; } elsif (defined $lv) {
} %{$json} = get_lv_info($lv);
elsif ($what eq 'allocation'){ } else{
my $ret = (defined $info{allocated_to_snapshot}) ? $info{allocated_to_snapshot} : "ZBX_NOTSUPPORTED"; usage();
$ret =~ s/,/\./;
print $ret;
} }
elsif ($what eq 'allocation_pool_data'){
my $ret = (defined $info{allocated_pool_data}) ? $info{allocated_pool_data} : "ZBX_NOTSUPPORTED"; # Normalize float values
$ret =~ s/,/\./; foreach (qw(allocated_to_snapshot allocated_pool_data allocated_meta_data)){
print $ret; $json->{$_} =~ s/,/./g if (defined $json->{$_});
}
elsif ($what eq 'allocation_metadata'){
my $ret = (defined $info{allocated_meta_data}) ? $info{allocated_meta_data} : "ZBX_NOTSUPPORTED";
$ret =~ s/,/\./;
print $ret;
} }
elsif ($what eq 'status'){ # Compat with older versions
print $info{status}; my $old_keys = {
allocation => 'allocated_to_snapshot',
allocation_pool_data => 'allocated_pool_data',
allocation_metadata => 'allocated_meta_data'
};
if (defined $what && defined $old_keys->{$what}){
$what = $old_keys->{$what};
} }
else{
usage(); if (defined $what and $what ne ''){
print ((defined $json->{$what}) ? $json->{$what} : 'ZBX_NOTSUPPOTED');
} else {
print to_json($json, { pretty => $pretty });
} }
exit(0); exit(0);

Loading…
Cancel
Save