Have been looking at running a script that creates config for Nagios based on the shell command "route -n" now that my route tables are controlled by quagga/bgp/zebra. Awk is my friend ...
Bit of script stuff to find pingable ips on Air-Stream...
route -n | awk '{print($1" " $3)}' | awk '!a[$0]++' | awk '{print("ipcalc "$1"/"$2)}' | sh | awk '{if ($1 == "Network:") print($2)}' | awk '{print("nmap -sP "$0)}' | sh
...and a bit more to parse out the important Nagios bits from (tcp)traceroute output...
cat ip_trace_routes_break_21_6_09 | awk '{
i = 0;
while ($1 != "break") { arr[$1] = $2; getline; i++; }
if (i < 30) if (i > 1) print (arr[i]" "arr[i-1]);else print (arr[i]);
}' | awk '{
if ( $1 != $2 ) if ( $2 != "" ) if ( $2 != "*" ) if ( $1 != "*" ) print($0);
}' | awk ' BEGIN {
print("define host {\nuse linux-server\nhost_name 10.122.128.3\nalias 10.122.128.3\naddress 10.122.128.3\n}\n")
print("define host {\nuse linux-server\nhost_name 10.122.128.1\nalias 10.122.128.1\naddress 10.122.128.1\nparents 10.122.128.3\n}\n")
}
{ print("define host {\nuse linux-server\nhost_name "$1"\nalias "$1"\naddress "$1"\nparents "$2"\n}\n");
}'
Still very "alpha" :-)
PS:Basically "while ($1 != "break") { arr[$1] = $2; getline; i++; } if (i < 30) if (i > 1) print (arr[i]" "arr[i-1]);else print (arr[i]);" is the engine, the rest is just fixing the "alpha" LOL. Perfectly redundent input created okay localhost.cfg as by /etc/init.d/nagios checkconfig - promising!
