Skip to content

Commit

Permalink
monitoring/Service': Add getStateText()', let `getHost()' return th…
Browse files Browse the repository at this point in the history
…e host object

refs #6593
  • Loading branch information
lippserd committed Sep 16, 2014
1 parent d091e21 commit cc2d06e
Showing 1 changed file with 66 additions and 7 deletions.
73 changes: 66 additions & 7 deletions modules/monitoring/library/Monitoring/Object/Service.php
Expand Up @@ -4,13 +4,39 @@

namespace Icinga\Module\Monitoring\Object;

use InvalidArgumentException;
use Icinga\Module\Monitoring\Backend;

/**
* A Icinga service
*/
class Service extends MonitoredObject
{
/**
* Service state 'OK'
*/
const STATE_OK = 0;

/**
* Service state 'WARNING'
*/
const STATE_WARNING = 1;

/**
* Service state 'CRITICAL'
*/
const STATE_CRITICAL = 2;

/**
* Service state 'UNKNOWN'
*/
const STATE_UNKNOWN = 3;

/**
* Service state 'PENDING'
*/
const STATE_PENDING = 99;

/**
* Type of the Icinga service
*
Expand All @@ -26,9 +52,9 @@ class Service extends MonitoredObject
public $prefix = 'service_';

/**
* Host name the service is running on
* Host the service is running on
*
* @var string
* @var Host
*/
protected $host;

Expand All @@ -49,14 +75,14 @@ class Service extends MonitoredObject
public function __construct(Backend $backend, $host, $service)
{
parent::__construct($backend);
$this->host = $host;
$this->host = new Host($backend, $host);
$this->service = $service;
}

/**
* Get the host name the service is running on
* Get the host the service is running on
*
* @return string
* @return Host
*/
public function getHost()
{
Expand All @@ -68,7 +94,7 @@ public function getHost()
*
* @return string
*/
public function getService()
public function getName()
{
return $this->service;
}
Expand Down Expand Up @@ -167,7 +193,40 @@ protected function getDataView()
'service_process_performance_data',
'service_percent_state_change'
))
->where('host_name', $this->host)
->where('host_name', $this->host->getName())
->where('service_description', $this->service);
}

/**
* Get the translated textual representation of a service state
*
* @param int $state
*
* @return string
* @throws InvalidArgumentException If the service state is not valid
*/
public static function getStateText($state)
{
switch ((int) $state) {
case self::STATE_OK:
$text = mt('monitoring', 'ok');
break;
case self::STATE_WARNING:
$text = mt('monitoring', 'warning');
break;
case self::STATE_CRITICAL:
$text = mt('monitoring', 'critical');
break;
case self::STATE_UNKNOWN:
$text = mt('monitoring', 'unknown');
break;
case self::STATE_PENDING:
$text = mt('monitoring', 'pending');
break;
default:
throw new InvalidArgumentException('Invalid service state \'%s\'', $state);
break;
}
return $text;
}
}

0 comments on commit cc2d06e

Please sign in to comment.