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

Delete snmp_cisco_bug

parent 56102cb5
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#
# 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
# import os
import json
import ConfigParser
def inv_cisco_bug(info, params):
def get_OS_Version(cw_version, sysdescription, inventory):
version = None
pid = ''
# cw_version = None
sys_version = None
phy_version = None
if str(cw_version).find('CW_VERSION$') == 0:
cw_version = cw_version.split('$')[1] # .upper()
sysdescription = sysdescription.split(',')
# sys description from N5K-C5672UP (has two version entrys :-( )
# Cisco NX-OS(tm) n6000, Software (n6000-uk9), Version 7.0(8)N1(1), RELEASE SOFTWARE Copyright (c) 2002-2012 \
# by Cisco Systems, Inc. Device Manager Version 6.0(2)N1(1), Compiled 2/20/2016 21:00:00
for entry in sysdescription:
if not sys_version and 'version' in entry.lower(): # get only the first 'version' entry
sys_version = entry[entry.lower().find('version') + 7:].strip()
if sys_version.startswith(':'): # AsyncOS
sys_version = sys_version[1:].strip()
sys_version = sys_version.split(' ')[0].strip()
sys_version = sys_version # .upper()
low_index = 1000000
for phyentry in inventory:
phyindex, physoftwarerev, phymodelname, physicalclass = phyentry
if physicalclass == '3': # chassis
if int(phyindex) <= low_index:
if phymodelname != '': # PID at all
if phymodelname.find(' ') == -1: # no spaces in PID
low_index = int(phyindex)
pid = phymodelname
phy_version = physoftwarerev.split(',')[0]
version = cw_version
if version == '' and sys_version:
version = sys_version
if version == '' and phy_version:
version = phy_version
# remove leading '0' in IOSXE version numbers
if version and version[0] == '0':
version = version.replace('.0', '.')
version = version.lstrip('0')
version = version.rstrip(';')
# todo: cut intermediate for ASA version as option
return version, pid
def get_bug_status(bug_status):
_bug_status = {
'F': 'Fixed',
'O': 'Open',
'T': 'Terminated'
}
return _bug_status.get(bug_status, bug_status)
def get_bug_behavior_changed(behavior_changed):
_behavior_changed = {
'Y': 'yes',
'N': 'no',
}
return _behavior_changed.get(behavior_changed, behavior_changed)
set_loglevel()
# disable_bug = False
optionalcolumns = [
'base_pid',
# 'bug_id',
# 'behavior_changed',
'description',
# 'headline',
'id',
'known_affected_releases',
# 'known_fixed_releases',
# 'last_modified_date',
'product',
# 'severity',
# 'status',
# 'support_case_count',
]
# version = ''
not_updated = 10000000
dont_show_older_then = '0000-00-00'
conf_file = '~/etc/ciscoapi/ciscoapi.conf'
conf_file = os.path.expanduser(conf_file)
bug_status = {}
# prepare path variables (expand homedir and add '/')
base_path = '~/var/ciscoapi'
cw_version, sysdescription = info[0][0]
pids = info[1]
# get parameters from wato
if params:
# do nothing, if suggestion inventory is not explicit enabled via wato
if params.get('disable_bug', False):
return
else:
optionalcolumns = params.get('removecolumns', optionalcolumns)
# get OS version
version, pid = get_OS_Version(cw_version, sysdescription, pids)
if version == '' or pid == '':
return
# check for conf_file and read parameters
if os.path.isfile(conf_file):
configParser = ConfigParser.RawConfigParser()
configParser.read(conf_file)
if configParser.has_option('global', 'base_path'):
base_path = configParser.get('global', 'base_path')
bug_dir = base_path + '/bug'
path_found = expand_path(bug_dir + '/found/')
path_not_found = expand_path(bug_dir + '/not_found/')
path_request = expand_path(bug_dir + '/request/')
status_path = expand_path(base_path + '/status')
# node = inv_tree_list('software.support.cisco_bug.')
node = inv_tree('software.support.cisco_bug.')
node['os_version'] = version
node['PID'] = pid
pid = pid.replace('/', '_')
# bug report found
if os.path.isfile(path_found + pid + '/' + version):
logging.info('snmp_cisco_bug:report found: %s, %s' % (pid, version))
modifytime = os.path.getmtime(path_found + pid + '/' + version)
node['Last_checked'] = time.strftime('%Y-%m-%d', time.localtime(modifytime))
node['status'] = 'found'
bug_record = ''
with open(path_found + pid + '/' + version) as f:
try:
bug_record = json.load(f)
except ValueError, e:
logging.warning('%s:snmp_cisco_bug:bug_found:JSON load error: %s' % (host_name, e))
if bug_record != '':
node['Total_records'] = bug_record.get('total_records', 0)
missing = bug_record.get('missing', {})
if len(missing.keys()) != 0:
node['missing_records'] = len(missing.keys()) * 10
bugs = bug_record.get('bugs')
bug_ids = []
clean_bugs = []
for bug in bugs:
if bug.get('bug_id') not in bug_ids:
bug_ids.append(bug.get('bug_id'))
#bug['known_fixed_releases'] = bug['known_fixed_releases'].split(' ')
#bug['known_affected_releases'] = bug['known_affected_releases'].split(' ')
bug['status'] = get_bug_status(bug['status'])
bug['behavior_changed'] = get_bug_behavior_changed(bug['behavior_changed'])
logging.info('remove columns: %s' % optionalcolumns)
if optionalcolumns is not None:
for column in optionalcolumns:
logging.info('remove column: %s' % column)
bug.pop(column, None)
clean_bugs.append(bug)
node['bugs'] = clean_bugs
node['duplicate_records'] = len(bugs) - len(clean_bugs)
# bug report not found
elif os.path.isfile(path_not_found + pid + '/' + version):
logging.info('snmp_cisco_bug:report not found: %s, %s' % (pid, version))
modifytime = os.path.getmtime(path_not_found + pid + '/' + version)
node['Last_checked'] = time.strftime('%Y-%m-%d', time.localtime(modifytime))
node['status'] = 'Not found'
else:
# create new request
path_request = expand_path(path_request + pid)
if not os.path.isfile(path_request + '/' + version):
logging.info('snmp_cisco_bug:create request: %s, %s' % (pid, version))
with open(path_request + '/' + version, 'w+') as f:
pass
modifytime = os.path.getmtime(path_request + '/' + version)
node['Last_checked'] = time.strftime('%Y-%m-%d', time.localtime(modifytime))
node['status'] = 'requested'
logging.info('bug::node : %s' % node)
# # create and write back api status, will be used for active check cisco_api_status
# apistatus = {}
# lastrun = {}
# laststatus = {}
# thisrun = []
# apiname = 'bug'
# rewrite = False
# use_keys = ['sir', 'advisoryTitle', 'lastUpdated']
#
# if bug_status != {}:
#
# # in CMK v1.5.x global variable g_hostname was replaced by API call host_name()
# try:
# host_name = host_name()
# except NameError:
# host_name = g_hostname
#
# if os.path.isfile(status_path + host_name):
# with open(status_path + host_name) as f:
# try:
# apistatus = json.load(f)
# except ValueError, e:
# logging.warning('snmp_cisco_bug:status:JSON load error: %s' % e)
#
# if apistatus.get(apiname, None) is not None:
# lastrun = apistatus.get(apiname).get('lastrun', {})
# laststatus.update({'status': apistatus.get(apiname).get('status', '')})
# laststatus.update({'product_family': apistatus.get(apiname).get('product_family', '')})
# laststatus.update({'Last_checked': apistatus.get(apiname).get('Last_checked', '')})
# else:
# apistatus.update({apiname: {}})
#
# if bug_status != laststatus:
# apistatus.get(apiname).update(bug_status)
# rewrite = True
#
# if bug_status != node:
# # cleanup bug infos for status
# advisories = node.get('advisories', {})
# if advisories != {}:
# for entry in advisories:
# this_entry = {}
# for key in entry.keys():
# if key in use_keys:
# this_entry.update({key: entry.get(key)})
# thisrun.append(this_entry)
#
# if lastrun != thisrun:
# apistatus.get(apiname).update({'lastrun': thisrun})
# rewrite = True
# if rewrite:
# with open(status_path + host_name, 'w') as f:
# json.dump(apistatus, f)
return node
inv_info['inv_cisco_bug'] = {
'inv_function' : inv_cisco_bug,
'snmp_info' : [('.1.3.6.1',
[
'4.1.9.9.25.1.1.1.2.5', # CISCO-IMAGE-MIB::CW_VERSION
'2.1.1.1.0', # sysDescription
]
),
('.1.3.6.1.2.1.47.1.1.1.1', # ENTITY-MIB::entPhysicalEntry
[
OID_END, # index of entry
'10', # entPhysicalSoftwareRev
'13', # entPhysicalModelName
'5', # entPhysicalClass
]
)],
'snmp_scan_function': lambda oid: 'cisco' in oid('.1.3.6.1.2.1.1.1.0').lower() or '.1.3.6.1.4.1.9.1' in oid('.1.3.6.1.2.1.1.2.0'),
'includes' : ['ciscoapi.include'],
}
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