Collection of CheckMK checks (see https://checkmk.com/). All checks and plugins are provided as is. Absolutely no warranty. Send any comments to thl-cmk[at]outlook[dot]com

Skip to content
Snippets Groups Projects
Commit 657526c4 authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

update project

parent dc1f4120
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 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.
# 2022-03-06: extended to use snmpEngineTime if available
# snmpEngineTime : The number of seconds since the value of the snmpEngineBoots object last changed. When
# incrementing this object's value would cause it to exceed its maximum, snmpEngineBoots is
# incremented as if a re-initialization had occurred, and this object's value consequently
# reverts to zero.
# snmpEngineBoots: The number of times that the SNMP engine has (re-)initialized itself since snmpEngineID was
# last configured. On Cisco Device this gives the number of reboots
#
from typing import Optional
from cmk.base.plugins.agent_based.agent_based_api.v1 import exists, register, SNMPTree
from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import StringTable
from cmk.base.plugins.agent_based.utils import uptime
def parse_snmp_uptime(string_table: StringTable) -> Optional[uptime.Section]:
"""
>>> parse_snmp_uptime([['2297331594', '']])
Section(uptime_sec=22973315, message=None)
>>> parse_snmp_uptime([['124:21:26:42.03', '124:21:29:01.14']])
Section(uptime_sec=10790941, message=None)
>>> None is parse_snmp_uptime([[u'', u'Fortigate 80C']]) # nonsense
True
"""
if not string_table:
return None
sysUpTime, hrSystemUptime, snmpEngineTime = string_table[0]
ticks = sysUpTime or hrSystemUptime
if len(ticks) < 3:
return None
try:
return uptime.Section(int(snmpEngineTime), None)
except ValueError:
pass
try:
return uptime.Section(int(ticks[:-2]), None)
except ValueError:
pass
try:
days, h, m, s = ticks.split(":")
return uptime.Section(
(int(days) * 86400) + (int(h) * 3600) + (int(m) * 60) + int(float(s)),
None,
)
except ValueError:
pass
return None
register.snmp_section(
name="snmp_uptime",
parsed_section_name="uptime",
parse_function=parse_snmp_uptime,
fetch=SNMPTree(
base=".1.3.6.1",
oids=[
# On Linux appliances: .1.3.6.1.2.1.1.3.0 means uptime of snmpd
# .1.3.6.1.2.1.25.1.1.0 means system uptime
"2.1.1.3", # DISMAN-EVENT-MIB::sysUpTime
"2.1.25.1.1", # HOST-RESOURCES-MIB::hrSystemUptime
"6.3.10.2.1.3", # SNMP-FRAMEWORK-MIB::snmpEngineTime
],
),
detect=exists(".1.3.6.1.2.1.1.1.0"),
)
{'author': u'Th.L. Th.L. (thl-cmk[at]outlook[dot]com)', {'author': 'Th.L. (thl-cmk[at]outlook[dot]com)',
'description': '\trewrite of snmp_uptime\n\tuses hrSystemUptime instead of sysUpTime if available.\n\thrSystemUptime is the real system uptime,\n\tsysUpTime is the uptime of the snmp agent\n', 'description': 'This check is based on the snmp_uptime check form CMK 2.0. It '
'adds the SNMP-FRAMEWORK-MIB::snmpEngineTime OID to the check. '
'This in seconds not ticks and therefore the Uptime can now be '
'around 68 years before a rollover of the counter.\n'
'\n',
'download_url': 'https://thl-cmk.hopto.org', 'download_url': 'https://thl-cmk.hopto.org',
'files': {'checks': ['snmp_uptime']}, 'files': {'agent_based': ['snmp_uptime.py']},
'name': 'snmp_uptime', 'name': 'snmp_uptime',
'num_files': 1, 'num_files': 1,
'title': u'monitor system uptime via hrSystemUptime', 'title': 'SNMP Uptime',
'version': '20190810.v.0.1', 'version': '20220306.v0.0.1',
'version.min_required': '1.2.8b8', 'version.min_required': '2021.09.20',
'version.packaged': '1.4.0p35'} 'version.packaged': '2021.09.20',
\ No newline at end of file 'version.usable_until': None}
\ No newline at end of file
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment