Deduplicate Hosts and Services-Controller
Create functions in abstract class for filtering hosts and services, instead of reimplementing it in the controller.
This commit is contained in:
parent
1cfcb934b0
commit
266e781a93
|
@ -105,27 +105,19 @@ class Monitoring_HostsController extends Controller
|
||||||
'host_active_checks_enabled',
|
'host_active_checks_enabled',
|
||||||
'host_obsessing'*/
|
'host_obsessing'*/
|
||||||
));
|
));
|
||||||
$unhandledObjects = array();
|
$unhandledObjects = $this->hostList->getUnhandledObjects();
|
||||||
$unhandledFilterExpressions = array();
|
$unhandledFilterExpressions = array();
|
||||||
$acknowledgedObjects = array();
|
foreach ($unhandledObjects as $object) {
|
||||||
$objectsInDowntime = array();
|
$unhandledFilterExpressions[] = Filter::where('host', $object->getName());
|
||||||
$downtimeFilterExpressions = array();
|
|
||||||
|
|
||||||
foreach ($this->hostList as $host) {
|
|
||||||
/** @var Host $host */
|
|
||||||
$unhandled = (bool) $host->problem === true && (bool) $host->handled === false;
|
|
||||||
if ($unhandled) {
|
|
||||||
$unhandledObjects[] = $host;
|
|
||||||
$unhandledFilterExpressions[] = Filter::where('host', $host->getName());
|
|
||||||
}
|
|
||||||
if ((bool) $host->acknowledged === true) {
|
|
||||||
$acknowledgedObjects[] = $host;
|
|
||||||
}
|
|
||||||
if ((bool) $host->in_downtime === true) {
|
|
||||||
$objectsInDowntime[] = $host;
|
|
||||||
$downtimeFilterExpressions[] = Filter::where('downtime_host', $host->getName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$objectsInDowntime = $this->hostList->getObjectsInDowntime();
|
||||||
|
$downtimeFilterExpressions = array();
|
||||||
|
foreach ($objectsInDowntime as $object) {
|
||||||
|
$downtimeFilterExpressions[] = Filter::where('downtime_host', $object->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
$acknowledgedObjects = $this->hostList->getAcknowledgedObjects();
|
||||||
if (! empty($acknowledgedObjects)) {
|
if (! empty($acknowledgedObjects)) {
|
||||||
$removeAckForm = new RemoveAcknowledgementCommandForm();
|
$removeAckForm = new RemoveAcknowledgementCommandForm();
|
||||||
$removeAckForm
|
$removeAckForm
|
||||||
|
|
|
@ -127,32 +127,25 @@ class Monitoring_ServicesController extends Controller
|
||||||
'service_active_checks_enabled',
|
'service_active_checks_enabled',
|
||||||
'service_obsessing'*/
|
'service_obsessing'*/
|
||||||
));
|
));
|
||||||
$unhandledObjects = array();
|
$unhandledObjects = $this->serviceList->getUnhandledObjects();
|
||||||
$unhandledFilterExpressions = array();
|
$unhandledFilterExpressions = array();
|
||||||
$acknowledgedObjects = array();
|
foreach ($unhandledObjects as $service) {
|
||||||
$objectsInDowntime = array();
|
$unhandledFilterExpressions[] = Filter::matchAll(
|
||||||
$downtimeFilterExpressions = array();
|
Filter::where('host', $service->getHost()->getName()),
|
||||||
|
Filter::where('service', $service->getName())
|
||||||
foreach ($this->serviceList as $service) {
|
);
|
||||||
/** @var Service $service */
|
|
||||||
if ((bool) $service->problem === true && (bool) $service->handled === false) {
|
|
||||||
$unhandledObjects[] = $service;
|
|
||||||
$unhandledFilterExpressions[] = Filter::matchAll(
|
|
||||||
Filter::where('host', $service->getHost()->getName()),
|
|
||||||
Filter::where('service', $service->getName())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if ((bool) $service->acknowledged === true) {
|
|
||||||
$acknowledgedObjects[] = $service;
|
|
||||||
}
|
|
||||||
if ((bool) $service->in_downtime === true) {
|
|
||||||
$objectsInDowntime[] = $service;
|
|
||||||
$downtimeFilterExpressions[] = Filter::matchAll(
|
|
||||||
Filter::where('downtime_host', $service->getHost()->getName()),
|
|
||||||
Filter::where('downtime_service', $service->getName())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$objectsInDowntime = $this->serviceList->getObjectsInDowntime();
|
||||||
|
$downtimeFilterExpressions = array();
|
||||||
|
foreach ($objectsInDowntime as $service) {
|
||||||
|
$downtimeFilterExpressions[] = Filter::matchAll(
|
||||||
|
Filter::where('downtime_host', $service->getHost()->getName()),
|
||||||
|
Filter::where('downtime_service', $service->getName())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$acknowledgedObjects = $this->serviceList->getAcknowledgedObjects();
|
||||||
if (! empty($acknowledgedObjects)) {
|
if (! empty($acknowledgedObjects)) {
|
||||||
$removeAckForm = new RemoveAcknowledgementCommandForm();
|
$removeAckForm = new RemoveAcknowledgementCommandForm();
|
||||||
$removeAckForm
|
$removeAckForm
|
||||||
|
|
|
@ -86,6 +86,39 @@ abstract class ObjectList implements Countable, IteratorAggregate
|
||||||
return $this->backend->select()->from('comment')->applyFilter($this->filter);
|
return $this->backend->select()->from('comment')->applyFilter($this->filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAcknowledgedObjects()
|
||||||
|
{
|
||||||
|
$acknowledgedObjects = array();
|
||||||
|
foreach ($this as $object) {
|
||||||
|
if ((bool) $object->acknowledged === true) {
|
||||||
|
$acknowledgedObjects[] = $object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $acknowledgedObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getObjectsInDowntime()
|
||||||
|
{
|
||||||
|
$objectsInDowntime = array();
|
||||||
|
foreach ($this as $object) {
|
||||||
|
if ((bool) $object->in_downtime === true) {
|
||||||
|
$objectsInDowntime[] = $object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $objectsInDowntime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUnhandledObjects()
|
||||||
|
{
|
||||||
|
$unhandledObjects = array();
|
||||||
|
foreach ($this as $object) {
|
||||||
|
if ((bool) $object->problem === true && (bool) $object->handled === false) {
|
||||||
|
$unhandledObjects[] = $object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $unhandledObjects;
|
||||||
|
}
|
||||||
|
|
||||||
protected function prepareStateNames($prefix, array $names) {
|
protected function prepareStateNames($prefix, array $names) {
|
||||||
$new = array();
|
$new = array();
|
||||||
foreach ($names as $name) {
|
foreach ($names as $name) {
|
||||||
|
|
Loading…
Reference in New Issue