Skip to content

Instantly share code, notes, and snippets.

@agramajo
Created April 15, 2015 14:22
Show Gist options
  • Save agramajo/b29a795dce650b9d0484 to your computer and use it in GitHub Desktop.
Save agramajo/b29a795dce650b9d0484 to your computer and use it in GitHub Desktop.
xymon ssl check
|=1;
use strict;
use Time::Piece;
use Time::Seconds;
# BB and related test constants
use constant GREEN => 'green';
use constant YELLOW => 'yellow';
use constant RED => 'red';
# BB Global variables
my $bbtest = 'sslcheck';
my $now = Time::Piece->new;
my %hosts;
my $debug = 1;
# MAIN
print "DEBUG $ENV{BBHOME}/bin/bbhostgrep $bbtest $bbtest*\n" if $debug;
open GREP, "$ENV{BBHOME}/bin/bbhostgrep $bbtest $bbtest* |" or die $!;
while (<GREP>) {
my ($ip, $host, $x, $var) = split ' ';
my $port = 443;
if ($var =~ /$bbtest:(\d+)/) {
$port = $1;
}
$hosts{$host} = $port;
print "DEBUG $host $port\n" if $debug;
}
close GREP;
foreach my $h (keys %hosts) {
print "DEBUG $h:$hosts{$h}\n" if $debug;
my $color = GREEN;
my $status = $bbtest . " OK";
my $data = `echo | openssl s_client -servername $h -connect $h:$hosts{$h} 2>/dev/null | openssl x509 -noout -subject -dates -nameopt multiline`;
if ($data =~ /notAfter=(.*)/) {
my $d = Time::Piece->strptime($1, "%b %e %T %Y %Z") - $now;
my $diff = int($d->days);
if ($diff < 10) {
$color = RED;
$status = $bbtest . " NOT OK";
$data .= "\n&red ";
}
elsif ($diff < 30) {
$color = YELLOW;
$status = $bbtest . " NOT OK";
$data .= "\n&yellow ";
}
else {
$data .= "\n&green ";
}
$data .= "SSL $h expires in $diff days\n";
}
else {
$color = RED;
$status = $bbtest . " NOT OK";
$data .= "\n&red ";
$data .= "SSL $h error";
}
# Send to Hobbit
my $date = `date`; chomp($date);
system("$ENV{BB} $ENV{BBDISP} 'status+90 $h.$bbtest $color $date - $status\n\n$data'\n");
print "DEBUG data=$data status=$status host=$h\n" if $debug;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment