mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-04-08 17:15:08 +02:00
CommandHandler now uses Status/HostView, fix sql IN-Query bug
This commit is contained in:
parent
1aa4c0bb98
commit
dc5182d4bf
@ -113,10 +113,13 @@ class TreeToSqlParser
|
||||
$queryString = '';
|
||||
$leftQuery = $this->nodeToSqlQuery($node->left);
|
||||
$rightQuery = $this->nodeToSqlQuery($node->right);
|
||||
|
||||
if ($leftQuery != '') {
|
||||
$queryString .= $leftQuery . ' ';
|
||||
}
|
||||
|
||||
if ($rightQuery != '') {
|
||||
|
||||
$queryString .= (($queryString !== '') ? $node->type . ' ' : ' ') . $rightQuery;
|
||||
}
|
||||
return $queryString;
|
||||
@ -133,6 +136,7 @@ class TreeToSqlParser
|
||||
if (!$this->query->isValidFilterTarget($node->left) && $this->query->getMappedField($node->left)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->query->requireColumn($node->left);
|
||||
$queryString = '(' . $this->query->getMappedField($node->left) . ')';
|
||||
|
||||
@ -172,7 +176,7 @@ class TreeToSqlParser
|
||||
$valueString = join(',', $values);
|
||||
|
||||
if (count($values) > 1) {
|
||||
return '( '. $valueString . ')';
|
||||
return $query . '( '. $valueString . ')';
|
||||
}
|
||||
return $query . $valueString;
|
||||
}
|
||||
@ -190,6 +194,7 @@ class TreeToSqlParser
|
||||
}
|
||||
$tree->root = $tree->normalizeTree($tree->root);
|
||||
$sql = $this->nodeToSqlQuery($tree->root);
|
||||
|
||||
if ($this->filtersAggregate()) {
|
||||
$baseQuery->having($sql);
|
||||
} else {
|
||||
|
@ -175,45 +175,21 @@ class Monitoring_CommandController extends ActionController
|
||||
if (!$hostname && !$servicename) {
|
||||
throw new MissingParameterException("No target given for this command");
|
||||
}
|
||||
|
||||
if ($hostname) {
|
||||
$filter["host_name"] = $hostname;
|
||||
$view = \Icinga\Module\Monitoring\DataView\HostStatus::fromRequest($this->getRequest());
|
||||
}
|
||||
if ($servicename && !$hostOnly) {
|
||||
$filter["service_description"] = $servicename;
|
||||
$fields[] = "service_description";
|
||||
$fields[] = "service_state";
|
||||
$view = \Icinga\Module\Monitoring\DataView\ServiceStatus::fromRequest($this->getRequest());
|
||||
}
|
||||
$query = $view->getQuery()->from("status", $fields);
|
||||
return $data = $query->fetchAll();
|
||||
|
||||
// Implemented manuall search because api is not ready.
|
||||
// @TODO Implement this using the database api #4663 (mh)
|
||||
|
||||
$query = Backend::createBackend($this->_getParam('backend'))->select()->from("status", $fields);
|
||||
$data = $query->fetchAll();
|
||||
|
||||
$out = array();
|
||||
|
||||
foreach ($data as $o) {
|
||||
if ($o->host_name === $hostname) {
|
||||
if (!$servicename) {
|
||||
$out[] = (object) array(
|
||||
"host_name" => $o->host_name
|
||||
);
|
||||
} elseif ($servicename && strtolower($o->service_description) === strtolower($servicename)) {
|
||||
$out[] = (object) array(
|
||||
"host_name" => $o->host_name,
|
||||
"service_description" => $o->service_description
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $out;
|
||||
} catch (\Exception $e) {
|
||||
Logger::error(
|
||||
"CommandController: SQL Query '%s' failed (message %s) ",
|
||||
$query ? (string) $query->getQuery()->dump() : '--', $e->getMessage()
|
||||
$query ? (string) $query->dump() : '--', $e->getMessage()
|
||||
);
|
||||
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user