예제 #1
0
def can_run():
    '''
    This list is eveluated in order
    '''
    profile = get_instance_profile()
    profile.sync_deployment_id()
    profile.sync_salt()

    if not profile.visibility:
        report.report("not-opted-in", True)
        return False

    if not profile.opt_in_is_up_to_date():
        report.report("opt-in-out-of-date-license-only", True)

    report.report("profile.visibility", profile.visibility)
    report.report("profile.cluster_mode", profile.profile.get('cluster_mode'))
    report.report("profile.roles", profile.roles)

    if (profile.roles.get('search_head')
            and not profile.roles.get('shc_member')
        ) or profile.roles.get('sh_captain'):
        report.report("profile.retry_transaction", True)
        profile.retry_transaction()

    if profile.server_info.get('product_type') == "splunk":
        report.report("instance.type", 'Cloud')
        return False

    return True
예제 #2
0
    def _get_visibility(self, events):
        result = {}
        i = get_instance_profile(self._splunkrc)
        visibility = i.visibility

        for event in events:
            vis = event.get('visibility') or []
            for key in vis.split(','):
                if key in visibility:
                    result[key] = True
        return sorted(result.keys())
예제 #3
0
def run(dateRange, schema_file):
    profile = get_instance_profile()
    ms = load_schema(schema_file, profile.visibility)
    sm = ScheduleManager(ms, dataPointFactory)
    logging.info("INST Started")

    if profile.visibility:
        sm.collect(dateRange)
        sleep(5)
        sm.send(dateRange)
    logging.info("INST Done")
예제 #4
0
        def get_file_value(self, earliest, latest, visibility):
            _packager = packager.Packager(splunkrc=self.splunkrc())
            _instance_profile = instance_profile.get_instance_profile(splunkrc=self.splunkrc())
            deployment_id = _instance_profile.get_deployment_id()
            transaction_id = _packager.get_transactionID()
            value = self.get_events_package(earliest, latest, visibility, forExport=True)

            ret_value = {
                "deploymentID": deployment_id,
                "transactionID": transaction_id,
                "data": value}
            return json.dumps(ret_value)
예제 #5
0
    def __init__(self, metricSchema, dataPointFactory, splunkrc=None, phase=1):
        self.metricSchema = metricSchema
        self.dataPointFactory = dataPointFactory
        self.splunkrc = splunkrc
        self.profile = get_instance_profile()
        self.phase = phase

        splunkd = Splunkd(**SPLUNKRC)
        services = ServiceBundle(splunkd)
        salt_manager = SaltManager(services)
        self.salt = salt_manager.get_salt()
        self.scheme = {"hash": self.salt}
예제 #6
0
    def __init__(self,
                 splunkrc=None,
                 deploymentID=None,
                 schema=None,
                 factory=None,
                 send_data=None,
                 send_log=None,
                 instance_profile=None,
                 quick_draw=None):
        self._splunkrc = splunkrc
        self.deploymentID = deploymentID
        self.transaction_id = None
        if not instance_profile:
            self.instance_profile = get_instance_profile(self._splunkrc)
        else:
            self.instance_profile = instance_profile
        if not schema:
            schema = metrics_schema.load_schema(
                INST_SCHEMA_FILE, visibility=self.instance_profile.visibility)
        self.schema = schema
        if not factory:
            factory = dataPointFactory
        self.factory = factory
        self.deliverySchema = self.schema.delivery
        if not quick_draw:
            qd = get_quick_draw()
        else:
            qd = quick_draw
        if qd:
            self.deliverySchema.url = qd.get('url')

        self.transaction_id = self.get_transactionID()

        if not send_data:
            self.sd = SendData(
                deploymentID=self.instance_profile.get_deployment_id(),
                deliverySchema=self.deliverySchema,
                transaction_id=self.get_transactionID())
        else:
            self.sd = send_data

        if not send_log:
            self.sl = SendLog(splunkrc=self._splunkrc)
        else:
            self.sl = send_log

        self.result = None
        self.is_cloud = self.instance_profile.server_is_cloud
예제 #7
0
def run_input(dateRange):
    profile = get_instance_profile()
    pre_run(profile)

    logging.info("INST Started")
    try:
        run_phase_1_for_all_nodes(dateRange, INST_SCHEMA_FILE)
    except Exception as ex:
        report.report('input.error', str(ex))

    if can_run_phase2(profile):
        try:
            run_phase_2(profile, dateRange, INST_SCHEMA_FILE)
            report.send()
        except Exception as ex:
            report.report('input.error', str(ex))

    logging.info("INST Done")
예제 #8
0
 def __init__(self, metricSchema, dataPointFactory, splunkrc=None, phase=1):
     self.metricSchema = metricSchema
     self.dataPointFactory = dataPointFactory
     self.splunkrc = splunkrc
     self.profile = get_instance_profile()
     self.phase = phase
예제 #9
0
def can_run():
    '''
    This list is eveluated in order
    '''
    req_list = [
        {
            "requirements": ['indexer', '!search_peer', '!cluster_slave', '!shc_member'],
            "label": "Single",
            "result": True
        },

        {
            "requirements": ['cluster_master'],
            "label": "Cluster Master",
            "result": True
        },
        {
            "requirements": ['!cluster_master', 'in_cluster'],
            "label": "Cluster Member not Cluster Master",
            "result": False
        },
        # assume we are already not a cluster member from the above requirements
        {
            "requirements": ['shc_captain'],
            "label": "Search Captain in a non cluster",
            "result": True
        },
        {
            "requirements": ['!cluster_master', 'search_head', '!search_peer',
                             '!in_cluster', '!cluster_slave', '!shc_member'],
            "label": "Single Search Head",
            "result": True
        },
    ]
    profile = get_instance_profile()
    profile.sync_deployment_id()
    profile.sync_salt()

    if not profile.visibility:
        report.report("not-opted-in", True)
        return False

    if not profile.opt_in_is_up_to_date():
        report.report("opt-in-out-of-date", True)
        return False

    report.report("profile.visibility", profile.visibility)
    report.report("profile.cluster_mode", profile.profile.get('cluster_mode'))
    report.report("profile.roles", profile.roles)

    if (profile.roles.get('search_head') and not profile.roles.get('shc_member')) or profile.roles.get('sh_captain'):
        report.report("profile.retry_transaction", True)
        profile.retry_transaction()

    for req in req_list:
        result = eval_instance(profile, req['requirements'], req['result'],
                               req['label'])
        if result is not None:
            return result

    if profile.server_info.get('product_type') == "splunk":
        report.report("instance.type", 'Cloud')
        return False

    report.report("instance.type", 'No Match')
    return False