monitoring: Provide service stats on both the host and the service object

This commit is contained in:
Eric Lippmann 2014-09-23 22:17:22 -07:00
parent 6625e8d391
commit df18eab69b
2 changed files with 51 additions and 37 deletions

View File

@ -60,13 +60,6 @@ class Host extends MonitoredObject
*/ */
protected $services; protected $services;
/**
* Stats
*
* @var object
*/
protected $stats;
/** /**
* Create a new host * Create a new host
* *
@ -160,36 +153,6 @@ class Host extends MonitoredObject
return $this; return $this;
} }
/**
* Fetch stats
*
* @return $this
*/
public function fetchStats()
{
$this->stats = $this->backend->select()->from('statusSummary', array(
'services_total',
'services_ok',
'services_problem',
'services_problem_handled',
'services_problem_unhandled',
'services_critical',
'services_critical_unhandled',
'services_critical_handled',
'services_warning',
'services_warning_unhandled',
'services_warning_handled',
'services_unknown',
'services_unknown_unhandled',
'services_unknown_handled',
'services_pending',
))
->where('service_host_name', $this->host)
->getQuery()
->fetchRow();
return $this;
}
/** /**
* Get the optional translated textual representation of a host state * Get the optional translated textual representation of a host state
* *

View File

@ -8,6 +8,7 @@ use InvalidArgumentException;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\Exception\InvalidPropertyException; use Icinga\Exception\InvalidPropertyException;
use Icinga\Module\Monitoring\Backend; use Icinga\Module\Monitoring\Backend;
use Icinga\Web\UrlParams;
/** /**
* A monitored Icinga object, i.e. host or service * A monitored Icinga object, i.e. host or service
@ -108,6 +109,13 @@ abstract class MonitoredObject
*/ */
protected $eventhistory; protected $eventhistory;
/**
* Stats
*
* @var object
*/
protected $stats;
/** /**
* Create a monitored object, i.e. host or service * Create a monitored object, i.e. host or service
* *
@ -381,6 +389,36 @@ abstract class MonitoredObject
return $this; return $this;
} }
/**
* Fetch stats
*
* @return $this
*/
public function fetchStats()
{
$this->stats = $this->backend->select()->from('statusSummary', array(
'services_total',
'services_ok',
'services_problem',
'services_problem_handled',
'services_problem_unhandled',
'services_critical',
'services_critical_unhandled',
'services_critical_handled',
'services_warning',
'services_warning_unhandled',
'services_warning_handled',
'services_unknown',
'services_unknown_unhandled',
'services_unknown_handled',
'services_pending',
))
->where('service_host_name', $this->host_name)
->getQuery()
->fetchRow();
return $this;
}
/** /**
* Fetch all available data of the object * Fetch all available data of the object
* *
@ -419,4 +457,17 @@ abstract class MonitoredObject
} }
throw new InvalidPropertyException('Can\'t access property \'%s\'. Property does not exist.', $name); throw new InvalidPropertyException('Can\'t access property \'%s\'. Property does not exist.', $name);
} }
/**
* @deprecated
*/
public static function fromParams(UrlParams $params)
{
if ($params->has('service') && $params->has('host')) {
return new Service(Backend::createBackend(), $params->get('host'), $params->get('service'));
} elseif ($params->has('host')) {
return new Host(Backend::createBackend(), $params->get('host'));
}
return null;
}
} }