Modernize lvm monitoring scripts
support getting all the value at once in a JSON structure, support VG monitoring, and various other cleanups GLPI #47654
This commit is contained in:
parent
b95cca848c
commit
bf190465bf
|
@ -5,4 +5,5 @@ UserParameter=vfs.lvm.discovery[*],/usr/bin/sudo /var/lib/zabbix/bin/disco_lvm_s
|
|||
# Type: Agent or Agent (active)
|
||||
# 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
|
||||
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
|
||||
|
||||
use Zabbix::Agent::Addons::LVM;
|
||||
use Getopt::Long;
|
||||
use JSON;
|
||||
|
||||
Zabbix::Agent::Addons::LVM->units(B);
|
||||
|
||||
if (@ARGV < 2){
|
||||
usage();
|
||||
exit(1);
|
||||
my $vg = undef;
|
||||
my $lv = undef;
|
||||
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];
|
||||
my $what = $ARGV[1];
|
||||
if (not defined $lv and not defined $vg){
|
||||
usage();
|
||||
exit 1;
|
||||
}
|
||||
|
||||
sub usage {
|
||||
print<<"EOF";
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
my %info = get_lv_info($vol);
|
||||
my $json;
|
||||
if (defined $vg){
|
||||
%{$json} = get_volume_group_information($vg);
|
||||
} elsif (defined $lv) {
|
||||
%{$json} = get_lv_info($lv);
|
||||
} else{
|
||||
usage();
|
||||
}
|
||||
|
||||
if ($what eq 'size'){
|
||||
print $info{size};
|
||||
# Normalize float values
|
||||
foreach (qw(allocated_to_snapshot allocated_pool_data allocated_meta_data)){
|
||||
$json->{$_} =~ s/,/./g if (defined $json->{$_});
|
||||
}
|
||||
elsif ($what eq 'allocation'){
|
||||
my $ret = (defined $info{allocated_to_snapshot}) ? $info{allocated_to_snapshot} : "ZBX_NOTSUPPORTED";
|
||||
$ret =~ s/,/\./;
|
||||
print $ret;
|
||||
# Compat with older versions
|
||||
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};
|
||||
}
|
||||
elsif ($what eq 'allocation_pool_data'){
|
||||
my $ret = (defined $info{allocated_pool_data}) ? $info{allocated_pool_data} : "ZBX_NOTSUPPORTED";
|
||||
$ret =~ s/,/\./;
|
||||
print $ret;
|
||||
}
|
||||
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'){
|
||||
print $info{status};
|
||||
}
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue