Browse Source

Adding the script

master
Alarig Le Lay 1 year ago
parent
commit
cd3f036961
1 changed files with 86 additions and 0 deletions
  1. 86
    0
      bird_

+ 86
- 0
bird_ View File

@@ -0,0 +1,86 @@
1
+#!/bin/sh
2
+
3
+# Copyright 2017 alarig <alarig@grifon.fr>
4
+# Copyright 2017 petrus <petrus@grifon.fr>
5
+#
6
+# BSD-3-Clause licence
7
+#
8
+# Redistribution and use in source and binary forms, with or without
9
+# modification, are permitted provided that the following conditions are met:
10
+#
11
+# 1. Redistributions of source code must retain the above copyright notice,
12
+# this list of conditions and the following disclaimer.
13
+#
14
+# 2. Redistributions in binary form must reproduce the above copyright notice,
15
+# this list of conditions and the following disclaimer in the documentation
16
+# and/or other materials provided with the distribution.
17
+#
18
+# 3. Neither the name of the copyright holder nor the names of its contributors
19
+# may be used to endorse or promote products derived from this software without
20
+# specific prior written permission.
21
+#
22
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+# POSSIBILITY OF SUCH DAMAGE.
33
+
34
+config() {
35
+	local proto=$1
36
+	local type=$2
37
+	local line=$3
38
+
39
+	printf "${proto}_${type}.label ${proto}_${type}\n"
40
+	printf "${proto}_${type}.draw LINE${line}\n"
41
+}
42
+
43
+draw() {
44
+	local proto=$1
45
+	local type=$2
46
+
47
+	printf "${proto}_${type}.value "
48
+#	$birdc show protocols all $proto | awk "/Routes:/ { print $field }";
49
+	nbroutes="$($birdc show protocols all $proto | grep 'Routes:' | \
50
+		sed -Ee '/'$type'/{ s/^.* ([0-9]+) '$type'.*$/\1/; p;}' -e d)"
51
+	if [ "$nbroutes" = "" ]; then
52
+		printf "0\n"
53
+	else
54
+		printf "$nbroutes\n"
55
+	fi
56
+}
57
+
58
+if [ "${0#*_}" = 'v4' ]; then
59
+        version='IPv4'
60
+        birdc='birdc'
61
+elif [ "${0#*_}" = 'v6' ]; then
62
+        version='IPv6'
63
+        birdc='birdc6'
64
+else
65
+	exit 1;
66
+fi
67
+
68
+if [ "$1" = "config" ]; then
69
+        echo "graph_title bird $version routes and neighbors"
70
+        echo 'graph_args -l 0'
71
+        echo 'graph_category Network'
72
+        echo 'graph_scale no'
73
+        for proto in $($birdc show protocols | awk 'NR > 2 { print $1 }'); do
74
+		config ${proto} imported 1;
75
+		config ${proto} filtered 1;
76
+		config ${proto} exported 1;
77
+		config ${proto} preferred 2;
78
+        done
79
+        exit 0
80
+fi
81
+for proto in $($birdc show protocols | awk 'NR > 2 { print $1 }'); do
82
+	draw ${proto} imported;
83
+	draw ${proto} filtered;
84
+	draw ${proto} exported;
85
+	draw ${proto} preferred;
86
+done

Loading…
Cancel
Save