Skip to content

Commit

Permalink
monitoring/MonitoredObject': Use host_name' and `service_descriptio…
Browse files Browse the repository at this point in the history
…n' for filtering
  • Loading branch information
lippserd committed Sep 16, 2014
1 parent 44c4ec7 commit c04768e
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions modules/monitoring/library/Monitoring/Object/MonitoredObject.php
Expand Up @@ -162,6 +162,19 @@ public function assertOneOf(array $oneOf)
return true;
}

/**
* Set the object's properties
*
* @param object $properties
*
* @return $this
*/
public function setProperties($properties)
{
$this->properties = (object) $properties;
return $this;
}

/**
* Fetch the object's comments
*
Expand All @@ -178,9 +191,9 @@ public function fetchComments()
))
->where('comment_type', array('comment', 'ack'))
->where('comment_objecttype', $this->type)
->where('comment_host', $this->host);
->where('comment_host', $this->host_name);
if ($this->type === self::TYPE_SERVICE) {
$comments->where('comment_service', $this->service);
$comments->where('comment_service', $this->service_description);
}
$this->comments = $comments->getQuery()->fetchAll();
return $this;
Expand Down Expand Up @@ -210,11 +223,11 @@ public function fetchDowntimes()
'service' => 'downtime_service'
))
->where('downtime_objecttype', $this->type)
->where('downtime_host', $this->host)
->where('downtime_host', $this->host_name)
->order('downtime_is_in_effect', 'DESC')
->order('downtime_scheduled_start', 'ASC');
if ($this->type === self::TYPE_SERVICE) {
$downtimes->where('downtime_service', $this->service);
$downtimes->where('downtime_service', $this->service_description);
}
$this->downtimes = $downtimes->getQuery()->fetchAll();
return $this;
Expand Down Expand Up @@ -265,9 +278,9 @@ public function fetchCustomvars()
'varvalue'
))
->where('object_type', $this->type)
->where('host_name', $this->host);
->where('host_name', $this->host_name);
if ($this->type === self::TYPE_SERVICE) {
$query->where('service_description', $this->service);
$query->where('service_description', $this->service_description);
}

$this->customvars = array();
Expand Down Expand Up @@ -299,7 +312,7 @@ public function fetchContacts()
))
->where('host_name', $this->host_name);
if ($this->type === self::TYPE_SERVICE) {
$contacts->where('service_description', $this->service);
$contacts->where('service_description', $this->service_description);
}
$this->contacts = $contacts->getQuery()->fetchAll();
return $this;
Expand All @@ -316,8 +329,8 @@ public function fetchServicegroups()
'servicegroup_name',
'servicegroup_alias'
))
->where('service_host_name', $this->host)
->where('service_description', $this->service);
->where('service_host_name', $this->host_name)
->where('service_description', $this->service_description);
$this->servicegroups = $serviceGroups->getQuery()->fetchPairs();
return $this;
}
Expand All @@ -333,9 +346,9 @@ public function fetchContactgroups()
'contactgroup_name',
'contactgroup_alias'
))
->where('host_name', $this->host);
->where('host_name', $this->host_name);
if ($this->type === self::TYPE_SERVICE) {
$contactsGroups->where('service_description', $this->service);
$contactsGroups->where('service_description', $this->service_description);
}
$this->contactgroups = $contactsGroups->getQuery()->fetchAll();
return $this;
Expand All @@ -360,9 +373,9 @@ public function fetchEventhistory()
'type'
))
->order('timestamp', 'DESC')
->where('host_name', $this->host);
->where('host_name', $this->host_name);
if ($this->type === self::TYPE_SERVICE) {
$eventHistory->where('service_description', $this->service);
$eventHistory->where('service_description', $this->service_description);
}
$this->eventhistory = $eventHistory->getQuery();
return $this;
Expand Down Expand Up @@ -398,10 +411,12 @@ public function __get($name)
$this->$fetchMethod();
return $this->$name;
}
if (substr($name, 0, strlen($this->prefix)) === $this->prefix) {
throw new InvalidPropertyException('Can\'t access property \'%s\'. Property does not exist.', $name);
if (substr($name, 0, strlen($this->prefix)) !== $this->prefix) {
$prefixedName = $this->prefix . strtolower($name);
if (property_exists($this->properties, $prefixedName)) {
return $this->properties->$prefixedName;
}
}
$prefixedName = $this->prefix . strtolower($name);
return $this->$prefixedName;
throw new InvalidPropertyException('Can\'t access property \'%s\'. Property does not exist.', $name);
}
}

0 comments on commit c04768e

Please sign in to comment.