bin/check_tlsa-record
changeset 14 ddefd02de6c5
parent 13 198dd181ba37
child 16 f5593514ab44
--- a/bin/check_tlsa-record	Mon May 30 16:55:06 2016 +0200
+++ b/bin/check_tlsa-record	Mon May 30 22:51:07 2016 +0200
@@ -7,12 +7,12 @@
 use File::Basename;
 use Monitoring::Plugin;
 
-my $ME      = basename $0;
-my $blurb   = 'This Plugin is intended to check validity of TLSA Records';
-my $url     = 'http://www.schlittermann.de';
-my $author  = 'Heike Yvonne Pesch';
-my $email   = '<pesch@schlittermann.de>';
-my $usage   = <<_;
+my $ME     = basename $0;
+my $blurb  = 'This Plugin is intended to check validity of TLSA Records';
+my $url    = 'http://www.schlittermann.de';
+my $author = 'Heike Yvonne Pesch';
+my $email  = '<pesch@schlittermann.de>';
+my $usage  = <<_;
 Usage: %s [ -v|--verbose ] -H <host> [-t <timeout>] 
                          [ -f|--hostlist=<hostlist> ] 
                          [ -c|--critical=<critical threshold> ] 
@@ -21,7 +21,7 @@
                          [ -q|--queryserver=<DNS-Server-IP> ] 
 _
 
-my $extra   = <<_;
+my $extra = <<_;
 
 NOTICE
 If you want to use a hostlist, you have to put entries like this:
@@ -40,63 +40,62 @@
 For more information visit $url
 _
 
-
-my $nagios_tlsa  = Monitoring::Plugin->new(
-  usage   => $usage,
-  blurb   => $blurb,
-  extra   => $extra,
-  url     => $url,
-  plugin  => $ME,
-  timeout => 120,
+my $nagios_tlsa = Monitoring::Plugin->new(
+    usage   => $usage,
+    blurb   => $blurb,
+    extra   => $extra,
+    url     => $url,
+    plugin  => $ME,
+    timeout => 120,
 
 );
 
 #@TODO exit 1 &Co in eigenes die || oh_shit
 $nagios_tlsa->add_arg(
-  spec     => 'host|H=s',
-  help     => 'Host/Domain to check',
-  required => 0,
+    spec     => 'host|H=s',
+    help     => 'Host/Domain to check',
+    required => 0,
 );
 
 $nagios_tlsa->add_arg(
-  spec     => 'hostlist|f=s',
-  help     => 'Host/Domainlist in file to check',
-  required => 0,
+    spec     => 'hostlist|f=s',
+    help     => 'Host/Domainlist in file to check',
+    required => 0,
 );
 
 $nagios_tlsa->add_arg(
-  spec     => 'expiry|e',
-  help     => 'check expiry of Certificate',
-  required => 0,
+    spec     => 'expiry|e',
+    help     => 'check expiry of Certificate',
+    required => 0,
 );
 
 $nagios_tlsa->add_arg(
-  spec     => 'port|p=i',
-  help     => 'Port of Domain to check the TLSA (default: 443)',
-  required => 0,
-  default  => 443,
+    spec     => 'port|p=i',
+    help     => 'Port of Domain to check the TLSA (default: 443)',
+    required => 0,
+    default  => 443,
 );
 
 $nagios_tlsa->add_arg(
-  spec     => 'queryserver|q=s',
-  required => 0,
-  help     =>
-  'DNS Server to ask to check the TLSA (default: defined in resolve.conf)',
+    spec     => 'queryserver|q=s',
+    required => 0,
+    help =>
+      'DNS Server to ask to check the TLSA (default: defined in resolve.conf)',
 
 );
 
 $nagios_tlsa->add_arg(
-  spec     => 'protocol|P=s',
-  help     => 'Protocol to ask to check the TLSA record of domain (default: tcp)',
-  required => 0,
-  default  => 'tcp',
+    spec => 'protocol|P=s',
+    help => 'Protocol to ask to check the TLSA record of domain (default: tcp)',
+    required => 0,
+    default  => 'tcp',
 );
 
 $nagios_tlsa->add_arg(
-  spec     => 'timeout|t=i',
-  help     => 'Timeout in seconds for check (default: 120)',
-  required => 0,
-  default  => 120,
+    spec     => 'timeout|t=i',
+    help     => 'Timeout in seconds for check (default: 120)',
+    required => 0,
+    default  => 120,
 );
 
 $nagios_tlsa->getopts;
@@ -110,35 +109,35 @@
 if (!$domain && !$domainlist) {
     my $script = basename $0;
     say "Please set -H <domain> or -f <domainlist>\n"
-    . "For all options try $script --help";
+      . "For all options try $script --help";
 
     exit 1;
 }
 
-if ($domainlist)
-{
-  get_domains();
-  exit 0;
+if ($domainlist) {
+    get_domains();
+    exit 0;
 }
 
 if ($domain) {
 
-  if ($domain =~ /^(?<domain>\S*\.[a-z]{2,4}?):{1}(?<port>[0-9]+$)/gi) {
-    $domain = $+{domain};
-    $port   = $+{port};
-  }
+    if ($domain =~ /^(?<domain>\S*\.[a-z]{2,4}?):{1}(?<port>[0-9]+$)/gi) {
+        $domain = $+{domain};
+        $port   = $+{port};
+    }
+
+    if (not $port or $port eq '') {
+        $port = 443;
+    }
 
-  if (not $port or $port eq '') {
-    $port = 443;
-  }
+    if (not $protocol or $protocol ne 'tcp' or $protocol ne 'udp') {
+        $protocol = 'tcp';
+    }
 
-  if (not $protocol or $protocol ne 'tcp' or $protocol ne 'udp') {
-    $protocol = 'tcp';
-  }
-
-  my $return = Nagios::Check::DNS::check_tlsa_record::main(($domain, $port, $protocol));
-  say $return;
-  exit 0;
+    my $return =
+      Nagios::Check::DNS::check_tlsa_record::main(($domain, $port, $protocol));
+    say $return;
+    exit 0;
 }
 
 sub get_domains {
@@ -148,10 +147,11 @@
         if (/^(?<domain>\S*\.[a-z]{2,4}?):{0,1}(?<port>[0-9]*$)/ig) {
             $domain = $+{domain};
 
-            if ("$+{port}" =~ /^\s*$/) { $port = '443'; }
-            else { $port   = $+{port}; }
+            if   ("$+{port}" =~ /^\s*$/) { $port = '443'; }
+            else                         { $port = $+{port}; }
 
-            my $return = Nagios::Check::DNS::check_tlsa_record::main(($domain, $port));
+            my $return =
+              Nagios::Check::DNS::check_tlsa_record::main(($domain, $port));
             say $return;
         }
         else {