compat: add config options: {status,objects}path

requires automake target for localstatedir as default, if not set.

refs #2796
This commit is contained in:
Michael Friedrich 2012-09-28 14:26:01 +02:00
parent b48ff35348
commit edb9a47c97
4 changed files with 52 additions and 5 deletions

View 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

View 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);

View 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;
};
}

View 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",
*/
}
/**