]> granicus.if.org Git - icinga2/commitdiff
Implemented host acknowledgements.
authorGunnar Beutner <gunnar@beutner.name>
Sun, 27 Jan 2013 10:35:47 +0000 (11:35 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Sun, 27 Jan 2013 10:35:47 +0000 (11:35 +0100)
lib/icinga/Makefile.am
lib/icinga/acknowledgement.h [new file with mode: 0644]
lib/icinga/externalcommand.cpp
lib/icinga/externalcommand.h
lib/icinga/host.cpp
lib/icinga/host.h
lib/icinga/i2-icinga.h
lib/icinga/icinga.vcxproj
lib/icinga/icinga.vcxproj.filters
lib/icinga/service.h

index e6c9a6dd7558b03b17de1a3e423ae7393985418d..0650d2e29da805611db243559283a7d15fcc9a2c 100644 (file)
@@ -5,6 +5,7 @@ pkglib_LTLIBRARIES =  \
        libicinga.la
 
 libicinga_la_SOURCES =  \
+       acknowledgement.h \
        cib.cpp \
        cib.h \
        externalcommand.cpp \
diff --git a/lib/icinga/acknowledgement.h b/lib/icinga/acknowledgement.h
new file mode 100644 (file)
index 0000000..eb0fbf0
--- /dev/null
@@ -0,0 +1,40 @@
+/******************************************************************************
+ * 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 ACKNOWLEDGEMENT_H
+#define ACKNOWLEDGEMENT_H
+
+namespace icinga
+{
+
+/**
+ * The acknowledgement type of a host/service.
+ *
+ * @ingroup icinga
+ */
+enum AcknowledgementType
+{
+       AcknowledgementNone = 0,
+       AcknowledgementNormal = 1,
+       AcknowledgementSticky = 2
+};
+
+}
+
+#endif /* ACKNOWLEDGEMENT_H */
index c0d9883aa1cd172529c5d8c551fabcd57021f04d..79a4ed13e308858634848878222703b038322cd7 100644 (file)
@@ -70,7 +70,10 @@ void ExternalCommand::Execute(double time, const String& command, const vector<S
                RegisterCommand("DISABLE_HOST_SVC_CHECKS", &ExternalCommand::DisableHostSvcChecks);
                RegisterCommand("ACKNOWLEDGE_SVC_PROBLEM", &ExternalCommand::AcknowledgeSvcProblem);
                RegisterCommand("ACKNOWLEDGE_SVC_PROBLEM_EXPIRE", &ExternalCommand::AcknowledgeSvcProblemExpire);
-               RegisterCommand("REMOVE_SVC_ACKNOWLEDGEMENT", &ExternalCommand::RemoveSvcAcknowledgement);
+               RegisterCommand("REMOVE_SVC_ACKNOWLEDGEMENT", &ExternalCommand::RemoveHostAcknowledgement);
+               RegisterCommand("ACKNOWLEDGE_HOST_PROBLEM", &ExternalCommand::AcknowledgeHostProblem);
+               RegisterCommand("ACKNOWLEDGE_HOST_PROBLEM_EXPIRE", &ExternalCommand::AcknowledgeHostProblemExpire);
+               RegisterCommand("REMOVE_HOST_ACKNOWLEDGEMENT", &ExternalCommand::RemoveHostAcknowledgement);
                RegisterCommand("ENABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommand::EnableHostgroupSvcChecks);
                RegisterCommand("DISABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommand::DisableHostgroupSvcChecks);
                RegisterCommand("ENABLE_SERVICEGROUP_SVC_CHECKS", &ExternalCommand::EnableServicegroupSvcChecks);
@@ -358,6 +361,62 @@ void ExternalCommand::RemoveSvcAcknowledgement(double time, const vector<String>
        service->SetAcknowledgementExpiry(0);
 }
 
+void ExternalCommand::AcknowledgeHostProblem(double time, const vector<String>& arguments)
+{
+       if (arguments.size() < 7)
+               throw_exception(invalid_argument("Expected 7 arguments."));
+
+       if (!Host::Exists(arguments[1]))
+               throw_exception(invalid_argument("The host '" + arguments[1] + "' does not exist."));
+
+       int sticky = arguments[2].ToDouble();
+
+       Host::Ptr host = Host::GetByName(arguments[1]);
+
+       if (host->IsUp())
+               throw_exception(invalid_argument("The host '" + arguments[1] + "' is OK."));
+
+       Logger::Write(LogInformation, "icinga", "Setting acknowledgement for host '" + host->GetName() + "'");
+       host->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
+       host->SetAcknowledgementExpiry(0);
+}
+
+void ExternalCommand::AcknowledgeHostProblemExpire(double time, const vector<String>& arguments)
+{
+       if (arguments.size() < 8)
+               throw_exception(invalid_argument("Expected 8 arguments."));
+
+       if (!Host::Exists(arguments[1]))
+               throw_exception(invalid_argument("The host '" + arguments[1] + "' does not exist."));
+
+       int sticky = arguments[2].ToDouble();
+       double timestamp = arguments[5].ToDouble();
+
+       Host::Ptr host = Host::GetByName(arguments[1]);
+
+       if (host->IsUp())
+               throw_exception(invalid_argument("The host '" + arguments[1] + "' is OK."));
+
+       Logger::Write(LogInformation, "icinga", "Setting timed acknowledgement for host '" + host->GetName() + "'");
+       host->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
+       host->SetAcknowledgementExpiry(timestamp);
+}
+
+void ExternalCommand::RemoveHostAcknowledgement(double time, const vector<String>& arguments)
+{
+       if (arguments.size() < 2)
+               throw_exception(invalid_argument("Expected 2 arguments."));
+
+       if (!Host::Exists(arguments[1]))
+               throw_exception(invalid_argument("The host '" + arguments[1] + "' does not exist."));
+
+       Host::Ptr host = Host::GetByName(arguments[1]);
+
+       Logger::Write(LogInformation, "icinga", "Removing acknowledgement for host '" + host->GetName() + "'");
+       host->SetAcknowledgement(AcknowledgementNone);
+       host->SetAcknowledgementExpiry(0);
+}
+
 void ExternalCommand::EnableHostgroupSvcChecks(double time, const vector<String>& arguments)
 {
        if (arguments.size() < 1)
index 973113bdf4ac160020941c2da2d0489f828c0a99..fd24708ee439dbd388d1eb02506f0bb7d24f24ee 100644 (file)
@@ -42,6 +42,9 @@ public:
        static void AcknowledgeSvcProblem(double time, const vector<String>& arguments);
        static void AcknowledgeSvcProblemExpire(double time, const vector<String>& arguments);
        static void RemoveSvcAcknowledgement(double time, const vector<String>& arguments);
+       static void AcknowledgeHostProblem(double time, const vector<String>& arguments);
+       static void AcknowledgeHostProblemExpire(double time, const vector<String>& arguments);
+       static void RemoveHostAcknowledgement(double time, const vector<String>& arguments);
        static void EnableHostgroupSvcChecks(double time, const vector<String>& arguments);
        static void DisableHostgroupSvcChecks(double time, const vector<String>& arguments);
        static void EnableServicegroupSvcChecks(double time, const vector<String>& arguments);
index bea0aee9818d793c53dd34e8ac087b5fc214bb1d..e359fdc804cb8d29b8f209f90292fb9dae780db4 100644 (file)
@@ -26,7 +26,9 @@ bool Host::m_ServicesCacheValid = true;
 
 static AttributeDescription hostAttributes[] = {
        { "alias", Attribute_Config },
-       { "hostgroups", Attribute_Config }
+       { "hostgroups", Attribute_Config },
+       { "acknowledgement", Attribute_Replicated },
+       { "acknowledgement_expiry", Attribute_Replicated }
 };
 
 REGISTER_TYPE(Host, hostAttributes);
@@ -307,6 +309,49 @@ set<Service::Ptr> Host::GetServices(void) const
        return services;
 }
 
+AcknowledgementType Host::GetAcknowledgement(void)
+{
+       Value value = Get("acknowledgement");
+
+       if (value.IsEmpty())
+               return AcknowledgementNone;
+
+       int ivalue = static_cast<int>(value);
+       AcknowledgementType avalue = static_cast<AcknowledgementType>(ivalue);
+
+       if (avalue != AcknowledgementNone) {
+               double expiry = GetAcknowledgementExpiry();
+
+               if (expiry != 0 && expiry < Utility::GetTime()) {
+                       avalue = AcknowledgementNone;
+                       SetAcknowledgement(avalue);
+                       SetAcknowledgementExpiry(0);
+               }
+       }
+
+       return avalue;
+}
+
+void Host::SetAcknowledgement(AcknowledgementType acknowledgement)
+{
+       Set("acknowledgement", static_cast<long>(acknowledgement));
+}
+
+double Host::GetAcknowledgementExpiry(void) const
+{
+       Value value = Get("acknowledgement_expiry");
+
+       if (value.IsEmpty())
+               return 0;
+
+       return static_cast<double>(value);
+}
+
+void Host::SetAcknowledgementExpiry(double timestamp)
+{
+       Set("acknowledgement_expiry", timestamp);
+}
+
 void Host::InvalidateServicesCache(void)
 {
        m_ServicesCacheValid = false;
index f57bc1a66737089bc5477e9a39d97fc383e85dde..a3797b5d3568168cce9e2f96e7220992304184b6 100644 (file)
@@ -44,9 +44,16 @@ public:
 
        String GetAlias(void) const;
        Dictionary::Ptr GetGroups(void) const;
+
        set<Host::Ptr> GetParents(void);
        Dictionary::Ptr GetMacros(void) const;
 
+       AcknowledgementType GetAcknowledgement(void);
+       void SetAcknowledgement(AcknowledgementType acknowledgement);
+
+       double GetAcknowledgementExpiry(void) const;
+       void SetAcknowledgementExpiry(double timestamp);
+
        bool IsReachable(void);
        bool IsUp(void);
 
index 62a952d2eaf6c70191e848f23a81ce0a98a82e67..bfb6a0ba20ce6fd167d6a13a6dfac61a65525b26 100644 (file)
@@ -48,6 +48,8 @@ using boost::algorithm::is_any_of;
 
 #include "timeperiod.h"
 
+#include "acknowledgement.h"
+
 #include "host.h"
 #include "hostgroup.h"
 #include "service.h"
index 6ee43a2cdc270cd6d7d76db0c5eb5a09458ff29d..69e6adf11c11b949e83dde73f9b76600a8da5938 100644 (file)
@@ -39,6 +39,7 @@
     <ClCompile Include="timeperiod.cpp" />
   </ItemGroup>
   <ItemGroup>
+    <ClInclude Include="acknowledgement.h" />
     <ClInclude Include="cib.h" />
     <ClInclude Include="externalcommand.h" />
     <ClInclude Include="host.h" />
index 6775eca2ffd71d6632bc27a928cc1561e2a7601a..4bd00b018478a1d2b9410e085db2cf2e9b546af5 100644 (file)
@@ -81,6 +81,9 @@
     <ClInclude Include="externalcommand.h">
       <Filter>Headerdateien</Filter>
     </ClInclude>
+    <ClInclude Include="acknowledgement.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <Filter Include="Headerdateien">
index 79185265079f3efd47d871ec21289d0ad82f8c9c..a9a5980c452c35d9bb9460eaddfb93250f8ebe30 100644 (file)
@@ -48,18 +48,6 @@ enum ServiceStateType
        StateTypeHard
 };
 
-/**
- * The acknowledgement type of a service.
- *
- * @ingroup icinga
- */
-enum AcknowledgementType
-{
-       AcknowledgementNone = 0,
-       AcknowledgementNormal = 1,
-       AcknowledgementSticky = 2
-};
-
 class CheckResultMessage;
 class ServiceStatusMessage;