diff --git a/modules/monitoring/application/controllers/MultiController.php b/modules/monitoring/application/controllers/MultiController.php
index 5c2da9f1c..de4fefd0a 100644
--- a/modules/monitoring/application/controllers/MultiController.php
+++ b/modules/monitoring/application/controllers/MultiController.php
@@ -64,6 +64,7 @@ class Monitoring_MultiController extends ActionController
'host_unhandled_service_count',
'host_passive_checks_enabled',
'host_obsessing',
+ 'host_state',
'host_notifications_enabled',
'host_event_handler_enabled',
'host_flap_detection_enabled',
@@ -90,8 +91,8 @@ class Monitoring_MultiController extends ActionController
$this->view->hostnames = $this->getProperties($hosts, 'host_name');
$this->view->downtimes = $this->getDowntimes($hosts);
$this->view->errors = $errors;
- $this->view->states = $this->countStates($hosts);
- $this->view->pie = $this->createPie($this->view->states);
+ $this->view->states = $this->countStates($hosts, 'host', 'host_name');
+ $this->view->pie = $this->createPie($this->view->states, $this->view->getHelper('MonitoringState')->getHostStateColors());
// Handle configuration changes
$this->handleConfigurationForm(array(
@@ -147,10 +148,10 @@ class Monitoring_MultiController extends ActionController
$this->view->hostnames = $this->getProperties($services, 'host_name');
$this->view->servicenames = $this->getProperties($services, 'service_description');
$this->view->downtimes = $this->getDowntimes($services);
- $this->view->service_states = $this->countStates($services);
- $this->view->host_states = $this->countStates($services, 'host_name', 'host_state');
- $this->view->service_pie = $this->createPie($this->view->service_states);
- $this->view->host_pie = $this->createPie($this->view->host_states);
+ $this->view->service_states = $this->countStates($services, 'service');
+ $this->view->host_states = $this->countStates($services, 'host', 'host_name');
+ $this->view->service_pie = $this->createPie($this->view->service_states, $this->view->getHelper('MonitoringState')->getServiceStateColors());
+ $this->view->host_pie = $this->createPie($this->view->host_states, $this->view->getHelper('MonitoringState')->getHostStateColors());
$this->view->errors = $errors;
$this->handleConfigurationForm(array(
@@ -242,16 +243,14 @@ class Monitoring_MultiController extends ActionController
return $problems;
}
- private function countStates($objects, $unique = null, $state = 'service_state')
+ private function countStates($objects, $type = 'host', $unique = null)
{
- $known = array();
- $states = array(
- '0' => 0,
- '1' => 0,
- '2' => 0,
- '3' => 0,
- '99' => 0
- );
+ $known = array();
+ if ($type === 'host') {
+ $states = array_fill_keys($this->view->getHelper('MonitoringState')->getHostStateNames(), 0);
+ } else {
+ $states = array_fill_keys($this->view->getHelper('MonitoringState')->getServiceStateNames(), 0);
+ }
foreach ($objects as $object) {
if (isset($unique)) {
if (array_key_exists($object->$unique, $known)) {
@@ -259,22 +258,16 @@ class Monitoring_MultiController extends ActionController
}
$known[$object->$unique] = true;
}
- $states[$object->$state]++;
+ $states[$this->view->monitoringState($object, $type)]++;
}
- return array(
- 'up' => $states['0'],
- 'down' => $states['1'],
- 'unreachable' => $states['2'],
- 'unknown' => $states['3'],
- 'pending' => $states['99']
- );
+ return $states;
}
- private function createPie($states)
+ private function createPie($states, $colors)
{
$chart = new InlinePie(
array_values($states),
- array('#44bb77', '#FF5566', '#FF5566', '#E066FF', '#77AAFF')
+ $colors
);
$chart->setLabels(array_keys($states))
->setHeight(100)
diff --git a/modules/monitoring/application/views/helpers/MonitoringState.php b/modules/monitoring/application/views/helpers/MonitoringState.php
index dff80a205..2051975b7 100644
--- a/modules/monitoring/application/views/helpers/MonitoringState.php
+++ b/modules/monitoring/application/views/helpers/MonitoringState.php
@@ -7,7 +7,6 @@ class Zend_View_Helper_MonitoringState extends Zend_View_Helper_Abstract
public function monitoringState($object, $type = 'service')
{
-
if ($type === 'service') {
return $this->servicestates[$object->service_state];
} elseif ($type === 'host') {
@@ -15,6 +14,26 @@ class Zend_View_Helper_MonitoringState extends Zend_View_Helper_Abstract
}
}
+ public function getServiceStateColors()
+ {
+ return array('#44bb77', '#FFCC66', '#FF5566', '#E066FF', '#77AAFF');
+ }
+
+ public function getHostStateColors()
+ {
+ return array('#44bb77', '#FF5566', '#E066FF', '#77AAFF');
+ }
+
+ public function getServiceStateNames()
+ {
+ return array_values($this->servicestates);
+ }
+
+ public function getHostStateNames()
+ {
+ return array_values($this->hoststates);
+ }
+
public function getStateFlags($object, $type = 'service')
{
$state_classes = array();
diff --git a/modules/monitoring/application/views/scripts/multi/components/summary.phtml b/modules/monitoring/application/views/scripts/multi/components/summary.phtml
index e3ba1cb2a..fb761cce2 100644
--- a/modules/monitoring/application/views/scripts/multi/components/summary.phtml
+++ b/modules/monitoring/application/views/scripts/multi/components/summary.phtml
@@ -15,7 +15,7 @@
'monitoring/command/reschedulenextcheck',
array(
'host' => $this->target['host'],
- 'service' => $this->target['service'],
+ 'service' => array_key_exists('service', $this->target) ? $this->target['service'] : null,
'checktime' => time(),
'forcecheck' => '1'
)
diff --git a/modules/monitoring/application/views/scripts/multi/host.phtml b/modules/monitoring/application/views/scripts/multi/host.phtml
index 165ece8ef..e473ba05a 100644
--- a/modules/monitoring/application/views/scripts/multi/host.phtml
+++ b/modules/monitoring/application/views/scripts/multi/host.phtml
@@ -1,33 +1,59 @@
is_service = false;
$this->hostquery = implode($this->hostnames, ',');
-$this->target = array(
- 'host' => $this->hostquery
-);
+$this->target = array('host' => $this->hostquery);
?>
-= $this->tabs->render($this); ?>
-
-
-
Hosts (= count($objects) ?> objects)
-
-
-
-
-
- = $this->render('multi/components/summary.phtml'); ?>
-
+
+ = $this->tabs; ?>
-= $this->render('multi/components/comments.phtml'); ?>
-= $this->render('multi/components/downtimes.phtml'); ?>
-= $this->render('multi/components/configuration.phtml'); ?>
+
+
Summary for = count($objects) ?> hosts
+
+ = $this->render('multi/components/objectlist.phtml'); ?>
+
+
+
+ = array_sum(array_values($states)) ?> Hosts
+ |
+ |
+
+
+
+ = $this->pie->render(); ?>
+ |
+
+ $count) {
+ if ($count > 0) {
+ echo ucfirst($state) . ': ' . $count . ' ';
+ }
+ }
+ ?>
+ |
+ |
+
+
+
+
=$this->icon('hostgroup.png')?> Host Actions
+
+
+
+ = $this->render('multi/components/summary.phtml'); ?>
+ = $this->render('multi/components/comments.phtml'); ?>
+ = $this->render('multi/components/downtimes.phtml'); ?>
+
+
+
+ = $this->render('multi/components/flags.phtml') ?>
+
+
+
+
+
diff --git a/public/js/icinga/events.js b/public/js/icinga/events.js
index df0fc86be..fcce23e4a 100644
--- a/public/js/icinga/events.js
+++ b/public/js/icinga/events.js
@@ -135,7 +135,7 @@
$(document).on('click', '.tree .handle', { self: this }, this.treeNodeToggle);
// Toggle all triStateButtons
- $(document).on('click', '.tristate input.tristate', { self: this}, this.clickTriState);
+ $(document).on('click', 'div.tristate .tristate-dummy', { self: this }, this.clickTriState);
// TBD: a global autocompletion handler
// $(document).on('keyup', 'form.auto input', this.formChangeDelayed);
@@ -253,12 +253,13 @@
clickTriState: function (event) {
var $tristate = $(this);
- var old = $tristate.data('icinga-old');
var triState = parseInt($tristate.data('icinga-tristate'), 10);
- var value = $tristate.data('icinga-value');
- var self = event.data.self;
- // update value
+ // load current values
+ var old = $tristate.data('icinga-old');
+ var value = $tristate.parent().find('input:radio:checked').first().prop('checked', false).val();
+
+ // calculate the new value
if (triState) {
// 1 => 0
// 0 => unchanged
@@ -269,19 +270,17 @@
// 0 => 1
value = value === '1' ? '0' : '1';
}
- $tristate.data('icinga-value', value);
+ // update form value
+ $tristate.parent().find('input:radio[value="' + value + '"]').prop('checked', true);
+ // update dummy
- // also set form value
- $tristate.prop('value', value);
-
- var $changed = $tristate.parent().find('.tristate-status').first();
- if (old != value) {
- $changed.text('changed');
+ console.log(value + ' === ' + old + ' ?');
+ if (value !== old) {
+ $tristate.parent().find('b.tristate-changed').css('visibility', 'visible');
} else {
- $changed.empty();
+ $tristate.parent().find('b.tristate-changed').hide();
}
- $tristate.find('.tristate-status').text(value);
- self.icinga.ui.updateTriState(value.toString(), $tristate);
+ self.icinga.ui.setTriState(value.toString(), $tristate);
},
/**
@@ -600,6 +599,7 @@
$(document).off('mouseleave', '.historycolorgrid td', this.historycolorgidUnhover);
$(document).off('mouseenter', 'li.dropdown', this.dropdownHover);
$(document).off('mouseleave', 'li.dropdown', this.dropdownLeave);
+ $(document).off('click', 'div.tristate .tristate-dummy', this.clickTriState);
},
destroy: function() {
diff --git a/public/js/icinga/ui.js b/public/js/icinga/ui.js
index 9bbf1620f..6d8366b53 100644
--- a/public/js/icinga/ui.js
+++ b/public/js/icinga/ui.js
@@ -469,35 +469,32 @@
initializeTriStates: function ($html) {
var self = this;
$('div.tristate', $html).each(function(index, item) {
- var target = item;
- var $target = $(target);
- var value = $target.find('input:checked').first().val();
- var triState = value === 'unchanged' ? true : false;
- var name = $('input', target).first().attr('name');
- var old = value;
+ var $target = $(item);
- var getStateDescription = function(value) {
- if (value === 'unchanged') {
- return '(mixed values)';
- }
- return '';
- };
-
- $target.empty();
- $target.parent().parent()
- .find('label')
- .append('
');
+ // hide input boxess and remove text nodes
+ $target.find("input").hide();
+ $target.contents().filter(function() { return this.nodeType == 3; }).remove();
+
+ // has three states?
+ var triState = $target.find('input[value="unchanged"]').size() > 0 ? 1 : 0;
+
+ // fetch current value from radiobuttons
+ var value = $target.find('input:checked').first().val();
+
$target.append(
- '
' +
- '
' + getStateDescription(value) + '
'
- );
+ '
(changed) '
+ );
+ if (triState) {
+ // TODO: find a better way to activate indeterminate checkboxes after load.
+ $target.append(
+ ''
+ );
+ }
});
},
@@ -507,20 +504,16 @@
* @param value {String} The value to set, can be '1', '0' and 'unchanged'
* @param $checkbox {jQuery} The checkbox
*/
- updateTriState: function(value, $checkbox)
+ setTriState: function(value, $checkbox)
{
- console.log($checkbox);
switch (value) {
case ('1'):
- console.log('checked true; indeterminate: false');
$checkbox.prop('checked', true).prop('indeterminate', false);
break;
case ('0'):
- console.log('checked false; indeterminate: false');
$checkbox.prop('checked', false).prop('indeterminate', false);
break;
case ('unchanged'):
- console.log('checked false; indeterminate: true');
$checkbox.prop('checked', false).prop('indeterminate', true);
break;
}