Hello all,

I am attempting to parse a Nagios status.dat file and am curious about what the most efficient way to do this would be. I'm sure I could come up with something but it would be very convoluted and I'm sure there is a better way. Below is a sample of the file. The sections I am interested in are the "hoststatus" sections. Any other section I want to simply ignore. Within the hoststatus sections are a few lines I am looking for: host_name=<whatever> and current_state=<whatever>, I'd simply like to perform a task based on these "whatever"'s. For example, output lines such as:

some_host:1
another_host:0

Where some_host and another_host are host_name's from the file, and 1 and 0 are current_state's for the corresponding host.

Any pointers or examples would be appreciated!

Here is a sample of the file:

info {
        created=1328049467
        version=3.2.3
        last_update_check=1328014790
        update_available=1
        last_version=3.2.3
        new_version=3.3.1
        }

programstatus {
        modified_host_attributes=0
        modified_service_attributes=0
        nagios_pid=1370
        daemon_mode=1
        (lots of stuff)
        }

hoststatus {
        host_name=some_host
        modified_attributes=0
        check_command=check-host-alive
        check_period=
        notification_period=24x7
        check_interval=5.000000
        retry_interval=1.000000
        event_handler=
        has_been_checked=1
        should_be_scheduled=1
        check_execution_time=0.012
        check_latency=0.246
        check_type=0
        current_state=1
        last_hard_state=0
        last_event_id=0
        current_event_id=0
        current_problem_id=0
        last_problem_id=0
        plugin_output=OK - 10.1.1.1.1: rta 1.822ms, lost 0%
        long_plugin_output=
performance_data=rta=1.822ms;3000.000;5000.000;0; pl=0%;80;100;; rtmax=1.822ms;;;; rtmin=1.822ms;;;;
        last_check=1328049317
        next_check=1328049627
        check_options=0
        current_attempt=1
        max_attempts=10
        state_type=1
        last_state_change=1328047050
        last_hard_state_change=1328047050
        last_time_up=1328049327
        last_time_down=0
        last_time_unreachable=0
        last_notification=0
        next_notification=0
        no_more_notifications=0
        current_notification_number=0
        current_notification_id=0
        notifications_enabled=1
        problem_has_been_acknowledged=0
        acknowledgement_type=0
        active_checks_enabled=1
        passive_checks_enabled=1
        event_handler_enabled=1
        flap_detection_enabled=1
        failure_prediction_enabled=1
        process_performance_data=1
        obsess_over_host=1
        last_update=1328049467
        is_flapping=0
        percent_state_change=0.00
        scheduled_downtime_depth=0
        }

hoststatus {
        host_name=another_host
        modified_attributes=0
        check_command=check-host-alive
        check_period=
        notification_period=24x7
        check_interval=5.000000
        retry_interval=1.000000
        event_handler=
        has_been_checked=1
        should_be_scheduled=1
        check_execution_time=10.011
        check_latency=0.268
        check_type=0
        current_state=0
        last_hard_state=0
        last_event_id=7
        current_event_id=8
        current_problem_id=3
        last_problem_id=1
        plugin_output=CRITICAL - 10.1.1.2: rta nan, lost 100%
        long_plugin_output=
performance_data=rta=0.000ms;3000.000;5000.000;0; pl=100%;80;100;; rtmax=0.000ms;;;; rtmin=0.000ms;;;;
        last_check=1328049417
        next_check=1328049497
        check_options=0
        current_attempt=3
        max_attempts=10
        state_type=0
        last_state_change=1328049437
        last_hard_state_change=1328049057
        last_time_up=1328049057
        last_time_down=1328049437
        last_time_unreachable=0
        last_notification=0
        next_notification=0
        no_more_notifications=0
        current_notification_number=0
        current_notification_id=0
        notifications_enabled=1
        problem_has_been_acknowledged=0
        acknowledgement_type=0
        active_checks_enabled=1
        passive_checks_enabled=1
        event_handler_enabled=1
        flap_detection_enabled=1
        failure_prediction_enabled=1
        process_performance_data=1
        obsess_over_host=1
        last_update=1328049467
        is_flapping=0
        percent_state_change=17.30
        scheduled_downtime_depth=0
        }

servicestatus {
        host_name=some_host
        service_description=PING
        modified_attributes=0
        check_command=check_ping!7000.0,40%!9000.0,70%
        check_period=24x7
        notification_period=24x7
        check_interval=5.000000
        (lots more stuff...)
        }
(file has lots more, but excluded here for brevity)

Thanks,
Brandon

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to