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.
50 lines
804 B
50 lines
804 B
#!/usr/bin/perl -w
|
|
|
|
use strict;
|
|
use warnings;
|
|
use LWP::Simple;
|
|
use Getopt::Long;
|
|
|
|
my $uri = 'http://127.0.0.1/server-status';
|
|
my $what = undef;
|
|
my $help = 0;
|
|
|
|
GetOptions(
|
|
"uri=s" => \$uri,
|
|
"what=s" => \$what,
|
|
"help" => \$help
|
|
);
|
|
|
|
my %res = ();
|
|
my $status = get($uri . '?auto');
|
|
|
|
|
|
unless ($status){
|
|
print 'ZBX_UNSUPPOTED';
|
|
exit 1;
|
|
}
|
|
|
|
foreach my $line (split(/\n/, $status)){
|
|
my ($key, $val) = split(/:/, $line);
|
|
$key =~ s/\s/_/g;
|
|
$key = lc $key;
|
|
# Remove leading and trailing spaces
|
|
$val =~ s/^\s+|\s+$//g;
|
|
# Add 0 before the . when needed
|
|
$val =~ s/^(\.\d+)$/0$1/;
|
|
$res{$key} = $val;
|
|
}
|
|
|
|
if ($help || !$what){
|
|
print "Valid keys are:\n\n";
|
|
print "$_\n" for keys %res;
|
|
exit 0;
|
|
}
|
|
|
|
if (defined $res{$what}){
|
|
print $res{$what};
|
|
}
|
|
else{
|
|
print 'ZBX_UNSUPPOTED';
|
|
}
|
|
exit 0;
|
|
|