You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.9 KiB
76 lines
2.9 KiB
# -*- coding: utf-8 -*-
|
|
# Core Python Imports
|
|
import sys
|
|
import logging
|
|
import logging.handlers
|
|
import json
|
|
import splunk.search as splunkSearch
|
|
|
|
# CherryPy Web Controller Imports
|
|
import cherrypy
|
|
import splunk.appserver.mrsparkle.controllers as controllers
|
|
from splunk.appserver.mrsparkle.lib.decorators import expose_page
|
|
from splunk.appserver.mrsparkle.lib.routes import route
|
|
from splunk.clilib.bundle_paths import make_splunkhome_path
|
|
|
|
# Splunkd imports
|
|
import splunk
|
|
|
|
sys.path.append(make_splunkhome_path(['etc', 'apps', 'DA-ITSI-CP-vmware-dashboards', 'local', 'data']))
|
|
|
|
def setupLogger(logger=None, log_format='%(asctime)s %(levelname)s [IsNetappInstalled] %(message)s',
|
|
level=logging.INFO, log_name="is_netapp_installed.log", logger_name="is_netapp_installed"):
|
|
"""
|
|
Setup a logger suitable for splunkd consumption
|
|
:param logger: Logger object
|
|
:param log_format : Format for the log to be stored in logger.
|
|
:param level: Logging level
|
|
:param log_name: Name of the log file to be created
|
|
:param logger_name: Name of the logger.
|
|
"""
|
|
if logger is None:
|
|
logger = logging.getLogger(logger_name)
|
|
|
|
logger.propagate = False # Prevent the log messages from being duplicated in the python.log file
|
|
logger.setLevel(level)
|
|
|
|
file_handler = logging.handlers.RotatingFileHandler(make_splunkhome_path(['var', 'log', 'splunk', log_name]),
|
|
maxBytes=2500000, backupCount=5)
|
|
formatter = logging.Formatter(log_format)
|
|
file_handler.setFormatter(formatter)
|
|
|
|
logger.handlers = []
|
|
logger.addHandler(file_handler)
|
|
|
|
logger.debug("init netapp install check logger")
|
|
|
|
return logger
|
|
|
|
logger = setupLogger()
|
|
splunk.setDefault()
|
|
local_host_path = splunk.mergeHostPath()
|
|
|
|
class IsNetAppInstalled(controllers.BaseController):
|
|
'''This class will be used to check whether any data
|
|
from Content Pack for NetApp Data ONTAP Dashboards and Reports is present or not'''
|
|
|
|
@route('/:action=check')
|
|
@expose_page(must_login=True, methods=['GET'])
|
|
def check(self, action):
|
|
"""
|
|
Sets flag value by determining the availability of Ontap data using metadata search.
|
|
Returns netapp_installed = 0 if no Ontap data is found otherwise 1.
|
|
:param app: DA-ITSI-CP-vmware-dashboards
|
|
:param action: check
|
|
:return: netapp_installed {boolean}
|
|
"""
|
|
sessionKey = cherrypy.session.get('sessionKey')
|
|
search = '| metadata type=sourcetypes `ontap-index`'
|
|
logger.info('Retrieving metadata for Ontap Sourcetypes')
|
|
results = splunkSearch.searchOne(search, hostPath=local_host_path, sessionKey=sessionKey, namespace=None, owner='nobody')
|
|
netapp_installed = 0
|
|
if results is not None and len(results.values()) > 0:
|
|
netapp_installed = 1
|
|
logger.info("Found Netapp Ontap data")
|
|
return self.render_json(netapp_installed)
|