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 0da69dc9 authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

update project

parent f0550dbe
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#
# 05.09.2018 : changes for CMK 1.5.x (replaced global variable g_hostname with api call host_name())
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
#
# 2018-09-05 : changes for CMK 1.5.x (replaced global variable g_hostname with api call host_name())
# 2020-08-08 : cleanup
#
def cisco_api_status_arguments(params):
# print params
......@@ -15,40 +19,42 @@ def cisco_api_status_arguments(params):
if params:
if params.get('psirt'):
if params.get('psirt').get('crit-days'):
args.append('--psirt-crit-days %s' % params.get('psirt').get('crit-days'))
if params.get('psirt').get('warn-days'):
args.append('--psirt-warn-days %s' % params.get('psirt').get('warn-days'))
if params.get('psirt').get('warn-severity'):
args.append('--psirt-warn-severity %s' % params.get('psirt').get('warn-severity'))
if params.get('psirt').get('crit-severity'):
args.append('--psirt-crit-severity %s' % params.get('psirt').get('crit-severity'))
if params.get('psirt').get('not-active'):
args.append('--psirt-not-active %s' % params.get('psirt').get('not-active'))
for key, value in [
('--psirt-crit-days', 'crit-days'),
('--psirt-warn-days', 'warn-days'),
('--psirt-warn-severity', 'warn-severity'),
('--psirt-crit-severity', 'crit-severity'),
('--psirt-not-active', 'not-active'),
]:
if params['psirt'].get(value):
args.append('%s %s' % (key, params['psirt'].get(value)))
if params.get('eox'):
if params.get('eox').get('crit-new'):
args.append('--eox-crit-new %s' % params.get('eox').get('crit-new'))
if params.get('eox').get('warn-new'):
args.append('--eox-warn-new %s' % params.get('eox').get('warn-new'))
if params.get('eox').get('crit-change'):
args.append('--eox-crit-change %s' % params.get('eox').get('crit-change'))
if params.get('eox').get('warn-change'):
args.append('--eox-warn-change %s' % params.get('eox').get('warn-change'))
if params.get('eox').get('not-active'):
args.append('--eox-not-active %s' % params.get('eox').get('not-active'))
for key, value in [
('--eox-crit-new', 'crit-new'),
('--eox-warn-new', 'warn-new'),
('--eox-crit-change', 'crit-change'),
('--eox-warn-change', 'warn-change'),
('--eox-not-active', 'not-active'),
]:
if params['eox'].get(value):
args.append('%s %s' % (key, params['eox'].get(value)))
if params.get('sn2info'):
if params.get('sn2info').get('crit-change'):
args.append('--sn2info-crit-change %s' % params.get('sn2info').get('crit-change'))
if params.get('sn2info').get('warn-change'):
args.append('--sn2info-warn-change %s' % params.get('sn2info').get('warn-change'))
if params.get('sn2info').get('not-active'):
args.append('--sn2info-not-active %s' % params.get('sn2info').get('not-active'))
for key, value in [
('--sn2info-crit-change', 'crit-change'),
('--sn2info-warn-change', 'warn-change'),
('--sn2info-not-active', 'not-active'),
]:
if params['sn2info'].get(value):
args.append('%s %s' % (key, params['sn2info'].get(value)))
if params.get('suggestion'):
if params.get('suggestion').get('not-active'):
args.append('--suggestion-not-active %s' % params.get('suggestion').get('not-active'))
for key, value in [
('--suggestion-not-active', 'not-active'),
]:
if params['suggestion'].get(value):
args.append('%s %s' % (key, params['suggestion'].get(value)))
# in CMK v1.5.x global variable g_hostname was replaced by API call host_name()
try:
......
No preview for this file type
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#
# 20.03.2017 : writen by Th.L.
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2017-03-20
#
# include file, will be used with snmp_cisco_eox and snmp_cisco_contract
# 29.05.2017 : fixed empty pid handling
#
# 2017-05-29 : fixed empty pid handling
# : added serial number cleanup
#
......
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#
# 26.12.2018 : writen by Th.L.
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2018-12-26
#
# 13.08.2019 : changes for cmk 1.5: inv_tree_list to inv_tree, comment out split for cmk 1.5
# #bug['known_fixed_releases'] = bug['known_fixed_releases'].split(' ')
# #bug['known_affected_releases'] = bug['known_affected_releases'].split(' ')
#
#
#
# import is done by Check_MK
# import logging
......
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#
# 05.07.2017 : writen by Th.L. to collect/show Cisco psirt information for IOS/IOSXE
# 09-04.2018 : removed import
# 04.09.2018 : changes for CMK 1.5.x (inv_tree --> inv_tree_list)
# 05.09.2018 : changes for CMK 1.5.x (replaced global variable g_hostname with api call host_name())
# 06.01.2018 : minor changes, added status info for removed advisories (not updated, older than, ...)
# 13.08.2019 : changed for cmk 1.5
# #node = inv_tree_list('software.support.cisco_psirt.')
# node = inv_tree('software.support.cisco_psirt.')
# changed variable host_name to _hostname for cmk 1.5
#37 advisory.update({'bugIDs': ' '.join(advisory.get('bugIDs', ''))})
#38 advisory.update({'firstFixed': ' '.join(advisory.get('firstFixed', ''))})
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2017-07-05
#
# collect/show Cisco psirt information for IOS/IOSXE
#
# 2018-04-09 : removed import
# 2018-09-04 : changes for CMK 1.5.x (inv_tree --> inv_tree_list)
# 2018-09-05 : changes for CMK 1.5.x (replaced global variable g_hostname with api call host_name())
# 2018-01-06 : minor changes, added status info for removed advisories (not updated, older than, ...)
# 2019-08-13 : changed for cmk 1.5
# #node = inv_tree_list('software.support.cisco_psirt.')
# node = inv_tree('software.support.cisco_psirt.')
# changed variable host_name to _hostname for cmk 1.5
#
# import is done by Check_MK
# import logging
......
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#
# 31.07.2017 : writen by Th.L. to add Cisco suggested software
# 09-04.2018 : removed import
# 04.09.2018 : changes for CMK 1.5.x (inv_tree --> inv_tree_list)
# 05.09.2018 : changes for CMK 1.5.x (replaced global variable g_hostname with api call host_name())
# 13.08.2019 : changes for cmk 1.5.x varianle host_name changed to _hotname
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2017-07-13
#
# add Cisco suggested software
#
# 2018-04-09 : removed import
# 2018-09-04 : changes for CMK 1.5.x (inv_tree --> inv_tree_list)
# 2018-09-05 : changes for CMK 1.5.x (replaced global variable g_hostname with api call host_name())
# 2019-08-13 : changes for cmk 1.5.x varianle host_name changed to _hotname
#
# todo: new layout for cmk 1.5.x
#
......
#!/usr/bin/python
# encoding: utf-8
#
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
#
# 2020-03-15: changed getopt to argparse
#
import os
import sys
import getopt
import argparse
import ConfigParser
import json
from datetime import datetime
......@@ -14,61 +18,6 @@ import logging
import sys
def bail_out(reason):
# set logg modul name <file>:<module>.<function>
logger = logging.getLogger(__file__ + ':' + __name__ + '.' + sys._getframe().f_code.co_name)
sys.stderr.write("FATAL ERROR: %s\n" % reason)
sys.exit(3)
def usage():
# set logg modul name <file>:<module>.<function>
logger = logging.getLogger(__file__ + ':' + __name__ + '.' + sys._getframe().f_code.co_name)
print """cisco_api_atatus [options] TARGET
Check status of Cisco APIs for TARGET. TARGET is the hostname used by Check_MK.
Other options:
PSIRT options
--psirt-crit-severity <severity> if new/updated advisory equal or above severity set outcome to critical
--psirt-crit-days <days> set outcome to critical is new/updated advisory not older then days
--psirt-warn-severity <severity> if new/updated advisory equal or above severity set outcome to warning
--psirt-warn-days <days> set outcome to warning is new/updated advisory not older then days
--psirt-not-active <status> set outcome to status if PSIRT API is not active
--psirt-crit-days should be less then --psirt-warn-days
--psirt-warn-severity should be less then --psirt-crit-severity
EoX options
--eox-crit-new <days> set outcome to critical if new announcement not older then days
--eox-warn-new <days> set outcome to warning if new announcement not older then days
--eox-crit-change <days> set outcome to critical if announcement is about to change in lees then days
--eox-warn-change <days> set outcome to warning if announcement is about to change in lees then days
--eox-not-active <status> set outcome to status if EoX API is not active
sn2info (contract) options
--sn2info-crit-change <days> set outcome to critical if contract is about to change in lees then days
--sn2info-warn-change <days> set outcome to warning if contract is about to change in lees then days
--sn2info-not-active <status> set outcome to status if sn2info API is not active
suggestion options
--suggestion-not-active <status> set outcome to status if suggestion API is not active
<severity> is one of : 1 (Critical), 2 (High), 3 (Medium), 4 (Low), 0 (All)
<days> : >= 1
<status> is one of : 0 (Ok), 1 (Warning), 2 (Critical)
-h, --help show this help and exit
--debug show Python exceptions verbosely
"""
# check if dir exists, if not try to create it.
# return True if dir exists or creation was ok.
# return False if dir not exists and creation was not ok
......@@ -100,7 +49,7 @@ def expand_path(path):
return path
def check_eox_status(apistatus, options):
def check_eox_status(apistatus, options, cmd_args):
# set logg modul name <file>:<module>.<function>
logger = logging.getLogger(__file__ + ':' + __name__ + '.' + sys._getframe().f_code.co_name)
......@@ -112,10 +61,10 @@ def check_eox_status(apistatus, options):
lastrun = apistatus.get('lastrun')
refresh_known = options.get('refresh_known', 31)
refresh_unknown = options.get('refresh_unknown', 7)
crit_new = options.get('crit-new', 0)
warn_new = options.get('warn-new', 0)
crit_change = options.get('crit-change', 0)
warn_change = options.get('warn-change', 0)
crit_new = cmd_args.eox_crit_new
warn_new = cmd_args.eox_warn_new
crit_change = cmd_args.eox_crit_change
warn_change = cmd_args.eox_warn_change
for entry in lastrun:
last_checked = entry.get('Last_checked')
......@@ -142,7 +91,7 @@ def check_eox_status(apistatus, options):
# check if date is about to change
for key in entry.keys():
if key in EoL_dates:
if key in EoL_dates and entry.get(key) != '':
change_days = (datetime.strptime(entry.get(key), '%Y-%m-%d').date() - datetime.now().date()).days
change_text = EoL_dates_desc.get(key, 'key not found')
if ((change_days < crit_change) or (change_days < warn_change)) and (change_days >= 0):
......@@ -189,7 +138,7 @@ def check_eox_status(apistatus, options):
return output, long_output, status
def check_psirt_status(apistatus, options):
def check_psirt_status(apistatus, options, cmd_args):
# set logg modul name <file>:<module>.<function>
logger = logging.getLogger(__file__ + ':' + __name__ + '.' + sys._getframe().f_code.co_name)
......@@ -212,10 +161,10 @@ def check_psirt_status(apistatus, options):
refresh_found = options.get('refresh_found', 1)
refresh_notfound = options.get('refresh_notfound', 1)
warn_days = options.get('warn-days')
crit_days = options.get('crit-days')
warn_severity = options.get('warn-severity', 0)
crit_severity = options.get('crit-severity', 0)
warn_days = cmd_args.psirt_warn_days
crit_days = cmd_args.psirt_crit_days
warn_severity = cmd_args.psirt_warn_severity
crit_severity = cmd_args.psirt_crit_severity
if (psirt_status == 'found') and (last_refresh > refresh_found):
max_refresh_known = last_refresh
......@@ -254,7 +203,7 @@ def check_psirt_status(apistatus, options):
return output, long_output, status
def check_sn2info_status(apistatus, options):
def check_sn2info_status(apistatus, options, cmd_args):
# set logg modul name <file>:<module>.<function>
logger = logging.getLogger(__file__ + ':' + __name__ + '.' + sys._getframe().f_code.co_name)
......@@ -267,8 +216,8 @@ def check_sn2info_status(apistatus, options):
refresh_covered = options.get('refresh_covered', 31)
refresh_notcovered = options.get('refresh_notcovered', 7)
crit_change = options.get('crit-change', 0)
warn_change = options.get('warn-change', 0)
crit_change = cmd_args.sn2info_crit_change
warn_change = cmd_args.sn2info_warn_change
for entry in lastrun:
last_checked = entry.get('Last_checked')
......@@ -322,7 +271,7 @@ def check_sn2info_status(apistatus, options):
return output, long_output, status
def check_suggestion_status(apistatus, options):
def check_suggestion_status(apistatus, options, cmd_args):
# set logg modul name <file>:<module>.<function>
logger = logging.getLogger(__file__ + ':' + __name__ + '.' + sys._getframe().f_code.co_name)
......@@ -377,7 +326,6 @@ def main():
output = ''
long_output = ''
apistatus = {}
target = ''
loglevel = 'warning'
......@@ -421,79 +369,29 @@ def main():
os.unsetenv("LANG")
# short_options = "hw:W:c:C:nTI"
short_options = 'h'
long_options = ['help', 'debug',
'psirt-crit-severity=', 'psirt-crit-days=', 'psirt-warn-severity=', 'psirt-warn-days=', 'psirt-not-active=',
'eox-not-active=', 'eox-crit-new=', 'eox-warn-new=', 'eox-crit-change=', 'eox-warn-change=',
'sn2info-not-active=', 'sn2info-crit-change=', 'sn2info-warn-change=',
'suggestion-not-active=',
]
try:
opts, args = getopt.getopt(sys.argv[1:], short_options, long_options)
# first parse modifers
# for o, a in opts:
# if o in [ '-v', '--verbose' ]:
# opt_verbose += 1
# elif o in [ '-d', '--debug' ]:
# opt_debug = True
# elif o in [ '-w', '-W', '-c', '-C' ]:
# routes.append((o[1], a))
# elif o == '-n':
# opt_nodns = True
# elif o in [ '-T', '-I' ]:
# opt_method = o
# now handle action options
for o, a in opts:
if o in ['--psirt-crit-severity']:
opt_psirt.update({'crit-severity': int(a)})
if o in ['--psirt-warn-severity']:
opt_psirt.update({'warn-severity': int(a)})
if o in ['--psirt-crit-days']:
if int(a) > 0:
opt_psirt.update({'crit-days': int(a)})
if o in ['--psirt-warn-days']:
if int(a) > 0:
opt_psirt.update({'warn-days': int(a)})
if o in ['--psirt-not-active']:
opt_psirt.update({'not-active': int(a)})
if o in ['--eox-not-active']:
opt_eox.update({'not-active': int(a)})
if o in ['--eox-crit-new']:
opt_eox.update({'crit-new': int(a)})
if o in ['--eox-warn-new']:
opt_eox.update({'warn-new': int(a)})
if o in ['--eox-crit-change']:
opt_eox.update({'crit-change': int(a)})
if o in ['--eox-warn-change']:
opt_eox.update({'warn-change': int(a)})
if o in ['--sn2info-not-active']:
opt_sn2info.update({'not-active': int(a)})
if o in ['--sn2info-crit-change']:
opt_sn2info.update({'crit-change': int(a)})
if o in ['--sn2info-warn-change']:
opt_sn2info.update({'warn-change': int(a)})
if o in ['--suggestion-not-active']:
opt_suggestion.update({'not-active': int(a)})
if o in ['-h', '--help']:
usage()
sys.exit(0)
if len(args) < 1:
bail_out("Please specify the target.")
target = args[0]
except Exception, e:
bail_out(e)
parser = argparse.ArgumentParser()
parser.add_argument('TARGET', type=str, help='Host to check (exact name form CheckMK)')
parser.add_argument('--psirt-crit-days', type=int, default=0, help='set check status to critical if new/updated advisory not older then days, should be less then --psirt-warn-days')
parser.add_argument('--psirt-warn-days', type=int, default=0, help='set check status to warning if new/updated advisory not older then days')
parser.add_argument('--psirt-crit-severity', type=int, default=0, choices=[0, 1, 2, 3, 4], help='if new/updated advisory equal or above severity {All, Critical, High, Medium, Low} set check status to critical')
parser.add_argument('--psirt-warn-severity', type=int, default=0, choices=[0, 1, 2, 3, 4], help='if new/updated advisory equal or above severity {All, Critical, High, Medium, Low} set check status to warning, should be less then --psirt-crit-severity')
parser.add_argument('--psirt-not-active', type=int, choices=[0, 1, 2], help='set check status to {Ok, Warn, Crit} if PSIRT API is not active')
parser.add_argument('--eox-crit-new', type=int, default=0, help='set check status to critical if new announcement not older then days')
parser.add_argument('--eox-warn-new', type=int, default=0, help='set check status to warning if new announcement not older then days')
parser.add_argument('--eox-crit-change', type=int, default=0, help='set check status to critical if announcement is about to change in lees then days')
parser.add_argument('--eox-warn-change', type=int, default=0, help='set check status to warning if announcement is about to change in lees then days')
parser.add_argument('--eox-not-active', type=int, choices=[0, 1, 2], help='set check status to {Ok, Warn, Crit} if EoX API is not active')
parser.add_argument('--sn2info-crit-change', type=int, default=0, help='set check status to critical if contract is about to change in lees then days')
parser.add_argument('--sn2info-warn-change', type=int, default=0, help='set check status to warning if contract is about to change in lees then days')
parser.add_argument('--sn2info-not-active', type=int, choices=[0, 1, 2], help='set check status to {Ok, Warn, Crit} if sn2info API is not active')
parser.add_argument('--suggestion-not-active', type=int, choices=[0, 1, 2], help='set check status to {Ok, Warn, Crit} if suggestion API is not active')
parser.parse_args()
cmd_args = parser.parse_args()
# print 'cmd_args: {}'.format(cmd_args)
target = cmd_args.TARGET
not_active = []
eox_output = ''
eox_long_output = ''
......@@ -515,16 +413,16 @@ def main():
output = 'Cisco API active.'
with open(ciscoapistatus + target) as f:
apistatus = json.load(f)
long_output = 'active APIs found: ' + ', '.join(apistatus.keys())
long_output = 'active API(s) found: ' + ', '.join(apistatus.keys())
for key in apistatus.keys():
if key == 'eox':
eox_output, eox_long_output, eox_status = check_eox_status(apistatus.get(key), opt_eox)
eox_output, eox_long_output, eox_status = check_eox_status(apistatus.get(key), opt_eox, cmd_args)
if key == 'psirt':
psirt_output, psirt_long_output, psirt_status = check_psirt_status(apistatus.get(key), opt_psirt)
psirt_output, psirt_long_output, psirt_status = check_psirt_status(apistatus.get(key), opt_psirt, cmd_args)
if key == 'sn2info':
sn2info_output, sn2info_long_output, sn2info_status = check_sn2info_status(apistatus.get(key), opt_sn2info)
sn2info_output, sn2info_long_output, sn2info_status = check_sn2info_status(apistatus.get(key), opt_sn2info, cmd_args)
if key == 'suggestion':
suggestion_output, suggestion_long_output, suggestion_status = check_suggestion_status(apistatus.get(key), opt_suggestion)
suggestion_output, suggestion_long_output, suggestion_status = check_suggestion_status(apistatus.get(key), opt_suggestion, cmd_args)
long_output += eox_long_output + sn2info_long_output + psirt_long_output + suggestion_long_output + '\n'
......@@ -538,26 +436,24 @@ def main():
if status > 0:
output += ' (see long output for details)'
if opt_psirt.get('not-active') and ('psirt' not in apistatus.keys()):
if status <= opt_psirt.get('not-active'):
status = opt_psirt.get('not-active')
output += ' PSIRT API not active.'
if opt_eox.get('not-active') and ('eox' not in apistatus.keys()):
if status <= opt_eox.get('not-active'):
status = opt_eox.get('not-active')
output += ' EoX API not active.'
if opt_sn2info.get('not-active') and ('sn2info' not in apistatus.keys()):
if status <= opt_sn2info.get('not-active'):
status = opt_sn2info.get('not-active')
output += ' SN2INFO API not active.'
if opt_suggestion.get('not-active') and ('suggestion' not in apistatus.keys()):
if status <= opt_suggestion.get('not-active'):
status = opt_suggestion.get('not-active')
output += ' SUGGESTION API not active.'
if cmd_args.psirt_not_active is not None and ('psirt' not in apistatus.keys()):
status = max(status, cmd_args.psirt_not_active)
not_active.append('PSIRT')
if cmd_args.eox_not_active is not None and ('eox' not in apistatus.keys()):
status = max(status, cmd_args.eox_not_active)
not_active.append('EoX')
if cmd_args.sn2info_not_active is not None and ('sn2info' not in apistatus.keys()):
status = max(status, cmd_args.sn2info_not_active)
not_active.append('SN2INFO')
if cmd_args.suggestion_not_active is not None and ('suggestion' not in apistatus.keys()):
status = max(status, cmd_args.suggestion_not_active)
not_active.append('SUGGESTION')
if len(not_active) > 0:
output += ' Not active API(s): {}'.format(', '.join(not_active))
else:
output = 'Cisco API not active(!)'
status = max(1, status)
......@@ -565,5 +461,4 @@ def main():
sys.stdout.write(output + '\n' + long_output)
sys.exit(status)
main()
main()
\ No newline at end of file
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#
# Author: Th.L. (thl-cmk[at]outlook[dot]com)
# Date : 20170814
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2017-08-14
#
# CheckMK views for Cisco support APIs (EoX, SN2Info, PSIRT, SUGGESTION)
#
#
......
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