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

update project

parent b74c3811
No related branches found
No related tags found
No related merge requests found
......@@ -13,42 +13,41 @@ def cisco_api_status_arguments(params):
# example
# {'psirt': {'warn-severity': 3, 'warn-days': 31, 'crit-days': 7, 'crit-severity': 1}}
# print params
if params:
if params.get('psirt'):
if params.get('psirt').get('crit-days') is not None:
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') is not None:
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') is not None:
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') is not None:
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') is not None:
if params.get('psirt').get('not-active'):
args.append('--psirt-not-active %s' % params.get('psirt').get('not-active'))
if params.get('eox'):
if params.get('eox').get('crit-new') is not None:
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') is not None:
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') is not None:
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') is not None:
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') is not None:
if params.get('eox').get('not-active'):
args.append('--eox-not-active %s' % params.get('eox').get('not-active'))
if params.get('sn2info'):
if params.get('sn2info').get('crit-change') is not None:
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') is not None :
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') is not None:
if params.get('sn2info').get('not-active'):
args.append('--sn2info-not-active %s' % params.get('sn2info').get('not-active'))
if params.get('suggestion'):
if params.get('suggestion').get('not-active') is not None:
if params.get('suggestion').get('not-active'):
args.append('--suggestion-not-active %s' % params.get('suggestion').get('not-active'))
# in CMK v1.5.x global variable g_hostname was replaced by API call host_name()
......
No preview for this file type
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#
# 20.03.2017 : writen by Th.L. to collect/show Cisco hardware contract status
# License: GNU General Public License v2
#
# 29.05.2017 : fixed empty pid handling
# : added serial number cleanup
# 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 : chaged variable host_anme to _hostname for cmk1.5
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2027-03-20
#
# collect/show Cisco hardware contract status
#
# 2017-05-29 : fixed empty pid handling
# added serial number cleanup
# 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 : chaged variable host_anme to _hostname for cmk1.5
# 2020-08-04 : moved node tree from hardware.system.support to hardware.system
# cleanup create_sn2info_record
#
# import is done by Check_MK
# import logging
......@@ -17,7 +25,7 @@ import json
import ConfigParser
def create_sn2info_record(sn2infofile):
def create_sn2info_record(sn2infofile, optional_columns):
sn2info = {}
if os.path.isfile(sn2infofile):
with open(sn2infofile) as f:
......@@ -27,52 +35,26 @@ def create_sn2info_record(sn2infofile):
sn2info.update({'Last_checked': time.strftime('%Y-%m-%d', time.localtime(modifytime))
})
# get info's from sn2info File
serial_number = sn2inforecord.get('sr_no')
is_covered = sn2inforecord.get('is_covered')
contract_site_customer_name = sn2inforecord.get('contract_site_customer_name')
contract_site_address1 = sn2inforecord.get('contract_site_address1')
contract_site_city = sn2inforecord.get('contract_site_city')
contract_site_state_province = sn2inforecord.get('contract_site_state_province')
contract_site_country = sn2inforecord.get('contract_site_country')
service_line_descr = sn2inforecord.get('service_line_descr')
service_contract_number = sn2inforecord.get('service_contract_number')
covered_product_line_end_date = sn2inforecord.get('covered_product_line_end_date')
parent_sr_no = sn2inforecord.get('parent_sr_no')
warranty_type = sn2inforecord.get('warranty_type')
warranty_type_description = sn2inforecord.get('warranty_type_description')
warranty_end_date = sn2inforecord.get('warranty_end_date')
# add nonempty info's to sn2inforecord
if (serial_number is not None) and (serial_number != ''):
sn2info.update({'serial_number': serial_number})
if (is_covered is not None) and (is_covered != ''):
sn2info.update({'is_covered': is_covered})
if (contract_site_customer_name is not None) and (contract_site_customer_name != ''):
sn2info.update({'contract_site_customer_name': contract_site_customer_name})
if (contract_site_address1 is not None) and (contract_site_address1 != ''):
sn2info.update({'contract_site_address1': contract_site_address1})
if (contract_site_city is not None) and (contract_site_city != ''):
sn2info.update({'contract_site_city': contract_site_city})
if (contract_site_state_province is not None) and (contract_site_state_province != ''):
sn2info.update({'contract_site_state_province': contract_site_state_province})
if (contract_site_country is not None) and (contract_site_country != ''):
sn2info.update({'contract_site_country': contract_site_country})
if (service_line_descr is not None) and (service_line_descr != ''):
sn2info.update({'service_line_descr': service_line_descr})
if (service_contract_number is not None) and (service_contract_number != ''):
sn2info.update({'service_contract_number': service_contract_number})
if (covered_product_line_end_date is not None) and (covered_product_line_end_date != ''):
sn2info.update({'covered_product_line_end_date': covered_product_line_end_date})
if (parent_sr_no is not None) and (parent_sr_no != ''):
sn2info.update({'parent_sr_no': parent_sr_no})
if (warranty_type is not None) and (warranty_type != ''):
sn2info.update({'warranty_type': warranty_type})
if (warranty_type_description is not None) and (warranty_type_description != ''):
sn2info.update({'warranty_type_description': warranty_type_description})
if (warranty_end_date is not None) and (warranty_end_date != ''):
sn2info.update({'warranty_end_date': warranty_end_date})
# add nonempty values to sn2inforecord
for key, value in [
('serial_number', sn2inforecord.get('sr_no')),
('is_covered', sn2inforecord.get('is_covered')),
('contract_site_customer_name', sn2inforecord.get('contract_site_customer_name')),
('contract_site_address1', sn2inforecord.get('contract_site_address1')),
('contract_site_city', sn2inforecord.get('contract_site_city')),
('contract_site_state_province', sn2inforecord.get('contract_site_state_province')),
('contract_site_country', sn2inforecord.get('contract_site_country')),
('service_line_descr', sn2inforecord.get('service_line_descr')),
('service_contract_number', sn2inforecord.get('service_contract_number')),
('covered_product_line_end_date', sn2inforecord.get('covered_product_line_end_date')),
('parent_sr_no', sn2inforecord.get('parent_sr_no')),
('warranty_type', sn2inforecord.get('warranty_type')),
('warranty_type_description', sn2inforecord.get('warranty_type_description')),
('warranty_end_date', sn2inforecord.get('warranty_end_date')),
]:
value = value.strip()
if value != '' and key not in optional_columns:
sn2info[key] = value
logging.info('create_sn2info_record sn2info: %s' % sn2info)
return sn2info
......@@ -119,7 +101,7 @@ def inv_cisco_contract(info, params):
path_request = expand_path(sn2info_dir + '/request/')
status_path = expand_path(base_path + '/status')
node = inv_tree_list('hardware.system.support.cisco_contract:')
node = inv_tree_list('hardware.support.cisco_contract:')
serials = []
serialscontract = []
......@@ -142,15 +124,17 @@ def inv_cisco_contract(info, params):
logging.info('raw sn : %s' % physerialnum)
logging.info('raw desc : %s' % phydescr)
pid = phymodelname.split()[0].upper() # cut PID at first space sign, change to all Uppercase
# cut PID/SN at first space sign, change to all Uppercase
pid = phymodelname.split()[0].upper()
physerialnum = physerialnum.split()[0].upper()
# drop all PIDs on Black List
# drop all PIDs on Black List, create default node entry for SN
if not pid_on_black_list(pid):
logging.info('PID not on blacklist: %s' % pid)
if phydescr == "":
phydescr = 'requested'
physerialnum = physerialnum.split()[0].upper()
# create list of serial numbers to request contract info for
serials.append(physerialnum)
......@@ -167,7 +151,7 @@ def inv_cisco_contract(info, params):
# find serial in SER-sn2info-covered
if os.path.isfile(path_found + serial):
logging.info("Serial number covered: %s" % serial)
serialscontract.append(create_sn2info_record(path_found + serial))
serialscontract.append(create_sn2info_record(path_found + serial, optionalcolumns))
logging.info("Serial number Record: %s" % serialscontract)
# find serial in SER-sn2info-notcovered
elif os.path.isfile(path_not_found + serial):
......@@ -191,17 +175,12 @@ def inv_cisco_contract(info, params):
logging.info("Serials contract : %s" % serialscontract)
# update default entrys with data
for i in node:
# add contract data by serial number
for serial in serialscontract:
if i.get('serial_number') == serial.get('serial_number'):
i.update(serial)
# remove optional columns
logging.info('remove columns: %s' % optionalcolumns)
if optionalcolumns is not None:
for column in optionalcolumns:
logging.info('remove column: %s' % column)
i.pop(column, None)
# create and write back api status, will be used for active check cisco_api_status
apistatus = {}
......
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#
# 20.03.2017 : writen by Th.L. to collect/show Cisco hardware EoX status
# License: GNU General Public License v2
#
# 29.05.2017 : fixed empty pid handling
# : added serial number cleanup
# 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.2018 : changed variable host_name to _hostname for cmk 1.5
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2017-03-20
#
# collect/show Cisco hardware EoX status
#
# 2017-05-29 : fixed empty pid handling
# added serial number cleanup
# 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-08-13 : changed variable host_name to _hostname for cmk 1.5
# 2020-08-04 : code cleanup (create_eox_record function)
# moved node tree from hardware.system.support to hardware.system
#
# import is done by Check_MK
......@@ -18,79 +26,52 @@ import json
import ConfigParser
def create_eox_record(eoxfile):
def create_eox_record(eoxfile, optional_columns):
eox = {}
if os.path.isfile(eoxfile):
with open(eoxfile) as f:
eoxrecord = json.load(f)
modifytime = os.path.getmtime(eoxfile)
eox.update({'Last_checked': time.strftime('%Y-%m-%d', time.localtime(modifytime))})
eox.update({'pid': eoxrecord.get('EOLProductID')})
# get infos from EOX File
ProductIDDescription = eoxrecord.get('ProductIDDescription')
EOXExternalAnnouncementDate = eoxrecord.get('EOXExternalAnnouncementDate').get('value')
EndOfSaleDate = eoxrecord.get('EndOfSaleDate').get('value')
EndOfSvcAttachDate = eoxrecord.get('EndOfSvcAttachDate').get('value')
LastDateOfSupport = eoxrecord.get('LastDateOfSupport').get('value')
ProductBulletinNumber = eoxrecord.get('ProductBulletinNumber')
LinkToProductBulletinURL = eoxrecord.get('LinkToProductBulletinURL')
UpdatedTimeStamp = eoxrecord.get('UpdatedTimeStamp').get('value')
EndOfSecurityVulSupportDate = eoxrecord.get('EndOfSecurityVulSupportDate').get('value')
EndOfSWMaintenanceReleases = eoxrecord.get('EndOfSWMaintenanceReleases').get('value')
EndOfRoutineFailureAnalysisDate = eoxrecord.get('EndOfRoutineFailureAnalysisDate').get('value')
EOXInputType = eoxrecord.get('EOXInputType')
eox['Last_checked'] = time.strftime('%Y-%m-%d', time.localtime(modifytime))
eox['pid'] = eoxrecord.get('EOLProductID')
# Migration Info
EOXMigrationDetails = eoxrecord.get('EOXMigrationDetails')
MigrationProductId = EOXMigrationDetails.get('MigrationProductId')
MigrationInformation = EOXMigrationDetails.get('MigrationInformation')
MigrationProductInfoURL = EOXMigrationDetails.get('MigrationProductInfoURL')
MigrationProductName = EOXMigrationDetails.get('MigrationProductName')
# add nonempty infos to eoxrecord
if (ProductIDDescription is not None) and (ProductIDDescription != ' '):
eox.update({'ProductIDDescription': ProductIDDescription})
if (EOXExternalAnnouncementDate is not None) and (EOXExternalAnnouncementDate != ' '):
eox.update({'EOXExternalAnnouncementDate': EOXExternalAnnouncementDate})
if (EndOfSaleDate is not None) and (EndOfSaleDate != ' '):
eox.update({'EndOfSaleDate': EndOfSaleDate})
if (EndOfSvcAttachDate is not None) and (EndOfSvcAttachDate != ' '):
eox.update({'EndOfSvcAttachDate': EndOfSvcAttachDate})
if (LastDateOfSupport is not None) and (LastDateOfSupport != ' '):
eox.update({'LastDateOfSupport': LastDateOfSupport})
if (ProductBulletinNumber is not None) and (ProductBulletinNumber != ' '):
eox.update({'ProductBulletinNumber': ProductBulletinNumber})
if (LinkToProductBulletinURL is not None) and (LinkToProductBulletinURL != ' '):
eox.update({'LinkToProductBulletinURL': LinkToProductBulletinURL})
if (UpdatedTimeStamp is not None) and (UpdatedTimeStamp != ' '):
eox.update({'UpdatedTimeStamp': UpdatedTimeStamp})
if (EndOfSecurityVulSupportDate is not None) and (EndOfSecurityVulSupportDate != ' '):
eox.update({'EndOfSecurityVulSupportDate': EndOfSecurityVulSupportDate})
if (EndOfSWMaintenanceReleases is not None) and (EndOfSWMaintenanceReleases != ' '):
eox.update({'EndOfSWMaintenanceReleases': EndOfSWMaintenanceReleases})
if (EndOfRoutineFailureAnalysisDate is not None) and (EndOfRoutineFailureAnalysisDate != ' '):
eox.update({'EndOfRoutineFailureAnalysisDate' : EndOfRoutineFailureAnalysisDate})
# Migration Info
if (MigrationProductId is not None) and (MigrationProductId != ' '):
eox.update({'MigrationProductId': MigrationProductId})
if (MigrationInformation is not None) and (MigrationInformation != ' '):
eox.update({'MigrationInformation': MigrationInformation})
if (MigrationProductInfoURL is not None) and (MigrationProductInfoURL != ' '):
eox.update({'MigrationProductInfoURL': MigrationProductInfoURL})
if (MigrationProductName is not None) and (MigrationProductName != ' '):
eox.update({'MigrationProductName': MigrationProductName})
for key, value in [
('ProductIDDescription', eoxrecord.get('ProductIDDescription', '')),
('EOXExternalAnnouncementDate', eoxrecord.get('EOXExternalAnnouncementDate').get('value', '')),
('EndOfSaleDate', eoxrecord.get('EndOfSaleDate').get('value', '')),
('EndOfSvcAttachDate', eoxrecord.get('EndOfSvcAttachDate').get('value', '')),
('LastDateOfSupport', eoxrecord.get('LastDateOfSupport').get('value', '')),
('ProductBulletinNumber', eoxrecord.get('ProductBulletinNumber', '')),
('LinkToProductBulletinURL', eoxrecord.get('LinkToProductBulletinURL', '')),
('UpdatedTimeStamp', eoxrecord.get('UpdatedTimeStamp').get('value', '')),
('EndOfSecurityVulSupportDate', eoxrecord.get('EndOfSecurityVulSupportDate').get('value', '')),
('EndOfSWMaintenanceReleases', eoxrecord.get('EndOfSWMaintenanceReleases').get('value', '')),
('EndOfRoutineFailureAnalysisDate', eoxrecord.get('EndOfRoutineFailureAnalysisDate').get('value', '')),
# Migration Info
('MigrationProductId', EOXMigrationDetails.get('MigrationProductId', '')),
('MigrationInformation', EOXMigrationDetails.get('MigrationInformation', '')),
('MigrationProductInfoURL', EOXMigrationDetails.get('MigrationProductInfoURL', '')),
('MigrationProductName', EOXMigrationDetails.get('MigrationProductName', '')),
]:
value = value.strip()
if value != '' and key not in optional_columns:
eox[key] = value
# add serial if EoX from get_eox_by_serial
EOXInputType = eoxrecord.get('EOXInputType')
if EOXInputType == 'ShowEOXBySerialNumber':
eox.update({'serial_number': eoxrecord.get('EOXInputValue')})
eox['serial_number'] = eoxrecord.get('EOXInputValue')
return eox
def inv_cisco_eox(info, params):
set_loglevel()
# list of PIDs to drop
......@@ -109,6 +90,7 @@ def inv_cisco_eox(info, params):
'MigrationProductInfoURL',
'MigrationProductName',
]
base_path = '~/var/ciscoapi'
conf_file = '~/etc/ciscoapi/ciscoapi.conf'
conf_file = os.path.expanduser(conf_file)
......@@ -151,7 +133,7 @@ def inv_cisco_eox(info, params):
status_path = expand_path(base_path + '/status')
node = inv_tree_list('hardware.system.support.cisco_eox:')
node = inv_tree_list('hardware.support.cisco_eox:')
pids = []
pidseox = []
......@@ -177,18 +159,17 @@ def inv_cisco_eox(info, params):
logging.info('raw sn : %s' % physerialnum)
logging.info('raw desc : %s' % phydescr)
# cut PID at first space sign, change to all Uppercase
# cut PID/SN at first space sign, change to all Uppercase
pid = phymodelname.split()[0].upper()
physerialnum = physerialnum.split()[0].upper()
# drop all PIDs on Black List
# drop all PIDs/SNs on Black List
if not pid_on_black_list(pid) and not sn_on_black_list(physerialnum):
logging.info('PID not on blacklist: %s' % pid)
if phydescr == "":
phydescr = 'requested'
physerialnum = physerialnum.split()[0].upper()
# check if PID on bad list, if so try serial number
if pid_on_bad_list(pid) or always_use_serial:
logging.info('PID on bad list: %s' % pid)
......@@ -198,6 +179,7 @@ def inv_cisco_eox(info, params):
pids.append(pid)
logging.info('PID not on bad list: %s' % pid)
# create default node entry for PID/SN
node.append({
"serial_number" : physerialnum,
"pid" : pid,
......@@ -216,7 +198,7 @@ def inv_cisco_eox(info, params):
# find pid in PID-EOX-known
if os.path.isfile(path_found_pid + pidfile):
logging.info("PID known: %s" % pid)
pidseox.append(create_eox_record(path_found_pid + pidfile))
pidseox.append(create_eox_record(path_found_pid + pidfile, optionalcolumns))
logging.info("EOX Record: %s" % pidseox)
# find pid in PID-EOX-unknown
elif os.path.isfile(path_not_found_pid + pidfile):
......@@ -244,7 +226,7 @@ def inv_cisco_eox(info, params):
# find serial in SER-EOX-known
if os.path.isfile(path_found_ser + serial):
logging.info("Serialnumber known: %s" % serial)
serialseox.append(create_eox_record(path_found_ser + serial))
serialseox.append(create_eox_record(path_found_ser + serial, optionalcolumns))
logging.info("Serialnumber Record: %s" % serialseox)
# find serial in SER-EOX-unknown
elif os.path.isfile(path_not_found_ser + serial):
......@@ -269,6 +251,7 @@ def inv_cisco_eox(info, params):
logging.info("PID EoX : %s" % pidseox)
logging.info("Serials EoX : %s" % serialseox)
# update default entrys with data
for i in node:
# add EoX data by pid
for pid in pidseox:
......@@ -278,12 +261,6 @@ def inv_cisco_eox(info, params):
for serial in serialseox:
if i.get('serial_number') == serial.get('serial_number'):
i.update(serial)
# remove optional columns
logging.info('remove columns: %s' % optionalcolumns)
if optionalcolumns is not None:
for column in optionalcolumns:
logging.info('remove column: %s' % column)
i.pop(column, None)
# create and write back api status, will be used for active check cisco_api_status
apistatus = {}
......
......@@ -69,8 +69,8 @@ def create_suggested_record(pidfile, optionalcolumns):
for product in cleanrecord:
for suggestion in product.get('suggestion'):
for key in suggestion.keys():
temp_value = suggestion.get(key)
if (temp_value is None) or (temp_value == '') or (key in optionalcolumns):
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'
......@@ -257,12 +257,12 @@ def inv_cisco_suggestion(info, params):
for product in suggestions:
if i.get('pid') == product.get('pid'):
i.update(product)
# remove optional columns
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)
# 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 = {}
......
#!/usr/bin/python
# encoding: utf-8
# Monitor Cisco API plugins for CheckMK
# Author: thl-cmk[al]outlook[dot]com
#
#
# 15.03.2020: changed getopt to argparse
import os
import argparse
import sys
import getopt
import ConfigParser
import json
from datetime import datetime
......@@ -16,6 +14,61 @@ 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
......@@ -47,7 +100,7 @@ def expand_path(path):
return path
def check_eox_status(apistatus, options, cmd_args):
def check_eox_status(apistatus, options):
# set logg modul name <file>:<module>.<function>
logger = logging.getLogger(__file__ + ':' + __name__ + '.' + sys._getframe().f_code.co_name)
......@@ -59,10 +112,10 @@ def check_eox_status(apistatus, options, cmd_args):
lastrun = apistatus.get('lastrun')
refresh_known = options.get('refresh_known', 31)
refresh_unknown = options.get('refresh_unknown', 7)
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
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)
for entry in lastrun:
last_checked = entry.get('Last_checked')
......@@ -89,7 +142,7 @@ def check_eox_status(apistatus, options, cmd_args):
# check if date is about to change
for key in entry.keys():
if key in EoL_dates and entry.get(key) != '':
if key in EoL_dates:
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):
......@@ -136,7 +189,7 @@ def check_eox_status(apistatus, options, cmd_args):
return output, long_output, status
def check_psirt_status(apistatus, options, cmd_args):
def check_psirt_status(apistatus, options):
# set logg modul name <file>:<module>.<function>
logger = logging.getLogger(__file__ + ':' + __name__ + '.' + sys._getframe().f_code.co_name)
......@@ -159,10 +212,10 @@ def check_psirt_status(apistatus, options, cmd_args):
refresh_found = options.get('refresh_found', 1)
refresh_notfound = options.get('refresh_notfound', 1)
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
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)
if (psirt_status == 'found') and (last_refresh > refresh_found):
max_refresh_known = last_refresh
......@@ -201,7 +254,7 @@ def check_psirt_status(apistatus, options, cmd_args):
return output, long_output, status
def check_sn2info_status(apistatus, options, cmd_args):
def check_sn2info_status(apistatus, options):
# set logg modul name <file>:<module>.<function>
logger = logging.getLogger(__file__ + ':' + __name__ + '.' + sys._getframe().f_code.co_name)
......@@ -214,8 +267,8 @@ def check_sn2info_status(apistatus, options, cmd_args):
refresh_covered = options.get('refresh_covered', 31)
refresh_notcovered = options.get('refresh_notcovered', 7)
crit_change = cmd_args.sn2info_crit_change
warn_change = cmd_args.sn2info_warn_change
crit_change = options.get('crit-change', 0)
warn_change = options.get('warn-change', 0)
for entry in lastrun:
last_checked = entry.get('Last_checked')
......@@ -269,7 +322,7 @@ def check_sn2info_status(apistatus, options, cmd_args):
return output, long_output, status
def check_suggestion_status(apistatus, options, cmd_args):
def check_suggestion_status(apistatus, options):
# set logg modul name <file>:<module>.<function>
logger = logging.getLogger(__file__ + ':' + __name__ + '.' + sys._getframe().f_code.co_name)
......@@ -324,6 +377,7 @@ def main():
output = ''
long_output = ''
apistatus = {}
target = ''
loglevel = 'warning'
......@@ -367,29 +421,79 @@ def main():
os.unsetenv("LANG")
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 = []
# 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)
eox_output = ''
eox_long_output = ''
......@@ -411,16 +515,16 @@ def main():
output = 'Cisco API active.'
with open(ciscoapistatus + target) as f:
apistatus = json.load(f)
long_output = 'active API(s) found: ' + ', '.join(apistatus.keys())
long_output = 'active APIs 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, cmd_args)
eox_output, eox_long_output, eox_status = check_eox_status(apistatus.get(key), opt_eox)
if key == 'psirt':
psirt_output, psirt_long_output, psirt_status = check_psirt_status(apistatus.get(key), opt_psirt, cmd_args)
psirt_output, psirt_long_output, psirt_status = check_psirt_status(apistatus.get(key), opt_psirt)
if key == 'sn2info':
sn2info_output, sn2info_long_output, sn2info_status = check_sn2info_status(apistatus.get(key), opt_sn2info, cmd_args)
sn2info_output, sn2info_long_output, sn2info_status = check_sn2info_status(apistatus.get(key), opt_sn2info)
if key == 'suggestion':
suggestion_output, suggestion_long_output, suggestion_status = check_suggestion_status(apistatus.get(key), opt_suggestion, cmd_args)
suggestion_output, suggestion_long_output, suggestion_status = check_suggestion_status(apistatus.get(key), opt_suggestion)
long_output += eox_long_output + sn2info_long_output + psirt_long_output + suggestion_long_output + '\n'
......@@ -434,24 +538,26 @@ def main():
if status > 0:
output += ' (see long output for details)'
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))
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.'
else:
output = 'Cisco API not active(!)'
status = max(1, status)
......
......@@ -30,4 +30,4 @@
'title': u'Inventory for Cisco Bug, EoX, contract status, PSIRT advisories and suggested software',
'version': '20190830.v0.0.11',
'version.min_required': '1.4.0p1',
'version.packaged': '1.6.0p8'}
\ No newline at end of file
'version.packaged': '1.4.0p38'}
\ No newline at end of file
This diff is collapsed.
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