Additional scripts for Zabbix agent on Linux to discover and monitor several services
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use Zabbix::Agent::Addons::Disks;
|
|
|
|
use JSON;
|
|
|
|
use File::Which;
|
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
my $pretty = 0;
|
|
|
|
GetOptions(
|
|
|
|
'pretty' => \$pretty
|
|
|
|
);
|
|
|
|
|
|
|
|
my $lsblk = which('lsblk');
|
|
|
|
|
|
|
|
my $json;
|
|
|
|
@{$json->{data}} = ();
|
|
|
|
if (defined $lsblk){
|
|
|
|
foreach my $line (qx($lsblk -o KNAME,TYPE,SIZE -r -n -b)){
|
|
|
|
my ($block,$type,$size) = split(/\s+/, $line);
|
|
|
|
push @{$json->{data}}, {
|
|
|
|
"{#BLOCKDEVICE}" => $block, # Compat with previous zabbix-agent-addons
|
|
|
|
"{#DEVNAME}" => $block, # New macro name for the native vfs.dev.discovery key in 4.4
|
|
|
|
"{#DEVTYPE}" => $type,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
# Fallback if lsblk is not available
|
|
|
|
foreach my $block (Zabbix::Agent::Addons::Disks::list_block_dev()){
|
|
|
|
push @{$json->{data}}, {
|
|
|
|
"{#BLOCKDEVICE}" => $block,
|
|
|
|
"{#DEVNAME}" => $block,
|
|
|
|
"{#DEVTYPE}" => 'disk'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print to_json($json, { pretty => $pretty });
|
|
|
|
exit(0);
|