Example #1
0
def run_input(dateRange):
    if can_run():
        try:
            run(dateRange, INST_SCHEMA_FILE)
            report.send()
        except Exception as ex:
            report.report('input.error', str(ex))
Example #2
0
def processRequest(req):
    
    sessionID=req.get('responseId')
    result = req.get("queryResult")
    user_says=result.get("queryText")  
    parameters = result.get("parameters")
    
    intent = result.get("intent").get('displayName')
    
    if (intent=='cust_details'):
        result = req.get("queryResult")
        user_says=result.get("queryText")
        
        parameters = result.get("parameters")
        cust_name=parameters.get("name")
        
        cust_contact = parameters.get("phone")
        cust_email=parameters.get("email")


        #Webscrap from website
        state, state_dic=webscrap.webscrap()
        
        # Pushing data to database
        users_dic=[{"cust_name":cust_name}, {"cust_email":cust_email},{"cust_contact":cust_contact}]
        pushtodb.pushtodb(state_dic, users_dic )
       
        # Report generation
        report.report(state)

        #sending email
        sendemail.sendemail(cust_email)       
        # terminating the session 
        fulfillmentText="Thanks for sharing details, a report has been sent to your email id"
        
        return {
            "fulfillmentText": fulfillmentText
        }
    elif(intent=='stat'):

        state_ut=parameters.get("geo-state")
        
        from pymongo import MongoClient
        from bson.json_util import dumps 
       
        client=MongoClient('mongodb+srv://test:[email protected]/test?retryWrites=true&w=majority')
        mydb=client['covid']
        information=mydb.collection
        statistics=dumps(information.find({"States/UT":state_ut}).limit(1))
        print(statistics)
        string=statistics[47:]
        string=string.replace('"','')
        string=string.replace(']','')
        string=string.replace('}','')

        return {
            "fulfillmentText": string
        }     
Example #3
0
def eval_instance(profile, requirements, result, label):
    for reqi in requirements:
        if (reqi[0] == "!"):
            reqi = reqi.replace("!", "")
            if profile.roles.get(reqi):
                return None
        elif not profile.roles.get(reqi):
            return None
    report.report("instance.type", label)
    return result
Example #4
0
def test2():
    IMAGE_NAME = "image/yangxuanyue/yangxuanyue.jpg"
    cutout(IMAGE_NAME)
    center_points = roi(IMAGE_NAME)
    report_list = {}
    report_list.update(feature_7(IMAGE_NAME))
    report_list.update(feature_9(IMAGE_NAME))
    report_list.update(feature_10(IMAGE_NAME))
    print(center_points)
    showall(IMAGE_NAME, center_points)
    report(IMAGE_NAME, report_list)
Example #5
0
def test_report():
    parms = {
        'templtJson':
        '/home/testData/mapping_report/data/mapping_template.json',
        'template': '/home/testData/mapping_report/mapping_template.md'
    }
    res = report(parms)
def run_phase_1_for_all_nodes(dateRange, schema_file):
    '''
    phase 1 runs by all nodes to collect role based data and index to data to _introspection
    phase 1 does not check opt in options

    :param profile
    :param dateRange
    :param schema_file
    :return: None
    '''

    report.report('Running_Phase[]', 1)
    ms = load_schema(schema_file, '*')
    sm = ScheduleManager(ms, dataPointFactory)

    # to add phase 1 and ignore visibility
    sm.phase_1(dateRange, INTROSPECTION_INDEX_NAME)
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")
def run_phase_2(profile, dateRange, schema_file):
    '''
    phase 2 runs by lead node only and only runs when a deployment is opted in.
    sm.phase_2() does the following:
    - collects and indexes data points marked as phase = 2
    - query data collected by phase = 1 and phase = 2 and send the data to splunkx

    :param profile
    :param dateRange
    :param schema_file
    :return: None
    '''
    report.report('Running_Phase[]', 2)
    ms = load_schema(schema_file, profile.visibility)
    sm = ScheduleManager(ms, dataPointFactory)

    sleep(5)
    sm.phase_2(dateRange, INTROSPECTION_INDEX_NAME)
def pre_run(profile):
    '''
    Do some work to keep the environment healthy
        - sync deployment id from CM to current node
        - sync salt from CM to current node
        - retry transaction if retryTransaction in telemtry.conf is not empty

    :param profile
    :return: None
    '''

    profile.sync_deployment_id()
    profile.sync_salt()

    # if current node is a single search head or a seach head captain in SHC env
    # call profile.retry_transaction() to retry sync telemetry conf values to Cluster Master
    # TelemetryHandler.cpp SHOULD sync telemetry.conf to CM already whenever any value is changed.
    # This is to handle the case when it failed
    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()
Example #10
0
def can_run_phase2(profile):
    '''
    determine if current node can run phase 2
    the requirement is that the current node needs to be the lead node and
    that the deployment is opted-in (profile.visibility is not empty)

    :param profile
    :return: Boolean
    '''
    if is_lead_node(profile.roles) is False:
        report.report("lead node", False)
        return False

    report.report("lead node", True)
    report.report("profile.visibility", profile.visibility)
    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.cluster_mode", profile.profile.get('cluster_mode'))
    report.report("profile.roles", profile.roles)

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

    return True
Example #11
0
import logging
from report import report
from time import sleep
from schedule_manager import ScheduleManager
from splunk_instrumentation.dataPoints.data_point import dataPointFactory
from splunk_instrumentation.metrics.metrics_schema import load_schema
from splunk_instrumentation.metrics.instance_profile import get_instance_profile, is_lead_node
from splunk_instrumentation.constants import INTROSPECTION_INDEX_NAME

logging.root.setLevel(INST_DEBUG_LEVEL)
formatter = logging.Formatter('%(levelname)s %(message)s')
handler = logging.StreamHandler(stream=sys.stderr)
handler.setFormatter(formatter)
logging.root.addHandler(handler)

report.report('executionID', INST_EXECUTION_ID)


def pre_run(profile):
    '''
    Do some work to keep the environment healthy
        - sync deployment id from CM to current node
        - sync salt from CM to current node
        - retry transaction if retryTransaction in telemtry.conf is not empty

    :param profile
    :return: None
    '''

    profile.sync_deployment_id()
    profile.sync_salt()
Example #12
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
Example #13
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