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 $this->xtra_js
[] = 'application/media/js/jquery.datePicker.js';
72 $this->xtra_js
[] = 'application/media/js/jquery.timePicker.js';
73 $this->xtra_js
[] = $this->add_path('reports/js/common.js');
74 $this->xtra_js
[] = $this->add_path('summary/js/summary.js');
76 $this->xtra_css
[] = $this->add_path('reports/css/datePicker.css');
78 $this->js_strings
.= reports
::js_strings();
79 $this->js_strings
.= "var _scheduled_label = '"._('Scheduled')."';\n";
81 $this->template
->toolbar
= new Toolbar_Controller(_('Summary report'));
84 $this->template
->js_strings
= $this->js_strings
;
86 $template->type
= $this->type
;
87 $template->scheduled_ids
= $scheduled_ids;
88 $template->scheduled_periods
= $scheduled_periods;
90 $template->available_schedule_periods
= Scheduled_reports_Model
::get_available_report_periods();
91 $template->saved_reports
= $this->options
->get_all_saved();
93 $this->template
->title
= _("Reporting » Alert summary » Setup");
97 * Generates an alert summary report
99 public function generate($input=false)
101 $this->setup_options_obj($input);
103 $report_members = $this->options
->get_report_members();
104 if (empty($report_members)) {
105 $_SESSION['report_err_msg'] = _("No objects could be found in your selected groups to base the report on");
106 return url
::redirect(Router
::$controller.'/index');
109 $reports_model = new Summary_Reports_Model($this->options
);
112 switch ($this->options
['summary_type']) {
113 case Summary_options
::TOP_ALERT_PRODUCERS
:
114 $result = $reports_model->top_alert_producers();
117 case Summary_options
::RECENT_ALERTS
:
118 $result = $reports_model->recent_alerts();
121 case Summary_options
::ALERT_TOTALS
:
122 $result = $reports_model->alert_totals();
126 echo Kohana
::debug("Case fallthrough");
131 if ($this->options
['output_format'] == 'csv') {
132 csv
::csv_http_headers($this->type
, $this->options
);
133 $this->template
= $this->add_view('summary/csv');
134 $this->template
->options
= $this->options
;
135 $this->template
->summary_type
= $this->options
['summary_type'];
136 $this->template
->result
= $result;
137 $this->template
->date_format
= nagstat
::date_format();
138 $this->template
->host_state_names
= $this->host_state_names
;
139 $this->template
->service_state_names
= $this->service_state_names
;
144 $this->template
->disable_refresh
= true;
145 $this->xtra_js
[] = 'application/media/js/jquery.datePicker.js';
146 $this->xtra_js
[] = 'application/media/js/jquery.timePicker.js';
147 $this->xtra_js
[] = $this->add_path('reports/js/common.js');
148 $this->xtra_js
[] = $this->add_path('summary/js/summary.js');
149 $this->xtra_css
[] = $this->add_path('reports/css/datePicker.css');
152 Summary_options
::TOP_ALERT_PRODUCERS
=> 'toplist',
153 Summary_options
::RECENT_ALERTS
=> 'latest',
154 Summary_options
::ALERT_TOTALS
=> 'alert_totals',
157 $this->template
->content
= $this->add_view('reports/index');
158 $this->template
->content
->header
= $this->add_view('summary/header');
159 $this->template
->content
->header
->standard_header
= $this->add_view('reports/header');
160 $header = $this->template
->content
->header
->standard_header
;
161 $this->template
->content
->report_options
= $this->add_view('summary/options');
162 $header->report_time_formatted
= $this->format_report_time(nagstat
::date_format());
163 $this->template
->content
->content
=
164 $this->add_view("summary/" . $views[$this->options
['summary_type']]);
166 $content = $this->template
->content
->content
;
168 $content->host_state_names
= $this->host_state_names
;
169 $content->service_state_names
= $this->service_state_names
;
171 $this->js_strings
.= reports
::js_strings();
172 $this->js_strings
.= "var _scheduled_label = '"._('Scheduled')."';\n";
173 $this->template
->js_strings
= $this->js_strings
;
175 $content->result
= $result;
176 $this->template
->title
= _("Reporting » Alert summary » Report");
177 $header->title
= $this->options
->get_value('summary_type');
179 $scheduled_info = Scheduled_reports_Model
::report_is_scheduled($this->type
, $this->options
['report_id']);
180 if($scheduled_info) {
181 $schedule_id = $this->input
->get('schedule_id', null);
183 $le_schedule = current(array_filter($scheduled_info, function($item) use ($schedule_id) {
184 return $item['id'] == $schedule_id && $item['attach_description'] && $item['description'];
187 $header->description
= $this->options
['description'] ?
$this->options
['description']."\n".$le_schedule['description'] : $le_schedule['description'];
193 if ($this->options
['output_format'] == 'pdf') {
194 return $this->generate_pdf();