Port ScalityRing to CheckMK 2.4.
This commit is contained in:
parent
df4ae026e9
commit
fbc07dbbfd
@ -0,0 +1,206 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (C) 2025 Spearhead Systems SRL
|
||||||
|
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
|
||||||
|
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
|
||||||
|
# conditions defined in the file COPYING, which is part of this source code package.
|
||||||
|
|
||||||
|
|
||||||
|
from cmk.agent_based.v2 import (
|
||||||
|
Result,
|
||||||
|
Metric,
|
||||||
|
Service,
|
||||||
|
State,
|
||||||
|
CheckPlugin,
|
||||||
|
SNMPTree,
|
||||||
|
SNMPSection,
|
||||||
|
contains,
|
||||||
|
get_value_store,
|
||||||
|
)
|
||||||
|
from cmk.plugins.lib.df import (
|
||||||
|
df_check_filesystem_single,
|
||||||
|
FILESYSTEM_DEFAULT_PARAMS,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def check_scality_disks(item, params, section):
|
||||||
|
data = section["rings"].get(item)
|
||||||
|
if not data:
|
||||||
|
return
|
||||||
|
|
||||||
|
ringdisktotal = data["disks"]
|
||||||
|
yield Metric("disks", ringdisktotal)
|
||||||
|
|
||||||
|
if not params:
|
||||||
|
yield Result(state=State.OK, summary=f"Number of disks: {ringdisktotal}")
|
||||||
|
return
|
||||||
|
|
||||||
|
warn = params["warn"]
|
||||||
|
crit = params["crit"]
|
||||||
|
infotext = f"Number of disks: {ringdisktotal}. "
|
||||||
|
|
||||||
|
if ringdisktotal <= crit:
|
||||||
|
infotext += f"This is lower or equal to {crit} (critical level)"
|
||||||
|
yield Result(state=State.CRIT, summary=infotext)
|
||||||
|
elif ringdisktotal <= warn:
|
||||||
|
infotext += f"This is lower or equal to {warn} (warning level)"
|
||||||
|
yield Result(state=State.WARN, summary=infotext)
|
||||||
|
else:
|
||||||
|
yield Result(state=State.OK, summary=infotext)
|
||||||
|
|
||||||
|
|
||||||
|
def check_scality_storages(item, params, section):
|
||||||
|
data = section["rings"].get(item)
|
||||||
|
if not data:
|
||||||
|
return
|
||||||
|
|
||||||
|
yield from df_check_filesystem_single(
|
||||||
|
value_store = get_value_store(),
|
||||||
|
mountpoint = item,
|
||||||
|
filesystem_size = data["avail_storage"],
|
||||||
|
free_space = data["total_storage"],
|
||||||
|
reserved_space = 0,
|
||||||
|
inodes_total = None,
|
||||||
|
inodes_avail = None,
|
||||||
|
params = params,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def check_scality_states(item, params, section):
|
||||||
|
data = section["rings"].get(item)
|
||||||
|
if not data:
|
||||||
|
return
|
||||||
|
|
||||||
|
ringstate = data["state"]
|
||||||
|
|
||||||
|
if ringstate == "RUN":
|
||||||
|
status = State.OK
|
||||||
|
text = "Ring is in RUN state"
|
||||||
|
elif ringstate == "LOOP":
|
||||||
|
status = State.CRIT
|
||||||
|
text = "Ring is LOOP state"
|
||||||
|
else:
|
||||||
|
status = State.CRIT
|
||||||
|
text = "Ring is in balancing state"
|
||||||
|
|
||||||
|
yield Result(state=status, summary=text)
|
||||||
|
|
||||||
|
|
||||||
|
def check_scality_supervisors(item, params, section):
|
||||||
|
data = section["supervisors"].get(item)
|
||||||
|
if not data:
|
||||||
|
return
|
||||||
|
|
||||||
|
supNbSrvTotal = data["total"]
|
||||||
|
supNbSrvNok = data["not_ok"]
|
||||||
|
supAvailable = data["avail"]
|
||||||
|
|
||||||
|
if supAvailable != 1:
|
||||||
|
yield Result(state=State.CRIT, summary="Supervisor is not available")
|
||||||
|
else:
|
||||||
|
yield Result(state=State.OK, summary="Supervisor is available")
|
||||||
|
|
||||||
|
if supNbSrvNok > 0:
|
||||||
|
yield Result(state=State.CRIT, summary=f"{supNbSrvNok} out of {supNbSrvTotal} servers are unavailable")
|
||||||
|
else:
|
||||||
|
yield Result(state=State.OK, summary=f"all {supNbSrvTotal} servers are available")
|
||||||
|
|
||||||
|
|
||||||
|
def discover_scality_rings(section):
|
||||||
|
for name in section["rings"].keys():
|
||||||
|
yield Service(item=name)
|
||||||
|
|
||||||
|
|
||||||
|
def discover_scality_supervisors(section):
|
||||||
|
for name in section["supervisors"].keys():
|
||||||
|
yield Service(item=name)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_scality(string_table):
|
||||||
|
rings = {}
|
||||||
|
supervisors = {}
|
||||||
|
|
||||||
|
for name, state, disks, avail, total in string_table[0]:
|
||||||
|
rings[name] = {
|
||||||
|
"state": state,
|
||||||
|
"disks": int(disks),
|
||||||
|
"avail_storage": int(avail),
|
||||||
|
"total_storage": int(total),
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, total, not_ok, avail in string_table[1]:
|
||||||
|
supervisors[name] = {
|
||||||
|
"total": int(total),
|
||||||
|
"not_ok": int(not_ok),
|
||||||
|
"avail": int(avail),
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
"rings": rings,
|
||||||
|
"supervisors": supervisors,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
check_plugin_scality_disk = CheckPlugin(
|
||||||
|
name = "scality_ring_disk",
|
||||||
|
sections = [ "scality_ring" ],
|
||||||
|
service_name = "Ring %s Disks",
|
||||||
|
discovery_function = discover_scality_rings,
|
||||||
|
check_function = check_scality_disks,
|
||||||
|
check_ruleset_name = "scality_ring_disk",
|
||||||
|
check_default_parameters = {},
|
||||||
|
)
|
||||||
|
check_plugin_scality_storage = CheckPlugin(
|
||||||
|
name = "scality_ring_storage",
|
||||||
|
sections = [ "scality_ring" ],
|
||||||
|
service_name = "Ring %s Storage",
|
||||||
|
discovery_function = discover_scality_rings,
|
||||||
|
check_function = check_scality_storages,
|
||||||
|
check_default_parameters = FILESYSTEM_DEFAULT_PARAMS,
|
||||||
|
)
|
||||||
|
check_plugin_scality_state = CheckPlugin(
|
||||||
|
name = "scality_ring_state",
|
||||||
|
sections = [ "scality_ring" ],
|
||||||
|
service_name = "Ring %s State",
|
||||||
|
discovery_function = discover_scality_rings,
|
||||||
|
check_function = check_scality_states,
|
||||||
|
check_default_parameters = {},
|
||||||
|
)
|
||||||
|
check_plugin_scality_supervisor = CheckPlugin(
|
||||||
|
name = "scality_ring_supervisor",
|
||||||
|
sections = [ "scality_ring" ],
|
||||||
|
service_name = "Supervison %s",
|
||||||
|
discovery_function = discover_scality_supervisors,
|
||||||
|
check_function = check_scality_supervisors,
|
||||||
|
check_default_parameters = {},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
snmp_section_scality = SNMPSection(
|
||||||
|
name = "scality_ring",
|
||||||
|
parse_function = parse_scality,
|
||||||
|
detect = contains(".1.3.6.1.2.1.1.1.0", "scality"),
|
||||||
|
fetch = [
|
||||||
|
SNMPTree(
|
||||||
|
base=".1.3.6.1.4.1.37489.2.1.1.1.4.1.1",
|
||||||
|
oids=[
|
||||||
|
"2", #ringName
|
||||||
|
# "3", #ringStateRun
|
||||||
|
"8", #ringState
|
||||||
|
"9", #ringDiskTotal
|
||||||
|
# "13", #ringStorageUsed
|
||||||
|
"14", #ringStorageAvailable
|
||||||
|
"15", #ringStorageTotal
|
||||||
|
]),
|
||||||
|
SNMPTree(
|
||||||
|
base=".1.3.6.1.4.1.37489.2.1.1.1.4.2.1",
|
||||||
|
oids=[
|
||||||
|
"2", #supName
|
||||||
|
"5", #supNbSrvTotal
|
||||||
|
# "6", #supNbSrvOK
|
||||||
|
"7", #supNbSrvNok
|
||||||
|
"8", #supAvailable
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (C) 2025 Spearhead Systems SRL
|
||||||
|
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
|
||||||
|
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
|
||||||
|
# conditions defined in the file COPYING, which is part of this source code package.
|
||||||
|
|
||||||
|
from cmk.rulesets.v1.form_specs import Dictionary, DictElement, Integer
|
||||||
|
from cmk.rulesets.v1.rule_specs import CheckParameters, HostAndItemCondition, Topic, Title, Help
|
||||||
|
from cmk.rulesets.v1.form_specs.validators import NumberInRange
|
||||||
|
|
||||||
|
|
||||||
|
def _parameters_scality():
|
||||||
|
return Dictionary(
|
||||||
|
title = Title("Minimum Number of Disks"),
|
||||||
|
help_text = Help(
|
||||||
|
"Set lower limits for the number of disks in the scality ring "
|
||||||
|
"system. Applied for each ring."
|
||||||
|
),
|
||||||
|
elements = {
|
||||||
|
"warn": DictElement(
|
||||||
|
required = True,
|
||||||
|
parameter_form = Integer(
|
||||||
|
title = Title("Warn"),
|
||||||
|
help_text = Help("Warn if below this number of disks"),
|
||||||
|
custom_validate = (NumberInRange(min_value=0),),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"crit": DictElement(
|
||||||
|
required = True,
|
||||||
|
parameter_form = Integer(
|
||||||
|
title = Title("Crit"),
|
||||||
|
help_text = Help("Crit if below this number of disks"),
|
||||||
|
custom_validate = (NumberInRange(min_value=0),),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
rule_spec_scality_ring = CheckParameters(
|
||||||
|
name = "scality_ring_disk",
|
||||||
|
title = Title("Scality Ring Disk Number"),
|
||||||
|
topic = Topic.GENERAL,
|
||||||
|
condition = HostAndItemCondition(item_title = Title("Ring")),
|
||||||
|
parameter_form = _parameters_scality,
|
||||||
|
)
|
||||||
BIN
scality-ring/2.4/scality_ring-1.2.0.mkp
Executable file
BIN
scality-ring/2.4/scality_ring-1.2.0.mkp
Executable file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user