Skip to content

Commit

Permalink
Merge pull request freddy36#16 from HeinleinSupport/cmk2.2
Browse files Browse the repository at this point in the history
BIRD extension for Checkmk 2.2
  • Loading branch information
freddy36 authored Jan 23, 2024
2 parents 0601d26 + 30e64de commit 75c4100
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
Binary file removed bird/bird-4.5.mkp
Binary file not shown.
Binary file added bird/bird-4.9.0.mkp
Binary file not shown.
38 changes: 17 additions & 21 deletions bird/lib/check_mk/base/plugins/agent_based/bird.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@
import time
import datetime

from cmk.utils import debug
from pprint import pprint

_bird_status_default_levels = {
"uptime_low_threshold": 300,
"config_file_min_age": 60,
Expand All @@ -128,7 +125,7 @@

def _bird_strptime(string):
# bird uses different time formats depending on the version/settings
for f in ['%d-%m-%Y %H:%M:%S', '%Y-%m-%d %H:%M:%S']:
for f in ['%d-%m-%Y %H:%M:%S.%f', '%Y-%m-%d %H:%M:%S.%f', '%d-%m-%Y %H:%M:%S', '%Y-%m-%d %H:%M:%S']:
try:
return datetime.datetime.strptime(string, f)
except ValueError:
Expand All @@ -137,7 +134,7 @@ def _bird_strptime(string):

def _bird_si_to_int(value, unit):
_prefix = {'': 1, 'k': 1024, 'M': 1048576, 'G': 1073741824}
return int(value) * _prefix[unit.rstrip('B')]
return int(float(value) * _prefix[unit.rstrip('B')])

def _bird_x_to_key(value):
return "_".join(value).rstrip(':')
Expand Down Expand Up @@ -173,9 +170,14 @@ def parse_bird(string_table):
elif code == 1018:
if line[-1][-1] == 'B': # ignore lines which don't end vith B (not memory stats)
memory = section.setdefault('memory', [])
name = " ".join(line[1:-2]).rstrip(":")
value_text = " ".join(line[-2:])
value_bytes = _bird_si_to_int(line[-2], line[-1])
split_index = next(filter(lambda i: ':' in line[i], range(1, len(line))))
name = " ".join(line[1:split_index+1]).rstrip(":")
if split_index == len(line) - 5:
value_text = "E={} {}; O={} {}".format(*line[-4:])
value_bytes = _bird_si_to_int(line[-4], line[-3]) + _bird_si_to_int(line[-2], line[-1])
else:
value_text = " ".join(line[split_index+1:])
value_bytes = _bird_si_to_int(line[-2], line[-1])
memory.append((name, value_text, value_bytes))
elif code == 1002:
protocols = section.setdefault('protocols', {})
Expand All @@ -194,17 +196,17 @@ def parse_bird(string_table):
last_protocol['description'] = " ".join(line[2:])
if line[1] == "Preference:":
last_protocol['preference'] = line[2]
elif line[2] == "filter:":
elif len(line) >= 3 and line[2] == "filter:":
key = _bird_x_to_key(line[1:3])
last_protocol[key] = " ".join(line[3:])
elif line[2] == "limit:" and line[1] != 'Route':
elif len(line) >= 3 and line[2] == "limit:" and line[1] != 'Route':
limits = last_protocol.setdefault('limits', {})
last_limit = limits[line[1]] = {}
last_limit['value'] = int(line[3])
last_limit['hit'] = (len(line) >= 5 and line[4] == "[HIT]")
elif line[1] == "Action:":
last_limit['action'] = line[2]
elif line[2] == "limit:" and line[1] == 'Route': # legacy "route limit" option
elif len(line) >= 3 and line[2] == "limit:" and line[1] == 'Route': # legacy "route limit" option
limits = last_protocol.setdefault('limits', {})
if 'Import' in limits:
continue # ignore in case we already have a import limit
Expand Down Expand Up @@ -254,10 +256,9 @@ def parse_bird(string_table):

def discover_bird_status(section) -> DiscoveryResult:
if 'status' in section: # bird is running
yield Service(parameters=section)
yield Service()

def check_bird_status(params, section) -> CheckResult:
# params is a snapshot of the parsed data at the point of time of inventory
if 'error' in section:
yield Result(state=State.CRIT,
summary="ERROR: "+section['error'])
Expand Down Expand Up @@ -306,10 +307,9 @@ def check_bird_status(params, section) -> CheckResult:

def discover_bird_memory(section) -> DiscoveryResult:
if 'memory' in section: # bird is running
yield Service(parameters=section)
yield Service()

def check_bird_memory(params, section) -> CheckResult:
# params is a snapshot of the parsed data at the point of time of inventory
if 'error' in section:
yield Result(state=State.CRIT,
summary="ERROR: "+section['error'])
Expand All @@ -319,7 +319,7 @@ def check_bird_memory(params, section) -> CheckResult:
summary="No memory data available")
return
for name, value_text, value_bytes in section['memory']:
key = name.replace(" ", "_")
key = name.replace(" ", "_").split(":")[0] # memory part wasn't parsed correctly, quick fix
warn, crit = params.get('memory_levels_'+key, (None, None))
yield from check_levels(value_bytes,
levels_upper=(warn, crit),
Expand All @@ -328,14 +328,10 @@ def check_bird_memory(params, section) -> CheckResult:
label=name)

def discover_bird_protocols(section) -> DiscoveryResult:
if debug.enabled():
pprint(section)
for protocol in section.get('protocols', {}):
yield Service(item=protocol, parameters=section)
yield Service(item=protocol, parameters={'protocols': { protocol: section['protocols'][protocol] }})

def check_bird_protocols(item, params, section) -> CheckResult:
# params is a snapshot of the parsed data at the point of time of inventory

this_time = time.time()
if 'error' in section:
yield Result(state=State.CRIT,
Expand Down
4 changes: 2 additions & 2 deletions bird/web/plugins/perfometer/bird.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#
# Copyright 2014 by Frederik Kriewitz <[email protected]>.

from cmk.gui.plugins.views.perfometers.check_mk import perfometer_check_mk_uptime
from cmk.gui.plugins.views.perfometers import perfometer_logarithmic
from cmk.gui.views.perfometer.legacy_perfometers.check_mk import perfometer_check_mk_uptime
from cmk.gui.views.perfometer.legacy_perfometers.utils import perfometer_logarithmic

perfometers["check_mk-bird_status"] = perfometer_check_mk_uptime
perfometers["check_mk-bird6_status"] = perfometer_check_mk_uptime
Expand Down

0 comments on commit 75c4100

Please sign in to comment.