def parseData(fn, keyList, dataset=1):

    # initialize dictionary

    dataDict = {}

   

    # open file for reading

    f = open(fn)

   

    # skip to required data set

    for _ in range(dataset):

        s = f.next()

        while '{' not in s:

            s = f.next()

 

    for line in f:

        if '{' not in line:

            dataList = line.strip().split('=')

            if dataList[0].strip() in keyList:

                dataDict[dataList[0].strip()] = dataList[1].strip()

        else:

            break

    f.close()

    return dataDict

 

keyList = ['host_name', 'plugin_output', 'performance_data', 'last_check', 'next_check', 'current_notification_number']

 

fn = r'H:\TEMP\temsys\data11.txt'

 

dd = parseData(fn, keyList, 2)

 

for key in dd:

    print '%s = %s' % (key, dd[key])

 

''' DATA FILE

Header Information

 

Header Information

 

Header Information

 

service {

 

        host_name=testserver1

 

        service_description=Connections

 

        modified_attributes=0

 

        check_command=syschk_tux_chk!t1!500

 

        event_handler=

 

        has_been_checked=1

 

        should_be_scheduled=1

 

        check_execution_time=2.405

 

        check_latency=0.230

 

        check_type=0

 

        current_state=0

 

        last_hard_state=0

 

        current_attempt=1

 

        max_attempts=4

 

        state_type=1

 

        last_state_change=1182753132

 

        last_hard_state_change=1182753132

 

        last_time_ok=1184258344

 

        last_time_warning=1179900125

 

        last_time_unknown=0

 

        last_time_critical=1182749532

 

        plugin_output=0: No leaked tuxedo conns (greater than 500) found

 

        performance_data=

 

        last_check=1184258344

 

        next_check=1184261944

 

        current_notification_number=0

 

        last_notification=0

 

        next_notification=0

 

        no_more_notifications=0

 

        notifications_enabled=1

 

        active_checks_enabled=1

 

        passive_checks_enabled=1

 

        event_handler_enabled=1

 

        problem_has_been_acknowledged=0

 

        acknowledgement_type=0

 

        flap_detection_enabled=1

 

        failure_prediction_enabled=1

 

        process_performance_data=1

 

        obsess_over_service=1

 

        last_update=1184260373

 

        is_flapping=0

 

        percent_state_change=0.00

 

        scheduled_downtime_depth=0

 

        }

 

 

 

service {

 

        host_name=testserver2

 

        service_description=UNDOTableCount

 

        modified_attributes=0

 

        check_command=syschk_undodb_count!t1!10000!

 

        event_handler=

 

        has_been_checked=1

 

        should_be_scheduled=1

 

        check_execution_time=1.330

 

        check_latency=0.140

 

        check_type=0

 

        current_state=0

 

        last_hard_state=0

 

        current_attempt=1

 

        max_attempts=3

 

        state_type=1

 

        last_state_change=1182752136

 

        last_hard_state_change=1182752136

 

        last_time_ok=1184260360

 

        last_time_warning=1179925702

 

        last_time_unknown=0

 

        last_time_critical=1182751946

 

        plugin_output=0: Record Count OK: Current depth is 8, threshold is 10000

 

        performance_data=

 

        last_check=1184260360

 

        next_check=1184260420

 

        current_notification_number=0

 

        last_notification=0

 

        next_notification=0

 

        no_more_notifications=0

 

        notifications_enabled=1

 

        active_checks_enabled=1

 

        passive_checks_enabled=1

 

        event_handler_enabled=1

 

        problem_has_been_acknowledged=0

 

        acknowledgement_type=0

 

        flap_detection_enabled=1

 

        failure_prediction_enabled=1

 

        process_performance_data=1

 

        obsess_over_service=1

 

        last_update=1184260373

 

        is_flapping=0

 

        percent_state_change=0.00

 

        scheduled_downtime_depth=0

 

        }

'''

 

''' OUTPUT

>>> plugin_output = 0: No leaked tuxedo conns (greater than 500) found

last_check = 1184258344

performance_data =

current_notification_number = 0

next_check = 1184261944

host_name = testserver1

>>>

'''