Skip to content

Commit

Permalink
monitoring: Adapt host and service classes to match their base class'…
Browse files Browse the repository at this point in the history
… interface
  • Loading branch information
lippserd committed Sep 12, 2014
1 parent aca5a2e commit c0e3447
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 57 deletions.
66 changes: 49 additions & 17 deletions modules/monitoring/library/Monitoring/Object/Host.php
Expand Up @@ -4,32 +4,64 @@

namespace Icinga\Module\Monitoring\Object;

use Icinga\Module\Monitoring\DataView\HostStatus;
use Icinga\Data\Db\DbQuery;
use Icinga\Module\Monitoring\Backend;

/**
* A Icinga host
*/
class Host extends MonitoredObject
{
public $type = 'host';
/**
* Type of the Icinga host
*
* @var string
*/
public $type = self::TYPE_HOST;

/**
* Prefix of the Icinga host
*
* @var string
*/
public $prefix = 'host_';

protected function applyObjectFilter(DbQuery $query)
/**
* Host name
*
* @var string
*/
protected $host;

/**
* Create a new host
*
* @param Backend $backend Backend to fetch host information from
* @param string $host Host name
*/
public function __construct(Backend $backend, $host)
{
return $query->where('host_name', $this->host_name);
parent::__construct($backend);
$this->host = $host;
}

public function populate()
/**
* Get the host name
*
* @return string
*/
public function getHost()
{
$this->fetchComments()
->fetchHostgroups()
->fetchContacts()
->fetchContactGroups()
->fetchCustomvars()
->fetchDowntimes();
return $this->host;
}

protected function getProperties()
/**
* Get the data view to fetch the host information from
*
* @return \Icinga\Module\Monitoring\DataView\HostStatus
*/
protected function getDataView()
{
$this->view = HostStatus::fromParams(array('backend' => null), array(
return $this->backend->select()->from('hostStatus', array(
'host_name',
'host_alias',
'host_address',
Expand Down Expand Up @@ -70,8 +102,8 @@ protected function getProperties()
'host_notes_url',
'host_modified_host_attributes',
'host_problem',
'process_perfdata' => 'host_process_performance_data',
))->where('host_name', $this->params->get('host'));
return $this->view->getQuery()->fetchRow();
'host_process_performance_data'
))
->where('host_name', $this->host);
}
}
110 changes: 70 additions & 40 deletions modules/monitoring/library/Monitoring/Object/Service.php
Expand Up @@ -4,33 +4,83 @@

namespace Icinga\Module\Monitoring\Object;

use Icinga\Module\Monitoring\DataView\ServiceStatus;
use Icinga\Data\Db\DbQuery;
use Icinga\Module\Monitoring\Backend;

/**
* A Icinga service
*/
class Service extends MonitoredObject
{
public $type = 'service';
/**
* Type of the Icinga service
*
* @var string
*/
public $type = self::TYPE_SERVICE;

/**
* Prefix of the Icinga service
*
* @var string
*/
public $prefix = 'service_';

protected function applyObjectFilter(DbQuery $query)
/**
* Host name the service is running on
*
* @var string
*/
protected $host;

/**
* Service name
*
* @var string
*/
protected $service;

/**
* Create a new service
*
* @param Backend $backend Backend to fetch service information from
* @param string $host Host name the service is running on
* @param string $service Service name
*/
public function __construct(Backend $backend, $host, $service)
{
return $query->where('service_host_name', $this->host_name)
->where('service_description', $this->service_description);
parent::__construct($backend);
$this->host = $host;
$this->service = $service;
}

public function populate()
/**
* Get the host name the service is running on
*
* @return string
*/
public function getHost()
{
$this->fetchComments()
->fetchServicegroups()
->fetchContacts()
->fetchContactGroups()
->fetchCustomvars()
->fetchDowntimes();
return $this->host;
}

protected function getProperties()
/**
* Get the service name
*
* @return string
*/
public function getService()
{
$this->view = ServiceStatus::fromParams(array('backend' => null), array(
return $this->service;
}

/**
* Get the data view
*
* @return \Icinga\Module\Monitoring\DataView\ServiceStatus
*/
protected function getDataView()
{
return $this->backend->select()->from('serviceStatus', array(
'host_name',
'host_state',
'host_state_type',
Expand Down Expand Up @@ -114,30 +164,10 @@ protected function getProperties()
'service_flap_detection_enabled',
'service_flap_detection_enabled_changed',
'service_modified_service_attributes',
'process_perfdata' => 'service_process_performance_data',
))->where('host_name', $this->params->get('host'))
->where('service_description', $this->params->get('service'));

return $this->view->getQuery()->fetchRow();
}

/**
* Get the host name the service is running on
*
* @return string
*/
public function getHostName()
{
return $this->params->get('host');
}

/**
* Get the service name
*
* @return string
*/
public function getName()
{
return $this->params->get('service');
'service_process_performance_data',
'service_percent_state_change'
))
->where('host_name', $this->host)
->where('service_description', $this->service);
}
}

0 comments on commit c0e3447

Please sign in to comment.