Skip to content

Commit

Permalink
Areca HBA SNMP checks for CMK 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gurubert committed Dec 2, 2024
1 parent 4c56b63 commit 4bd1357
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 254 deletions.
1 change: 0 additions & 1 deletion areca/agent_based/areca_hba_fans.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def check_areca_hba_fans(item, params, section) -> CheckResult:
fetch = SNMPTree(
base = ".1.3.6.1.4.1.18928.1.2.2.1.9.1",
oids = [
# "1", # hwControllerBoardFanIndex
"2", # hwControllerBoardFanDesc
"3", # hwControllerBoardFanSpeed
]
Expand Down
8 changes: 0 additions & 8 deletions areca/agent_based/areca_hba_ldisks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# +------------------------------------------------------------------+
#
# This file is an addon for Check_MK.
# The official homepage for this check is at http://bitbucket.org/darkfader
#
# check_mk is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
Expand All @@ -36,9 +35,6 @@
startswith,
)

from cmk.utils import debug
from pprint import pprint # type: ignore

def parse_areca_hba_ldisks(string_table):
section = {}
for vsf_id, vsf_name, vsf_rsf, vsf_size, vsf_state, vsf_rbld in string_table:
Expand All @@ -49,9 +45,6 @@ def parse_areca_hba_ldisks(string_table):
"state": vsf_state,
"rbld": int(vsf_rbld) / 10.0,
}
if debug.enabled():
pprint(string_table)
pprint(section)
return section

