Monitoring\Object: replace fromRequest with params

This is only a temporary solution, the Monitoring\Object should be
fetched from the backend created in our front controller.
This commit is contained in:
Thomas Gelf 2014-06-17 13:10:54 +00:00
parent 0ecd527e8c
commit 3ccfe347f3
4 changed files with 23 additions and 23 deletions

View File

@ -57,12 +57,12 @@ class Monitoring_ShowController extends Controller
public function init()
{
if ($this->getRequest()->getActionName() === 'host') {
$this->view->object = new Host($this->getRequest());
$this->view->object = new Host($this->params);
} elseif ($this->getRequest()->getActionName() === 'service') {
$this->view->object = new Service($this->getRequest());
$this->view->object = new Service($this->params);
} else {
// TODO: Well... this could be done better
$this->view->object = AbstractObject::fromRequest($this->getRequest());
$this->view->object = AbstractObject::fromParams($this->params);
}
if (Hook::has('ticket')) {
$this->view->tickets = Hook::first('ticket');

View File

@ -17,7 +17,8 @@ use Icinga\Module\Monitoring\DataView\Hostgroup;
use Icinga\Module\Monitoring\DataView\Comment;
use Icinga\Module\Monitoring\DataView\Servicegroup;
use Icinga\Module\Monitoring\DataView\Customvar;
use Icinga\Web\Request;
use Icinga\Web\UrlParams;
abstract class AbstractObject
{
@ -35,14 +36,14 @@ abstract class AbstractObject
protected $view;
private $properties = array();
private $request = null;
protected $params;
// TODO: Fetching parent states if any would be nice
// Same goes for host/service dependencies
public function __construct(Request $request)
public function __construct(UrlParams $params)
{
$this->request = $request;
$this->params = $params;
$this->properties = $this->getProperties();
}
@ -117,9 +118,7 @@ abstract class AbstractObject
public function fetchCustomvars()
{
$query = Customvar::fromRequest(
$this->request,
array(
$query = Customvar::fromParams(array('backend' => null), array(
'varname',
'varvalue'
)
@ -173,14 +172,13 @@ abstract class AbstractObject
public function fetchServicegroups()
{
$query = Servicegroup::fromRequest(
$this->request,
array(
$query = Servicegroup::fromParams(array('backend' => null), array(
'servicegroup_name',
'servicegroup_alias',
)
);
$query->where('service_host_name', $this->host_name);
$query->where('service_description', $this->service_description);
$this->servicegroups = $query->getQuery()->fetchPairs();
return $this;
}
@ -226,7 +224,7 @@ abstract class AbstractObject
'output',
'type'
)
)->sort('raw_timestamp', 'DESC');
)->sort('timestamp', 'DESC');
if ($this->type === 'service') {
$query->where('service_host_name', $this->host_name);
$query->where('service_description', $this->service_description);
@ -253,12 +251,12 @@ abstract class AbstractObject
return $this->$expandedName;
}
public static function fromRequest(Request $request)
public static function fromParams(UrlParams $params)
{
if ($request->has('service') && $request->has('host')) {
return new Service($request);
} elseif ($request->has('host')) {
return new Host($request);
if ($params->has('service') && $params->has('host')) {
return new Service($params);
} elseif ($params->has('host')) {
return new Host($params);
}
}

View File

@ -27,7 +27,7 @@ class Host extends AbstractObject
protected function getProperties()
{
$this->view = HostStatus::fromRequest($this->request, array(
$this->view = HostStatus::fromParams(array('backend' => null), array(
'host_name',
'host_alias',
'host_address',

View File

@ -28,7 +28,7 @@ class Service extends AbstractObject
protected function getProperties()
{
$this->view = ServiceStatus::fromRequest($this->request, array(
$this->view = ServiceStatus::fromParams(array('backend' => null), array(
'host_name',
'host_state',
'host_state_type',
@ -111,7 +111,9 @@ class Service extends AbstractObject
'service_flap_detection_enabled',
'service_flap_detection_enabled_changed',
'service_modified_service_attributes',
));
))->where('host_name', $this->params->get('host'))
->where('service_description', $this->params->get('service'));
return $this->view->getQuery()->fetchRow();
}
}