Module: check_mk
Branch: master
Commit: 65de1b164ee1d10867880a9da44d8152f81c39b6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=65de1b164ee1d1…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Apr 16 20:22:47 2019 +0200
Wow, second potential bug found by adding some simple type hints
Change-Id: I79235a35bb6175efe8de0045fee071c5aaf9418d
---
cmk_base/snmp.py | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/cmk_base/snmp.py b/cmk_base/snmp.py
index eea24fc..60c42c2 100644
--- a/cmk_base/snmp.py
+++ b/cmk_base/snmp.py
@@ -147,10 +147,16 @@ def create_snmp_host_config(hostname):
# type: (str) -> cmk_base.snmp_utils.SNMPHostConfig
host_config = config.get_config_cache().get_host_config(hostname)
- return cmk_base.snmp_utils.SNMPHostConfig(
+ # ip_lookup.lookup_ipv4_address() returns Optional[str] in general, but for
+ # all cases that reach the code here we seem to have "str".
+ address = ip_lookup.lookup_ip_address(hostname)
+ if address is None:
+ raise MKGeneralException("Failed to gather IP address of %s" %
hostname)
+
+ return cmk_base.snmp_utils.SNMPHostConfig( # type: ignore
is_ipv6_primary=host_config.is_ipv6_primary,
hostname=hostname,
- ipaddress=ip_lookup.lookup_ipv4_address(hostname),
+ ipaddress=address,
credentials=config.snmp_credentials_of(hostname),
port=config.snmp_port_of(hostname),
is_bulkwalk_host=config.is_bulkwalk_host(hostname),