]> granicus.if.org Git - icinga2/commitdiff
Refactor the livestatus library.
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 25 Sep 2013 07:31:52 +0000 (09:31 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 25 Sep 2013 07:33:59 +0000 (09:33 +0200)
components/livestatus/Makefile.am
components/livestatus/hoststable.cpp
components/livestatus/listener.cpp [moved from components/livestatus/component.cpp with 75% similarity]
components/livestatus/listener.h [moved from components/livestatus/component.h with 88% similarity]
components/livestatus/livestatus-type.conf
components/livestatus/servicestable.cpp
components/livestatus/statustable.cpp

index 60629b9e991c0c4730a32674a44aa3262a7f8d45..a986bbe5402f80c57a106a164123d16b592f5739 100644 (file)
@@ -26,8 +26,6 @@ liblivestatus_la_SOURCES = \
        commandstable.h \
        commentstable.cpp \
        commentstable.h \
-       component.cpp \
-       component.h \
        contactgroupstable.cpp \
        contactgroupstable.h \
        contactstable.cpp \
@@ -46,6 +44,8 @@ liblivestatus_la_SOURCES = \
        invavgaggregator.h \
        invsumaggregator.cpp \
        invsumaggregator.h \
+       listener.cpp \
+       listener.h \
        livestatus-type.conf \
        logtable.cpp \
        logtable.h \
index 85c365940fcbf771785621de001aa81026a37868..2ea1a990dfdd14271e44ce3963ad64625747768b 100644 (file)
@@ -1098,7 +1098,7 @@ Value HostsTable::ContactsAccessor(const Value& row)
 
                std::copy(users.begin(), users.end(), std::inserter(allUsers, allUsers.begin()));
 
-               BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetGroups()) {
+               BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetUserGroups()) {
                        std::set<User::Ptr> members = ug->GetMembers();
                        std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin()));
                }
@@ -1607,7 +1607,7 @@ Value HostsTable::ContactGroupsAccessor(const Value& row)
        BOOST_FOREACH(const Notification::Ptr& notification, hc->GetNotifications()) {
                ObjectLock olock(notification);
 
-               BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetGroups()) {
+               BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetUserGroups()) {
                        contactgroups->Add(ug->GetName());
                }
        }
similarity index 75%
rename from components/livestatus/component.cpp
rename to components/livestatus/listener.cpp
index 9bb07b565d4df325818db19dd5dfe45ff1b2a65d..1be2a851c09edb603e66655cc7faeaa6602f2d10 100644 (file)
@@ -17,7 +17,7 @@
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-#include "livestatus/component.h"
+#include "livestatus/listener.h"
 #include "base/objectlock.h"
 #include "base/dynamictype.h"
 #include "base/logger_fwd.h"
@@ -30,7 +30,7 @@
 using namespace icinga;
 using namespace livestatus;
 
-REGISTER_TYPE(LivestatusComponent);
+REGISTER_TYPE(LivestatusListener);
 
 static int l_ClientsConnected = 0;
 static int l_Connections = 0;
@@ -39,15 +39,15 @@ static boost::mutex l_ComponentMutex;
 /**
  * Starts the component.
  */
-void LivestatusComponent::Start(void)
+void LivestatusListener::Start(void)
 {
        DynamicObject::Start();
 
        if (GetSocketType() == "tcp") {
                TcpSocket::Ptr socket = boost::make_shared<TcpSocket>();
-               socket->Bind(GetHost(), GetPort(), AF_INET);
+               socket->Bind(GetBindHost(), GetBindPort(), AF_INET);
 
-               boost::thread thread(boost::bind(&LivestatusComponent::ServerThreadProc, this, socket));
+               boost::thread thread(boost::bind(&LivestatusListener::ServerThreadProc, this, socket));
                thread.detach();
        }
        else if (GetSocketType() == "unix") {
@@ -55,7 +55,7 @@ void LivestatusComponent::Start(void)
                UnixSocket::Ptr socket = boost::make_shared<UnixSocket>();
                socket->Bind(GetSocketPath());
 
-               boost::thread thread(boost::bind(&LivestatusComponent::ServerThreadProc, this, socket));
+               boost::thread thread(boost::bind(&LivestatusListener::ServerThreadProc, this, socket));
                thread.detach();
 #else
                /* no unix sockets on windows */
@@ -65,7 +65,7 @@ void LivestatusComponent::Start(void)
        }
 }
 
