Munin plugin written in shell designed to graph BGP routes
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

87 Zeilen
2.8KB

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