livestatus: bugfixes.

This commit is contained in:
Michael Friedrich 2013-07-12 10:54:57 +02:00
parent 904830ee3e
commit 26cc0ecb02
1 changed files with 45 additions and 38 deletions

View File

@ -72,7 +72,10 @@ Query::Query(const std::vector<String>& lines)
size_t col_index = line.FindFirstOf(":"); size_t col_index = line.FindFirstOf(":");
String header = line.SubStr(0, col_index); String header = line.SubStr(0, col_index);
String params = line.SubStr(col_index + 2); String params;
if (line.GetLength() > col_index + 2)
params = line.SubStr(col_index + 2);
if (header == "ResponseHeader") if (header == "ResponseHeader")
m_ResponseHeader = params; m_ResponseHeader = params;
@ -83,67 +86,64 @@ Query::Query(const std::vector<String>& lines)
else if (header == "ColumnHeaders") else if (header == "ColumnHeaders")
m_ColumnHeaders = (params == "on"); m_ColumnHeaders = (params == "on");
else if (header == "Filter") { else if (header == "Filter") {
Filter::Ptr filter = ParseFilter(params); Filter::Ptr filter = ParseFilter(params);
if (!filter) { if (!filter) {
m_Verb = "ERROR"; m_Verb = "ERROR";
m_ErrorCode = 452; m_ErrorCode = 452;
m_ErrorMessage = "Invalid filter specification."; m_ErrorMessage = "Invalid filter specification: " + line;
return; return;
} }
std::deque<Filter::Ptr>& deq = filters; filters.push_back(filter);
deq.push_back(filter); } else if (header == "Stats") {
}
else if (header == "Stats") {
std::vector<String> tokens; std::vector<String> tokens;
boost::algorithm::split(tokens, params, boost::is_any_of(" ")); boost::algorithm::split(tokens, params, boost::is_any_of(" "));
if (tokens.size() < 2) {
m_Verb = "ERROR";
m_ErrorCode = 452;
m_ErrorMessage = "Missing aggregator column name: " + line;
return;
}
String aggregate_arg = tokens[0]; String aggregate_arg = tokens[0];
String aggregate_attr = tokens[1]; String aggregate_attr = tokens[1];
if (aggregate_arg == "sum") { Aggregator::Ptr aggregator;
Aggregator::Ptr aggregator = boost::make_shared<SumAggregator>(aggregate_attr); Filter::Ptr filter;
aggregators.push_back(aggregator);
}
else if(aggregate_arg == "min") {
/* TODO */
}
else if (aggregate_arg == "max") {
/* TODO */
}
else if (aggregate_arg == "avg") {
/* TODO */
}
else if (aggregate_arg == "std") {
/* TODO */
}
else if (aggregate_arg == "suminv") {
/* TODO */
}
else if (aggregate_arg == "avginv") {
/* TODO */
if (aggregate_arg == "sum") {
aggregator = boost::make_shared<SumAggregator>(aggregate_attr);
} else if (aggregate_arg == "min") {
/* TODO */
} else if (aggregate_arg == "max") {
/* TODO */
} else if (aggregate_arg == "avg") {
/* TODO */
} else if (aggregate_arg == "std") {
/* TODO */
} else if (aggregate_arg == "suminv") {
/* TODO */
} else if (aggregate_arg == "avginv") {
/* TODO */
} else { } else {
Filter::Ptr filter = ParseFilter(params); filter = ParseFilter(params);
if (!filter) { if (!filter) {
m_Verb = "ERROR"; m_Verb = "ERROR";
m_ErrorCode = 452; m_ErrorCode = 452;
m_ErrorMessage = "Invalid filter specification."; m_ErrorMessage = "Invalid filter specification: " + line;
return; return;
} }
std::deque<Filter::Ptr>& deq = stats; aggregator = boost::make_shared<CountAggregator>();
deq.push_back(filter);
Aggregator::Ptr aggregator = boost::make_shared<CountAggregator>();
aggregator->SetFilter(filter);
aggregators.push_back(aggregator);
} }
aggregator->SetFilter(filter);
aggregators.push_back(aggregator);
stats.push_back(filter);
} else if (header == "Or" || header == "And") { } else if (header == "Or" || header == "And") {
std::deque<Filter::Ptr>& deq = (header == "Or" || header == "And") ? filters : stats; std::deque<Filter::Ptr>& deq = (header == "Or" || header == "And") ? filters : stats;
@ -179,7 +179,14 @@ Query::Query(const std::vector<String>& lines)
} }
Filter::Ptr filter = deq.back(); Filter::Ptr filter = deq.back();
filters.pop_back(); deq.pop_back();
if (!filter) {
m_Verb = "ERROR";
m_ErrorCode = 451;
m_ErrorMessage = "Negate/StatsNegate used, however last stats doesn't have a filter";
return;
}
deq.push_back(boost::make_shared<NegateFilter>(filter)); deq.push_back(boost::make_shared<NegateFilter>(filter));