2013-06-27 10:14:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
class Zend_View_Helper_MonitoringState extends Zend_View_Helper_Abstract
|
|
|
|
{
|
|
|
|
private $servicestates = array('ok', 'warning', 'critical', 'unknown', 99 => 'pending', null => 'pending');
|
|
|
|
private $hoststates = array('up', 'down', 'unreachable', 99 => 'pending', null => 'pending');
|
|
|
|
|
2013-07-12 10:23:58 +02:00
|
|
|
public function monitoringState($object, $type = 'service')
|
|
|
|
{
|
2013-06-27 10:14:41 +02:00
|
|
|
|
|
|
|
if ($type === 'service') {
|
|
|
|
return $this->servicestates[$object->service_state];
|
2013-07-12 10:23:58 +02:00
|
|
|
} elseif ($type === 'host') {
|
2013-06-27 10:14:41 +02:00
|
|
|
return $this->hoststates[$object->host_state];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-12 10:23:58 +02:00
|
|
|
public function getStateFlags($object, $type = 'service')
|
|
|
|
{
|
|
|
|
$state_classes = array();
|
|
|
|
if ($type === 'host') {
|
|
|
|
$state_classes[] = $this->monitoringState($object, "host");
|
|
|
|
if ($object->host_acknowledged || $object->host_in_downtime) {
|
|
|
|
$state_classes[] = 'handled';
|
|
|
|
}
|
|
|
|
if ($object->host_last_state_change > (time() - 600)) {
|
|
|
|
$state_classes[] = 'new';
|
|
|
|
}
|
2013-07-19 17:45:51 +02:00
|
|
|
} else {
|
|
|
|
$state_classes[] = $this->monitoringState($object, "service");
|
|
|
|
if ($object->service_acknowledged || $object->service_in_downtime) {
|
|
|
|
$state_classes[] = 'handled';
|
|
|
|
}
|
|
|
|
if ($object->service_last_state_change > (time() - 600)) {
|
|
|
|
$state_classes[] = 'new';
|
|
|
|
}
|
2013-07-12 10:23:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $state_classes;
|
|
|
|
}
|
2013-06-27 10:14:41 +02:00
|
|
|
|
2013-07-12 10:23:58 +02:00
|
|
|
public function getStateTitle($object, $type)
|
|
|
|
{
|
|
|
|
return strtoupper($this->monitoringState($object, $type))
|
|
|
|
. ' since '
|
|
|
|
. date('Y-m-d H:i:s', $object->{$type.'_last_state_change'});
|
|
|
|
}
|
|
|
|
}
|