Skip to content

Instantly share code, notes, and snippets.

@bldewolf
Created June 10, 2011 19:31
Show Gist options
  • Save bldewolf/1019589 to your computer and use it in GitHub Desktop.
Save bldewolf/1019589 to your computer and use it in GitHub Desktop.
traceroute output to smokeping config converter
#!/usr/bin/perl
use strict;
use warnings;
my @s;
my $hop = 0;
while(<>) {
chomp;
# Match lines without hosts. Example:
# 12 * * *
next if(/^ ?\d+ \* \* \*$/);
# Match a successful hop
if(/^ ?\d+ (\S+) \((\S+)\)/) {
my $fqdn = $1;
my $ip = $2;
# Skip hosts on our lan
next if($ip =~ /^192\.168\./);
# Count hops that we like
$hop++;
# Generate a shortname, smokeping doesn't like dots in names
my $name = $fqdn;
$name =~ s/\./_/g;
# Change the +'s to suit your desired depth
push @s, sprintf "++ %s\n\nmenu = Hop %d\ntitle = %s\nhost = %s\n\n",
$name, $hop, $fqdn, $ip;
}
}
# Reversing means farthest is listed first
foreach (reverse @s) {
print $_;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment