Browse Source

Icinga2: Add options to check_bird_bgp, to ignore some sessions being down.

  check_bird_bgp now supports the following new command line paramters:

    --sessions_down_ok LIST
                          List of sessions which are OK to be down. Provide a
                          space separated list.
    --sessions_down_ok_file FILENAME
                          List of sessions which are OK to be down. Provide one
                          interfaces per line.
    --ignore_missing_file
                          Ignore a possible non-existent file given as

Signed-off-by: Maximilian Wilhelm <max@rfc2324.org>
Maximilian Wilhelm 6 years ago
parent
commit
78ae45f021
3 changed files with 49 additions and 0 deletions
  1. 7 0
      icinga2/commands.d/network.conf
  2. 38 0
      icinga2/plugins/check_bird_bgp
  3. 4 0
      icinga2/services/network.conf

+ 7 - 0
icinga2/commands.d/network.conf

@@ -56,6 +56,13 @@ object CheckCommand "bird_bgp" {
 		"--disabled_ok" = {		# Treat sessions disabled in bird as OK.
 			set_if = "$disabled_ok$"
 		}
+		"--sessions_down_ok" = "$sessions_down_ok$"
+						# List of sessions which are OK to be down. (Space separated list)
+		"--sessions_down_ok_file" = "$sessions_down_ok_file$"
+						# List of sessions which are OK to be down. (One per line)
+		"--ignore_missing_file" = {	# Ignore a possible non-existent file given as --sessions_down_ok_file
+			set_if = "$ignore_missing_file$"
+		}
 	}
 
 	vars.proto = "4"

+ 38 - 0
icinga2/plugins/check_bird_bgp

@@ -7,10 +7,32 @@
 #
 
 import argparse
+import os
 import re
 import subprocess
 import sys
 
+
+def read_sessions_from_file (file_path, missing_ok):
+	sessions = []
+
+	# If we shouldn't care, we won't care if it's not there.
+	if not os.path.isfile (file_path) and missing_ok:
+		return sessions
+
+	try:
+		with open (args.sessions_down_ok_file, 'r') as ido_fh:
+			for session in ido_fh.readlines ():
+				if not session.startswith ('#'):
+					sessions.append (session.strip ())
+
+	except IOError as (errno, strerror):
+		print "Failed to read sessions_down_ok from '%s': %s" % (args.sessions_down_ok_file, strerror)
+		sys.exit (1)
+
+	return sessions
+
+
 parser = argparse.ArgumentParser (description = 'check bird iBGP sessions')
 
 parser.add_argument ('--proto', '-p', help = 'IP protocol version to check', default = '4', choices = ['4', '6'])
@@ -22,6 +44,10 @@ parser.add_argument ('--ebgp', '-e', help = "Check eBGP sessions", action = 'sto
 parser.add_argument ('--ebgp_w', help = "Warning interval for down eBGP sessions", default = "1:1", metavar = "RANGE")
 parser.add_argument ('--ebgp_c', help = "Critical interval for down eBGP sessions", default = "2:", metavar = "RANGE")
 parser.add_argument ('--disabled_ok', help = "Treat sessions disabled in bird as OK.", action = 'store_true')
+parser.add_argument ('--sessions_down_ok', metavar = "LIST", help = "List of sessions which are OK to be down. Provide a space separated list.")
+parser.add_argument ('--sessions_down_ok_file', metavar = "FILENAME", help = "List of sessions which are OK to be down. Provide one interfaces per line.")
+parser.add_argument ('--ignore_missing_file', help = "Ignore a possible non-existent file given as --interfaces_down_ok_file", action = 'store_true')
+
 
 args = parser.parse_args ()
 
@@ -35,6 +61,14 @@ session_down_codes = {
 	'c' : 2,
 }
 
+# Are some sessions ok being down?
+sessions_down_ok = []
+if args.sessions_down_ok:
+	sessions_down_ok = args.sessions_down_ok.split ()
+
+if args.sessions_down_ok_file:
+	sessions_down_ok.extend (read_sessions_from_file (args.sessions_down_ok_file, args.ignore_missing_file))
+
 ################################################################################
 #                         Query BGP protocols from bird                        #
 ################################################################################
@@ -212,6 +246,10 @@ for protoname, config in sorted (bgp_sessions.items ()):
 	elif bgp_state == 'Down' and args.disabled_ok:
 		up.append (session_desc + " (Disabled)")
 
+	# Session down but in session_down_ok* list
+	elif protoname in sessions_down_ok:
+		up.append (session_desc + " (Down/OK)")
+
 	# Something's broken
 	else:
 		last_error = 'Disabled' if bgp_state == 'Down' else config.get ('Last error', 'unkown')

+ 4 - 0
icinga2/services/network.conf

@@ -109,6 +109,8 @@ apply Service "bird_ibgp4" {
 	vars.ibgp_c = "2:"
 	vars.asn = 65132
 	vars.proto = "4"
+	vars.sessions_down_ok_file = "/etc/icinga2/ffho-conf.d/bird_ibgp_sessions_down_ok.txt"
+	vars.ignore_missing_file = true
 
 	assign where host.address && host.vars.os == "Linux" && "router" in host.vars.roles
 }
@@ -127,6 +129,8 @@ apply Service "bird_ibgp6" {
 	vars.ibgp_c = "2:"
 	vars.asn = 65132
 	vars.proto = "6"
+	vars.sessions_down_ok_file = "/etc/icinga2/ffho-conf.d/bird_ibgp_sessions_down_ok.txt"
+	vars.ignore_missing_file = true
 
 	assign where host.address && host.vars.os == "Linux" && "router" in host.vars.roles
 }