1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
3 * Alert Summary controller
4 * Requires authentication
6 * op5, and the op5 logo are trademarks, servicemarks, registered servicemarks
7 * or registered trademarks of op5 AB.
8 * All other trademarks, servicemarks, registered trademarks, and registered
9 * servicemarks mentioned herein may be the property of their respective owner(s).
10 * The information contained herein is provided AS IS with NO WARRANTY OF ANY
11 * KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY, AND FITNESS FOR A
14 class Summary_Controller
extends Base_reports_Controller
16 public $type = 'summary';
18 private $host_state_names = array();
19 private $service_state_names = array();
21 public function __construct()
23 parent
::__construct();
24 $this->host_state_names
= array(
25 Reports_Model
::HOST_UP
=> _('UP'),
26 Reports_Model
::HOST_DOWN
=> _('DOWN'),
27 Reports_Model
::HOST_UNREACHABLE
=> _('UNREACHABLE')
29 $this->service_state_names
= array(
30 Reports_Model
::SERVICE_OK
=> _('OK'),
31 Reports_Model
::SERVICE_WARNING
=> _('WARNING'),
32 Reports_Model
::SERVICE_CRITICAL
=> _('CRITICAL'),
33 Reports_Model
::SERVICE_UNKNOWN
=> _('UNKNOWN')
38 * Setup options for alert summary report
40 public function index($input=false)
42 $this->setup_options_obj($input);
43 $reports_model = new Summary_Reports_Model($this->options
);
45 # check if we have all required parts installed
46 if (!$reports_model->_self_check()) {
47 return url
::redirect('reports/invalid_setup');
50 # what scheduled reports are there?
51 $scheduled_ids = array();
52 $scheduled_periods = null;
53 $scheduled_res = Scheduled_reports_Model
::get_scheduled_reports($this->type
);
54 if ($scheduled_res && count($scheduled_res)!=0) {
55 foreach ($scheduled_res as $sched_row) {
56 $scheduled_ids[] = $sched_row->report_id
;
57 $scheduled_periods[$sched_row->report_id
] = $sched_row->periodname
;
61 $this->template
->disable_refresh
= true;
62 $this->template
->content
= $this->add_view('summary/setup');
63 $this->template
->content
->report_options
= $this->add_view('summary/options');
64 $template = $this->template
->content
;
66 if(isset($_SESSION['report_err_msg'])) {
67 $template->error_msg
= $_SESSION['report_err_msg'];
68 unset($_SESSION['report_err_msg']);
71 # get all saved reports for user
72 $saved_reports = Saved_reports_Model
::get_saved_reports($this->type
);
74 $old_config_names = Saved_reports_Model
::get_all_report_names($this->type
);
75 $old_config_names_js = empty($old_config_names) ?
"false" : "new Array('".implode("', '", array_map('addslashes', $old_config_names))."');";
77 $this->template
->js_header
= $this->add_view('js_header');
78 $this->xtra_js
[] = 'application/media/js/jquery.datePicker.js';
79 $this->xtra_js
[] = 'application/media/js/jquery.timePicker.js';
80 $this->xtra_js
[] = $this->add_path('reports/js/common.js');
81 $this->xtra_js
[] = $this->add_path('summary/js/summary.js');
83 $this->template
->css_header
= $this->add_view('css_header');
84 $this->xtra_css
[] = $this->add_path('reports/css/datePicker.css');
85 $this->template
->css_header
->css
= $this->xtra_css
;
87 $this->js_strings
.= reports
::js_strings();
88 $this->js_strings
.= "var _scheduled_label = '"._('Scheduled')."';\n";
89 $this->inline_js
.= "var invalid_report_names = ".$old_config_names_js .";\n";
91 if ($this->options
['report_id']) {
92 $this->js_strings
.= "var _report_data = " . $this->options
->as_json() . "\n";
94 else if (!$this->options
['standardreport']) {
95 $this->inline_js
.= "set_selection(document.getElementsByName('report_type').item(0).value);\n";
98 $this->template
->toolbar
= new Toolbar_Controller(_('Summary report'));
101 $this->template
->inline_js
= $this->inline_js
;
102 $this->template
->js_strings
= $this->js_strings
;
104 $template->type
= $this->type
;
105 $template->old_config_names_js
= $old_config_names_js;
106 $template->old_config_names
= $old_config_names;
107 $template->scheduled_ids
= $scheduled_ids;
108 $template->scheduled_periods
= $scheduled_periods;
110 $template->available_schedule_periods
= Scheduled_reports_Model
::get_available_report_periods();
112 $template->saved_reports
= $saved_reports;
114 $this->template
->title
= _("Reporting » Alert summary » Setup");
118 * Generates an alert summary report
120 public function generate($input=false)
122 $this->setup_options_obj($input);
124 $report_members = $this->options
->get_report_members();
125 if (empty($report_members)) {
126 $_SESSION['report_err_msg'] = "No objects could be found in your selected groups to base the report on";
127 return url
::redirect(Router
::$controller.'/index');
130 $reports_model = new Summary_Reports_Model($this->options
);
133 switch ($this->options
['summary_type']) {
134 case Summary_options
::TOP_ALERT_PRODUCERS
:
135 $result = $reports_model->top_alert_producers();
138 case Summary_options
::RECENT_ALERTS
:
139 $result = $reports_model->recent_alerts();
142 case Summary_options
::ALERT_TOTALS
:
143 $result = $reports_model->alert_totals();
147 echo Kohana
::debug("Case fallthrough");
152 if ($this->options
['output_format'] == 'csv') {
153 csv
::csv_http_headers($this->type
, $this->options
);
154 $this->template
= $this->add_view('summary/csv');
155 $this->template
->options
= $this->options
;
156 $this->template
->summary_type
= $this->options
['summary_type'];
157 $this->template
->result
= $result;
158 $this->template
->date_format
= nagstat
::date_format();
159 $this->template
->host_state_names
= $this->host_state_names
;
160 $this->template
->service_state_names
= $this->service_state_names
;
165 $this->template
->disable_refresh
= true;
166 $this->xtra_js
[] = 'application/media/js/jquery.datePicker.js';
167 $this->xtra_js
[] = 'application/media/js/jquery.timePicker.js';
168 $this->xtra_js
[] = $this->add_path('reports/js/common.js');
169 $this->xtra_js
[] = $this->add_path('summary/js/summary.js');
170 $this->template
->js_header
= $this->add_view('js_header');
171 $this->template
->css_header
= $this->add_view('css_header');
172 $this->xtra_css
[] = $this->add_path('reports/css/datePicker.css');
173 $this->template
->css_header
->css
= $this->xtra_css
;
175 if ($this->type
== 'summary') {
176 $old_config_names = Saved_reports_Model
::get_all_report_names($this->type
);
177 $old_config_names_js = empty($old_config_names) ?
"false" : "new Array('".implode("', '", array_map('addslashes', $old_config_names))."');";
178 $this->inline_js
.= "var invalid_report_names = ".$old_config_names_js .";\n";
181 if($this->options
['report_period'] && $this->options
['report_period'] != 'custom')
182 $report_time_formatted = $this->options
->get_value('report_period');
184 $report_time_formatted = sprintf(_("%s to %s"), date(nagstat
::date_format(), $this->options
['start_time']), date(nagstat
::date_format(), $this->options
['end_time']));
186 if($this->options
['rpttimeperiod'] != '')
187 $report_time_formatted .= " - {$this->options['rpttimeperiod']}";
190 Summary_options
::TOP_ALERT_PRODUCERS
=> 'toplist',
191 Summary_options
::RECENT_ALERTS
=> 'latest',
192 Summary_options
::ALERT_TOTALS
=> 'alert_totals',
195 $this->template
->content
= $this->add_view('reports/index');
196 $this->template
->content
->header
= $this->add_view('summary/header');
197 $this->template
->content
->header
->standard_header
= $this->add_view('reports/header');
198 $header = $this->template
->content
->header
->standard_header
;
199 $this->template
->content
->report_options
= $this->add_view('summary/options');
200 $header->report_time_formatted
= $report_time_formatted;
201 $this->template
->content
->content
=
202 $this->add_view("summary/" . $views[$this->options
['summary_type']]);
204 $content = $this->template
->content
->content
;
206 $content->host_state_names
= $this->host_state_names
;
207 $content->service_state_names
= $this->service_state_names
;
209 $this->js_strings
.= reports
::js_strings();
210 $this->js_strings
.= "var _scheduled_label = '"._('Scheduled')."';\n";
211 if (!$this->options
['standardreport']) {
212 $this->js_strings
.= "var _report_data = " . $this->options
->as_json() . "\n";
214 else if (!$this->options
['standardreport']) {
215 $this->inline_js
.= "set_selection(document.getElementsByName('report_type').item(0).value);\n";
217 $this->template
->js_strings
= $this->js_strings
;
218 $this->template
->inline_js
= $this->inline_js
;
220 $content->result
= $result;
221 $this->template
->title
= _("Reporting » Alert summary » Report");
222 $header->title
= $this->options
->get_value('summary_type');
224 $scheduled_info = Scheduled_reports_Model
::report_is_scheduled($this->type
, $this->options
['report_id']);
225 if($scheduled_info) {
226 $schedule_id = $this->input
->get('schedule_id', null);
228 $le_schedule = current(array_filter($scheduled_info, function($item) use ($schedule_id) {
229 return $item['id'] == $schedule_id && $item['attach_description'] && $item['description'];
232 $header->description
= $this->options
['description'] ?
$this->options
['description']."\n".$le_schedule['description'] : $le_schedule['description'];
238 if ($this->options
['output_format'] == 'pdf') {
239 return $this->generate_pdf();