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.

96 lines
4.7 KiB

# Copyright (C) 2005-2025 Splunk Inc. All Rights Reserved.
import json
import splunk.rest as rest
from itsi.upgrade.constants import ENTITY_TYPE_OBJECT_URL
from migration.migration_precheck import MigrationPreCheck
class IMPrechecks(MigrationPreCheck):
"""
IM migration prechecks. The checks being performed are:
* Check for dashboard drilldowns in entity type objects
"""
def __init__(self, session_key, logger, pre_checks, skip_pre_checks=[]):
MigrationPreCheck.__init__(
self, session_key, logger, pre_checks, skip_pre_checks)
def precheck_DBOARD_DRILLDOWN(self):
'''
* check splunk_dashboard should have empty base_url
* check OOTB dashboards should have empty base_url
* check navigation link dashboard should have non-empty base_url
@rtype: list
@return: list of dictionaries that has following key/values:
{bool} if the precheck passed
{string} corresponding recommendation
'''
ret_list = []
preconfigured_ids = ['nix_overview_dashboard',
'addon_overview_dashboard',
'vmware_cluster_overview_dashboard',
'vmware_datastore_overview_dashboard',
'vmware_esxi_overview_dashboard',
'vmware_vcenter_overview_dashboard',
'vmware_vm_overview_dashboard',
'windows_overview_dashboard']
entity_types = self.get_entity_type_objects()
if isinstance(entity_types, tuple):
return [self._make_result(entity_types[0], entity_types[1], 'Error')]
for entity_type in entity_types:
dboard_drilldown = entity_type.get('dashboard_drilldowns')
if dboard_drilldown:
for dboard in dboard_drilldown:
if 'is_splunk_dashboard' in dboard:
if dboard.get('is_splunk_dashboard') and dboard.get('base_url') != '':
ret_list.append(self._make_result(False, ('%s Entity type has %s dashboard (xml) for which'
' the base_url is %s but actual base_url should'
' be empty' % (
entity_type.get('title'), dboard.get(
'title'), dboard.get('base_url'))), 'Warn'))
if (not dboard.get('is_splunk_dashboard') and dboard.get('id') in preconfigured_ids
and dboard.get('base_url') != ''):
ret_list.append(self._make_result(
False, '%s Entity type has %s dashboard (udf) for which the base_url is %s'
' but actual base_url should be empty' % (
entity_type.get('title'), dboard.get(
'title'), dboard.get('base_url')), 'Warn'))
if (not dboard.get('is_splunk_dashboard') and dboard.get('id') not in preconfigured_ids
and dboard.get('base_url') == ''):
ret_list.append(self._make_result(
False, '%s Entity type has %s dashboard (navigation link) for which the'
' base_url is Empty but actual base_url'
' should not be empty' % (
entity_type.get('title'), dboard.get(
'title')), 'Warn'))
if len(ret_list) == 0:
return [self._make_result(True, 'dashboard prechecks passed', 'Success')]
return ret_list
def get_entity_type_objects(self):
'''
Get entity type objects
@rtype: list or tuple
@return: list of entity types object if success, otherwise return tuple for any failures.
'''
try:
response, content = rest.simpleRequest(ENTITY_TYPE_OBJECT_URL, sessionKey=self.session_key, method='GET',
getargs={'output_mode': 'json'}, rawResult=True)
except Exception as e:
self.logger.exception(e)
return False, "Failed to fetch entity type objects."
if response.status != 200:
message = 'Error retrieving entity type objects. Response: %s, Content: %s' % (
response, content)
self.logger.error(message)
return False, message
return json.loads(content)