From 625b767798470b5890cda834767436c1eda12971 Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Wed, 19 Mar 2014 07:01:55 +0000 Subject: [PATCH] get all ips configured on an interface --- gatherer/interface_information.sh | 43 ++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/gatherer/interface_information.sh b/gatherer/interface_information.sh index e8088a5..9eef021 100644 --- a/gatherer/interface_information.sh +++ b/gatherer/interface_information.sh @@ -73,25 +73,34 @@ gather_if_info_ip() { no=r_if_numbers[if_no]; if ($3 == "inet") { split($4,addr,/[\/]/); - print "IF" no "_IPV4=\"${IF" no "_IPV4}" addr[1] " \";"; + ipv4=ipv4 addr[1] " "; network(no, addr[1], addr[2]); classes=classes addr[1] " " } if ($3 == "inet6") { split($4,addr,/[\/]/); - print "IF" no "_IPV6=\"${IF" no "_IPV6}" addr[1] " \";"; + ipv6=ipv6 addr[1] " "; classes=classes addr[1] " " } } + $1 != current_if { + print "IF" no "_IPV4=\"" ipv4 "\";"; + print "IF" no "_IPV6=\"" ipv6 " \";"; + print "IF" no "_NETWORK=\"" net "\";"; + print "IF" no "_MASK=\"" mask "\";"; + current_if=$1; + ipv6=ipv4=""; + } BEGIN { classes=""; sub(/^ */,"",if_numbers); sub(/ *$/,"",if_numbers); - split(if_numbers,tmp_array,/ /) + split(if_numbers,tmp_array,/ /); for(no in tmp_array) { if_no=tmp_array[no]; r_if_numbers[if_no]=no; } + current_if=$1; } END { print "set_class " classes ";" @@ -122,8 +131,8 @@ gather_if_info_ip() { } } classes=classes net " "; - print "IF" no "_NETWORK=\"" net "\"; export " name "_NETWORK;"; - print "IF" no "_MASK=\"" mask "\"; export " name "_MASK;"; + networks=networks net " "; + netmasks=netmasks mask " "; }') } @@ -133,29 +142,39 @@ gather_if_info_ip() { # gather_if_info_ifconfig() { eval $(${IFCONFIG} -a | ${AWK} ' - /ether/ { mac=$2 } - /inet / { ipv4=ipv4 $2 " " } - /inet6/ { ipv6=ipv6 $2 " " } + /ether/ { mac=$2 } + /inet / { ipv4=ipv4 $2 " "; classes=classes $2 " " } /^[^ \t]/ { - if ("" != ipv4 || "" != ipv6) state="UP"; else state="DOWN"; + if ("UP" == state) classes=classes mac " "; if ("" != name) { print "IF" no "_NAME=" name ";IF" no "_STATE=" state ";IF" no "_MAC=" mac ";" \ "IF" no "_IPV4=\"${IF" no "_IPV4}" ipv4 " \";" \ "IF" no "_IPV6=\"${IF" no "_IPV6}" ipv6 " \";"; no++; } - ipv4=ipv6=""; + ipv4=ipv6=mac=""; sub(/:/,"",$1); - name=$1 + name=$1; + state="DOWN"; + } + /inet6/ { + sub(/%.*/,"",$2); + ipv6=ipv6 $2 " "; + classes=classes $2 " " } + (/status/ && /active/) || /^lo[0-9]/ { state="UP" } BEGIN { + classes=""; + state="DOWN"; no=1; + mac=""; } END { - if ("" != ipv4 || "" != ipv6) state="UP"; else state="DOWN"; + if ("UP" == state) classes=classes mac " "; print "IF" no "_NAME=" name ";IF" no "_STATE=" state ";IF" no "_MAC=" mac ";" \ "IF" no "_IPV4=\"${IF" no "_IPV4}" ipv4 " \";" \ "IF" no "_IPV6=\"${IF" no "_IPV6}" ipv6 " \";"; + print "set_class " classes ";"; print "NINTERFACES=" no }') }