python/plugins: adjusted error handling to comply with doc/dev/error-handling.md
import kdb
import socket
-
"""
Usage:
> sudo kdb mount file.ini /python python script=/path/to/dns_plugin.py
@@ -70,7 +69,22 @@ class ElektraDNSPlugin(object):
print(f"Couldn't resolve domain name for key: {k}")
if warning_list:
- parentKey.setMeta("warning", f"Couldn't resolve domain name for key(s): {warning_list}")
+ parentKey.setMeta("warnings", str(len(warning_list)))
+ c = 0
+ for warn_key in warning_list:
+ if c == 100:
+ c = 0
+ if c > 9:
+ index = "#_" + str(c)
+ else:
+ index = "#" + str(c)
+
+ parentKey.setMeta(f"warnings/{index}/number", "101")
+ parentKey.setMeta(f"warnings/{index}/description", "Could not validate key")
+ parentKey.setMeta(f"warnings/{index}/reason", f"Failed to resolve domain name for key {warn_key}")
+ parentKey.setMeta(f"warnings/{index}/module", "python check/dns script")
+ c += 1
+
return -1
return 1
@@ -81,14 +95,15 @@ class ElektraDNSPlugin(object):
# 0 : on success with no changed keys in database
# -1 : failure
"""
- error_list = []
for k in returned:
if not check_key(k):
- error_list.append(k)
- print(f"Couldn't validate key {k}")
+ parentKey.setMeta("error", f"number description reason module")
+ parentKey.setMeta("error/number", "101")
+ parentKey.setMeta("error/description", "Could not validate key")
+ parentKey.setMeta("error/reason", f"Failed to resolve domain name for key {k}")
+ parentKey.setMeta("error/module", "python check/dns script")
- if error_list:
- parentKey.setMeta("error", f"Couldn't resolve domain name for key(s): {error_list}")
+ print(f"Couldn't validate key {k}")
return -1
return 1
