diff --git a/components/compat/Makefile.am b/components/compat/Makefile.am index 830d100de..2024c432d 100644 --- a/components/compat/Makefile.am +++ b/components/compat/Makefile.am @@ -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 diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index a68eb35cc..39bbea762 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -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); diff --git a/components/compat/compatcomponent.h b/components/compat/compatcomponent.h index 078f99bce..08d1b57e9 100644 --- a/components/compat/compatcomponent.h +++ b/components/compat/compatcomponent.h @@ -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; }; } diff --git a/icinga-app/config/icinga2.conf.dist b/icinga-app/config/icinga2.conf.dist index dda39f2a1..768ea0f28 100644 --- a/icinga-app/config/icinga2.conf.dist +++ b/icinga-app/config/icinga2.conf.dist @@ -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", +*/ } /**