bin/check_tlsa-record
changeset 16 f5593514ab44
parent 14 ddefd02de6c5
child 40 b0dce1770a15
--- a/bin/check_tlsa-record	Tue May 31 16:35:56 2016 +0200
+++ b/bin/check_tlsa-record	Tue May 31 16:47:06 2016 +0200
@@ -13,14 +13,12 @@
 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> ] 
-                         [ -w|--warning=<warning threshold> ] 
-                         [ -p|--port=<portnumber> ] 
-                         [ -q|--queryserver=<DNS-Server-IP> ] 
+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 $extra = <<_;
 
 NOTICE
@@ -49,8 +47,6 @@
     timeout => 120,
 
 );
-
-#@TODO exit 1 &Co in eigenes die || oh_shit
 $nagios_tlsa->add_arg(
     spec     => 'host|H=s',
     help     => 'Host/Domain to check',
@@ -65,13 +61,13 @@
 
 $nagios_tlsa->add_arg(
     spec     => 'expiry|e',
-    help     => 'check expiry of Certificate',
+    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)',
+    help     => 'port of host to check the TLSA (default: 443)',
     required => 0,
     default  => 443,
 );
@@ -80,7 +76,7 @@
     spec     => 'queryserver|q=s',
     required => 0,
     help =>
-      'DNS Server to ask to check the TLSA (default: defined in resolve.conf)',
+      'DNS server to ask to check the TLSA (default: defined in resolv.conf)',
 
 );
 
@@ -91,13 +87,6 @@
     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;
@@ -105,12 +94,14 @@
 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;
-    say "Please set -H <domain> or -f <domainlist>\n"
+    my $excuse = "Please set -H <domain> or -f <domainlist>\n"
       . "For all options try $script --help";
 
+    say $excuse;
     exit 1;
 }
 
@@ -121,16 +112,17 @@
 
 if ($domain) {
 
-    if ($domain =~ /^(?<domain>\S*\.[a-z]{2,4}?):{1}(?<port>[0-9]+$)/gi) {
+    my $pattern = '^(?<domain>\S*\.[a-z]{2,4}?):{1}(?<port>[0-9]+$)';
+    if ($domain =~ /$pattern/gi) {
         $domain = $+{domain};
         $port   = $+{port};
     }
 
-    if (not $port or $port eq '') {
+    if (!$port || $port eq '') {
         $port = 443;
     }
 
-    if (not $protocol or $protocol ne 'tcp' or $protocol ne 'udp') {
+    if (!$protocol || $protocol ne 'tcp' || $protocol ne 'udp') {
         $protocol = 'tcp';
     }
 
@@ -144,7 +136,7 @@
     open(my $filehandle, '<', $domainlist);
 
     while (<$filehandle>) {
-        if (/^(?<domain>\S*\.[a-z]{2,4}?):{0,1}(?<port>[0-9]*$)/ig) {
+        if (/$pattern/ig) {
             $domain = $+{domain};
 
             if   ("$+{port}" =~ /^\s*$/) { $port = '443'; }