-String LivestatusComponent::GetSocketType(void) const
+String LivestatusListener::GetSocketType(void) const
 {
        Value socketType = m_SocketType;
        if (socketType.IsEmpty())
@@ -74,7 +74,7 @@ String LivestatusComponent::GetSocketType(void) const
                return socketType;
 }
 
-String LivestatusComponent::GetSocketPath(void) const
+String LivestatusListener::GetSocketPath(void) const
 {
        Value socketPath = m_SocketPath;
        if (socketPath.IsEmpty())
@@ -83,39 +83,37 @@ String LivestatusComponent::GetSocketPath(void) const
                return socketPath;
 }
 
-String LivestatusComponent::GetHost(void) const
+String LivestatusListener::GetBindHost(void) const
 {
-       Value node = m_Host;
-       if (node.IsEmpty())
+       if (m_BindHost.IsEmpty())
                return "127.0.0.1";
        else
-               return node;
+               return m_BindHost;
 }
 
-String LivestatusComponent::GetPort(void) const
+String LivestatusListener::GetBindPort(void) const
 {
-       Value service = m_Port;
-       if (service.IsEmpty())
+       if (m_BindPort.IsEmpty())
                return "6558";
        else
-               return service;
+               return m_BindPort;
 }
 
-int LivestatusComponent::GetClientsConnected(void)
+int LivestatusListener::GetClientsConnected(void)
 {
        boost::mutex::scoped_lock lock(l_ComponentMutex);
 
        return l_ClientsConnected;
 }
 
-int LivestatusComponent::GetConnections(void)
+int LivestatusListener::GetConnections(void)
 {
        boost::mutex::scoped_lock lock(l_ComponentMutex);
 
        return l_Connections;
 }
 
-void LivestatusComponent::ServerThreadProc(const Socket::Ptr& server)
+void LivestatusListener::ServerThreadProc(const Socket::Ptr& server)
 {
        server->Listen();
 
@@ -124,12 +122,12 @@ void LivestatusComponent::ServerThreadProc(const Socket::Ptr& server)
 
                Log(LogInformation, "livestatus", "Client connected");
 
-               boost::thread thread(boost::bind(&LivestatusComponent::ClientThreadProc, this, client));
+               boost::thread thread(boost::bind(&LivestatusListener::ClientThreadProc, this, client));
                thread.detach();
        }
 }
 
-void LivestatusComponent::ClientThreadProc(const Socket::Ptr& client)
+void LivestatusListener::ClientThreadProc(const Socket::Ptr& client)
 {
        {
                boost::mutex::scoped_lock lock(l_ComponentMutex);
@@ -163,26 +161,26 @@ void LivestatusComponent::ClientThreadProc(const Socket::Ptr& client)
        }
 }
 
-void LivestatusComponent::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+void LivestatusListener::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
 {
        DynamicObject::InternalSerialize(bag, attributeTypes);
 
        if (attributeTypes & Attribute_Config) {
                bag->Set("socket_type", m_SocketType);
                bag->Set("socket_path", m_SocketPath);
-               bag->Set("host", m_Host);
-               bag->Set("port", m_Port);
+               bag->Set("bind_host", m_BindHost);
+               bag->Set("bind_port", m_BindPort);
        }
 }
 
-void LivestatusComponent::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+void LivestatusListener::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
 {
        DynamicObject::InternalDeserialize(bag, attributeTypes);
 
        if (attributeTypes & Attribute_Config) {
                m_SocketType = bag->Get("socket_type");
                m_SocketPath = bag->Get("socket_path");
-               m_Host = bag->Get("host");
-               m_Port = bag->Get("port");
+               m_BindHost = bag->Get("bind_host");
+               m_BindPort = bag->Get("bind_port");
        }
 }
similarity index 88%
rename from components/livestatus/component.h
rename to components/livestatus/listener.h
index 50ab0430b7c929ffbb1f2f7c25cc796d52a45ccf..9fd86b3afd838b3b2f6db7011e7500f2ca318d98 100644 (file)
@@ -17,8 +17,8 @@
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-#ifndef LIVESTATUSCOMPONENT_H
-#define LIVESTATUSCOMPONENT_H
+#ifndef LIVESTATUSLISTENER_H
+#define LIVESTATUSLISTENER_H
 
 #include "livestatus/query.h"
 #include "base/dynamicobject.h"
