diff --git a/library/Icinga/Data/Db/TreeToSqlParser.php b/library/Icinga/Data/Db/TreeToSqlParser.php index 92b42c356..67d1f944c 100644 --- a/library/Icinga/Data/Db/TreeToSqlParser.php +++ b/library/Icinga/Data/Db/TreeToSqlParser.php @@ -75,7 +75,12 @@ class TreeToSqlParser if (count($right) > 1) { return 'IN'; } else { - return 'LIKE'; + foreach ($right as $r) { + if (strpos($r, '*') !== false) { + return 'LIKE'; + } + } + return '='; } case Node::OPERATOR_EQUALS_NOT: if (count($right) > 1) { @@ -171,7 +176,11 @@ class TreeToSqlParser if ($node->context === Node::CONTEXT_TIMESTRING && !is_numeric($value)) { $value = strtotime($value); } - $values[] = $this->query->getDatasource()->getConnection()->quote($value); + if (preg_match('/^\d+$/', $value)) { + $values[] = $value; + } else { + $values[] = $this->query->getDatasource()->getConnection()->quote($value); + } } $valueString = join(',', $values); diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php index c5b7e0e26..9cbea76e6 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php @@ -113,9 +113,9 @@ class ContactgroupQuery extends IdoQuery +-------------------------+-------------+------------+------------------------+ */ - $this->baseQuery->join( - // array('scg' => $this->prefix . 'service_contactgroups'), - array('scg' => $scgSub), + $this->baseQuery->distinct()->join( + array('scg' => $this->prefix . 'service_contactgroups'), + // array('scg' => $scgSub), 'scg.contactgroup_object_id = cg.contactgroup_object_id', array() )->join( diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CustomvarQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CustomvarQuery.php index d4e516dc2..6f0810a4a 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CustomvarQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CustomvarQuery.php @@ -14,11 +14,23 @@ class CustomvarQuery extends IdoQuery 'service_host_name' => 'cvo.name1 COLLATE latin1_general_ci', 'service_description' => 'cvo.name2 COLLATE latin1_general_ci', 'contact_name' => 'cvo.name1 COLLATE latin1_general_ci', - 'object_type' => "CASE cvo.objecttype_id WHEN 1 THEN 'host' WHEN 2 THEN 'service' WHEN 10 THEN 'contact' ELSE 'invalid' END" + 'object_type' => "CASE cvo.objecttype_id WHEN 1 THEN 'host' WHEN 2 THEN 'service' WHEN 10 THEN 'contact' ELSE 'invalid' END", + 'object_type_id' => 'cvo.objecttype_id' // 'object_type' => "CASE cvo.objecttype_id WHEN 1 THEN 'host' WHEN 2 THEN 'service' WHEN 3 THEN 'hostgroup' WHEN 4 THEN 'servicegroup' WHEN 5 THEN 'hostescalation' WHEN 6 THEN 'serviceescalation' WHEN 7 THEN 'hostdependency' WHEN 8 THEN 'servicedependency' WHEN 9 THEN 'timeperiod' WHEN 10 THEN 'contact' WHEN 11 THEN 'contactgroup' WHEN 12 THEN 'command' ELSE 'other' END" ), ); + public function where($expression, $parameters = null) + { + $types = array('host' => 1, 'service' => 2, 'contact' => 10); + if ($expression === 'object_type') { + parent::where('object_type_id', $types[$parameters]); + } else { + parent::where($expression, $parameters); + } + return $this; + } + protected function joinBaseTables() { $this->baseQuery = $this->db->select()->from(