mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-31 01:24:19 +02:00
compat: add config options: {status,objects}path
requires automake target for localstatedir as default, if not set. refs #2796
This commit is contained in:
parent
b48ff35348
commit
edb9a47c97
@ -1,4 +1,8 @@
|
|||||||
## Process this file with automake to produce Makefile.in
|
## Process this file with automake to produce Makefile.in
|
||||||
|
icinga2localstatedir = $(localstatedir)
|
||||||
|
icinga2localstate_DATA =
|
||||||
|
|
||||||
|
EXTRA_DIST = $(icinga2localstate_DATA)
|
||||||
|
|
||||||
pkglib_LTLIBRARIES = \
|
pkglib_LTLIBRARIES = \
|
||||||
compat.la
|
compat.la
|
||||||
|
@ -27,6 +27,35 @@ using namespace icinga;
|
|||||||
* performance (see http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch25s02.html).
|
* 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.
|
* Starts the component.
|
||||||
*/
|
*/
|
||||||
@ -171,8 +200,13 @@ void CompatComponent::StatusTimerHandler(void)
|
|||||||
{
|
{
|
||||||
Logger::Write(LogInformation, "compat", "Writing compat status information");
|
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;
|
ofstream statusfp;
|
||||||
statusfp.open("status.dat.tmp", ofstream::out | ofstream::trunc);
|
statusfp.open(statuspathtmp.CStr(), ofstream::out | ofstream::trunc);
|
||||||
|
|
||||||
statusfp << std::fixed;
|
statusfp << std::fixed;
|
||||||
|
|
||||||
@ -203,7 +237,7 @@ void CompatComponent::StatusTimerHandler(void)
|
|||||||
<< "\n";
|
<< "\n";
|
||||||
|
|
||||||
ofstream objectfp;
|
ofstream objectfp;
|
||||||
objectfp.open("objects.cache.tmp", ofstream::out | ofstream::trunc);
|
objectfp.open(objectspathtmp.CStr(), ofstream::out | ofstream::trunc);
|
||||||
|
|
||||||
objectfp << std::fixed;
|
objectfp << std::fixed;
|
||||||
|
|
||||||
@ -306,10 +340,10 @@ void CompatComponent::StatusTimerHandler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
statusfp.close();
|
statusfp.close();
|
||||||
rename("status.dat.tmp", "status.dat");
|
rename(statuspathtmp.CStr(), statuspath.CStr());
|
||||||
|
|
||||||
objectfp.close();
|
objectfp.close();
|
||||||
rename("objects.cache.tmp", "objects.cache");
|
rename(objectspathtmp.CStr(), objectspath.CStr());
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_COMPONENT(compat, CompatComponent);
|
EXPORT_COMPONENT(compat, CompatComponent);
|
||||||
|
@ -35,6 +35,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
Timer::Ptr m_StatusTimer;
|
Timer::Ptr m_StatusTimer;
|
||||||
|
|
||||||
|
String GetStatusPath(void) const;
|
||||||
|
String GetObjectsPath(void) const;
|
||||||
|
|
||||||
void DumpHostStatus(ofstream& fp, const Host::Ptr& host);
|
void DumpHostStatus(ofstream& fp, const Host::Ptr& host);
|
||||||
void DumpHostObject(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 DumpServiceObject(ofstream& fp, const Service::Ptr& service);
|
||||||
|
|
||||||
void StatusTimerHandler(void);
|
void StatusTimerHandler(void);
|
||||||
|
|
||||||
|
static const String DefaultStatusPath;
|
||||||
|
static const String DefaultObjectsPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,10 @@ local object Component "delegation" {
|
|||||||
* hosts and services.
|
* hosts and services.
|
||||||
*/
|
*/
|
||||||
local object Component "compat" {
|
local object Component "compat" {
|
||||||
|
/*
|
||||||
|
statuspath = "/var/icinga2/status.dat",
|
||||||
|
objectspath = "/var/icinga2/objects.cache",
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user