]> granicus.if.org Git - icinga2/commitdiff
Implement validator for LivestatusListener::socket_type.
authorGunnar Beutner <gunnar.beutner@netways.de>
Mon, 30 Sep 2013 08:07:49 +0000 (10:07 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Mon, 30 Sep 2013 08:07:49 +0000 (10:07 +0200)
Fixes #4751

components/livestatus/listener.cpp
components/livestatus/listener.h
components/livestatus/livestatus-type.conf

index f829fa696dbb1a73a5009e258709966f26709a90..88473ad7b44117b5179d0594ac82a7240717cbbf 100644 (file)
@@ -18,6 +18,7 @@
  ******************************************************************************/
 
 #include "livestatus/listener.h"
+#include "config/configcompilercontext.h"
 #include "base/objectlock.h"
 #include "base/dynamictype.h"
 #include "base/logger_fwd.h"
@@ -26,6 +27,7 @@
 #include "base/unixsocket.h"
 #include "base/networkstream.h"
 #include "base/application.h"
+#include "base/scriptfunction.h"
 #include <boost/smart_ptr/make_shared.hpp>
 #include <boost/exception/diagnostic_information.hpp>
 
@@ -34,6 +36,7 @@ using namespace icinga;
 using namespace livestatus;
 
 REGISTER_TYPE(LivestatusListener);
+REGISTER_SCRIPTFUNCTION(ValidateSocketType, &LivestatusListener::ValidateSocketType);
 
 static int l_ClientsConnected = 0;
 static int l_Connections = 0;
@@ -176,6 +179,16 @@ void LivestatusListener::ClientThreadProc(const Socket::Ptr& client)
        }
 }
 
+void LivestatusListener::ValidateSocketType(const String& location, const Dictionary::Ptr& attrs)
+{
+       Value socket_type = attrs->Get("socket_type");
+
+       if (!socket_type.IsEmpty() && socket_type != "unix" && socket_type != "tcp") {
+               ConfigCompilerContext::GetInstance()->AddMessage(true, "Validation failed for " +
+                   location + ": Socket type '" + socket_type + "' is invalid.");
+       }
+}
+
 void LivestatusListener::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
 {
        DynamicObject::InternalSerialize(bag, attributeTypes);
index 9fd86b3afd838b3b2f6db7011e7500f2ca318d98..a181c4f3ea100101afb01d30ac0b561e62118387 100644 (file)
@@ -46,6 +46,8 @@ public:
        static int GetClientsConnected(void);
        static int GetConnections(void);
 
+       static void ValidateSocketType(const String& location, const Dictionary::Ptr& attrs);
+
 protected:
        virtual void Start(void);
 
index 6695a70ae50aaa75765472e041ce1e99990a2fd2..9c7421cbf10f7cf75cef6f8df1cfd968ab6bc0dd 100644 (file)
@@ -18,6 +18,8 @@
  ******************************************************************************/
 
 type LivestatusListener {
+       %validator "ValidateSocketType",
+
        %attribute string "socket_type",
 
        %attribute string "socket_path",