Created
June 10, 2011 19:31
-
-
Save bldewolf/1019589 to your computer and use it in GitHub Desktop.
traceroute output to smokeping config converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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