servicestable.h \
statustable.cpp \
statustable.h \
+ sumaggregator.cpp \
+ sumaggregator.h \
timeperiodstable.cpp \
timeperiodstable.h \
table.cpp \
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
+ <ClInclude Include="aggregator.h" />
+ <ClInclude Include="countaggregator.h" />
+ <ClInclude Include="sumaggregator.h" />
<ClInclude Include="andfilter.h" />
<ClInclude Include="attributefilter.h" />
<ClInclude Include="column.h" />
<ClInclude Include="table.h" />
</ItemGroup>
<ItemGroup>
+ <ClCompile Include="aggregator.cpp" />
+ <ClCompile Include="countaggregator.cpp" />
+ <ClCompile Include="sumaggregator.cpp" />
<ClCompile Include="andfilter.cpp" />
<ClCompile Include="attributefilter.cpp" />
<ClCompile Include="column.cpp" />
<ClInclude Include="orfilter.h">
<Filter>Headerdateien</Filter>
</ClInclude>
+ <ClInclude Include="aggregator.h">
+ <Filter>Headerdateien</Filter>
+ </ClInclude>
+ <ClInclude Include="countaggregator.h">
+ <Filter>Headerdateien</Filter>
+ </ClInclude>
+ <ClInclude Include="sumaggregator.h">
+ <Filter>Headerdateien</Filter>
+ </ClInclude>
<ClInclude Include="andfilter.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClCompile Include="andfilter.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
+ <ClCompile Include="aggregator.cpp">
+ <Filter>Quelldateien</Filter>
+ </ClCompile>
+ <ClCompile Include="countaggregator.cpp">
+ <Filter>Quelldateien</Filter>
+ </ClCompile>
+ <ClCompile Include="sumaggregator.cpp">
+ <Filter>Quelldateien</Filter>
+ </ClCompile>
<ClCompile Include="attributefilter.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
#include "livestatus/query.h"
#include "livestatus/countaggregator.h"
+#include "livestatus/sumaggregator.h"
#include "livestatus/attributefilter.h"
#include "livestatus/negatefilter.h"
#include "livestatus/orfilter.h"
boost::algorithm::split(m_Columns, params, boost::is_any_of(" "));
else if (header == "ColumnHeaders")
m_ColumnHeaders = (params == "on");
- else if (header == "Filter" || header == "Stats") {
+ else if (header == "Filter") {
Filter::Ptr filter = ParseFilter(params);
-
+
if (!filter) {
m_Verb = "ERROR";
m_ErrorCode = 452;
return;
}
- std::deque<Filter::Ptr>& deq = (header == "Filter") ? filters : stats;
+ std::deque<Filter::Ptr>& deq = filters;
deq.push_back(filter);
-
- if (deq == stats) {
+ }
+ else if (header == "Stats") {
+
+ std::vector<String> tokens;
+ boost::algorithm::split(tokens, params, boost::is_any_of(" "));
+
+ String aggregate_arg = tokens[0];
+ String aggregate_attr = tokens[1];
+
+ if (aggregate_arg == "sum") {
+ Aggregator::Ptr aggregator = boost::make_shared<SumAggregator>(aggregate_attr);
+ 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 */
+
+ } else {
+ Filter::Ptr filter = ParseFilter(params);
+
+ if (!filter) {
+ m_Verb = "ERROR";
+ m_ErrorCode = 452;
+ m_ErrorMessage = "Invalid filter specification.";
+ return;
+ }
+
+ std::deque<Filter::Ptr>& deq = stats;
+ deq.push_back(filter);
+
Aggregator::Ptr aggregator = boost::make_shared<CountAggregator>();
aggregator->SetFilter(filter);
aggregators.push_back(aggregator);
}
+
} else if (header == "Or" || header == "And") {
std::deque<Filter::Ptr>& deq = (header == "Or" || header == "And") ? filters : stats;
filters.pop_back();
deq.push_back(boost::make_shared<NegateFilter>(filter));
-
+
if (deq == stats) {
Aggregator::Ptr aggregator = aggregators.back();
aggregator->SetFilter(filter);
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#include "livestatus/sumaggregator.h"
+
+using namespace livestatus;
+
+SumAggregator::SumAggregator(const String& attr)
+ : m_Sum(0)
+{
+ m_SumAttr = attr;
+}
+
+void SumAggregator::Apply(const Table::Ptr& table, const Value& row)
+{
+ Column column = table->GetColumn(m_SumAttr);
+
+ Value value = column.ExtractValue(row);
+
+ m_Sum += value;
+}
+
+double SumAggregator::GetResult(void) const
+{
+ return m_Sum;
+}
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#ifndef SUMAGGREGATOR_H
+#define SUMAGGREGATOR_H
+
+#include "livestatus/table.h"
+#include "livestatus/aggregator.h"
+
+namespace livestatus
+{
+
+/**
+ * @ingroup livestatus
+ */
+class SumAggregator : public Aggregator
+{
+public:
+ DECLARE_PTR_TYPEDEFS(SumAggregator);
+
+ SumAggregator(const String& attr);
+
+ virtual void Apply(const Table::Ptr& table, const Value& row);
+ virtual double GetResult(void) const;
+
+private:
+ double m_Sum;
+ String m_SumAttr;
+};
+
+}
+
+#endif /* SUMAGGREGATOR_H */