@@ -33,13 +33,15 @@ namespace livestatus
 /**
  * @ingroup livestatus
  */
-class LivestatusComponent : public DynamicObject
+class LivestatusListener : public DynamicObject
 {
 public:
+       DECLARE_PTR_TYPEDEFS(LivestatusListener);
+
        String GetSocketType(void) const;
        String GetSocketPath(void) const;
-       String GetHost(void) const;
-       String GetPort(void) const;
+       String GetBindHost(void) const;
+       String GetBindPort(void) const;
 
        static int GetClientsConnected(void);
        static int GetConnections(void);
@@ -53,8 +55,8 @@ protected:
 private:
        String m_SocketType;
        String m_SocketPath;
-       String m_Host;
-       String m_Port;
+       String m_BindHost;
+       String m_BindPort;
 
        void ServerThreadProc(const Socket::Ptr& server);
        void ClientThreadProc(const Socket::Ptr& client);
@@ -62,4 +64,4 @@ private:
 
 }
 
-#endif /* LIVESTATUSCOMPONENT_H */
+#endif /* LIVESTATUSLISTENER_H */
index cd6281736ce7ff17b06e8f300b53eee216566368..6695a70ae50aaa75765472e041ce1e99990a2fd2 100644 (file)
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-type LivestatusComponent {
+type LivestatusListener {
        %attribute string "socket_type",
 
        %attribute string "socket_path",
-       %attribute string "host",
-       %attribute string "port",
+       %attribute string "bind_host",
+       %attribute string "bind_port",
 }
index 4cdb96790170bb0ee3e3e7b99bb31e39648cb451..e0706d1eb2ecd97e41b1198183fb73b7b0883b7d 100644 (file)
@@ -762,7 +762,7 @@ Value ServicesTable::ContactsAccessor(const Value& row)
 
                std::copy(users.begin(), users.end(), std::inserter(allUsers, allUsers.begin()));
 
-               BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetGroups()) {
+               BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetUserGroups()) {
                        std::set<User::Ptr> members = ug->GetMembers();
                        std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin()));
                 }
@@ -1029,7 +1029,7 @@ Value ServicesTable::ContactGroupsAccessor(const Value& row)
        BOOST_FOREACH(const Notification::Ptr& notification, static_cast<Service::Ptr>(row)->GetNotifications()) {
                ObjectLock olock(notification);
 
-               BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetGroups()) {
+               BOOST_FOREACH(const UserGroup::Ptr& ug, notification->GetUserGroups()) {
                        contactgroups->Add(ug->GetName());
                 }
         }
index 44f595c2d1b6c12c913b153602731236ae83b00e..847d6912156396f60e98948d1f3e086ac420ac13 100644 (file)
@@ -18,7 +18,7 @@
  ******************************************************************************/
 
 #include "livestatus/statustable.h"
-#include "livestatus/component.h"
+#include "livestatus/listener.h"
 #include "icinga/icingaapplication.h"
 #include "icinga/cib.h"
 #include "icinga/host.h"
@@ -138,12 +138,12 @@ Value StatusTable::RequestsRateAccessor(const Value& row)
 
 Value StatusTable::ConnectionsAccessor(const Value& row)
 {
-       return LivestatusComponent::GetConnections();
+       return LivestatusListener::GetConnections();
 }
 
 Value StatusTable::ConnectionsRateAccessor(const Value& row)
 {
-       return (LivestatusComponent::GetConnections() / (Utility::GetTime() - IcingaApplication::GetInstance()->GetStartTime()));
+       return (LivestatusListener::GetConnections() / (Utility::GetTime() - IcingaApplication::GetInstance()->GetStartTime()));
 }
 
 Value StatusTable::ServiceChecksAccessor(const Value& row)
@@ -380,7 +380,7 @@ Value StatusTable::LivestatusVersionAccessor(const Value& row)
 
 Value StatusTable::LivestatusActiveConnectionsAccessor(const Value& row)
 {
-       return LivestatusComponent::GetClientsConnected();
+       return LivestatusListener::GetClientsConnected();
 }
 
 Value StatusTable::LivestatusQueuedConnectionsAccessor(const Value& row)