1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
4 $this->options
->get_value('summary_type'),
5 'From: '.$options->get_date('start_time'),
6 'To: '.$options->get_date('end_time'),
7 'Duration: '.($options['end_time'] - $options['start_time'])
11 if(Summary_options
::RECENT_ALERTS
== $options['summary_type']) {
13 $csv_content[] = array(
23 foreach($result as $log_entry) {
24 $output = $log_entry['output'];
25 if ($options['include_long_output'] && $log_entry['long_output'] !== NULL) {
26 $output .= "\n" . str_replace(PHP_EOL
, "\n", $log_entry['long_output']);
28 $csv_content[] = array(
29 date($date_format, $log_entry['timestamp']),
30 Reports_Model
::event_type_to_string($log_entry['event_type']),
31 isset($log_entry['host_name'])?
$log_entry['host_name']:'',
32 isset($log_entry['service_description'])?
$log_entry['service_description'] : 'N/A',
33 $log_entry['hard'] ?
_('Hard') : _('Soft'),
37 } elseif(Summary_options
::TOP_ALERT_PRODUCERS
== $options['summary_type']) {
38 // summary of services
40 $csv_content[] = array(
48 foreach($result as $log_entry) {
49 $csv_content[] = array(
50 $log_entry['host_name'],
51 isset($log_entry['service_description']) ?
$log_entry['service_description'] : null,
52 Reports_Model
::event_type_to_string($log_entry['event_type'], 'service'),
53 $log_entry['total_alerts']
57 // custom settings, even more alert types to choose from;
58 // also explains the nested layout of $result
67 switch($options['report_type']) {
69 $label = _('Hostgroup');
70 array_splice($header, 1, 1, 'HOSTGROUP');
76 $label = _('Service');
77 array_splice($header, 2, 0, 'SERVICE');
80 $label = _('Servicegroup');
81 array_splice($header, 1, 1, 'SERVICEGROUP');
84 $csv_content[] = $header;
85 foreach ($result as $host_name => $ary) {
87 if($options['report_type'] == 'services') {
88 list($host_name, $service_name) = explode(';', $host_name);
90 foreach($ary['host'] as $state => $host) {
94 $host_state_names[$state],
97 $host[0] +
$host[1] # total
100 array_splice($row, 2, 0, $service_name);
103 $csv_content[] = $row;
104 foreach($ary['service'] as $state => $service) {
108 $service_state_names[$state],
111 $service[0] +
$service[1] # total
114 array_splice($row, 2, 0, $service_name);
117 $csv_content[] = $row;
121 $out = fopen('php://output', 'w');
122 foreach ($csv_content as $line) {
123 fputcsv($out, $line);