]> granicus.if.org Git - icinga2/commitdiff
livestatus: add host and service group getters
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 9 Jul 2013 16:33:27 +0000 (18:33 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 9 Jul 2013 16:33:27 +0000 (18:33 +0200)
refs #4372

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

index 2bfaa58d9e61a205bc973db4d91adeef6b15ff92..2512fc5ecb6b22663a1af06c47d03d46497dd04b 100644 (file)
@@ -32,6 +32,8 @@ liblivestatus_la_SOURCES = \
        downtimestable.h \
        filter.cpp \
        filter.h \
+       hostgroupstable.cpp \
+       hostgroupstable.h \
        hoststable.cpp \
        hoststable.h \
        livestatus-type.cpp \
@@ -43,6 +45,8 @@ liblivestatus_la_SOURCES = \
        orfilter.h \
        query.cpp \
        query.h \
+       servicegroupstable.cpp \
+       servicegroupstable.h \
        servicestable.cpp \
        servicestable.h \
        statustable.cpp \
diff --git a/components/livestatus/hostgroupstable.cpp b/components/livestatus/hostgroupstable.cpp
new file mode 100644 (file)
index 0000000..8493111
--- /dev/null
@@ -0,0 +1,72 @@
+/******************************************************************************
+ * 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/hostgroupstable.h"
+#include "icinga/hostgroup.h"
+#include "base/dynamictype.h"
+#include <boost/foreach.hpp>
+
+using namespace icinga;
+using namespace livestatus;
+
+HostGroupsTable::HostGroupsTable(void)
+{
+       AddColumns(this);
+}
+
+void HostGroupsTable::AddColumns(Table *table, const String& prefix,
+    const Column::ObjectAccessor& objectAccessor)
+{
+       table->AddColumn(prefix + "name", Column(&HostGroupsTable::NameAccessor, objectAccessor));
+       table->AddColumn(prefix + "alias", Column(&HostGroupsTable::AliasAccessor, objectAccessor));
+       table->AddColumn(prefix + "members", Column(&HostGroupsTable::MembersAccessor, objectAccessor));
+}
+
+String HostGroupsTable::GetName(void) const
+{
+       return "hostgroups";
+}
+
+void HostGroupsTable::FetchRows(const AddRowFunction& addRowFn)
+{
+       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("HostGroup")) {
+               addRowFn(object);
+       }
+}
+
+Value HostGroupsTable::NameAccessor(const Object::Ptr& object)
+{
+       return static_pointer_cast<HostGroup>(object)->GetName();
+}
+
+Value HostGroupsTable::AliasAccessor(const Object::Ptr& object)
+{
+       return static_pointer_cast<HostGroup>(object)->GetName();
+}
+
+Value HostGroupsTable::MembersAccessor(const Object::Ptr& object)
+{
+       Array::Ptr members = boost::make_shared<Array>();
+
+       BOOST_FOREACH(const Host::Ptr& host, static_pointer_cast<HostGroup>(object)->GetMembers()) {
+               members->Add(host->GetName());
+       }
+
+       return members;
+}
diff --git a/components/livestatus/hostgroupstable.h b/components/livestatus/hostgroupstable.h
new file mode 100644 (file)
index 0000000..6280574
--- /dev/null
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * 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 HOSTGROUPSTABLE_H
+#define HOSTGROUPSTABLE_H
+
+#include "livestatus/table.h"
+
+using namespace icinga;
+
+namespace livestatus
+{
+
+/**
+ * @ingroup livestatus
+ */
+class HostGroupsTable : public Table
+{
+public:
+       DECLARE_PTR_TYPEDEFS(HostGroupsTable);
+
+       HostGroupsTable(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 Object::Ptr& object);
+       static Value AliasAccessor(const Object::Ptr& object);
+       static Value MembersAccessor(const Object::Ptr& object);
+};
+
+}
+
+#endif /* HOSTGROUPSTABLE_H */
index f6e66b707fbefc89420745ce63875a8d27745b6b..81ebdfc55475e198e4307b0270984c4c29778045 100644 (file)
     <ClInclude Include="contactstable.h" />
     <ClInclude Include="downtimestable.h" />
     <ClInclude Include="filter.h" />
+    <ClInclude Include="hostgroupstable.h" />
     <ClInclude Include="hoststable.h" />
     <ClInclude Include="i2-livestatus.h" />
     <ClInclude Include="component.h" />
     <ClInclude Include="negatefilter.h" />
     <ClInclude Include="orfilter.h" />
     <ClInclude Include="query.h" />
+    <ClInclude Include="servicegroupsstable.h" />
     <ClInclude Include="servicestable.h" />
     <ClInclude Include="statustable.h" />
     <ClInclude Include="logtable.h" />
     <ClCompile Include="contactstable.cpp" />
     <ClCompile Include="downtimestable.cpp" />
     <ClCompile Include="filter.cpp" />
+    <ClCompile Include="hostgroupstable.cpp" />
     <ClCompile Include="hoststable.cpp" />
     <ClCompile Include="livestatus-type.cpp" />
     <ClCompile Include="negatefilter.cpp" />
     <ClCompile Include="orfilter.cpp" />
     <ClCompile Include="query.cpp" />
