mirror of https://github.com/Icinga/icinga2.git
parent
5bc3b02758
commit
0978e46d5a
|
@ -383,7 +383,7 @@ void ClusterListener::ReplayLog(const Endpoint::Ptr& endpoint, const Stream::Ptr
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
std::vector<int> files;
|
std::vector<int> files;
|
||||||
Utility::Glob(GetClusterDir() + "log/*", boost::bind(&ClusterListener::LogGlobHandler, boost::ref(files), _1));
|
Utility::Glob(GetClusterDir() + "log/*", boost::bind(&ClusterListener::LogGlobHandler, boost::ref(files), _1), GlobFile);
|
||||||
std::sort(files.begin(), files.end());
|
std::sort(files.begin(), files.end());
|
||||||
|
|
||||||
BOOST_FOREACH(int ts, files) {
|
BOOST_FOREACH(int ts, files) {
|
||||||
|
@ -479,6 +479,8 @@ void ClusterListener::ReplayLog(const Endpoint::Ptr& endpoint, const Stream::Ptr
|
||||||
|
|
||||||
void ClusterListener::ConfigGlobHandler(const Dictionary::Ptr& config, const String& file, bool basename)
|
void ClusterListener::ConfigGlobHandler(const Dictionary::Ptr& config, const String& file, bool basename)
|
||||||
{
|
{
|
||||||
|
CONTEXT("Creating config update for file '" + file + "'");
|
||||||
|
|
||||||
Dictionary::Ptr elem = make_shared<Dictionary>();
|
Dictionary::Ptr elem = make_shared<Dictionary>();
|
||||||
|
|
||||||
std::ifstream fp(file.CStr());
|
std::ifstream fp(file.CStr());
|
||||||
|
@ -532,7 +534,7 @@ void ClusterListener::NewClientHandler(const Socket::Ptr& client, TlsRole role)
|
||||||
if (configFiles) {
|
if (configFiles) {
|
||||||
ObjectLock olock(configFiles);
|
ObjectLock olock(configFiles);
|
||||||
BOOST_FOREACH(const String& pattern, configFiles) {
|
BOOST_FOREACH(const String& pattern, configFiles) {
|
||||||
Utility::Glob(pattern, boost::bind(&ClusterListener::ConfigGlobHandler, boost::cref(config), _1, false));
|
Utility::Glob(pattern, boost::bind(&ClusterListener::ConfigGlobHandler, boost::cref(config), _1, false), GlobFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -591,7 +593,7 @@ void ClusterListener::ClusterTimerHandler(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> files;
|
std::vector<int> files;
|
||||||
Utility::Glob(GetClusterDir() + "log/*", boost::bind(&ClusterListener::LogGlobHandler, boost::ref(files), _1));
|
Utility::Glob(GetClusterDir() + "log/*", boost::bind(&ClusterListener::LogGlobHandler, boost::ref(files), _1), GlobFile);
|
||||||
std::sort(files.begin(), files.end());
|
std::sort(files.begin(), files.end());
|
||||||
|
|
||||||
BOOST_FOREACH(int ts, files) {
|
BOOST_FOREACH(int ts, files) {
|
||||||
|
@ -1391,7 +1393,7 @@ void ClusterListener::MessageHandler(const Endpoint::Ptr& sender, const Dictiona
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr localConfig = make_shared<Dictionary>();
|
Dictionary::Ptr localConfig = make_shared<Dictionary>();
|
||||||
Utility::Glob(dir + "/*", boost::bind(&ClusterListener::ConfigGlobHandler, boost::cref(localConfig), _1, true));
|
Utility::Glob(dir + "/*", boost::bind(&ClusterListener::ConfigGlobHandler, boost::cref(localConfig), _1, true), GlobFile);
|
||||||
|
|
||||||
bool configChange = false;
|
bool configChange = false;
|
||||||
|
|
||||||
|
|
|
@ -291,8 +291,8 @@ Value LogTable::CommandNameAccessor(const Value& row)
|
||||||
|
|
||||||
void LogTable::CreateLogIndex(const String& path)
|
void LogTable::CreateLogIndex(const String& path)
|
||||||
{
|
{
|
||||||
Utility::Glob(path + "/icinga.log", boost::bind(&LogTable::CreateLogIndexFileHandler, _1, boost::ref(m_LogFileIndex)));
|
Utility::Glob(path + "/icinga.log", boost::bind(&LogTable::CreateLogIndexFileHandler, _1, boost::ref(m_LogFileIndex)), GlobFile);
|
||||||
Utility::Glob(path + "/archives/*.log", boost::bind(&LogTable::CreateLogIndexFileHandler, _1, boost::ref(m_LogFileIndex)));
|
Utility::Glob(path + "/archives/*.log", boost::bind(&LogTable::CreateLogIndexFileHandler, _1, boost::ref(m_LogFileIndex)), GlobFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogTable::CreateLogIndexFileHandler(const String& path, std::map<unsigned long, String>& index)
|
void LogTable::CreateLogIndexFileHandler(const String& path, std::map<unsigned long, String>& index)
|
||||||
|
|
|
@ -518,8 +518,8 @@ Value StateHistTable::DurationPartUnmonitoredAccessor(const Value& row)
|
||||||
|
|
||||||
void StateHistTable::CreateLogIndex(const String& path)
|
void StateHistTable::CreateLogIndex(const String& path)
|
||||||
{
|
{
|
||||||
Utility::Glob(path + "/icinga.log", boost::bind(&StateHistTable::CreateLogIndexFileHandler, _1, boost::ref(m_LogFileIndex)));
|
Utility::Glob(path + "/icinga.log", boost::bind(&StateHistTable::CreateLogIndexFileHandler, _1, boost::ref(m_LogFileIndex)), GlobFile);
|
||||||
Utility::Glob(path + "/archives/*.log", boost::bind(&StateHistTable::CreateLogIndexFileHandler, _1, boost::ref(m_LogFileIndex)));
|
Utility::Glob(path + "/archives/*.log", boost::bind(&StateHistTable::CreateLogIndexFileHandler, _1, boost::ref(m_LogFileIndex)), GlobFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateHistTable::CreateLogIndexFileHandler(const String& path, std::map<unsigned long, String>& index)
|
void StateHistTable::CreateLogIndexFileHandler(const String& path, std::map<unsigned long, String>& index)
|
||||||
|
|
|
@ -35,6 +35,8 @@
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <glob.h>
|
#include <glob.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
typedef int SOCKET;
|
typedef int SOCKET;
|
||||||
#define INVALID_SOCKET (-1)
|
#define INVALID_SOCKET (-1)
|
||||||
|
|
|
@ -320,8 +320,10 @@ String Utility::NewUniqueID(void)
|
||||||
* Calls the specified callback for each file matching the path specification.
|
* Calls the specified callback for each file matching the path specification.
|
||||||
*
|
*
|
||||||
* @param pathSpec The path specification.
|
* @param pathSpec The path specification.
|
||||||
|
* @param callback The callback which is invoked for each matching file.
|
||||||
|
* @param type The file type (a combination of GlobFile and GlobDirectory)
|
||||||
*/
|
*/
|
||||||
bool Utility::Glob(const String& pathSpec, const boost::function<void (const String&)>& callback)
|
bool Utility::Glob(const String& pathSpec, const boost::function<void (const String&)>& callback, int type)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
HANDLE handle;
|
HANDLE handle;
|
||||||
|
@ -342,6 +344,12 @@ bool Utility::Glob(const String& pathSpec, const boost::function<void (const Str
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(type & GlobDirectory))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(type & GlobFile))
|
||||||
|
continue;
|
||||||
|
|
||||||
callback(DirName(pathSpec) + "/" + wfd.cFileName);
|
callback(DirName(pathSpec) + "/" + wfd.cFileName);
|
||||||
} while (FindNextFile(handle, &wfd));
|
} while (FindNextFile(handle, &wfd));
|
||||||
|
|
||||||
|
@ -375,6 +383,20 @@ bool Utility::Glob(const String& pathSpec, const boost::function<void (const Str
|
||||||
size_t left;
|
size_t left;
|
||||||
char **gp;
|
char **gp;
|
||||||
for (gp = gr.gl_pathv, left = gr.gl_pathc; left > 0; gp++, left--) {
|
for (gp = gr.gl_pathv, left = gr.gl_pathc; left > 0; gp++, left--) {
|
||||||
|
struct stat statbuf;
|
||||||
|
|
||||||
|
if (lstat(*gp, &statbuf) < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!S_ISDIR(statbuf.st_mode) && !S_ISREG(statbuf.st_mode))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (S_ISDIR(statbuf.st_mode) && !(type & GlobDirectory))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!S_ISDIR(statbuf.st_mode) && !(type & GlobFile))
|
||||||
|
continue;
|
||||||
|
|
||||||
callback(*gp);
|
callback(*gp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,12 @@ struct THREADNAME_INFO
|
||||||
# pragma pack(pop)
|
# pragma pack(pop)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
enum GlobType
|
||||||
|
{
|
||||||
|
GlobFile = 1,
|
||||||
|
GlobDirectory = 2
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper functions.
|
* Helper functions.
|
||||||
*
|
*
|
||||||
|
@ -69,7 +75,7 @@ public:
|
||||||
|
|
||||||
static String NewUniqueID(void);
|
static String NewUniqueID(void);
|
||||||
|
|
||||||
static bool Glob(const String& pathSpec, const boost::function<void (const String&)>& callback);
|
static bool Glob(const String& pathSpec, const boost::function<void (const String&)>& callback, int type = GlobFile | GlobDirectory);
|
||||||
|
|
||||||
static void QueueAsyncCallback(const boost::function<void (void)>& callback);
|
static void QueueAsyncCallback(const boost::function<void (void)>& callback);
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,7 @@ void ConfigCompiler::HandleFileInclude(const String& include, bool search,
|
||||||
|
|
||||||
std::vector<ConfigItem::Ptr> items;
|
std::vector<ConfigItem::Ptr> items;
|
||||||
|
|
||||||
if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CompileFile, _1)) && includePath.FindFirstOf("*?") == String::NPos) {
|
if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CompileFile, _1), GlobFile) && includePath.FindFirstOf("*?") == String::NPos) {
|
||||||
std::ostringstream msgbuf;
|
std::ostringstream msgbuf;
|
||||||
msgbuf << "Include file '" + include + "' does not exist: " << debuginfo;
|
msgbuf << "Include file '" + include + "' does not exist: " << debuginfo;
|
||||||
BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str()));
|
BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str()));
|
||||||
|
|
Loading…
Reference in New Issue