SCO-242 - update triton_wedge plugin to CheckMK's v2 API (optional in CheckMK 2.3.0, but mandatory in 2.4.0).
This commit is contained in:
parent
133224ed27
commit
34a51e5c79
@ -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",
|
||||
)
|
@ -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:
|
@ -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,
|
||||
|
||||
)
|
@ -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,
|
||||
)
|
||||
|
||||
|
@ -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
|
@ -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,
|
||||
)
|
||||
)
|
Binary file not shown.
BIN
wedge/triton_wedge-0.2.0.mkp
Executable file
BIN
wedge/triton_wedge-0.2.0.mkp
Executable file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user