1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
5 * op5, and the op5 logo are trademarks, servicemarks, registered servicemarks
6 * or registered trademarks of op5 AB.
7 * All other trademarks, servicemarks, registered trademarks, and registered
8 * servicemarks mentioned herein may be the property of their respective owner(s).
9 * The information contained herein is provided AS IS with NO WARRANTY OF ANY
10 * KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY, AND FITNESS FOR A
13 class Outages_Controller
extends Authenticated_Controller
15 const SERVICE_SEVERITY_DIVISOR
= 4; /**< Magical constant that tells us how many times less interesting a service is compared to a host */
19 * @desc default method
22 public function index()
24 return $this->display_network_outages();
28 * shows all hosts that are causing network outages
30 public function display_network_outages()
32 $ls = Livestatus
::instance();
33 $outages = $ls->getHosts( array(
43 if(count($outages) > 0) {
44 foreach($outages as &$host) {
46 # count number of affected hosts / services
48 list($affected_hosts,$affected_services,$severity) = $this->count_affected_hosts_and_services($host['name']);
49 $host['affected_hosts'] = $affected_hosts;
50 $host['affected_services'] = $affected_services;
51 $host['severity'] = $severity;
57 $this->template
->toolbar
= new Toolbar_Controller( _("Network outages"), _("Blocking outages") );
59 $this->template
->content
= $this->add_view('outages/network_outages');
60 $content = $this->template
->content
;
61 $content->title
= _('Blocking Outages');
63 $content->outage_data
= $outages;
64 $this->template
->title
= _('Monitoring ยป Network outages');
68 private function count_affected_hosts_and_services($host) {
69 /* FIXME: This method needs to be partly implemented in livestatus.
70 * That can be done by allowing the recursion in childs/parents-column
71 * to be handled within livestatus, and do a simple Stats-request instead
74 $affected_services = 0;
76 $hosts_to_test = array($host);
77 $hosts_services = array();
79 $ls = Livestatus
::instance();
80 $lsb = $ls->getBackend();
84 /* Iterate through all hosts with children. */
85 while( !empty( $hosts_to_test ) ) {
86 $host_name = array_shift($hosts_to_test);
88 /* Skip if already tested... */
89 if(isset($hosts_services[$host_name]))
92 $host = $ls->getHosts(array(
93 'filter'=>array('name'=>$host_name),
94 'columns' => array('name', 'childs', 'hourly_value', 'num_services')
96 $service_value = $lsb->getStats('services', array('value' => 'sum hourly_value'), array(
97 'filter' => array('host_name'=>$host[0]['name'])
100 $hosts_services[$host_name] = $host[0]['num_services'];
101 $hosts_to_test +
= $host[0]['childs'];
103 $severity_value +
= $host[0]['hourly_value'] +
$service_value[0]['value'];
106 return array(count($hosts_services), array_sum($hosts_services), $severity_value);