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

Delete snmp_cisco_suggestion

parent a6ee3ba6
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 : 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
#
# import is done by Check_MK
# import logging
# import os
import json
import ConfigParser
def create_suggested_record(pidfile, optionalcolumns):
##################################################################################
# sample original suggestion record
#
# 'suggestion': [{'product': {'productName': 'Nexus 56128P Switch',
# 'softwareType': 'NX-OS System Software'},
# 'mdfId': '283733641',
# 'suggestion': [{'errorDetailsResponse': None,
# 'id': '1',
# 'isSuggested': 'Y',
# 'majorRelease': '7',
# 'relDispName': '7.1(4)N1(1)',
# 'releaseDate': '08 Sep 2016',
# 'releaseFormat1': '7.1(4)N1(1)',
# 'releaseFormat2': '7.1(4)N1(1)',
# 'releaseLifeCycle': '',
# 'releaseTrain': '',
# 'trainDispName': ''}]},
# {'product': {'productName': 'Nexus 56128P Switch',
# 'softwareType': 'NX-OS Kick Start'},
# 'mdfId': '283733641',
# 'suggestion': [{'errorDetailsResponse': None,
# 'id': '1',
# 'isSuggested': 'Y',
# 'majorRelease': '7',
# 'relDispName': '7.1(4)N1(1)',
# 'releaseDate': '08 Sep 2016',
# 'releaseFormat1': '7.1(4)N1(1)',
# 'releaseFormat2': '7.1(4)N1(1)',
# 'releaseLifeCycle': '',
# 'releaseTrain': '',
# 'trainDispName': ''}]}]}
#
#################################################################################
suggestions = {}
if os.path.isfile(pidfile):
with open(pidfile) as f:
suggestedrecord = json.load(f)
modifytime = os.path.getmtime(pidfile)
suggestions.update({'Last_checked': time.strftime('%Y-%m-%d', time.localtime(modifytime))})
suggestions.update({'pid': pidfile.split('/')[-1].replace('_', '/')})
# remove all entry's with errors, for example 'errorDetailsResponse': {'errorCode': 'S3_NO_REC_FOUND'}
cleanrecord = []
for x in suggestedrecord:
if x.get('suggestion')[0].get('errorDetailsResponse') is None:
cleanrecord.append(x)
for product in cleanrecord:
for suggestion in product.get('suggestion'):
for key in suggestion.keys():
temp_value = suggestion.get(key, '')
if temp_value == '' or key in optionalcolumns:
suggestion.pop(key)
# move content from 'suggestion'.'product'.'suggestion' one stage up into 'suggestion'.'product'
product.get('product').update({'suggestion': product.get('suggestion')})
# remove 'suggestion'.'product'.'suggestion'
product.pop('suggestion')
# move content from 'suggestion'.'product' one stage up into 'suggestion'
product.update(product.get('product'))
# remove 'suggestion'.'product'
product.pop('product')
# remove MetaDataFramework ID mdfid, from suggestion api version 2
if 'mdfId' in product.keys():
product.pop('mdfId')
suggestions.update({'suggestion': cleanrecord})
##################################################################################
# sample transformed suggestion record
#
# 'suggestion': [{'productName': 'Nexus 56128P Switch',
# 'softwareType': 'NX-OS System Software',
# 'suggestion': [{'errorDetailsResponse': None,
# 'id': '1',
# 'isSuggested': 'Y',
# 'majorRelease': '7',
# 'relDispName': '7.1(4)N1(1)',
# 'releaseDate': '08 Sep 2016',
# 'releaseFormat1': '7.1(4)N1(1)',
# 'releaseFormat2': '7.1(4)N1(1)'}]},
# {'productName': 'Nexus 56128P Switch',
# 'softwareType': 'NX-OS Kick Start',
# 'suggestion': [{'errorDetailsResponse': None,
# 'id': '1',
# 'isSuggested': 'Y',
# 'majorRelease': '7',
# 'relDispName': '7.1(4)N1(1)',
# 'releaseDate': '08 Sep 2016',
# 'releaseFormat1': '7.1(4)N1(1)',
# 'releaseFormat2': '7.1(4)N1(1)'}]}
#
#################################################################################
logging.debug('snmp_cisco_suggestion:create_suggested_record:suggestions: %s' % suggestions)
return suggestions
def inv_cisco_suggestion(info, params):
# disabled till display hints will work with tables in tables :-(
# ToDo: recreate rendering of tables in tables
return
set_loglevel()
# list of PIDs to drop
global g_PID_black_list
disable_suggestion = False
optionalcolumns = ['isSuggested',
'majorRelease',
'relDispName',
'releaseFormat1',
'releaseTrain',
'trainDispName',
'mdfId',
]
base_path = '~/var/ciscoapi'
conf_file = '~/etc/ciscoapi/ciscoapi.conf'
conf_file = os.path.expanduser(conf_file)
# get parameters from wato
if params:
disable_suggestion = params.get('disable_suggestion', disable_suggestion)
optionalcolumns = params.get('removecolumns', optionalcolumns)
g_PID_black_list = list(set(g_PID_black_list + params.get('PID_black_list', g_PID_black_list)))
logging.debug('PID_black_list: %s' % g_PID_black_list)
# do nothing, if suggestion inventory is not explicit enabled via wato
if disable_suggestion:
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')
sugestion_dir = base_path + '/suggestion'
path_found = expand_path(sugestion_dir + '/found/')
path_not_found = expand_path(sugestion_dir + '/not_found/')
path_request = expand_path(sugestion_dir + '/request/')
status_path = expand_path(base_path + '/status')
node = inv_tree_list('software.support.cisco_suggestion:')
pids = []
suggestions = []
logging.debug('raw info: %s' % info)
raw_pids, sysdescription = info
# find phymodelname with class = chassis
for pid in raw_pids:
phydescr, physoftwarerev, phymodelname, physicalclass = pid
if saveint(physicalclass) == 3:
# check if it has empty version
if physoftwarerev == '':
# if so: extract version from sysDescr and add it to chassis id...
sysdescription = str(sysdescription).split(',')
for entry in sysdescription:
if entry.strip().lower().startswith('version'):
physoftwarerev = entry.strip().lower().replace('version ', '')
pid[1] = physoftwarerev.upper()
# remove all empty PIDs
raw_pids = [i for i in raw_pids if i[2] != '']
# remove all entry's without software version
raw_pids = [i for i in raw_pids if i[1] != '']
logging.debug('info non empty pid: %s' % raw_pids)
# raw_pids = compact_info_by_serial(raw_pids)
for phydescr, physoftwarerev, phymodelname, physicalclass in raw_pids:
logging.debug('inv_cisco_suggestion:raw pid : %s' % phymodelname)
logging.debug('inv_cisco_suggestion:raw version : %s' % physoftwarerev)
logging.debug('inv_cisco_suggestion:raw desc : %s' % phydescr)
pid = phymodelname.split()[0].upper() # cut PID at first space sign, change to all Uppercase
# pid = pid.split('/')[0] # cut PID at first '/' sign
# pid = pid.replace('/', '_')
physoftwarerev = physoftwarerev.split(',')[0] # cut version at first ',' sign
# drop all PIDs on Black List
if not pid_on_black_list(pid):
logging.debug('inv_cisco_suggestion:PID not on blacklist: %s' % pid)
if phydescr == '':
phydescr = 'requested'
# create list of pid's to request software suggestion info for
if pid not in pids:
pids.append(pid)
#temp_pid = pid.replace('_', '/')
node.append({
'pid': pid,
'ProductIDDescription': phydescr,
'software_version': physoftwarerev,
})
logging.debug('snmp_cisco_suggestion:pids : %s' % pids)
for pid in pids:
pidfile = pid.replace('/', '_')
logging.debug('snmp_cisco_suggestion:pid: %s ' % pid)
# find pid in suggestion_found
if os.path.isfile(path_found + pidfile):
logging.debug('snmp_cisco_suggestion:PID found: %s' % pid)
suggestions.append(create_suggested_record(path_found + pidfile, optionalcolumns))
# find pid in path_not_found
elif os.path.isfile(path_not_found + pidfile):
logging.debug('snmp_cisco_suggestion:PID not covered: %s' % pid)
modifytime = os.path.getmtime(path_not_found + pidfile)
suggestions.append({'pid': pid,
'suggestion': 'not found',
'Last_checked': time.strftime('%Y-%m-%d', time.localtime(modifytime)),
})
else:
# create new request in path_request
logging.debug('snmp_cisco_suggestion:PID request: %s' % pid)
if not os.path.isfile(path_request + pidfile):
with open(path_request + pidfile, 'w+') as f:
pass
modifytime = os.path.getmtime(path_request + pidfile)
suggestions.append({'pid': pid,
'suggestion': 'requested',
'Last_checked': time.strftime('%Y-%m-%d', time.localtime(modifytime)),
})
logging.debug('snmp_cisco_suggestion:pids : %s' % pids)
for i in node:
# add suggestion data by pid
for product in suggestions:
if i.get('pid') == product.get('pid'):
i.update(product)
# remove optional columns (already done by create_suggested_record)
#logging.debug('remove columns: %s' % optionalcolumns)
#if optionalcolumns is not None:
# for column in optionalcolumns:
# logging.debug('remove column: %s' % column)
# i.pop(column, None)
# create and write back api status, will be used for active checks
apistatus = {}
lastrun = {}
apiname = 'suggestion'
# in CMK v1.5.x global variable g_hostname was replaced by API call host_name()
try:
_hostname = host_name()
except NameError:
_hostname = g_hostname
if os.path.isfile(status_path + _hostname):
with open(status_path + _hostname) as f:
try:
apistatus = json.load(f)
except ValueError, e:
logging.warning('snmp_cisco_suggestion:status:JSON load error: %s' % e)
if apistatus.get(apiname, None) != None:
lastrun = apistatus.get(apiname).get('lastrun', {})
if lastrun != node:
apistatus.update({apiname: {}})
apistatus.get(apiname).update({'lastrun': node})
with open(status_path + _hostname, 'w') as f:
json.dump(apistatus, f)
return node
inv_info['inv_cisco_suggestion'] = {
'inv_function': inv_cisco_suggestion,
'snmp_info': [('.1.3.6.1.2.1.47.1.1.1.1', [ # ENTITY-MIB::entPhysicalEntry
'2', # entPhysicalDescr
'10', # entPhysicalSoftwareRev
'13', # entPhysicalModelName
'5', # entPhysicalClass
]),
('.1.3.6.1.2.1.1.1', ['0'] # sysDescr
)],
'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