1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
4 * Helper for CSV functionality
9 * Set HTTP headers appropriate for CSV files
11 * This is trickier than it should be, due to IE
13 public static function csv_http_headers($type, $options) {
15 // gosh darnit, now I can't do anything. Oh well...
18 $filename = $type . '.csv';
19 if ($options['schedule_id']) {
20 $schedule_info = Scheduled_reports_Model
::get_scheduled_data($options['schedule_id']);
22 $filename = $schedule_info['filename'];
24 header("Content-disposition: attachment; filename=".$filename);
25 if (isset($_SERVER['HTTP_USER_AGENT']) &&
26 (strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 7') ||
strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 8')))
28 header("Pragma: hack");
29 header("Content-Type: application/octet-stream");
30 header("Content-Transfer-Encoding: binary");
32 header("Content-type: text/csv");
37 * Return the fields used in an avail report
39 public static function avail_fields($type)
41 $fields['hosts'] = array(
44 'PERCENT_TIME_UP_SCHEDULED',
45 'PERCENT_KNOWN_TIME_UP_SCHEDULED',
46 'TIME_UP_UNSCHEDULED',
47 'PERCENT_TIME_UP_UNSCHEDULED',
48 'PERCENT_KNOWN_TIME_UP_UNSCHEDULED',
50 'PERCENT_TOTAL_TIME_UP',
51 'PERCENT_KNOWN_TIME_UP',
52 'TIME_DOWN_SCHEDULED',
53 'PERCENT_TIME_DOWN_SCHEDULED',
54 'PERCENT_KNOWN_TIME_DOWN_SCHEDULED',
55 'TIME_DOWN_UNSCHEDULED',
56 'PERCENT_TIME_DOWN_UNSCHEDULED',
57 'PERCENT_KNOWN_TIME_DOWN_UNSCHEDULED',
59 'PERCENT_TOTAL_TIME_DOWN',
60 'PERCENT_KNOWN_TIME_DOWN',
61 'TIME_UNREACHABLE_SCHEDULED',
62 'PERCENT_TIME_UNREACHABLE_SCHEDULED',
63 'PERCENT_KNOWN_TIME_UNREACHABLE_SCHEDULED',
64 'TIME_UNREACHABLE_UNSCHEDULED',
65 'PERCENT_TIME_UNREACHABLE_UNSCHEDULED',
66 'PERCENT_KNOWN_TIME_UNREACHABLE_UNSCHEDULED',
67 'TOTAL_TIME_UNREACHABLE',
68 'PERCENT_TOTAL_TIME_UNREACHABLE',
69 'PERCENT_KNOWN_TIME_UNREACHABLE',
70 'TIME_UNDETERMINED_NOT_RUNNING',
71 'PERCENT_TIME_UNDETERMINED_NOT_RUNNING',
72 'TIME_UNDETERMINED_NO_DATA',
73 'PERCENT_TIME_UNDETERMINED_NO_DATA',
74 'TOTAL_TIME_UNDETERMINED',
75 'PERCENT_TOTAL_TIME_UNDETERMINED'
77 $fields['services'] = array(
79 'SERVICE_DESCRIPTION',
81 'PERCENT_TIME_OK_SCHEDULED',
82 'PERCENT_KNOWN_TIME_OK_SCHEDULED',
83 'TIME_OK_UNSCHEDULED',
84 'PERCENT_TIME_OK_UNSCHEDULED',
85 'PERCENT_KNOWN_TIME_OK_UNSCHEDULED',
87 'PERCENT_TOTAL_TIME_OK',
88 'PERCENT_KNOWN_TIME_OK',
89 'TIME_WARNING_SCHEDULED',
90 'PERCENT_TIME_WARNING_SCHEDULED',
91 'PERCENT_KNOWN_TIME_WARNING_SCHEDULED',
92 'TIME_WARNING_UNSCHEDULED',
93 'PERCENT_TIME_WARNING_UNSCHEDULED',
94 'PERCENT_KNOWN_TIME_WARNING_UNSCHEDULED',
96 'PERCENT_TOTAL_TIME_WARNING',
97 'PERCENT_KNOWN_TIME_WARNING',
98 'TIME_UNKNOWN_SCHEDULED',
99 'PERCENT_TIME_UNKNOWN_SCHEDULED',
100 'PERCENT_KNOWN_TIME_UNKNOWN_SCHEDULED',
101 'TIME_UNKNOWN_UNSCHEDULED',
102 'PERCENT_TIME_UNKNOWN_UNSCHEDULED',
103 'PERCENT_KNOWN_TIME_UNKNOWN_UNSCHEDULED',
104 'TOTAL_TIME_UNKNOWN',
105 'PERCENT_TOTAL_TIME_UNKNOWN',
106 'PERCENT_KNOWN_TIME_UNKNOWN',
107 'TIME_CRITICAL_SCHEDULED',
108 'PERCENT_TIME_CRITICAL_SCHEDULED',
109 'PERCENT_KNOWN_TIME_CRITICAL_SCHEDULED',
110 'TIME_CRITICAL_UNSCHEDULED',
111 'PERCENT_TIME_CRITICAL_UNSCHEDULED',
112 'PERCENT_KNOWN_TIME_CRITICAL_UNSCHEDULED',
113 'TOTAL_TIME_CRITICAL',
114 'PERCENT_TOTAL_TIME_CRITICAL',
115 'PERCENT_KNOWN_TIME_CRITICAL',
116 'TIME_UNDETERMINED_NOT_RUNNING',
117 'PERCENT_TIME_UNDETERMINED_NOT_RUNNING',
118 'TIME_UNDETERMINED_NO_DATA',
119 'PERCENT_TIME_UNDETERMINED_NO_DATA',
120 'TOTAL_TIME_UNDETERMINED',
121 'PERCENT_TOTAL_TIME_UNDETERMINED'
123 if (isset($fields[$type])) {
124 return $fields[$type];
127 $ret = $fields[strpos($type, 'host') === 0 ?
'hosts' : 'services'];
128 array_unshift($ret, strtoupper($type));