0

I'd like to parse status.dat file for nagios and output as xml or json in c#. Does any know any plugin/library or method to parse it to xml or json??

Any help and pointing in the right direction will be highly appreciated.

The file looks like this:

########################################
#          NAGIOS STATUS FILE
#
# THIS FILE IS AUTOMATICALLY GENERATED
# BY NAGIOS.  DO NOT MODIFY THIS FILE!
########################################

info {
    created=1233491098
    version=2.11
    }

program {
    modified_host_attributes=0
    modified_service_attributes=0
    nagios_pid=15015
    daemon_mode=1
    program_start=1233490393
    last_command_check=0
    last_log_rotation=0
    enable_notifications=1
    active_service_checks_enabled=1
    passive_service_checks_enabled=1
    active_host_checks_enabled=1
    passive_host_checks_enabled=1
    enable_event_handlers=1
    obsess_over_services=0
    obsess_over_hosts=0
    check_service_freshness=1
    check_host_freshness=0
    enable_flap_detection=0
    enable_failure_prediction=1
    process_performance_data=0
    global_host_event_handler=
    global_service_event_handler=
    total_external_command_buffer_slots=4096
    used_external_command_buffer_slots=0
    high_external_command_buffer_slots=0
    total_check_result_buffer_slots=4096
    used_check_result_buffer_slots=0
    high_check_result_buffer_slots=2
    }

host {
    host_name=localhost
    modified_attributes=0
    check_command=check-host-alive
    event_handler=
    has_been_checked=1
    should_be_scheduled=0
    check_execution_time=0.019
    check_latency=0.000
    check_type=0
    current_state=0
    last_hard_state=0
    plugin_output=PING OK - Packet loss = 0%, RTA = 3.57 ms
    performance_data=
    last_check=1233490883
    next_check=0
    current_attempt=1
    max_attempts=10
    state_type=1
    last_state_change=1233489475
    last_hard_state_change=1233489475
    last_time_up=1233490883
    last_time_down=0
    last_time_unreachable=0
    last_notification=0
    next_notification=0
    no_more_notifications=0
    current_notification_number=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=1233491098
    is_flapping=0
    percent_state_change=0.00
    scheduled_downtime_depth=0
    }

service {
    host_name=gateway
    service_description=PING
    modified_attributes=0
    check_command=check_ping!100.0,20%!500.0,60%
    event_handler=
    has_been_checked=1
    should_be_scheduled=1
    check_execution_time=4.017
    check_latency=0.210
    check_type=0
    current_state=0
    last_hard_state=0
    current_attempt=1
    max_attempts=4
    state_type=1
    last_state_change=1233489432
    last_hard_state_change=1233489432
    last_time_ok=1233491078
    last_time_warning=0
    last_time_unknown=0
    last_time_critical=0
    plugin_output=PING OK - Packet loss = 0%, RTA = 2.98 ms
    performance_data=
    last_check=1233491078
    next_check=1233491378
    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=1233491098
    is_flapping=0
    percent_state_change=0.00
    scheduled_downtime_depth=0
    }
  • Please see ["Should questions include “tags” in their titles?"](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles), where the consensus is "no, they should not"! –  Apr 03 '15 at 11:20
  • How does a *Python* question relate to a *.NET* question? The "duplicate" question doesn't provide anything usable in .NET – Panagiotis Kanavos Apr 03 '15 at 11:51
  • @PanagiotisKanavos it really doesn't matter, as the question, viewing it from another angle, would yield "searching for utility", which is off topic to stackoverflow ... –  Apr 03 '15 at 12:28
  • @AndreasNiedermair Not at all. The question is - "how to parse a nagios dat file?" The answer is - with a hand-crafterd parser using a couple of regexes or by writing a grammar in ANTRL for Visual Studio, or fslex (if the OP uses F#). – Panagiotis Kanavos Apr 03 '15 at 12:32
  • @PanagiotisKanavos Nope, *Does any know any plugin/library or method to parse it to xml or json??* - that is the question, which would be closed as *Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.*. What you are referring to is just the title. –  Apr 03 '15 at 12:33
  • @AndreasNiedermair The OP is asking for *help*, he doesn't know what to do. If you didn't know about parsers you'd probably be asking the same way. Parsing the file is the first step, generating Json or XML the second. Arguably both can be done using one parser tool. Anyway, this isn't a duplicate and the answer isn't exactly trivial – Panagiotis Kanavos Apr 03 '15 at 12:36
  • @PanagiotisKanavos That is **exactly** what the close-reason is saying: *Instead, describe the problem and what has been done so far to solve it.* So, still ... legit to close with this very reason! Which may lead into editing the question, which may lead into reopening - but this is an absolut wanted approach/workflow for such an issue! Closing doesn't mean that you are doomed, there's always the option to edit! –  Apr 03 '15 at 12:55
  • The question was closed us a duplicate which it isn't. If you want to reopen the question to reclose it with another reason so it can be fixed and reopened, please do. Consider though that what may appear ambiguous to one, may be clearer to someone else. What happened to the primary directive "be nice" anyway? – Panagiotis Kanavos Apr 03 '15 at 13:01
  • @PanagiotisKanavos you might have misinterpreted my argumentation, which is just straight-forward - there was absolutely no offense involved on my side - sorry for that :) –  Apr 03 '15 at 13:07

0 Answers0