B
Bob Norfolk
I'm working on a ruby script to read Nagios's status.dat and output it's
data.
The data format looks like this:
service {
host_name=www.bob.com
service_description=bob-website
modified_attributes=0
check_command=check-bob-website
event_handler=
has_been_checked=1
should_be_scheduled=1
check_execution_time=0.155
check_latency=0.250
check_type=0
current_state=0
last_hard_state=0
current_attempt=1
max_attempts=3
state_type=1
last_state_change=1155243779
last_hard_state_change=1155243779
last_time_ok=1155507506
last_time_warning=1154915720
last_time_unknown=0
last_time_critical=1155243478
plugin_output=HTTP OK HTTP/1.1 200 OK - 0.117 second response
time
performance_data=time=0.116677s;;;0.000000 size=3998B;;;0
last_check=1155507506
next_check=1155507806
current_notification_number=0
last_notification=0
next_notification=0
no_more_notifications=0
notifications_enabled=1
active_checks_enabled=1
passive_checks_enabled=0
event_handler_enabled=0
problem_has_been_acknowledged=0
acknowledgement_type=0
flap_detection_enabled=0
failure_prediction_enabled=1
process_performance_data=1
obsess_over_service=1
last_update=1155507620
is_flapping=0
percent_state_change=0.00
scheduled_downtime_depth=0
}
What I've written works, but it only works for one block. I'm not quite
sure how to make it work for the whole block?
Any advice would be greatly appreciated.
Here's the code I've written:
Class server
def read_nagiosstatus(filename)
nagios_status = {}
for line in IO.readlines(filename):
line.strip! # Remove all extraneous
whitespace
line.sub!(/#.*$/, "") # Remove comments
next unless line.length > 0 # check for end of file
var, value = line.split(/\s*=\s*/, 2)
nagios_status[var.intern] = value
end
return nagios_status
end
nagiosstatus = read_nagiosstatus("status.dat")
puts "Host name is #{nagiosstatus[:host_name]}"
puts "Service description is #{nagiosstatus[:service_description]}"
data.
The data format looks like this:
service {
host_name=www.bob.com
service_description=bob-website
modified_attributes=0
check_command=check-bob-website
event_handler=
has_been_checked=1
should_be_scheduled=1
check_execution_time=0.155
check_latency=0.250
check_type=0
current_state=0
last_hard_state=0
current_attempt=1
max_attempts=3
state_type=1
last_state_change=1155243779
last_hard_state_change=1155243779
last_time_ok=1155507506
last_time_warning=1154915720
last_time_unknown=0
last_time_critical=1155243478
plugin_output=HTTP OK HTTP/1.1 200 OK - 0.117 second response
time
performance_data=time=0.116677s;;;0.000000 size=3998B;;;0
last_check=1155507506
next_check=1155507806
current_notification_number=0
last_notification=0
next_notification=0
no_more_notifications=0
notifications_enabled=1
active_checks_enabled=1
passive_checks_enabled=0
event_handler_enabled=0
problem_has_been_acknowledged=0
acknowledgement_type=0
flap_detection_enabled=0
failure_prediction_enabled=1
process_performance_data=1
obsess_over_service=1
last_update=1155507620
is_flapping=0
percent_state_change=0.00
scheduled_downtime_depth=0
}
What I've written works, but it only works for one block. I'm not quite
sure how to make it work for the whole block?
Any advice would be greatly appreciated.
Here's the code I've written:
Class server
def read_nagiosstatus(filename)
nagios_status = {}
for line in IO.readlines(filename):
line.strip! # Remove all extraneous
whitespace
line.sub!(/#.*$/, "") # Remove comments
next unless line.length > 0 # check for end of file
var, value = line.split(/\s*=\s*/, 2)
nagios_status[var.intern] = value
end
return nagios_status
end
nagiosstatus = read_nagiosstatus("status.dat")
puts "Host name is #{nagiosstatus[:host_name]}"
puts "Service description is #{nagiosstatus[:service_description]}"