+    <ClCompile Include="servicegroupstable.cpp" />
     <ClCompile Include="servicestable.cpp" />
     <ClCompile Include="statustable.cpp" />
     <ClCompile Include="logtable.cpp" />
index 38b49902c99a200f66270c91c04b29abe6f52a3e..4245d9d316d9f124107d5283e8901b14eb627fe5 100644 (file)
     <ClInclude Include="combinerfilter.h">
       <Filter>Headerdateien</Filter>
     </ClInclude>
+    <ClInclude Include="hostgroupstable.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
     <ClInclude Include="hoststable.h">
       <Filter>Headerdateien</Filter>
     </ClInclude>
     <ClInclude Include="column.h">
       <Filter>Headerdateien</Filter>
     </ClInclude>
+    <ClInclude Include="servicegroupstable.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
     <ClInclude Include="servicestable.h">
       <Filter>Headerdateien</Filter>
     </ClInclude>
     <ClCompile Include="combinerfilter.cpp">
       <Filter>Quelldateien</Filter>
     </ClCompile>
+    <ClCompile Include="hostgroupstable.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
     <ClCompile Include="hoststable.cpp">
       <Filter>Quelldateien</Filter>
     </ClCompile>
     <ClCompile Include="column.cpp">
       <Filter>Quelldateien</Filter>
     </ClCompile>
+    <ClCompile Include="servicegroupstable.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
     <ClCompile Include="servicestable.cpp">
       <Filter>Quelldateien</Filter>
     </ClCompile>
diff --git a/components/livestatus/servicegroupstable.cpp b/components/livestatus/servicegroupstable.cpp
new file mode 100644 (file)
index 0000000..305a6dc
--- /dev/null
@@ -0,0 +1,72 @@
+/******************************************************************************
+ * 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/servicegroupstable.h"
+#include "icinga/servicegroup.h"
+#include "base/dynamictype.h"
+#include <boost/foreach.hpp>
+
+using namespace icinga;
+using namespace livestatus;
+
+ServiceGroupsTable::ServiceGroupsTable(void)
+{
+       AddColumns(this);
+}
+
+void ServiceGroupsTable::AddColumns(Table *table, const String& prefix,
+    const Column::ObjectAccessor& objectAccessor)
+{
+       table->AddColumn(prefix + "name", Column(&ServiceGroupsTable::NameAccessor, objectAccessor));
+       table->AddColumn(prefix + "alias", Column(&ServiceGroupsTable::AliasAccessor, objectAccessor));
+       table->AddColumn(prefix + "members", Column(&ServiceGroupsTable::MembersAccessor, objectAccessor));
+}
+
+String ServiceGroupsTable::GetName(void) const
+{
+       return "servicegroups";
+}
+
+void ServiceGroupsTable::FetchRows(const AddRowFunction& addRowFn)
+{
+       BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("UserGroup")) {
+               addRowFn(object);
+       }
+}
+
+Value ServiceGroupsTable::NameAccessor(const Object::Ptr& object)
+{
+       return static_pointer_cast<ServiceGroup>(object)->GetName();
+}
+
+Value ServiceGroupsTable::AliasAccessor(const Object::Ptr& object)
+{
+       return static_pointer_cast<ServiceGroup>(object)->GetName();
+}
+
+Value ServiceGroupsTable::MembersAccessor(const Object::Ptr& object)
+{
+       Array::Ptr members = boost::make_shared<Array>();
+
+       BOOST_FOREACH(const Service::Ptr& service, static_pointer_cast<ServiceGroup>(object)->GetMembers()) {
+               members->Add(service->GetName());
+       }
+
+       return members;
+}
diff --git a/components/livestatus/servicegroupstable.h b/components/livestatus/servicegroupstable.h
new file mode 100644 (file)
index 0000000..4df140a
--- /dev/null
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * 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 SERVICEGROUPSTABLE_H
+#define SERVICEGROUPSTABLE_H
+
+#include "livestatus/table.h"
+
+using namespace icinga;
+
+namespace livestatus
+{
+
+/**
+ * @ingroup livestatus
+ */
+class ServiceGroupsTable : public Table
+{
+public:
+       DECLARE_PTR_TYPEDEFS(ServiceGroupsTable);
+
+       ServiceGroupsTable(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 Object::Ptr& object);
+       static Value AliasAccessor(const Object::Ptr& object);
+       static Value MembersAccessor(const Object::Ptr& object);
+};
+
+}
+
+#endif /* SERVICEGROUPSTABLE_H */
index 7c6a18fe28c7c1462161d271b658222e32b53ac5..3d0d45e0affa7c8f7ac1d7d7380c1d577bc91023 100644 (file)
@@ -49,8 +49,12 @@ Table::Ptr Table::GetByName(const String& name)
                return boost::make_shared<ContactGroupsTable>();
        else if (name == "contacts")
                return boost::make_shared<ContactsTable>();
+       else if (name == "hostgroups")
+               return boost::make_shared<HostsTable>();
        else if (name == "hosts")
                return boost::make_shared<HostsTable>();
+       else if (name == "servicegroups")
+               return boost::make_shared<ServicesTable>();
        else if (name == "services")
                return boost::make_shared<ServicesTable>();
        else if (name == "commands")