]> granicus.if.org Git - icinga2/commitdiff
livestatus: add timeperiods table
authorMichael Friedrich <michael.friedrich@netways.de>
Thu, 11 Jul 2013 11:03:14 +0000 (13:03 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Thu, 11 Jul 2013 11:03:14 +0000 (13:03 +0200)
refs #4372

components/livestatus/Makefile.am
components/livestatus/livestatus.vcxproj
components/livestatus/livestatus.vcxproj.filters
components/livestatus/table.cpp
components/livestatus/timeperiodstable.cpp [new file with mode: 0644]
components/livestatus/timeperiodstable.h [new file with mode: 0644]

index 2512fc5ecb6b22663a1af06c47d03d46497dd04b..67c1ed41d1bd62f002885b144c6a45f4cf1439fa 100644 (file)
@@ -51,6 +51,8 @@ liblivestatus_la_SOURCES = \
        servicestable.h \
        statustable.cpp \
        statustable.h \
+       timeperiodstable.cpp \
+       timeperiodstable.h \
        table.cpp \
        table.h
 
index 81ebdfc55475e198e4307b0270984c4c29778045..2c9440eb510d31c43c9e8a9f19dd59a9d78b9bf7 100644 (file)
@@ -39,6 +39,7 @@
     <ClInclude Include="servicegroupsstable.h" />
     <ClInclude Include="servicestable.h" />
     <ClInclude Include="statustable.h" />
+    <ClInclude Include="timeperiodstable.h" />
     <ClInclude Include="logtable.h" />
     <ClInclude Include="table.h" />
   </ItemGroup>
@@ -63,6 +64,7 @@
     <ClCompile Include="servicegroupstable.cpp" />
     <ClCompile Include="servicestable.cpp" />
     <ClCompile Include="statustable.cpp" />
+    <ClCompile Include="timeperiodstable.cpp" />
     <ClCompile Include="logtable.cpp" />
     <ClCompile Include="table.cpp" />
   </ItemGroup>
index 4245d9d316d9f124107d5283e8901b14eb627fe5..68f87a242be2ceca039ce056440afc2c7ed2c89c 100644 (file)
@@ -24,6 +24,9 @@
     <ClInclude Include="statustable.h">
       <Filter>Headerdateien</Filter>
     </ClInclude>
+    <ClInclude Include="timeperiodstable.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
     <ClInclude Include="logtable.h">
       <Filter>Headerdateien</Filter>
     </ClInclude>
@@ -89,6 +92,9 @@
     <ClCompile Include="statustable.cpp">
       <Filter>Quelldateien</Filter>
     </ClCompile>
+    <ClCompile Include="timeperiodstable.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
     <ClCompile Include="logtable.cpp">
       <Filter>Quelldateien</Filter>
     </ClCompile>
index 2f78272e6a3f0c4f6558bc52223170fb671a52f9..dfb5ac652191093f66f4c653d39edcc1dd029e34 100644 (file)
@@ -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<CommentsTable>();
        else if (name == "downtimes")
                return boost::make_shared<DowntimesTable>();
+       else if (name == "timeperiods")
+               return boost::make_shared<TimePeriodsTable>();
        else if (name == "log")
                return boost::make_shared<LogTable>();
 
diff --git a/components/livestatus/timeperiodstable.cpp b/components/livestatus/timeperiodstable.cpp
new file mode 100644 (file)
index 0000000..48890e0
--- /dev/null
@@ -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 <boost/foreach.hpp>
+#include <boost/algorithm/string/replace.hpp>
+
+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<TimePeriod::Ptr>(row)->GetName();
+}
+
+Value TimePeriodsTable::AliasAccessor(const Value& row)
+{
+       /* TODO GetDisplayName() ? */
+       return static_cast<TimePeriod::Ptr>(row)->GetName();
+}
+
diff --git a/components/livestatus/timeperiodstable.h b/components/livestatus/timeperiodstable.h
new file mode 100644 (file)
index 0000000..2595f5c
--- /dev/null
@@ -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 */