3 Will parse csv output from file specified below
7 $s_header = 'HOST_NAME,
9 PERCENT_TIME_UP_SCHEDULED,
10 PERCENT_KNOWN_TIME_UP_SCHEDULED,
12 PERCENT_TIME_UP_UNSCHEDULED,
13 PERCENT_KNOWN_TIME_UP_UNSCHEDULED,
15 PERCENT_TOTAL_TIME_UP,
16 PERCENT_KNOWN_TIME_UP,
18 PERCENT_TIME_DOWN_SCHEDULED,
19 PERCENT_KNOWN_TIME_DOWN_SCHEDULED,
20 TIME_DOWN_UNSCHEDULED,
21 PERCENT_TIME_DOWN_UNSCHEDULED,
22 PERCENT_KNOWN_TIME_DOWN_UNSCHEDULED,
24 PERCENT_TOTAL_TIME_DOWN,
25 PERCENT_KNOWN_TIME_DOWN,
26 TIME_UNREACHABLE_SCHEDULED,
27 PERCENT_TIME_UNREACHABLE_SCHEDULED,
28 PERCENT_KNOWN_TIME_UNREACHABLE_SCHEDULED,
29 TIME_UNREACHABLE_UNSCHEDULED,
30 PERCENT_TIME_UNREACHABLE_UNSCHEDULED,
31 PERCENT_KNOWN_TIME_UNREACHABLE_UNSCHEDULED,
32 TOTAL_TIME_UNREACHABLE,
33 PERCENT_TOTAL_TIME_UNREACHABLE,
34 PERCENT_KNOWN_TIME_UNREACHABLE,
35 TIME_UNDETERMINED_NOT_RUNNING,
36 PERCENT_TIME_UNDETERMINED_NOT_RUNNING,
37 TIME_UNDETERMINED_NO_DATA,
38 PERCENT_TIME_UNDETERMINED_NO_DATA,
39 TOTAL_TIME_UNDETERMINED,
40 PERCENT_TOTAL_TIME_UNDETERMINED';
42 // parameters that we actually are interested in
44 $svc_return_values = array('SERVICE_DESCRIPTION',
46 'TIME_OK_UNSCHEDULED',
47 'TIME_WARNING_SCHEDULED',
48 'TIME_WARNING_UNSCHEDULED',
49 'TIME_UNKNOWN_SCHEDULED',
50 'TIME_UNKNOWN_UNSCHEDULED',
51 'TIME_CRITICAL_SCHEDULED',
52 'TIME_CRITICAL_UNSCHEDULED',
53 'TIME_UNDETERMINED_NOT_RUNNING',
54 'TIME_UNDETERMINED_NO_DATA'
57 $return_values = array( 'TIME_UP_SCHEDULED',
58 'TIME_UP_UNSCHEDULED',
59 'TIME_DOWN_SCHEDULED',
60 'TIME_DOWN_UNSCHEDULED',
61 'TIME_UNREACHABLE_SCHEDULED',
62 'TIME_UNREACHABLE_UNSCHEDULED',
63 'TIME_UNDETERMINED_NOT_RUNNING',
64 'TIME_UNDETERMINED_NO_DATA');
66 // Read csv data from file
67 $_newfile = file('apa1');
69 $header = explode(',', $s_header);
72 Hard coded start- and end time
73 Set $is_service below to true to get servicename
74 and correct return values array
76 $start_time = 1196463600;
77 $end_time = 1199142000;
82 for ($i=1;$i<sizeof($_newfile);$i++
) {
83 // loop through all lines in _newfile
84 $newfile = explode(',', $_newfile[$i]);
86 $hostname = str_replace('"', '', $newfile[0]);
88 $service = str_replace('"', '', $newfile[1]);
89 $return_array_values = $svc_return_values;
91 $return_array_values = $return_values;
94 echo "test case ".$hostname." {\n";
95 echo "\tstart_time = $start_time
96 \tend_time = $end_time
97 \thostname = ".$hostname;
99 echo "\tservice = ".$service;
102 // print correct values
104 for ($a=0;$a<sizeof($newfile);$a++
) {
105 if (in_array(trim($header[$a]), $return_array_values)) {
106 echo "\n\t\t".trim($header[$a]) . " =" . $newfile[$a];