HSLIST=$1
LFILE=$2
STRING=$3
awk 'BEGIN {
while((getline < "'${HSLIST}'")>0)
S[$0]
FS="\n"; RS="}\n"
}
/servicestatus {/ && /service_description='${STRING}'/ {
for(X in D) delete D[X];
for(N=2; N<=NF; N++)
{
split($N, A, "=");
D[A[1]] = A[2]
i = 3;
while (i in A)
D[A[1]] = D[A[1]] "=" A[i++];
}
if (D[" host_name"] in S)
printf("%s -------- %s -------- %s -------- %s -------- %s -------- %s -------- %s -------- %s\n", D["host_name"], D["service_description"], D["check_execution_time"], D["check_latency"], D["last_check"], D["last_hard_state_change"], D["current_state"], D["plugin_output"])
}' $LFILE
Can someone please explain to me why the above code isn't pulling out anything from a file that contain several chunks like the one below?
when i run the above code, i get back nothing.
synopsis:
i have a file that contains several of the chunks below. the chunks belong to several servers. one server may have several chunks associated with it.
in the below example, this specific chunk belongs to a server called "sky-01.net". there may be other chunks like this in a file, with service description "CPU_CHECK", "DISK_CHECK", etc.
servicestatus {
host_name=sky-01.net
service_description=LOAD_CHECK
modified_attributes=1
check_command=check_load!68!90
check_period=24x7
notification_period=24x7
check_interval=30.000000
retry_interval=2.000000
event_handler=
has_been_checked=1
should_be_scheduled=1
check_execution_time=1.362
check_latency=7.887
check_type=0
current_state=0
last_hard_state=0
last_event_id=2523376
current_event_id=2611954
current_problem_id=0
last_problem_id=1127556
current_attempt=1
max_attempts=1
state_type=1
last_state_change=1337124526
last_hard_state_change=1337124526
last_time_ok=1337433055
last_time_warning=0
last_time_unknown=1335465427
last_time_critical=1337123063
plugin_output=INFORMATIONAL: Check is ok. NOthing to worry about.
long_plugin_output=
performance_data=
last_check=1337433055
next_check=1337434855
check_options=0
current_notification_number=0
current_notification_id=2699849
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=0
failure_prediction_enabled=1
process_performance_data=1
obsess_over_service=1
last_update=1337433118
is_flapping=0
percent_state_change=0.00
scheduled_downtime_depth=0
}