Skip to content

Instantly share code, notes, and snippets.

@mabauer
Last active January 27, 2021 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mabauer/b4db1bf821d5e25aedbba6cf06a8519c to your computer and use it in GitHub Desktop.
Save mabauer/b4db1bf821d5e25aedbba6cf06a8519c to your computer and use it in GitHub Desktop.
check_mk check -- problem with parse_function
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation in version 2. This file is distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# ails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
#<<<ttn_gateway>>>
#Markus TTIG (The Things Indoor Gateway 2.0.0): 64
factory_settings["ttn_gateway_lastseen_default_levels"] = {
"levels": (10*60, 15*60)
}
def parse_ttn_gateway_info(info):
pprint.pprint(info)
parsed = {}
for line in info:
if not line.startswith("<<<"):
(gateway, value) = line.split(":")
parsed[gateway.strip()] = value.strip()
return parsed
def inventory_ttn_gateway_lastseen(parsed):
pprint.pprint(parsed)
for gateway in parsed:
yield gateway, None
def check_ttn_gateway_lastseen(item, params, parsed):
if isinstance(params, tuple):
warn, crit = params
else:
warn, crit = params['levels']
for gateway in parsed:
if gateway == item:
value = saveint(parsed[gateway])
perfdata = [('last seen', value, warn, crit)]
if value < warn:
yield 0, "%d s since last seen" % value, perfdata
elif value < crit:
yield 1, "%d s since last seen" % value, perfdata
else:
yield 2, "%d s since last seen" % value, perfdata
check_info["ttn_gateway.lastseen"] = {
'parse_function' : parse_ttn_gateway_info,
'check_function' : check_ttn_gateway_lastseen,
'inventory_function' : inventory_ttn_gateway_lastseen,
'has_perfdata' : True,
'service_description' : 'TTN Gateway %s',
'default_levels_variable' : 'ttn_gateway_lastseen_default_levels'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment