...
 
Commits (8)
Changelog
=========
0.2 (2021-01-23)
----------------
- Add additional heading to long output
- Remove illegal chars from long output
- Use dash(-) instead of underscore(_) in arguments
- Option to resolve the hostnames of the hops
- Option to set report cycles
- Add TCP and UDP mode
- Change perfdata names
0.1 (2021-01-21)
----------------
......
......@@ -56,26 +56,51 @@ $mp->add_arg(
);
$mp->add_arg(
spec => 'latency_warn=s',
spec => 'latency-warn=s',
help => '',
);
$mp->add_arg(
spec => 'latency_crit=s',
spec => 'latency-crit=s',
help => '',
);
$mp->add_arg(
spec => 'packet_loss_warn=s',
spec => 'packet-loss-warn=s',
help => '',
);
$mp->add_arg(
spec => 'packet_loss_crit=s',
spec => 'packet-loss-crit=s',
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->add_arg(
spec => 'cycles=i',
help => 'Number of cycles to check hosts and the reliability. (Default: 4)',
default => 4,
);
$mp->add_arg(
spec => 'dns',
help => 'Try to resolve the hostnames of the hops.',
);
$mp->getopts;
......@@ -88,7 +113,30 @@ sub check
{
my @cmd;
push(@cmd, 'mtr');
push(@cmd, ('-n', '-c', '4', '--report', '--report-wide'));
push(@cmd, ('--report', '--report-wide'));
push(@cmd, ('--report-cycles', $mp->opts->cycles));
if ($mp->opts->dns) {
push(@cmd, '--show-ip');
} else {
push(@cmd, '--no-dns');
}
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: $!";
......@@ -96,12 +144,15 @@ sub check
close($pipe) or die "Broken pipe: $!";
my $hop_count = 0;
my $hop_reachable = 1;
# Heading in the long output
push(@g_long_message, "Hops:");
foreach my $line (@output) {
my $status = OK;
if ($line =~ /^\s*(\d+).\s*[|-]+?\s+([0-9a-f.:\?]+)\s+(\d+.\d+)%?\s+(\d+)\s+(\d+.\d+)\s+(\d+.\d+)\s+(.*?)\s.*?$/) {
if ($line =~ /^\s*(\d+).\s*[|-]+?\s+(([0-9a-f.:\?]+)|(\S+)\s+\(([0-9a-f.:\?]+)\))\s+(\d+.\d+)%?\s+(\d+)\s+(\d+.\d+)\s+(\d+.\d+)\s+(.*?)\s.*?$/) {
my $host_address = $2;
my $latency_value = $6;
my $packet_loss_value = $3;
my $latency_value = $9;
my $packet_loss_value = $6;
my $latency_status = OK;
my $packet_loss_status = OK;
......@@ -113,26 +164,26 @@ sub check
$hop_reachable = 1;
$latency_status = $mp->check_threshold(
check => $latency_value,
warning => $mp->opts->latency_warn,
critical => $mp->opts->latency_crit
warning => $mp->opts->get('latency-warn'),
critical => $mp->opts->get('latency-crit'),
);
$mp->add_perfdata(
label => "latency_$hop_count",
label => "hop_${hop_count}_rta",
value => $latency_value,
warning => $mp->opts->latency_warn,
critical => $mp->opts->latency_crit,
warning => $mp->opts->get('latency-warn'),
critical => $mp->opts->get('latency-crit'),
);
$packet_loss_status = $mp->check_threshold(
check => $packet_loss_value,
warning => $mp->opts->packet_loss_warn,
critical => $mp->opts->packet_loss_crit,
warning => $mp->opts->get('packet-loss-warn'),
critical => $mp->opts->get('packet-loss-crit'),
);
$mp->add_perfdata(
label => "packet_loss_$hop_count",
label => "hop_${hop_count}_pl",
value => $packet_loss_value,
warning => $mp->opts->packet_loss_warn,
critical => $mp->opts->packet_loss_crit,
warning => $mp->opts->get('packet-loss-warn'),
critical => $mp->opts->get('packet-loss-crit'),
);
}
......@@ -181,6 +232,7 @@ sub check
$status_msg = ' <- !!! Unknown !!!';
}
chomp($line);
$line = $line =~ s/\|--//r;
push(@g_long_message, $line.$status_msg);
}
}
......