diff --git a/wedge/local/lib/check_mk/base/plugins/agent_based/triton_wedge.py b/wedge/local/lib/python3/cmk_addons/plugins/triton_wedge/agent_based/triton_wedge.py similarity index 84% rename from wedge/local/lib/check_mk/base/plugins/agent_based/triton_wedge.py rename to wedge/local/lib/python3/cmk_addons/plugins/triton_wedge/agent_based/triton_wedge.py index d5c966e..74c9c49 100644 --- a/wedge/local/lib/check_mk/base/plugins/agent_based/triton_wedge.py +++ b/wedge/local/lib/python3/cmk_addons/plugins/triton_wedge/agent_based/triton_wedge.py @@ -3,7 +3,7 @@ # Parses and checks external VM IPs. import json -from cmk.base.plugins.agent_based.agent_based_api.v1 import register, Result, Service, State +from cmk.agent_based.v2 import Result, Service, State, CheckPlugin, AgentSection def parse_triton_wedge(string_table): @@ -18,7 +18,7 @@ def parse_triton_wedge(string_table): return lookup -register.agent_section( +agent_section_triton_wedge = AgentSection( name="triton_wedge", parse_function=parse_triton_wedge ) @@ -51,14 +51,13 @@ def check_triton_wedge(item, params, section): yield Result(state=State.WARN, summary=summary) else: lst = ", ".join(map(lambda vm: "VM %s (%s)" % (vm["vm"], vm["ip"]), wedged_vms)) - yield Result(state=State.CRIT, summary=f"Likely wedged detected for {lst}") + yield Result(state=State.CRIT, summary=f"Likely wedge detected for {lst}") -register.check_plugin( +check_plugin_triton_wedge = CheckPlugin( name="triton_wedge", service_name="Triton Wedge CN %s", discovery_function=discover_triton_wedge, check_function=check_triton_wedge, check_default_parameters={}, - check_ruleset_name="triton_wedge", ) diff --git a/wedge/local/share/check_mk/agents/special/agent_triton_wedge b/wedge/local/lib/python3/cmk_addons/plugins/triton_wedge/libexec/agent_triton_wedge similarity index 96% rename from wedge/local/share/check_mk/agents/special/agent_triton_wedge rename to wedge/local/lib/python3/cmk_addons/plugins/triton_wedge/libexec/agent_triton_wedge index 3d7cbb2..5da84b6 100755 --- a/wedge/local/share/check_mk/agents/special/agent_triton_wedge +++ b/wedge/local/lib/python3/cmk_addons/plugins/triton_wedge/libexec/agent_triton_wedge @@ -8,14 +8,15 @@ PORT_RANGE_END = 57128 CONNECT_RETRIES = 3 CHECK_REMOTE_PORTS = [443, 80] CONCURRENT_SCANS = 200 +NAPI_TIMEOUT = 10 # seconds import urllib.request, sys, argparse, asyncio, json, socket, errno -def get_url(url): +def get_url(url, timeout=None): request = urllib.request.Request(url) - with urllib.request.urlopen(request) as conn: + with urllib.request.urlopen(request, timeout=timeout) as conn: data = conn.read() return data @@ -24,7 +25,7 @@ def get_url(url): def query_napi(addr): url = 'http://%s/nics?nic_tag=external&belongs_to_type=zone&state=running' % addr try: - json_data = get_url(url) + json_data = get_url(url, NAPI_TIMEOUT) nics = json.loads(json_data) return nics except urllib.error.HTTPError as e: diff --git a/wedge/local/lib/python3/cmk_addons/plugins/triton_wedge/rulesets/triton_wedge.py b/wedge/local/lib/python3/cmk_addons/plugins/triton_wedge/rulesets/triton_wedge.py new file mode 100644 index 0000000..975d40b --- /dev/null +++ b/wedge/local/lib/python3/cmk_addons/plugins/triton_wedge/rulesets/triton_wedge.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +# +# GUI config page for triton_wedge. + +from cmk.rulesets.v1.form_specs.validators import LengthInRange +from cmk.rulesets.v1.form_specs import Dictionary, DictElement, String +from cmk.rulesets.v1.rule_specs import SpecialAgent, Topic, Title, Help + +def _formspec(): + return Dictionary( + title=Title("Triton Wedge Detection"), + elements={ + "instance": DictElement( + parameter_form=String( + title=Title("Hostname"), + help_text=Help("Hostname or IP of NAPI to query"), + custom_validate=(LengthInRange(min_value=1),), + ), + required=True + ) + } + ) + +rule_spec_agent_config_triton_wedge = SpecialAgent( + topic=Topic.NETWORKING, + name="triton_wedge", + title=Title("Triton Wedge Detector"), + parameter_form=_formspec, + +) diff --git a/wedge/local/lib/python3/cmk_addons/plugins/triton_wedge/server_side_calls/special_agent.py b/wedge/local/lib/python3/cmk_addons/plugins/triton_wedge/server_side_calls/special_agent.py new file mode 100644 index 0000000..2da8053 --- /dev/null +++ b/wedge/local/lib/python3/cmk_addons/plugins/triton_wedge/server_side_calls/special_agent.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 + + +from cmk.server_side_calls.v1 import noop_parser, SpecialAgentConfig, SpecialAgentCommand + +def _agent_arguments(params, host_config): + yield SpecialAgentCommand(command_arguments=[params["instance"]]) + +special_agent_triton_wedge = SpecialAgentConfig( + name="triton_wedge", + parameter_parser=noop_parser, + commands_function=_agent_arguments, +) + + diff --git a/wedge/local/share/check_mk/checks/agent_triton_wedge b/wedge/local/share/check_mk/checks/agent_triton_wedge deleted file mode 100644 index 2cfe785..0000000 --- a/wedge/local/share/check_mk/checks/agent_triton_wedge +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python3 - - -def agent_triton_wedge(params, hostname, ipaddress): - return [params["instance"]] - -special_agent_info["triton_wedge"] = agent_triton_wedge diff --git a/wedge/local/share/check_mk/web/plugins/wato/triton_wedge.py b/wedge/local/share/check_mk/web/plugins/wato/triton_wedge.py deleted file mode 100644 index f734e27..0000000 --- a/wedge/local/share/check_mk/web/plugins/wato/triton_wedge.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python3 -# -# GUI config page for triton_wedge. - -from cmk.gui.i18n import _ -from cmk.gui.plugins.wato.utils import ( - rulespec_registry, - HostRulespec, - RulespecGroupCheckParametersHardware -) -from cmk.gui.watolib.rulespecs import Rulespec -from cmk.gui.valuespec import ( - Dictionary, - Hostname, -) - - -def _valuespec_special_agents_triton_wedge(): - return Dictionary( - title=_("Triton Wedge Detection"), - help=_(""), - elements=[ - ( - "instance", - Hostname( - title=_("Hostname"), - help=_("Hostname or IP of NAPI to query"), - allow_empty=False, - ), - ), - ], - ) - - -rulespec_registry.register( - HostRulespec( - factory_default=Rulespec.FACTORY_DEFAULT_UNUSED, - name="special_agents:triton_wedge", - group=RulespecGroupCheckParametersHardware, - valuespec=_valuespec_special_agents_triton_wedge, - ) -) diff --git a/wedge/triton_wedge-0.1.0.mkp b/wedge/triton_wedge-0.1.0.mkp deleted file mode 100755 index e6bd128..0000000 Binary files a/wedge/triton_wedge-0.1.0.mkp and /dev/null differ diff --git a/wedge/triton_wedge-0.2.0.mkp b/wedge/triton_wedge-0.2.0.mkp new file mode 100755 index 0000000..9ecd718 Binary files /dev/null and b/wedge/triton_wedge-0.2.0.mkp differ