Rewrite LVM check script and add discovery capabilities

tags/zabbix-agent-addons-0.2.20-1
Daniel Berteaud 12 years ago
parent 532775e403
commit e7cf5f74cd
  1. 14
      conf/lvm.conf
  2. 63
      scripts/check_lvm_sudo
  3. 44
      scripts/disco_lvm_sudo

@ -1,8 +1,8 @@
# Type: Agent or Agent (active)
# Key: lvm[key] where key can be snapshot_max_alloc, snapshots, lv or vg
# Type of information: Numeric (integer 64bit)
# Units: depends on the key (snapshot_max_alloc is in %)
# Custom multiplier: Do not use
# Store Value: As is
# Discover LVM volume
# $1 can be groups, volumes or snapshots
UserParameter=vfs.lvm.discovery[*],/usr/bin/sudo /var/lib/zabbix/bin/disco_lvm_sudo $1
UserParameter=lvm[*],/usr/bin/sudo /var/lib/zabbix/bin/check_lvm_sudo $1
# 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

@ -1,38 +1,39 @@
#!/bin/bash
PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
# Return the greatest snapshot allocation
snapshot_max_alloc(){
MAX_PERCENT=0
for PERCENT in $(lvdisplay | grep % | sed -e 's/ Allocated to snapshot //g' -e 's/%//g'); do
if [[ "$PERCENT" > "$MAX_PERCENT" ]]; then
MAX_PERCENT=$PERCENT
fi
done
echo "$MAX_PERCENT"
}
#!/usr/bin/perl -w
# Number of active snapshots
snapshots(){
echo $(lvdisplay | grep % | wc -l)
}
use Linux::LVM;
Linux::LVM->units(B);
# Number of logical volumes
lv(){
echo $(lvdisplay | grep 'LV Name' | wc -l)
if (@ARGV < 2){
usage();
exit(1);
}
# Number of volume group
vg(){
echo $(vgdisplay | grep 'VG Name' | wc -l)
my $vol = $ARGV[0];
my $what = $ARGV[1];
sub usage {
print<<"EOF";
Usage: $0 <logical volume> [size|allocation|status]
EOF
}
case $1 in
snapshot_max_alloc|snapshots|lv|vg)
$1
;;
*)
echo 'ZBX_NOTSUPPORTED'
esac
my %info = get_lv_info($vol);
if ($what eq 'size'){
print $info{size};
}
elsif ($what eq 'allocation'){
my $ret = (defined $info{allocated_to_snapshot}) ? $info{allocated_to_snapshot} : "ZBX_NOTSUPPORTED";
$ret =~ s/,/\./;
print $ret;
}
elsif ($what eq 'status'){
print $info{status};
}
else{
usage();
}
exit(0);

@ -0,0 +1,44 @@
#!/usr/bin/perl -w
use Linux::LVM;
use JSON;
my $what = $ARGV[0];
open STDERR, '>/dev/null';
my $json;
if ($what eq "volumes"){
foreach my $group (get_volume_group_list()){
my %lvs = get_logical_volume_information($group);
foreach my $lv (keys %lvs){
push @{$json->{data}}, { "{#LVMVOL}" => "/dev/$group/$lv" };
}
}
}
elsif ($what eq "snapshots"){
foreach my $group (get_volume_group_list()){
my %lvs = get_logical_volume_information($group);
foreach my $lv (keys %lvs){
if (defined $lvs{$lv}->{allocated_to_snapshot}){
push @{$json->{data}}, { "{#LVMSNAP}" => "/dev/$group/$lv" };
}
}
}
}
elsif ($what eq "groups"){
foreach my $group (get_volume_group_list()){
push @{$json->{data}}, { "{#LVMGRP}" => $group };
}
}
else{
print <<"EOF";
Usage: $0 [volumes|snapshots|groups]
EOF
}
print to_json($json);
exit(0);
Loading…
Cancel
Save