bin/check_tlsa-record
changeset 12 c111a724d89c
parent 9 2041bac74e8d
child 13 198dd181ba37
--- a/bin/check_tlsa-record	Mon May 30 11:45:38 2016 +0200
+++ b/bin/check_tlsa-record	Mon May 30 16:52:51 2016 +0200
@@ -12,11 +12,15 @@
 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>] '
-            . '[ -c|--critical=<critical threshold> ] '
-            . '[ -w|--warning=<warning threshold> ] '
-            . '[ -p|--port=<portnumber> ] '
-            . '[ -q|--queryserver=<DNS-Server-IP> ] ';
+my $usage   = <<_;
+Usage: %s [ -v|--verbose ] -H <host> [-t <timeout>] 
+                         [ -f|--hostlist=<hostlist> ] 
+                         [ -c|--critical=<critical threshold> ] 
+                         [ -w|--warning=<warning threshold> ] 
+                         [ -p|--port=<portnumber> ] 
+                         [ -q|--queryserver=<DNS-Server-IP> ] 
+_
+
 my $extra   = <<_;
 
 NOTICE
@@ -46,27 +50,29 @@
   timeout => 120,
 
 );
+
+#@TODO exit 1 &Co in eigenes die || oh_shit
 $nagios_tlsa->add_arg(
   spec     => 'host|H=s',
-  help     => q|Host/Domain to check|,
+  help     => 'Host/Domain to check',
   required => 0,
 );
 
 $nagios_tlsa->add_arg(
   spec     => 'hostlist|f=s',
-  help     => q|Host/Domainlist in file to check|,
+  help     => 'Host/Domainlist in file to check',
   required => 0,
 );
 
 $nagios_tlsa->add_arg(
   spec     => 'expiry|e',
-  help     => q|check expiry of Certificate|,
+  help     => 'check expiry of Certificate',
   required => 0,
 );
 
 $nagios_tlsa->add_arg(
   spec     => 'port|p=i',
-  help     => q|Port of Domain to check the TLSA (default: 443)|,
+  help     => 'Port of Domain to check the TLSA (default: 443)',
   required => 0,
   default  => 443,
 );
@@ -75,17 +81,24 @@
   spec     => 'queryserver|q=s',
   required => 0,
   help     =>
-  q|DNS Server to ask to check the TLSA (default: defined in resolve.conf)|,
+  'DNS Server to ask to check the TLSA (default: defined in resolve.conf)',
 
 );
 
 $nagios_tlsa->add_arg(
   spec     => 'protocol|P=s',
-  help     => q|Protocol to ask to check the TLSA record of domain (default: tcp)|,
+  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,
+);
+
 $nagios_tlsa->getopts;
 
 my $domain     = $nagios_tlsa->opts->host;
@@ -93,15 +106,12 @@
 my $protocol   = $nagios_tlsa->opts->protocol;
 my $domainlist = $nagios_tlsa->opts->hostlist;
 my $expiry     = $nagios_tlsa->opts->expiry;
-my $pattern    = '^(?<domain>\S*\.[a-z]{2,4}?):{0,1}(?<port>[0-9]*$)';
-
 
 if (!$domain && !$domainlist) {
     my $script = basename $0;
-    my $excuse = "Please set -H <domain> or -f <domainlist>\n"
+    say "Please set -H <domain> or -f <domainlist>\n"
     . "For all options try $script --help";
 
-    say $excuse;
     exit 1;
 }
 
@@ -111,23 +121,18 @@
   exit 0;
 }
 
-if ($domain)
-{
+if ($domain) {
 
-  my $pattern    = '^(?<domain>\S*\.[a-z]{2,4}?):{1}(?<port>[0-9]+$)';
-  if ($domain =~ /$pattern/gi)
-  {
+  if ($domain =~ /^(?<domain>\S*\.[a-z]{2,4}?):{1}(?<port>[0-9]+$)/gi) {
     $domain = $+{domain};
     $port   = $+{port};
   }
 
-  if (!$port || $port eq '')
-  {
+  if (not $port or $port eq '') {
     $port = 443;
   }
 
-  if (!$protocol || $protocol ne 'tcp' || $protocol ne 'udp')
-  {
+  if (not $protocol or $protocol ne 'tcp' or $protocol ne 'udp') {
     $protocol = 'tcp';
   }
 
@@ -140,7 +145,7 @@
     open(my $filehandle, '<', $domainlist);
 
     while (<$filehandle>) {
-        if (/$pattern/ig) {
+        if (/^(?<domain>\S*\.[a-z]{2,4}?):{0,1}(?<port>[0-9]*$)/ig) {
             $domain = $+{domain};
 
             if ("$+{port}" =~ /^\s*$/) { $port = '443'; }