summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruvok cheetah2025-02-02 14:58:44 +0100
committeruvok cheetah2025-02-02 14:58:44 +0100
commit6078935504c752afebefd8e570a6f29f6b05bcdb (patch)
treed46c641beac6db0f20e977a5a6d2d6c07cb48615
parent49f947a17f51253eb8a8dee3dab3687ec45d90f5 (diff)
Various bird stuff (awk)
-rw-r--r--other_scripts/authkey1
-rw-r--r--other_scripts/bgpreport.sh19
-rw-r--r--other_scripts/bird2.awk29
-rw-r--r--other_scripts/birdroutes.awk48
4 files changed, 97 insertions, 0 deletions
diff --git a/other_scripts/authkey b/other_scripts/authkey
new file mode 100644
index 0000000..6f31e1a
--- /dev/null
+++ b/other_scripts/authkey
@@ -0,0 +1 @@
+command="/usr/sbin/birdcl -r s p | /usr/bin/awk -v print_info=0 -v pref='^p_' -f /root/bird.awk"
diff --git a/other_scripts/bgpreport.sh b/other_scripts/bgpreport.sh
new file mode 100644
index 0000000..ae82b0c
--- /dev/null
+++ b/other_scripts/bgpreport.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+echo "<table><tr><th>Peer</th><th>type</th><th>state</th></tr>";
+
+/usr/sbin/birdcl -r s p | while read -r line; do
+ outp=$(echo "$line" | /usr/bin/awk -v print_info=0 -v pref='^p_' -f /root/bird2.awk)
+ if [[ -z "$outp" ]]; then
+ continue
+ fi
+ echo "$outp"
+ protocol=$(echo "$line" | awk -e '{ print $1; }')
+ outp=$(birdcl -r "show route where bgp_large_community ~ [(CLEARNET_ASN, LC_FILTERED, *)] protocol ${protocol} table t_myas_unfiltered count" | grep t_myas_unfiltered | grep -E -o "[1-9][0-9]* of [0-9]+ routes")
+ if [[ -n "$outp" ]]; then
+ echo "<tr><td></td><td colspan='2'>filtered ${outp}</td></tr>"
+ else
+ echo "<tr><td></td><td colspan='2'>no filtered routes</td></tr>"
+ fi
+done
+
+echo "</table>"
diff --git a/other_scripts/bird2.awk b/other_scripts/bird2.awk
new file mode 100644
index 0000000..f61a35c
--- /dev/null
+++ b/other_scripts/bird2.awk
@@ -0,0 +1,29 @@
+# Intended purpose: Pipe birdc s p all into this script - line by line / protocol by protocol
+
+# initialize variable
+BEGIN {
+ if (!pref) {
+ pref="^p_";
+ }
+
+ proto="";
+}
+
+# default output for birdc, filter
+$1=="BIRD" || $1=="Name" {
+ next
+}
+
+# if line begins with dn and is a BGP line
+$0 ~ pref && $2=="BGP" {
+ proto=$1
+ print "<tr><td>" $1 "</td><td>" $2 "</td><td>" $4 "</td></tr>";
+ next
+}
+
+# for every other line "starting" a protocol
+/^[a-zA-Z]/ {
+ # reset proto
+ proto=""
+ next
+}
diff --git a/other_scripts/birdroutes.awk b/other_scripts/birdroutes.awk
new file mode 100644
index 0000000..615917a
--- /dev/null
+++ b/other_scripts/birdroutes.awk
@@ -0,0 +1,48 @@
+# Intended purpose: Pipe birdc s p all into this script
+
+# initialize variable
+BEGIN {
+ if (!pref) {
+ pref="^p_";
+ }
+ if (print_info=="") {
+ print_info=0;
+ }
+
+ proto="";
+ print "<table><tr><th>Peer</th><th>type</th><th>state</th>";
+ if (print_info == 1) {
+ print "<th>Info</th>";
+ }
+ print "</tr>";
+ #rowspan='2'
+# print "<tr><th>imported</th><th>exported</th><th>preferred</th></tr>";
+}
+END {
+ print "</table>";
+}
+
+
+# default output for birdc, filter
+$1=="BIRD" || $1=="Name" {
+ next
+}
+
+# if line begins with dn and is a BGP line
+$0 ~ pref && $2=="BGP" {
+ proto=$1
+ print "<tr><td>" $1 "</td><td>" $2 "</td><td>" $4 "</td>";
+ if (print_info == 1) {
+ print "<td>" $6 "</td>";
+ }
+ print "</tr>";
+ #rowspan='2'
+ next
+}
+
+# for every other line "starting" a protocol
+/^[a-zA-Z]/ {
+ # reset proto
+ proto=""
+ next
+}