diff -r 81f7087155cf -r f5593514ab44 bin/check_tlsa-record --- 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 = ''; my $usage = <<_; -Usage: %s [ -v|--verbose ] -H [-t ] - [ -f|--hostlist= ] - [ -c|--critical= ] - [ -w|--warning= ] - [ -p|--port= ] - [ -q|--queryserver= ] +Usage: %s [-v|--verbose ] [-H ] [-t ] + [-c|--critical=] + [-w|--warning=] + [-p|--port=] + [-q|--queryserver=] _ - 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 = '^(?\S*\.[a-z]{2,4}?):{0,1}(?[0-9]*$)'; if (!$domain && !$domainlist) { my $script = basename $0; - say "Please set -H or -f \n" + my $excuse = "Please set -H or -f \n" . "For all options try $script --help"; + say $excuse; exit 1; } @@ -121,16 +112,17 @@ if ($domain) { - if ($domain =~ /^(?\S*\.[a-z]{2,4}?):{1}(?[0-9]+$)/gi) { + my $pattern = '^(?\S*\.[a-z]{2,4}?):{1}(?[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 (/^(?\S*\.[a-z]{2,4}?):{0,1}(?[0-9]*$)/ig) { + if (/$pattern/ig) { $domain = $+{domain}; if ("$+{port}" =~ /^\s*$/) { $port = '443'; }