diff --git a/README.md b/README.md index ebc2514020f7041d5ee6267c3aa16c22583ff9f9..3b26bb438560da8adbf16fcab85c50f2c8394c3b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[PACKAGE]: ../../raw/master/mkp/unbound-1.2.2-20240521.mkp "unbound-1.2.2-20240521.mkp" +[PACKAGE]: ../../raw/master/mkp/unbound-1.2.3-20240521.mkp "unbound-1.2.3-20240521.mkp" # unbound This agent plugin cheks the state of the unbound dns daemon. For more information about unbound see: https://nlnetlabs.nl/projects/unbound/about/ diff --git a/mkp/unbound-1.2.3-20240521.mkp b/mkp/unbound-1.2.3-20240521.mkp new file mode 100644 index 0000000000000000000000000000000000000000..f3c0581a6f57039e9de08884ec61a10714828a09 Binary files /dev/null and b/mkp/unbound-1.2.3-20240521.mkp differ diff --git a/source/agent_based/unbound_status.py b/source/agent_based/unbound_status.py new file mode 100644 index 0000000000000000000000000000000000000000..7ced922daba226ab6a4750bf2a8991c639a9092d --- /dev/null +++ b/source/agent_based/unbound_status.py @@ -0,0 +1,136 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# License: GNU General Public License v2 +# +# Author: thl-cmk[at]outlook[dot]com +# URL : https://thl-cmk.hopto.org +# Date : 2024-05-21 +# File : unbound_status.py + +from dataclasses import dataclass + +from typing import ( + Any, + Mapping, + Sequence +) + +from cmk.utils import debug +from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( + CheckResult, + DiscoveryResult, + StringTable, +) + +from cmk.base.plugins.agent_based.agent_based_api.v1 import ( + Service, + check_levels, + register, + render, + Result, + State, +) + + +@dataclass(frozen=True) +class UnboundStatus: + version: str + verbosity: int + threads: int + modules: Sequence[str] + uptime: int + options: Sequence[str] + status: str + pid: int + + @classmethod + def parse(cls, string_table: StringTable): + for line in string_table: + key, value = line[0].split(' ', 1) + key = key.rstrip(':') + match key: + case 'version': + version = str(value) + case 'verbosity': + verbosity = int(value) + case 'threads': + threads = int(value) + case 'modules': + # 3 [ subnet validator iterator ] + modules = value.split(' [ ')[-1].strip(']').strip(' ').split(' ') + case 'uptime': + # 577 seconds + uptime = int(value.split(' ')[0]) + case 'options': + # reuseport control(ssl) + options = value.split(' ') + case 'unbound': + # (pid 520) is running... + pid = int(value.split(') ')[0].replace('(pid ', '')) + status = value.split(') ', -1)[-1].strip('.') + case _: + pass + + try: + return cls( + version=version, + verbosity=verbosity, + threads=threads, + modules=modules, + uptime=uptime, + options=options, + pid=pid, + status=status, + ) + except NameError as e: + if debug.enabled: + print(f'name error {e}') + return + + +def parse_unbound_status(string_table: StringTable) -> UnboundStatus | None: + return UnboundStatus.parse(string_table) + + +register.agent_section( + name="unbound_status", + parse_function=parse_unbound_status, +) + + +def discover_unbound_status(section: UnboundStatus) -> DiscoveryResult: + yield Service() + + +# UnboundStatus( +# version='1.13.1', +# verbosity=0, +# threads=1, +# modules=['subnet', 'validator', 'iterator'], +# uptime=1759, +# options=['reuseport', 'control(ssl)'], +# status='(pid 520) is running', +# pid=520 +# ) +def check_unbound_status(params: Mapping[str, Any], section: UnboundStatus, ) -> CheckResult: + yield Result(state=State.OK, summary=f'Status: {section.status}') + yield from check_levels( + value=section.uptime, + label='Uptime', + metric_name='uptime', + render_func=render.timespan + ) + yield Result(state=State.OK, summary=f'Version: {section.version}') + + +register.check_plugin( + name="unbound_status", + service_name="Unbound", + discovery_function=discover_unbound_status, + check_function=check_unbound_status, + check_default_parameters={}, + check_ruleset_name="unbound_status", +) + + diff --git a/source/agents/plugins/unbound b/source/agents/plugins/unbound index 0d77bf11841119c22aaaca2ea9c26e63bbdcc288..badb21e60e134f357c0e4438fc438b7ead92c080 100755 --- a/source/agents/plugins/unbound +++ b/source/agents/plugins/unbound @@ -13,4 +13,7 @@ if [ -f "$(which unbound-control)" ]; then echo '<<<unbound:sep(61)>>>' unbound-control stats_noreset -c $UNBOUND_CFG echo '<<<>>>' + echo '<<<unbound_status:sep(0)>>>' + unbound-control status -c $UNBOUND_CFG + echo '<<<>>>' fi diff --git a/source/packages/unbound b/source/packages/unbound index 087be7f33ca6601c9045461237b3c83f2d9fd9dd..457cef7311df1d0161772c3aba5c08d240fe5887 100644 --- a/source/packages/unbound +++ b/source/packages/unbound @@ -7,7 +7,7 @@ ' server:\n' ' extended-statistics: yes\n', 'download_url': 'https://github.com/PLUTEX/checkmk-unbound/', - 'files': {'agent_based': ['unbound.py'], + 'files': {'agent_based': ['unbound.py', 'unbound_status.py'], 'agents': ['plugins/unbound'], 'gui': ['metrics/unbound.py', 'wato/check_parameters/unbound.py', @@ -15,7 +15,7 @@ 'lib': ['python3/cmk/base/cee/plugins/bakery/unbound.py']}, 'name': 'unbound', 'title': 'Unbound', - 'version': '1.2.2-20240521', + 'version': '1.2.3-20240521', 'version.min_required': '2.2.0b1', 'version.packaged': '2.2.0p24', 'version.usable_until': None}