def discover_areca_hba_ldisks(section) -> DiscoveryResult:
Expand Down Expand Up @@ -79,7 +72,6 @@ def check_areca_hba_ldisks(item, section) -> CheckResult:
name = "areca_hba_ldisks",
parse_function = parse_areca_hba_ldisks,
detect = startswith(".1.3.6.1.2.1.1.2.0", ".1.3.6.1.4.1.18928.1"),
# detect = lambda oid: True,
fetch = SNMPTree(
base = ".1.3.6.1.4.1.18928.1.2.5.1.1",
oids = [
Expand Down
142 changes: 85 additions & 57 deletions areca/agent_based/areca_hba_pdisks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# +------------------------------------------------------------------+
#
# This file is an addon for Check_MK.
# The official homepage for this check is at http://bitbucket.org/darkfader
#
# check_mk is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -52,66 +51,95 @@
# | +-----field
# +-------enclosure

max_enclosures = 8

from cmk.agent_based.v2 import (
CheckPlugin,
CheckResult,
DiscoveryResult,
Result,
Service,
SNMPSection,
SNMPTree,
State,
startswith,
)
from cmk.agent_based.v2.render import bytes

def inventory_areca_hba_pdisks(info):
inventory = []
for enclosure_entry in info:
for slot_entry in enclosure_entry:
if len(slot_entry) == 8 and slot_entry[-1].split()[0] != "Empty":
enc, slot = slot_entry[0].split(".")
diskname = ("%d/%02d" % (int(enc), int(slot)))
inventory.append((diskname, None))
return inventory
def parse_areca_hba_pdisks(string_table):
section = {}
slot_type = {
"1": "SATA",
"2": "SAS",
}
for encl in range(max_enclosures):
installed, desc = string_table[encl * 2][0]
if installed == "1":
section[encl + 1] = {
"name": desc,
"slots": {},
}
for id, desc, name, serial, firmver, capacity, typ, state in string_table[encl * 2 + 1]:
if state != "Empty Slot":
section[encl + 1]["slots"][int(id)] = {
"desc": desc,
"name": name,
"serial": serial,
"firmver": firmver,
"capacity": int(capacity) * 1024 *1024,
"type": slot_type.get(typ),
"state": state,
}
return section

def check_areca_hba_pdisks(item, _no_params, info):
for enclosure_entry in info:
for slot_entry in enclosure_entry:
enc, slot = slot_entry[0].split(".")
diskname = ("%d/%02d" % (int(enc), int(slot)))
def discover_areca_hba_pdisks(section) -> DiscoveryResult:
for encl in section.keys():
for slot in section[encl]["slots"].keys():
yield Service(item="%d/%02d" % (encl, slot))

# We could do smarter by tracking the serial at inventory.
# I decided to not get too smart, and so we're not following a disk
# around if you put it somewhere else.
if diskname == item:
def check_areca_hba_pdisks(item, section) -> CheckResult:
encl, slot = list(map(int, item.split("/")))
if encl in section:
if slot in section[encl]["slots"]:
data = section[encl]["slots"][slot]
yield Result(state=State.OK, summary="%s %s %s (%s)" % (data["name"], data["serial"], data["firmver"], bytes(data["capacity"])))
if data["state"] == "Failed":
yield Result(state=State.CRIT, summary="failed")

disk_descr = "(%s %s)" % (slot_entry[2], slot_entry[3])
snmp_sections = []
for encl in range(1, max_enclosures + 1):
snmp_sections.append(SNMPTree(
base = f".1.3.6.1.4.1.18928.1.2.3.{encl}",
oids = [
"1.0", # ARECA-SNMP-MIB::hddEnclosureNNInstalled
"2.0", # ARECA-SNMP-MIB::hddEnclosureNNDescription
],
))
snmp_sections.append(SNMPTree(
base = f".1.3.6.1.4.1.18928.1.2.3.{encl}.4.1",
oids = [
"1", # ARECA-SNMP-MIB::hddEnclosureNNSlots
"2", # ARECA-SNMP-MIB::hddEnclosureNNDesc
"3", # ARECA-SNMP-MIB::hddEnclosureNNName
"4", # ARECA-SNMP-MIB::hddEnclosureNNSerial
"5", # ARECA-SNMP-MIB::hddEnclosureNNFirmVer
"6", # ARECA-SNMP-MIB::hddEnclosureNNCapacity
"7", # ARECA-SNMP-MIB::hddEnclosureNNType
"8", # ARECA-SNMP-MIB::hddEnclosureNNState
],
))

# What I'm checking here is a field that SEEMS to be the right one.
# Contact me if this seems wrong. Someone needs to test / adjust it
# with some JBOD mode array and pull some disks.
if slot_entry[7] == "Failed":
return (2, "CRIT - Disk is failed. %s" % disk_descr)
else:
return (0, "OK - Disk is OK. %s" % disk_descr)

return (3, "Disk not found in agent output")


# check_info["areca_hba_pdisks"] = {
# "check_function" : check_areca_hba_pdisks,
# "inventory_function" : inventory_areca_hba_pdisks,
# "has_perfdata" : False,
# "service_description" : "PDisk Enc/Sl %s",
# # Find Areca SAS MIB
# "snmp_scan_function" : lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.18928.1"),
# "snmp_info" : [(".1.3.6.1.4.1.18928.1.2.3",
# # unclear: how does it look in jbod mode?
# # where does i get pony?
# # There's up to 8 enclosures, "1" is hardcoded having 8 slots.
# # probably it's the ext. SAS connector.
# [ "1", "2", "3", "4", "5", "6", "7", "8" ],
# # Below each enclosure there's the following structure for disk data
# [ "4.1.1", # The slot ids
# "4.1.2", # The slot descrs
# "4.1.3", # The disk model
# "4.1.4", # The disk fw
# "4.1.5", # The disk size
# # The MIB seems wrong about the next ones
# "4.1.6", #
# "4.1.7", #
# "4.1.8", # Textual disk state
# ]
# )],
# }
snmp_section_areca_hba_pdisks = SNMPSection(
name = "areca_hba_pdisks",
parse_function = parse_areca_hba_pdisks,
detect = startswith(".1.3.6.1.2.1.1.2.0", ".1.3.6.1.4.1.18928.1"),
fetch = snmp_sections,
)

check_plugin_areca_hba_pdisks = CheckPlugin(
name = "areca_hba_pdisks",
sections = ["areca_hba_pdisks"],
service_name = "PDisk Enc/Sl %s",
discovery_function = discover_areca_hba_pdisks,
check_function = check_areca_hba_pdisks,
)
106 changes: 59 additions & 47 deletions areca/agent_based/areca_hba_raidsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# +------------------------------------------------------------------+
#
# This file is an addon for Check_MK.
# The official homepage for this check is at http://bitbucket.org/darkfader
#
# check_mk is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
Expand All @@ -24,55 +23,68 @@
# Boston, MA 02110-1301 USA.


def inventory_areca_hba_raidsets(info):
inventory = []
from cmk.agent_based.v2 import (
CheckPlugin,
CheckResult,
DiscoveryResult,
Result,
Service,
SimpleSNMPSection,
SNMPTree,
State,
startswith,
)

# not sure why i end up with my info double stacked
# but i'm sure it's me.
for line in info[0]:
if len(line) == 5:
rs_id, rs_name, rs_state, rs_mem_sz, rs_mem_names = line
inventory.append((rs_id, None))
return inventory

def check_areca_hba_raidsets(item, _no_params, info):
for line in info[0]:
rs_id, rs_name, rs_state, rs_mem_sz, rs_mem_names = line
def parse_areca_hba_raidsets(string_table):
section = {}
for id, name, state, members in string_table:
section[id] = {
"name": name,
"state": state,
"members": members,
}
return section

if rs_id == item:
if rs_state == "Normal":
state = 0
elif rs_state == "Rebuilding":
state = 1
# I hope Offline is correct.
elif rs_state in [ "Degraded", "Offline" ]:
state = 2
# Any state we don't know.
else:
state = 3
def discover_areca_hba_raidsets(section) -> DiscoveryResult:
for id in section.keys():
yield Service(item=id)

msg = "%s is %s. (members: %s)" % (rs_name, rs_state, rs_mem_names)
return (state, msg)

return (3, "UNKW - Raidset not found in agent output")
def check_areca_hba_raidsets(item, section) -> CheckResult:
if item in section:
data = section[item]
if data["state"] == "Normal":
state = State.OK
elif data["state"] == "Rebuilding":
state = State.WARN
elif data["state"] in ["Degraded", "Offline"]:
state = State.CRIT
else:
state = State.UNKNOWN
yield Result(
state=state,
summary="%s is %s, members: %s" % (data["name"], data["state"], data["members"])
)

snmp_section_areca_hba_raidsets = SimpleSNMPSection(
name="areca_hba_raidsets",
parse_function=parse_areca_hba_raidsets,
detect = startswith(".1.3.6.1.2.1.1.2.0", ".1.3.6.1.4.1.18928.1"),
fetch = SNMPTree(
base=".1.3.6.1.4.1.18928.1.2.4.1.1",
oids=[
"1", # ARECA-SNMP-MIB::raidNumber
"2", # ARECA-SNMP-MIB::raidName
"4", # ARECA-SNMP-MIB::raidState
"8", # ARECA-SNMP-MIB::raidMemberDiskChannels
],
),
)

# check_info["areca_hba_raidsets"] = {
# "check_function" : check_areca_hba_raidsets,
# "inventory_function" : inventory_areca_hba_raidsets,
# "has_perfdata" : False,
# "service_description" : "Raid set %s",
# # Find Areca SAS MIB
# "snmp_scan_function" : lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.18928.1"),
# "snmp_info" : [(".1.3.6.1.4.1.18928.1.2.4.1.1",
# # Below each enclosure there's the following structure for disk data
# [ #"2", "4"
# "1", # Raidset id
# "2", # Raidset name
# "4", # Raidset State
# "7", # Member disk size
# "8", # Member disk names and states
# ]
# )],
# }

check_plugin_areca_hba_raidsets = CheckPlugin(
name="areca_hba_raidsets",
sections=["areca_hba_raidsets"],
service_name="Raid set %s",
discovery_function=discover_areca_hba_raidsets,
check_function=check_areca_hba_raidsets,
)
Loading

0 comments on commit 4bd1357

Please sign in to comment.