Avail feature updated
[ninja.git] / modules / orm / models / servicegroup.php
blobb4b438bee430eca5a4bd797134afd0758d50444c
1 <?php
3 require_once( dirname(__FILE__).'/base/baseservicegroup.php' );
5 /**
6 * Describes a single object from livestatus
7 */
8 class ServiceGroup_Model extends BaseServiceGroup_Model {
9 /**
10 * An array of custom column dependencies
12 static public $rewrite_columns = array(
13 'service_stats' => array('name')
16 /**
17 * Get statistics about services in the group
19 public function get_service_stats() {
20 $set = ServicePool_Model::all()->reduce_by('groups', $this->get_name(), '>=');
22 if (config::get('checks.show_passive_as_active', '*')) {
23 $active_checks = ObjectPool_Model::get_by_query('[services] active_checks_enabled = 1 or accept_passive_checks = 1');
24 $disabled_checks = ObjectPool_Model::get_by_query('[services] active_checks_enabled = 0 and accept_passive_checks = 0');
25 } else {
26 $active_checks = ObjectPool_Model::get_by_query('[services] active_checks_enabled = 1');
27 $disabled_checks = ObjectPool_Model::get_by_query('[services] active_checks_enabled = 0');
30 $all = ObjectPool_Model::get_by_query('[services] state!=999');
31 $pending = ObjectPool_Model::get_by_query('[services] has_been_checked=0');
32 $ok = ObjectPool_Model::get_by_query('[services] state=0 and has_been_checked=1');
33 $warn = ObjectPool_Model::get_by_query('[services] state=1 and has_been_checked=1');
34 $critical = ObjectPool_Model::get_by_query('[services] state=2 and has_been_checked=1');
35 $unknown = ObjectPool_Model::get_by_query('[services] state=3 and has_been_checked=1');
37 $acknowledged = ObjectPool_Model::get_by_query('[services] acknowledged = 1');
38 $disabled_active = ObjectPool_Model::get_by_query('[services] check_type = 0')->intersect($disabled_checks);
39 $scheduled = ObjectPool_Model::get_by_query('[services] scheduled_downtime_depth > 0');
40 $unscheduled = ObjectPool_Model::get_by_query('[services] scheduled_downtime_depth = 0');
41 $unhandled = ObjectPool_Model::get_by_query('[services] acknowledged = 0 and scheduled_downtime_depth = 0')->intersect($active_checks);
43 $down_host = ObjectPool_Model::get_by_query('[services] host.state != 0');
45 $stats = array(
46 'ok' => $ok,
47 'warning' => $warn,
48 'warning_and_ack' => $warn->intersect($acknowledged),
49 'warning_and_disabled_active' => $warn->intersect($disabled_active),
50 'warning_and_scheduled' => $warn->intersect($scheduled),
51 'warning_and_unhandled' => $warn->intersect($unhandled),
52 'warning_on_down_host' => $warn->intersect($down_host),
53 'critical' => $critical,
54 'critical_and_ack' => $critical->intersect($acknowledged),
55 'critical_and_disabled_active' => $critical->intersect($disabled_active),
56 'critical_and_scheduled' => $critical->intersect($scheduled),
57 'critical_and_unhandled' => $critical->intersect($unhandled),
58 'critical_on_down_host' => $critical->intersect($down_host),
59 'unknown' => $unknown,
60 'unknown_and_ack' => $unknown->intersect($acknowledged),
61 'unknown_and_disabled_active' => $unknown->intersect($disabled_active),
62 'unknown_and_scheduled' => $unknown->intersect($scheduled),
63 'unknown_and_unhandled' => $unknown->intersect($unhandled),
64 'unknown_on_down_host' => $unknown->intersect($down_host),
65 'pending' => $pending
69 $queries = array();
70 foreach( $stats as $name => $stat ) {
71 $queries[$name] = $set->intersect($stat)->get_query();
73 return array( 'stats' => $set->stats($stats), 'queries' => $queries );