diff --git a/check_mtr.pl b/check_mtr.pl index 9ea7cbb44efa885d3ab1cb1e320920cf7e9f37fc..5f1979591734bfbfc967ea335a545287272fabd8 100755 --- a/check_mtr.pl +++ b/check_mtr.pl @@ -76,6 +76,20 @@ $mp->add_arg( help => '', ); +$mp->add_arg( + spec => 'tcp', + help => 'Use TCP instead of ICMP Echo. (Default port: 443)', +); + +$mp->add_arg( + spec => 'udp', + help => 'Use UDP instead of ICMP Echo. (Default port: 53)', +); + +$mp->add_arg( + spec => 'port=i', + help => 'Use the specified port. Only aplicable if TCP or UDP set.' +); $mp->getopts; @@ -89,6 +103,23 @@ sub check my @cmd; push(@cmd, 'mtr'); push(@cmd, ('-n', '-c', '4', '--report', '--report-wide')); + if ($mp->opts->tcp && $mp->opts->udp) { + wrap_exit(UNKNOWN, 'TCP and UDP mode can not be used in combination'); + } elsif ($mp->opts->tcp) { + push(@cmd, '--tcp'); + my $port = $mp->opts->port; + if (!defined $port) { + $port = 443; + } + push(@cmd, ('--port', $port)); + } elsif ($mp->opts->udp) { + push(@cmd, '--udp'); + my $port = $mp->opts->port; + if (!defined $port) { + $port = 53; + } + push(@cmd, ('--port', $port)); + } push(@cmd, $mp->opts->hostname); open(my $pipe,'-|',@cmd) or die "Can't start process: $!";