From 28bc57c258c2df432ce408c75a625064a84eb44f Mon Sep 17 00:00:00 2001
From: thl-cmk <thl-cmk@outlook.com>
Date: Mon, 20 Feb 2023 18:07:25 +0000
Subject: [PATCH] fix crash if metric data is None (backport from cmk 2.1
 version)

---
 agent_based/bgp_peer.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/agent_based/bgp_peer.py b/agent_based/bgp_peer.py
index 0427531..804bda1 100644
--- a/agent_based/bgp_peer.py
+++ b/agent_based/bgp_peer.py
@@ -28,6 +28,7 @@
 # 2022-09-11: optimized internal flow: > alias > not found > admin down > peer state > ...
 # 2023-01-21: changed to always yield fsm_established_time (not only if beep connects, but also on all other states)
 # 2023-01-22: fix output for admin_state
+# 2023-02-20: fix crash if metric data is None
 #
 
 # Example Agent Output:
@@ -206,7 +207,8 @@ def check_bgp_peer(item, params, section: Dict[str, BgpPeer]) -> CheckResult:
 
     for entry in peer.metric_count:
         key, value = entry
-        yield Metric(name=f'bgp_peer_{key}', value=value, boundaries=(0, None))
+        if value id not None:
+            yield Metric(name=f'bgp_peer_{key}', value=value, boundaries=(0, None))
 
 
 register.snmp_section(
-- 
GitLab