]> granicus.if.org Git - icinga2/commitdiff
compat: add config options: {status,objects}path
authorMichael Friedrich <michael.friedrich@gmail.com>
Fri, 28 Sep 2012 12:26:01 +0000 (14:26 +0200)
committerMichael Friedrich <michael.friedrich@gmail.com>
Fri, 28 Sep 2012 12:26:01 +0000 (14:26 +0200)
requires automake target for localstatedir as default, if not set.

refs #2796

components/compat/Makefile.am
components/compat/compatcomponent.cpp
components/compat/compatcomponent.h
icinga-app/config/icinga2.conf.dist

index 830d100de32d2cf3e8d24528a60a2234f2564029..2024c432d45a87cc6a90aa5fefdd20a483cc7bf3 100644 (file)
@@ -1,4 +1,8 @@
 ## Process this file with automake to produce Makefile.in
+icinga2localstatedir = $(localstatedir)
+icinga2localstate_DATA = 
+
+EXTRA_DIST = $(icinga2localstate_DATA)
 
 pkglib_LTLIBRARIES = \
        compat.la
index a68eb35cc0de25741b39795f5993745e31fa5015..39bbea762553faffd15ac9fb66351d3189ca9a91 100644 (file)
@@ -27,6 +27,35 @@ using namespace icinga;
  * performance (see http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch25s02.html).
  */
 
+const String CompatComponent::DefaultStatusPath = Application::GetLocalStateDir() + "/status.dat";
+const String CompatComponent::DefaultObjectsPath = Application::GetLocalStateDir() + "/objects.cache";
+
+/**
+ * Reads status path from config
+ * @returns statuspath from config, or static default
+ */
+String CompatComponent::GetStatusPath(void) const
+{
+       Value statuspath = GetConfig()->Get("statuspath");
+       if(statuspath.IsEmpty())
+               return DefaultStatusPath;
+       else
+               return statuspath;
+}
+
+/**
+ * Reads objects path from config
+ * @returns objectspath from config, or static default
+ */
+String CompatComponent::GetObjectsPath(void) const
+{
+        Value objectspath = GetConfig()->Get("objectspath");
+        if(objectspath.IsEmpty())
+                return DefaultObjectsPath;
+        else
+                return objectspath;
+}
+
 /**
  * Starts the component.
  */
@@ -171,8 +200,13 @@ void CompatComponent::StatusTimerHandler(void)
 {
        Logger::Write(LogInformation, "compat", "Writing compat status information");
 
+       String statuspath = GetStatusPath();
+       String objectspath = GetObjectsPath();
+       String statuspathtmp = statuspath + ".tmp"; /* XXX make this a global definition */
+       String objectspathtmp = objectspath + ".tmp";
+
        ofstream statusfp;
-       statusfp.open("status.dat.tmp", ofstream::out | ofstream::trunc);
+       statusfp.open(statuspathtmp.CStr(), ofstream::out | ofstream::trunc);
 
        statusfp << std::fixed;
 
@@ -203,7 +237,7 @@ void CompatComponent::StatusTimerHandler(void)
                 << "\n";
 
        ofstream objectfp;
-       objectfp.open("objects.cache.tmp", ofstream::out | ofstream::trunc);
+       objectfp.open(objectspathtmp.CStr(), ofstream::out | ofstream::trunc);
 
        objectfp << std::fixed;
 
@@ -306,10 +340,10 @@ void CompatComponent::StatusTimerHandler(void)
        }
 
        statusfp.close();
-       rename("status.dat.tmp", "status.dat");
+       rename(statuspathtmp.CStr(), statuspath.CStr());
 
        objectfp.close();
-       rename("objects.cache.tmp", "objects.cache");
+       rename(objectspathtmp.CStr(), objectspath.CStr());
 }
 
 EXPORT_COMPONENT(compat, CompatComponent);
index 078f99bce0a07331740e06e62bff0c16e8c74f30..08d1b57e94c57bfb786cb4ec81cdfaa9add50731 100644 (file)
@@ -35,6 +35,9 @@ public:
 private:
        Timer::Ptr m_StatusTimer;
 
+       String GetStatusPath(void) const;
+       String GetObjectsPath(void) const;
+
        void DumpHostStatus(ofstream& fp, const Host::Ptr& host);
        void DumpHostObject(ofstream& fp, const Host::Ptr& host);
 
@@ -58,6 +61,9 @@ private:
        void DumpServiceObject(ofstream& fp, const Service::Ptr& service);
 
        void StatusTimerHandler(void);
+
+       static const String DefaultStatusPath;
+       static const String DefaultObjectsPath;
 };
 
 }
index dda39f2a1978ab52e4cbd09908b179c5921de0a1..768ea0f285b7ed51e1fabc27a716ca821379b7fe 100644 (file)
@@ -37,7 +37,10 @@ local object Component "delegation" {
  * hosts and services.
  */
 local object Component "compat" {
-
+/*
+       statuspath = "/var/icinga2/status.dat",
+       objectspath = "/var/icinga2/objects.cache",
+*/
 }
 
 /**