zabbix-agent-addons/zabbix_scripts/check_httpd

56 lines
904 B
Plaintext
Raw Normal View History

#!/usr/bin/perl -w
2016-11-09 16:26:34 +01:00
use strict;
use warnings;
use LWP::Simple;
use Getopt::Long;
use JSON;
2016-11-09 16:26:34 +01:00
my $uri = 'http://127.0.0.1/server-status';
my $what = 'all';
2016-11-09 16:26:34 +01:00
my $help = 0;
GetOptions(
"uri=s" => \$uri,
2016-11-09 16:26:34 +01:00
"what=s" => \$what,
"help" => \$help
);
my %res = ();
my $status = get($uri . '?auto');
2016-11-09 16:26:34 +01:00
unless ($status){
print 'ZBX_NOTSUPPORTED';
2016-11-09 16:26:34 +01:00
exit 1;
}
foreach my $line (split(/\n/, $status)){
next unless ($line =~ m/^(\w+(\s\w+)?):\s([\.\d]+)/);
my ($key, $val) = ($1,$3);
2016-11-09 16:26:34 +01:00
$key =~ s/\s/_/g;
$key = lc $key;
2016-11-09 17:41:55 +01:00
# Remove leading and trailing spaces
2016-11-09 16:26:34 +01:00
$val =~ s/^\s+|\s+$//g;
2016-11-09 17:41:55 +01:00
# Add 0 before the . when needed
$val =~ s/^(\.\d+)$/0$1/;
2016-11-09 16:26:34 +01:00
$res{$key} = $val;
}
if ($help){
2016-11-09 16:26:34 +01:00
print "Valid keys are:\n\n";
print "$_\n" for keys %res;
exit 0;
}
if ($what eq 'all'){
print to_json(\%res);
}
elsif (defined $res{$what}){
2016-11-09 16:26:34 +01:00
print $res{$what};
}
else{
print 'ZBX_NOTSUPPORTED';
2016-11-09 16:26:34 +01:00
}
exit 0;