Added filterable to summary and histogram controllers
[ninja.git] / modules / reports / libraries / Summary_options.php
blob28ae33cc5b2a390a6223e1e10e6d4c46289257e8
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
3 /**
4 * Report options for all kinds of Summary reports
5 */
6 class Summary_options extends Report_options
8 public static $type = 'summary';
10 const RECENT_ALERTS = 1; /**< A summary that lists alerts from newest to oldest */
11 const ALERT_TOTALS = 2; /**< A summary that displays which ones and how many alerts each object has retrieved */
12 const TOP_ALERT_PRODUCERS = 3; /**< A summary that displays a top list of the most frequently alerting objects */
14 public function setup_properties()
16 parent::setup_properties();
17 $this->properties['summary_type'] = array('type' => 'enum', 'default' => self::TOP_ALERT_PRODUCERS, 'options' => array(
18 self::RECENT_ALERTS => _('Most recent alerts'),
19 self::ALERT_TOTALS => _('Alert totals'),
20 self::TOP_ALERT_PRODUCERS => _('Top alert producers')));
21 $this->properties['standardreport'] = array('type' => 'enum', 'default' => '', 'options' => array(
22 1 => _('Most recent hard alerts'),
23 2 => _('Most recent hard host alerts'),
24 3 => _('Most recent hard service alerts'),
25 4 => _('Top hard alert producers'),
26 5 => _('Top hard host alert producers'),
27 6 => _('Top hard service alert producers')));
29 $this->properties['alert_types'] = array(
30 'type' => 'enum',
31 'default' => 3,
32 'description' => _('Show events for this kind of objects'),
33 'options' => array(
34 3 => _('Host and service alerts'),
35 1 => _('Host alerts'),
36 2 => _('Service alerts'))
38 $this->properties['state_types'] = array(
39 'type' => 'enum',
40 'default' => 3,
41 'description' => _('Restrict events based on which state the event is in (soft vs hard)'),
42 'options' => array(
43 3 => _('Hard and soft states'),
44 2 => _('Hard states'),
45 1 => _('Soft states'))
47 $this->properties['host_states'] = array(
48 'type' => 'enum',
49 'default' => 7,
50 'description' => _('Limit the result set to a certain kind of host states'),
51 'options' => array(
52 7 => _('All host states'),
53 6 => _('Host problem states'),
54 1 => _('Host up states'),
55 2 => _('Host down states'),
56 4 => _('Host unreachable states'))
58 $this->properties['service_states'] = array(
59 'type' => 'enum',
60 'default' => 15,
61 'description' => _('Limit the result set to a certain kind of service states'),
62 'options' => array(
63 15 => _('All service states'),
64 14 => _('Service problem states'),
65 1 => _('Service OK states'),
66 2 => _('Service warning states'),
67 4 => _('Service critical states'),
68 8 => _('Service unknown states'))
70 $this->properties['summary_items'] = array(
71 'type' => 'int',
72 'default' => 25,
73 'description' => 'Number of summary items to include in reports'
75 $this->properties['include_long_output'] = array(
76 'type' => 'bool',
77 'default' => false,
78 'description' => 'Set this to include the full plugin output with the output of your reports'
81 $this->rename_options['displaytype'] = 'summary_type';
82 $this->properties['report_period']['options']['forever'] = _('Forever');
85 protected function update_value($name, $value)
87 switch ($name) {
88 case 'standardreport':
89 if (!$value)
90 return false;
91 $this['report_period'] = 'last7days';
92 if ($value < 4)
93 $this['summary_type'] = self::RECENT_ALERTS;
94 else
95 $this['summary_type'] = self::TOP_ALERT_PRODUCERS;
96 switch ($value) {
97 // By utilizing Report_options::ALL_AUTHORIZED, we pass on the
98 // explicit selection to the report model
99 case 1: case 4:
100 $this['alert_types'] = 3;
101 $this['state_types'] = 2;
102 $this['report_type'] = 'hosts';
103 $this->options['objects'] = Report_options::ALL_AUTHORIZED;
104 break;
106 case 2: case 5:
107 $this['alert_types'] = 1;
108 $this['state_types'] = 2;
109 $this['report_type'] = 'hosts';
110 $this->options['objects'] = Report_options::ALL_AUTHORIZED;
111 break;
113 case 3: case 6:
114 $this['alert_types'] = 2;
115 $this['state_types'] = 2;
116 $this['report_type'] = 'services';
117 $this->options['objects'] = Report_options::ALL_AUTHORIZED;
118 break;
120 default:
121 var_dump('unknown standard report');
122 Kohana::debug("Unknown standard report: $value");
123 die;
125 break;
127 return parent::update_value($name, $value);
130 protected function calculate_time($report_period) {
131 if ($report_period === 'forever') {
132 $this->options['start_time'] = 0;
133 $this->options['end_time'] = time();
134 return true;
136 return parent::calculate_time($report_period);