From 4731faea89cbed42e6d5a73ee5e428892f7f59f5 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 11 Jul 2013 13:03:14 +0200 Subject: [PATCH] livestatus: add timeperiods table refs #4372 --- components/livestatus/Makefile.am | 2 + components/livestatus/livestatus.vcxproj | 2 + .../livestatus/livestatus.vcxproj.filters | 6 ++ components/livestatus/table.cpp | 3 + components/livestatus/timeperiodstable.cpp | 66 +++++++++++++++++++ components/livestatus/timeperiodstable.h | 54 +++++++++++++++ 6 files changed, 133 insertions(+) create mode 100644 components/livestatus/timeperiodstable.cpp create mode 100644 components/livestatus/timeperiodstable.h diff --git a/components/livestatus/Makefile.am b/components/livestatus/Makefile.am index 2512fc5ec..67c1ed41d 100644 --- a/components/livestatus/Makefile.am +++ b/components/livestatus/Makefile.am @@ -51,6 +51,8 @@ liblivestatus_la_SOURCES = \ servicestable.h \ statustable.cpp \ statustable.h \ + timeperiodstable.cpp \ + timeperiodstable.h \ table.cpp \ table.h diff --git a/components/livestatus/livestatus.vcxproj b/components/livestatus/livestatus.vcxproj index 81ebdfc55..2c9440eb5 100644 --- a/components/livestatus/livestatus.vcxproj +++ b/components/livestatus/livestatus.vcxproj @@ -39,6 +39,7 @@ + @@ -63,6 +64,7 @@ + diff --git a/components/livestatus/livestatus.vcxproj.filters b/components/livestatus/livestatus.vcxproj.filters index 4245d9d31..68f87a242 100644 --- a/components/livestatus/livestatus.vcxproj.filters +++ b/components/livestatus/livestatus.vcxproj.filters @@ -24,6 +24,9 @@ Headerdateien + + Headerdateien + Headerdateien @@ -89,6 +92,9 @@ Quelldateien + + Quelldateien + Quelldateien diff --git a/components/livestatus/table.cpp b/components/livestatus/table.cpp index 2f78272e6..dfb5ac652 100644 --- a/components/livestatus/table.cpp +++ b/components/livestatus/table.cpp @@ -28,6 +28,7 @@ #include "livestatus/commandstable.h" #include "livestatus/commentstable.h" #include "livestatus/downtimestable.h" +#include "livestatus/timeperiodstable.h" #include "livestatus/logtable.h" #include "livestatus/filter.h" #include "base/array.h" @@ -65,6 +66,8 @@ Table::Ptr Table::GetByName(const String& name) return boost::make_shared(); else if (name == "downtimes") return boost::make_shared(); + else if (name == "timeperiods") + return boost::make_shared(); else if (name == "log") return boost::make_shared(); diff --git a/components/livestatus/timeperiodstable.cpp b/components/livestatus/timeperiodstable.cpp new file mode 100644 index 000000000..48890e0fc --- /dev/null +++ b/components/livestatus/timeperiodstable.cpp @@ -0,0 +1,66 @@ +/****************************************************************************** + * 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/timeperiodstable.h" +#include "icinga/icingaapplication.h" +#include "icinga/timeperiod.h" +#include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/convert.h" +#include +#include + +using namespace icinga; +using namespace livestatus; + +TimePeriodsTable::TimePeriodsTable(void) +{ + AddColumns(this); +} + +void TimePeriodsTable::AddColumns(Table *table, const String& prefix, + const Column::ObjectAccessor& objectAccessor) +{ + table->AddColumn(prefix + "name", Column(&TimePeriodsTable::NameAccessor, objectAccessor)); + table->AddColumn(prefix + "alias", Column(&TimePeriodsTable::AliasAccessor, objectAccessor)); +} + +String TimePeriodsTable::GetName(void) const +{ + return "timeperiod"; +} + +void TimePeriodsTable::FetchRows(const AddRowFunction& addRowFn) +{ + BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("TimePeriod")) { + addRowFn(object); + } +} + +Value TimePeriodsTable::NameAccessor(const Value& row) +{ + return static_cast(row)->GetName(); +} + +Value TimePeriodsTable::AliasAccessor(const Value& row) +{ + /* TODO GetDisplayName() ? */ + return static_cast(row)->GetName(); +} + diff --git a/components/livestatus/timeperiodstable.h b/components/livestatus/timeperiodstable.h new file mode 100644 index 000000000..2595f5c4c --- /dev/null +++ b/components/livestatus/timeperiodstable.h @@ -0,0 +1,54 @@ +/****************************************************************************** + * 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 TIMEPERIODSTABLE_H +#define TIMEPERIODSTABLE_H + +#include "livestatus/table.h" + +using namespace icinga; + +namespace livestatus +{ + +/** + * @ingroup livestatus + */ +class TimePeriodsTable : public Table +{ +public: + DECLARE_PTR_TYPEDEFS(TimePeriodsTable); + + TimePeriodsTable(void); + + static void AddColumns(Table *table, const String& prefix = String(), + const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor()); + + virtual String GetName(void) const; + +protected: + virtual void FetchRows(const AddRowFunction& addRowFn); + + static Value NameAccessor(const Value& row); + static Value AliasAccessor(const Value& row); +}; + +} + +#endif /* TIMEPERIODSTABLE_H */ -- 2.40.0