mirror of https://github.com/Icinga/icinga2.git
Use BOOST_FOREACH for most for loops.
This commit is contained in:
parent
9c7c039365
commit
e2bf3bd56b
|
@ -61,9 +61,9 @@ Application::~Application(void)
|
||||||
m_ShuttingDown = true;
|
m_ShuttingDown = true;
|
||||||
|
|
||||||
/* stop all components */
|
/* stop all components */
|
||||||
for (map<string, Component::Ptr>::iterator i = m_Components.begin();
|
Component::Ptr component;
|
||||||
i != m_Components.end(); i++) {
|
BOOST_FOREACH(tie(tuples::ignore, component), m_Components) {
|
||||||
i->second->Stop();
|
component->Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Components.clear();
|
m_Components.clear();
|
||||||
|
@ -243,8 +243,8 @@ string Application::GetExePath(void) const
|
||||||
boost::algorithm::split(paths, pathEnv, boost::is_any_of(":"));
|
boost::algorithm::split(paths, pathEnv, boost::is_any_of(":"));
|
||||||
|
|
||||||
bool foundPath = false;
|
bool foundPath = false;
|
||||||
for (vector<string>::iterator it = paths.begin(); it != paths.end(); it++) {
|
BOOST_FOREACH(string& path, paths) {
|
||||||
string pathTest = *it + "/" + argv0;
|
string pathTest = path + "/" + argv0;
|
||||||
|
|
||||||
if (access(pathTest.c_str(), X_OK) == 0) {
|
if (access(pathTest.c_str(), X_OK) == 0) {
|
||||||
executablePath = pathTest;
|
executablePath = pathTest;
|
||||||
|
|
|
@ -34,7 +34,6 @@ public:
|
||||||
typedef shared_ptr<Dictionary> Ptr;
|
typedef shared_ptr<Dictionary> Ptr;
|
||||||
typedef weak_ptr<Dictionary> WeakPtr;
|
typedef weak_ptr<Dictionary> WeakPtr;
|
||||||
|
|
||||||
typedef map<string, Variant>::const_iterator ConstIterator;
|
|
||||||
typedef map<string, Variant>::iterator Iterator;
|
typedef map<string, Variant>::iterator Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,7 +46,7 @@ public:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool Get(const string& key, T *value) const
|
bool Get(const string& key, T *value) const
|
||||||
{
|
{
|
||||||
ConstIterator i = m_Data.find(key);
|
map<string, Variant>::const_iterator i = m_Data.find(key);
|
||||||
|
|
||||||
if (i == m_Data.end())
|
if (i == m_Data.end())
|
||||||
return false;
|
return false;
|
||||||
|
@ -110,6 +109,33 @@ private:
|
||||||
map<string, Variant> m_Data;
|
map<string, Variant> m_Data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline Dictionary::Iterator range_begin(Dictionary::Ptr x)
|
||||||
|
{
|
||||||
|
return x->Begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Dictionary::Iterator range_end(Dictionary::Ptr x)
|
||||||
|
{
|
||||||
|
return x->End();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct range_mutable_iterator<icinga::Dictionary::Ptr>
|
||||||
|
{
|
||||||
|
typedef icinga::Dictionary::Iterator type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct range_const_iterator<icinga::Dictionary::Ptr>
|
||||||
|
{
|
||||||
|
typedef icinga::Dictionary::Iterator type;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* DICTIONARY_H */
|
#endif /* DICTIONARY_H */
|
||||||
|
|
|
@ -44,9 +44,9 @@ void Event::ProcessEvents(const system_time& wait_until)
|
||||||
events.swap(m_Events);
|
events.swap(m_Events);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<Event>::iterator it;
|
BOOST_FOREACH(const Event& ev, events) {
|
||||||
for (it = events.begin(); it != events.end(); it++)
|
ev.m_Callback();
|
||||||
it->m_Callback();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Event::Post(const function<void ()>& callback)
|
void Event::Post(const function<void ()>& callback)
|
||||||
|
|
|
@ -122,6 +122,8 @@ using std::type_info;
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
#include <boost/variant.hpp>
|
#include <boost/variant.hpp>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
#include <boost/tuple/tuple.hpp>
|
||||||
|
|
||||||
using boost::shared_ptr;
|
using boost::shared_ptr;
|
||||||
using boost::weak_ptr;
|
using boost::weak_ptr;
|
||||||
|
@ -134,6 +136,9 @@ using boost::thread_group;
|
||||||
using boost::mutex;
|
using boost::mutex;
|
||||||
using boost::condition_variable;
|
using boost::condition_variable;
|
||||||
using boost::system_time;
|
using boost::system_time;
|
||||||
|
using boost::tie;
|
||||||
|
|
||||||
|
namespace tuples = boost::tuples;
|
||||||
|
|
||||||
#if defined(__APPLE__) && defined(__MACH__)
|
#if defined(__APPLE__) && defined(__MACH__)
|
||||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
|
|
@ -93,10 +93,7 @@ LogSeverity Logger::GetMinSeverity(void) const
|
||||||
*/
|
*/
|
||||||
void Logger::ForwardLogEntry(const LogEntry& entry)
|
void Logger::ForwardLogEntry(const LogEntry& entry)
|
||||||
{
|
{
|
||||||
set<Logger::Ptr>::iterator it;
|
BOOST_FOREACH(const Logger::Ptr& logger, m_Loggers) {
|
||||||
for (it = m_Loggers.begin(); it != m_Loggers.end(); it++) {
|
|
||||||
Logger::Ptr logger = *it;
|
|
||||||
|
|
||||||
if (entry.Severity >= logger->GetMinSeverity())
|
if (entry.Severity >= logger->GetMinSeverity())
|
||||||
logger->ProcessLogEntry(entry);
|
logger->ProcessLogEntry(entry);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,9 @@ public:
|
||||||
m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectMap::ObjectCommittedHandler, this, _2));
|
m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectMap::ObjectCommittedHandler, this, _2));
|
||||||
m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectMap::ObjectRemovedHandler, this, _2));
|
m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectMap::ObjectRemovedHandler, this, _2));
|
||||||
|
|
||||||
for (typename ObjectSet<TValue>::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
|
BOOST_FOREACH(const TValue& object, m_Parent) {
|
||||||
AddObject(*it);
|
AddObject(object);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Range GetRange(TKey key)
|
Range GetRange(TKey key)
|
||||||
|
@ -60,8 +61,8 @@ public:
|
||||||
{
|
{
|
||||||
Range range = GetRange(key);
|
Range range = GetRange(key);
|
||||||
|
|
||||||
for (Iterator it = range.first; it != range.second; it++) {
|
BOOST_FOREACH(const TValue& object, range) {
|
||||||
callback(GetSelf(), *it);
|
callback(GetSelf(), object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,16 +84,16 @@ private:
|
||||||
{
|
{
|
||||||
TKey key;
|
TKey key;
|
||||||
if (!m_KeyGetter(object, &key))
|
if (!m_KeyGetter(object, &key))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pair<Iterator, Iterator> range = GetRange(key);
|
pair<Iterator, Iterator> range = GetRange(key);
|
||||||
|
|
||||||
for (Iterator i = range.first; i != range.second; i++) {
|
for (Iterator i = range.first; i != range.second; i++) {
|
||||||
if (i->second == object) {
|
if (i->second == object) {
|
||||||
m_Objects.erase(i);
|
m_Objects.erase(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckObject(const TValue& object)
|
void CheckObject(const TValue& object)
|
||||||
|
@ -117,6 +118,35 @@ private:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename TKey, typename TValue>
|
||||||
|
typename ObjectMap<TKey, TValue>::Iterator range_begin(typename ObjectMap<TKey, TValue>::Ptr x)
|
||||||
|
{
|
||||||
|
return x->Begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename TKey, typename TValue>
|
||||||
|
typename ObjectSet<TValue>::Iterator range_end(typename ObjectMap<TKey, TValue>::Ptr x)
|
||||||
|
{
|
||||||
|
return x->End();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
|
||||||
|
template<typename TKey, typename TValue>
|
||||||
|
struct range_mutable_iterator<shared_ptr<icinga::ObjectMap<TKey, TValue> > >
|
||||||
|
{
|
||||||
|
typedef typename shared_ptr<icinga::ObjectMap<TKey, TValue> >::Iterator type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename TKey, typename TValue>
|
||||||
|
struct range_const_iterator<shared_ptr<icinga::ObjectMap<TKey, TValue> > >
|
||||||
|
{
|
||||||
|
typedef typename shared_ptr<icinga::ObjectMap<TKey, TValue> > type;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* OBJECTMAP_H */
|
#endif /* OBJECTMAP_H */
|
||||||
|
|
|
@ -47,9 +47,10 @@ public:
|
||||||
m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _2));
|
m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _2));
|
||||||
m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectSet::ObjectRemovedHandler, this, _2));
|
m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectSet::ObjectRemovedHandler, this, _2));
|
||||||
|
|
||||||
for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
|
BOOST_FOREACH(const TValue& object, m_Parent) {
|
||||||
CheckObject(*it);
|
CheckObject(object);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddObject(const TValue& object)
|
void AddObject(const TValue& object)
|
||||||
|
@ -102,8 +103,8 @@ public:
|
||||||
|
|
||||||
void ForeachObject(function<void (const typename Object::Ptr&, const TValue&)> callback)
|
void ForeachObject(function<void (const typename Object::Ptr&, const TValue&)> callback)
|
||||||
{
|
{
|
||||||
for (Iterator it = Begin(); it != End(); it++) {
|
BOOST_FOREACH(const TValue& object, m_Objects) {
|
||||||
callback(GetSelf(), *it);
|
callback(GetSelf(), object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,6 +125,35 @@ private:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename TValue>
|
||||||
|
typename ObjectSet<TValue>::Iterator range_begin(shared_ptr<ObjectSet<TValue> > x)
|
||||||
|
{
|
||||||
|
return x->Begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename TValue>
|
||||||
|
typename ObjectSet<TValue>::Iterator range_end(shared_ptr<ObjectSet<TValue> > x)
|
||||||
|
{
|
||||||
|
return x->End();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
|
||||||
|
template<typename TValue>
|
||||||
|
struct range_mutable_iterator<shared_ptr<icinga::ObjectSet<TValue> > >
|
||||||
|
{
|
||||||
|
typedef typename icinga::ObjectSet<TValue>::Iterator type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename TValue>
|
||||||
|
struct range_const_iterator<shared_ptr<icinga::ObjectSet<TValue> > >
|
||||||
|
{
|
||||||
|
typedef typename icinga::ObjectSet<TValue>::Iterator type;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* OBJECTSET_H */
|
#endif /* OBJECTSET_H */
|
||||||
|
|
|
@ -66,11 +66,12 @@ void Process::WorkerThreadProc(void)
|
||||||
|
|
||||||
FD_ZERO(&readfds);
|
FD_ZERO(&readfds);
|
||||||
|
|
||||||
for (it = tasks.begin(); it != tasks.end(); it++) {
|
int fd;
|
||||||
if (it->first > nfds)
|
BOOST_FOREACH(tie(fd, tuples::ignore), tasks);
|
||||||
nfds = it->first;
|
if (fd > nfds)
|
||||||
|
nfds = fd;
|
||||||
|
|
||||||
FD_SET(it->first, &readfds);
|
FD_SET(fd, &readfds);
|
||||||
}
|
}
|
||||||
|
|
||||||
timeval tv;
|
timeval tv;
|
||||||
|
|
|
@ -90,6 +90,7 @@
|
||||||
<ClInclude Include="i2-cib.h" />
|
<ClInclude Include="i2-cib.h" />
|
||||||
<ClInclude Include="macroprocessor.h" />
|
<ClInclude Include="macroprocessor.h" />
|
||||||
<ClInclude Include="nagioschecktask.h" />
|
<ClInclude Include="nagioschecktask.h" />
|
||||||
|
<ClInclude Include="nullchecktask.h" />
|
||||||
<ClInclude Include="service.h" />
|
<ClInclude Include="service.h" />
|
||||||
<ClInclude Include="servicegroup.h" />
|
<ClInclude Include="servicegroup.h" />
|
||||||
<ClInclude Include="servicestatusmessage.h" />
|
<ClInclude Include="servicestatusmessage.h" />
|
||||||
|
@ -106,6 +107,7 @@
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="macroprocessor.cpp" />
|
<ClCompile Include="macroprocessor.cpp" />
|
||||||
<ClCompile Include="nagioschecktask.cpp" />
|
<ClCompile Include="nagioschecktask.cpp" />
|
||||||
|
<ClCompile Include="nullchecktask.cpp" />
|
||||||
<ClCompile Include="service.cpp" />
|
<ClCompile Include="service.cpp" />
|
||||||
<ClCompile Include="servicegroup.cpp" />
|
<ClCompile Include="servicegroup.cpp" />
|
||||||
<ClCompile Include="servicestatusmessage.cpp" />
|
<ClCompile Include="servicestatusmessage.cpp" />
|
||||||
|
|
|
@ -44,6 +44,9 @@
|
||||||
<ClInclude Include="servicestatusmessage.h">
|
<ClInclude Include="servicestatusmessage.h">
|
||||||
<Filter>Headerdateien</Filter>
|
<Filter>Headerdateien</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="nullchecktask.h">
|
||||||
|
<Filter>Headerdateien</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="checkresult.cpp">
|
<ClCompile Include="checkresult.cpp">
|
||||||
|
@ -79,5 +82,8 @@
|
||||||
<ClCompile Include="i2-cib.cpp">
|
<ClCompile Include="i2-cib.cpp">
|
||||||
<Filter>Quelldateien</Filter>
|
<Filter>Quelldateien</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="nullchecktask.cpp">
|
||||||
|
<Filter>Quelldateien</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
19
cib/host.cpp
19
cib/host.cpp
|
@ -69,9 +69,9 @@ set<string> Host::GetParents(void) const
|
||||||
if (GetProperty("dependencies", &dependencies)) {
|
if (GetProperty("dependencies", &dependencies)) {
|
||||||
dependencies = Service::ResolveDependencies(*this, dependencies);
|
dependencies = Service::ResolveDependencies(*this, dependencies);
|
||||||
|
|
||||||
Dictionary::Iterator it;
|
string dependency;
|
||||||
for (it = dependencies->Begin(); it != dependencies->End(); it++) {
|
BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
|
||||||
Service service = Service::GetByName(it->second);
|
Service service = Service::GetByName(dependency);
|
||||||
|
|
||||||
string parent = service.GetHost().GetName();
|
string parent = service.GetHost().GetName();
|
||||||
|
|
||||||
|
@ -99,9 +99,9 @@ bool Host::IsReachable(void) const
|
||||||
if (GetProperty("dependencies", &dependencies)) {
|
if (GetProperty("dependencies", &dependencies)) {
|
||||||
dependencies = Service::ResolveDependencies(*this, dependencies);
|
dependencies = Service::ResolveDependencies(*this, dependencies);
|
||||||
|
|
||||||
Dictionary::Iterator it;
|
string dependency;
|
||||||
for (it = dependencies->Begin(); it != dependencies->End(); it++) {
|
BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
|
||||||
Service service = Service::GetByName(it->second);
|
Service service = Service::GetByName(dependency);
|
||||||
|
|
||||||
if (!service.IsReachable() ||
|
if (!service.IsReachable() ||
|
||||||
(service.GetState() != StateOK && service.GetState() != StateWarning)) {
|
(service.GetState() != StateOK && service.GetState() != StateWarning)) {
|
||||||
|
@ -119,9 +119,10 @@ bool Host::IsUp(void) const
|
||||||
if (GetProperty("hostchecks", &hostchecks)) {
|
if (GetProperty("hostchecks", &hostchecks)) {
|
||||||
hostchecks = Service::ResolveDependencies(*this, hostchecks);
|
hostchecks = Service::ResolveDependencies(*this, hostchecks);
|
||||||
|
|
||||||
Dictionary::Iterator it;
|
string hostcheck;
|
||||||
for (it = hostchecks->Begin(); it != hostchecks->End(); it++) {
|
BOOST_FOREACH(tie(tuples::ignore, hostcheck), hostchecks) {
|
||||||
Service service = Service::GetByName(it->second);
|
Service service = Service::GetByName(hostcheck);
|
||||||
|
|
||||||
if (service.GetState() != StateOK && service.GetState() != StateWarning) {
|
if (service.GetState() != StateOK && service.GetState() != StateWarning) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,10 +38,8 @@ string MacroProcessor::ResolveMacros(const string& str, const vector<Dictionary:
|
||||||
string value;
|
string value;
|
||||||
bool resolved = false;
|
bool resolved = false;
|
||||||
|
|
||||||
vector<Dictionary::Ptr>::const_iterator it;
|
BOOST_FOREACH(const Dictionary::Ptr& macroDict, macroDicts) {
|
||||||
for (it = macroDicts.begin(); it != macroDicts.end(); it++) {
|
if (macroDict && macroDict->Get(name, &value)) {
|
||||||
Dictionary::Ptr macros = *it;
|
|
||||||
if (macros && macros->Get(name, &value)) {
|
|
||||||
resolved = true;
|
resolved = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,10 +110,7 @@ void NagiosCheckTask::ProcessCheckOutput(CheckResult& result, const string& outp
|
||||||
vector<string> lines;
|
vector<string> lines;
|
||||||
boost::algorithm::split(lines, output, is_any_of("\r\n"));
|
boost::algorithm::split(lines, output, is_any_of("\r\n"));
|
||||||
|
|
||||||
vector<string>::iterator it;
|
BOOST_FOREACH (const string& line, lines) {
|
||||||
for (it = lines.begin(); it != lines.end(); it++) {
|
|
||||||
const string& line = *it;
|
|
||||||
|
|
||||||
string::size_type delim = line.find('|');
|
string::size_type delim = line.find('|');
|
||||||
|
|
||||||
if (!text.empty())
|
if (!text.empty())
|
||||||
|
|
|
@ -41,6 +41,6 @@ void NullCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Variant
|
||||||
|
|
||||||
void NullCheckTask::Register(void)
|
void NullCheckTask::Register(void)
|
||||||
{
|
{
|
||||||
ScriptFunction::Ptr func = boost::make_shared<ScriptFunction>(&NullCheckTask::ScriptFunc);
|
ScriptFunction::Ptr func = boost::make_shared<ScriptFunction>(&NullCheckTask::ScriptFunc);
|
||||||
ScriptFunction::Register("native::NullCheck", func);
|
ScriptFunction::Register("native::NullCheck", func);
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,14 +117,14 @@ void Service::GetDependenciesRecursive(const Dictionary::Ptr& result) const {
|
||||||
if (!dependencies)
|
if (!dependencies)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Dictionary::Iterator it;
|
string dependency;
|
||||||
for (it = dependencies->Begin(); it != dependencies->End(); it++) {
|
BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
|
||||||
if (result->Contains(it->second))
|
if (result->Contains(dependency))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
result->Set(it->second, it->second);
|
result->Set(dependency, dependency);
|
||||||
|
|
||||||
Service service = Service::GetByName(it->second);
|
Service service = Service::GetByName(dependency);
|
||||||
service.GetDependenciesRecursive(result);
|
service.GetDependenciesRecursive(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,9 +148,9 @@ bool Service::IsReachable(void) const
|
||||||
Dictionary::Ptr dependencies = boost::make_shared<Dictionary>();
|
Dictionary::Ptr dependencies = boost::make_shared<Dictionary>();
|
||||||
GetDependenciesRecursive(dependencies);
|
GetDependenciesRecursive(dependencies);
|
||||||
|
|
||||||
Dictionary::Iterator it;
|
string dependency;
|
||||||
for (it = dependencies->Begin(); it != dependencies->End(); it++) {
|
BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
|
||||||
Service service = Service::GetByName(it->second);
|
Service service = Service::GetByName(dependency);
|
||||||
|
|
||||||
/* ignore ourselves */
|
/* ignore ourselves */
|
||||||
if (service.GetName() == GetName())
|
if (service.GetName() == GetName())
|
||||||
|
@ -379,10 +379,8 @@ bool Service::IsAllowedChecker(const string& checker) const
|
||||||
if (!checkers)
|
if (!checkers)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Dictionary::Iterator it;
|
string pattern;
|
||||||
for (it = checkers->Begin(); it != checkers->End(); it++) {
|
BOOST_FOREACH(tie(tuples::ignore, pattern), checkers) {
|
||||||
string pattern = it->second;
|
|
||||||
|
|
||||||
if (Utility::Match(pattern, checker))
|
if (Utility::Match(pattern, checker))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -397,14 +395,14 @@ Dictionary::Ptr Service::ResolveDependencies(Host host, const Dictionary::Ptr& d
|
||||||
|
|
||||||
Dictionary::Ptr result = boost::make_shared<Dictionary>();
|
Dictionary::Ptr result = boost::make_shared<Dictionary>();
|
||||||
|
|
||||||
Dictionary::Iterator it;
|
string dependency;
|
||||||
for (it = dependencies->Begin(); it != dependencies->End(); it++) {
|
BOOST_FOREACH(tie(tuples::ignore, dependency), dependencies) {
|
||||||
string name;
|
string name;
|
||||||
|
|
||||||
if (services && services->Contains(it->first))
|
if (services && services->Contains(dependency))
|
||||||
name = host.GetName() + "-" + it->first;
|
name = host.GetName() + "-" + dependency;
|
||||||
else
|
else
|
||||||
name = it->first;
|
name = dependency;
|
||||||
|
|
||||||
result->Set(name, name);
|
result->Set(name, name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,9 +171,7 @@ void CIBSyncComponent::FetchObjectsHandler(const Endpoint::Ptr& sender)
|
||||||
{
|
{
|
||||||
ConfigObject::Set::Ptr allObjects = ConfigObject::GetAllObjects();
|
ConfigObject::Set::Ptr allObjects = ConfigObject::GetAllObjects();
|
||||||
|
|
||||||
for (ConfigObject::Set::Iterator ci = allObjects->Begin(); ci != allObjects->End(); ci++) {
|
BOOST_FOREACH(const ConfigObject::Ptr& object, allObjects) {
|
||||||
ConfigObject::Ptr object = *ci;
|
|
||||||
|
|
||||||
if (!ShouldReplicateObject(object))
|
if (!ShouldReplicateObject(object))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@ void CompatComponent::DumpServiceStatus(ofstream& fp, Service service)
|
||||||
state = StateUnknown;
|
state = StateUnknown;
|
||||||
|
|
||||||
fp << "servicestatus {" << "\n"
|
fp << "servicestatus {" << "\n"
|
||||||
<< "\t" << "host_name=" << service.GetHost().GetName() << "\n"
|
<< "\t" << "host_name=" << service.GetHost().GetName() << "\n"
|
||||||
<< "\t" << "service_description=" << service.GetAlias() << "\n"
|
<< "\t" << "service_description=" << service.GetAlias() << "\n"
|
||||||
<< "\t" << "check_interval=" << service.GetCheckInterval() / 60.0 << "\n"
|
<< "\t" << "check_interval=" << service.GetCheckInterval() / 60.0 << "\n"
|
||||||
<< "\t" << "retry_interval=" << service.GetRetryInterval() / 60.0 << "\n"
|
<< "\t" << "retry_interval=" << service.GetRetryInterval() / 60.0 << "\n"
|
||||||
|
@ -233,31 +233,34 @@ void CompatComponent::StatusTimerHandler(void)
|
||||||
ConfigObject::TMap::Range range;
|
ConfigObject::TMap::Range range;
|
||||||
range = ConfigObject::GetObjects("host");
|
range = ConfigObject::GetObjects("host");
|
||||||
|
|
||||||
ConfigObject::TMap::Iterator it;
|
ConfigObject::Ptr object;
|
||||||
for (it = range.first; it != range.second; it++) {
|
BOOST_FOREACH(tie(tuples::ignore, object), range) {
|
||||||
Host host = it->second;
|
Host host = object;
|
||||||
|
|
||||||
Dictionary::Ptr dict;
|
Dictionary::Ptr dict;
|
||||||
Dictionary::Iterator dt;
|
|
||||||
|
|
||||||
dict = host.GetGroups();
|
dict = host.GetGroups();
|
||||||
|
|
||||||
if (dict) {
|
if (dict) {
|
||||||
for (dt = dict->Begin(); dt != dict->End(); dt++)
|
string hostgroup;
|
||||||
hostgroups[dt->second].push_back(host.GetName());
|
BOOST_FOREACH(tie(tuples::ignore, hostgroup), dict) {
|
||||||
|
hostgroups[hostgroup].push_back(host.GetName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DumpHostStatus(statusfp, host);
|
DumpHostStatus(statusfp, host);
|
||||||
DumpHostObject(objectfp, host);
|
DumpHostObject(objectfp, host);
|
||||||
}
|
}
|
||||||
|
|
||||||
map<string, vector<string> >::iterator hgt;
|
pair<string, vector<string > > hgt;
|
||||||
for (hgt = hostgroups.begin(); hgt != hostgroups.end(); hgt++) {
|
BOOST_FOREACH(hgt, hostgroups) {
|
||||||
objectfp << "define hostgroup {" << "\n"
|
const string& name = hgt.first;
|
||||||
<< "\t" << "hostgroup_name" << "\t" << hgt->first << "\n";
|
const vector<string>& hosts = hgt.second;
|
||||||
|
|
||||||
if (HostGroup::Exists(hgt->first)) {
|
objectfp << "define hostgroup {" << "\n"
|
||||||
HostGroup hg = HostGroup::GetByName(hgt->first);
|
<< "\t" << "hostgroup_name" << "\t" << name << "\n";
|
||||||
|
|
||||||
|
if (HostGroup::Exists(name)) {
|
||||||
|
HostGroup hg = HostGroup::GetByName(name);
|
||||||
objectfp << "\t" << "alias" << "\t" << hg.GetAlias() << "\n"
|
objectfp << "\t" << "alias" << "\t" << hg.GetAlias() << "\n"
|
||||||
<< "\t" << "notes_url" << "\t" << hg.GetNotesUrl() << "\n"
|
<< "\t" << "notes_url" << "\t" << hg.GetNotesUrl() << "\n"
|
||||||
<< "\t" << "action_url" << "\t" << hg.GetActionUrl() << "\n";
|
<< "\t" << "action_url" << "\t" << hg.GetActionUrl() << "\n";
|
||||||
|
@ -265,7 +268,7 @@ void CompatComponent::StatusTimerHandler(void)
|
||||||
|
|
||||||
objectfp << "\t" << "members" << "\t";
|
objectfp << "\t" << "members" << "\t";
|
||||||
|
|
||||||
DumpStringList(objectfp, hgt->second);
|
DumpStringList(objectfp, hosts);
|
||||||
|
|
||||||
objectfp << "\n"
|
objectfp << "\n"
|
||||||
<< "}" << "\n";
|
<< "}" << "\n";
|
||||||
|
@ -275,30 +278,34 @@ void CompatComponent::StatusTimerHandler(void)
|
||||||
|
|
||||||
map<string, vector<Service> > servicegroups;
|
map<string, vector<Service> > servicegroups;
|
||||||
|
|
||||||
for (it = range.first; it != range.second; it++) {
|
BOOST_FOREACH(tie(tuples::ignore, object), range) {
|
||||||
Service service = it->second;
|
Service service = object;
|
||||||
|
|
||||||
Dictionary::Ptr dict;
|
Dictionary::Ptr dict;
|
||||||
Dictionary::Iterator dt;
|
|
||||||
|
|
||||||
dict = service.GetGroups();
|
dict = service.GetGroups();
|
||||||
|
|
||||||
if (dict) {
|
if (dict) {
|
||||||
for (dt = dict->Begin(); dt != dict->End(); dt++)
|
string servicegroup;
|
||||||
servicegroups[dt->second].push_back(service);
|
BOOST_FOREACH(tie(tuples::ignore, servicegroup), dict) {
|
||||||
|
servicegroups[servicegroup].push_back(service);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DumpServiceStatus(statusfp, service);
|
DumpServiceStatus(statusfp, service);
|
||||||
DumpServiceObject(objectfp, service);
|
DumpServiceObject(objectfp, service);
|
||||||
}
|
}
|
||||||
|
|
||||||
map<string, vector<Service > >::iterator sgt;
|
pair<string, vector<Service > > sgt;
|
||||||
for (sgt = servicegroups.begin(); sgt != servicegroups.end(); sgt++) {
|
BOOST_FOREACH(sgt, servicegroups) {
|
||||||
objectfp << "define servicegroup {" << "\n"
|
const string& name = sgt.first;
|
||||||
<< "\t" << "servicegroup_name" << "\t" << sgt->first << "\n";
|
const vector<Service>& services = sgt.second;
|
||||||
|
|
||||||
if (ServiceGroup::Exists(sgt->first)) {
|
objectfp << "define servicegroup {" << "\n"
|
||||||
ServiceGroup sg = ServiceGroup::GetByName(sgt->first);
|
<< "\t" << "servicegroup_name" << "\t" << name << "\n";
|
||||||
|
|
||||||
|
if (ServiceGroup::Exists(name)) {
|
||||||
|
ServiceGroup sg = ServiceGroup::GetByName(name);
|
||||||
objectfp << "\t" << "alias" << "\t" << sg.GetAlias() << "\n"
|
objectfp << "\t" << "alias" << "\t" << sg.GetAlias() << "\n"
|
||||||
<< "\t" << "notes_url" << "\t" << sg.GetNotesUrl() << "\n"
|
<< "\t" << "notes_url" << "\t" << sg.GetNotesUrl() << "\n"
|
||||||
<< "\t" << "action_url" << "\t" << sg.GetActionUrl() << "\n";
|
<< "\t" << "action_url" << "\t" << sg.GetActionUrl() << "\n";
|
||||||
|
@ -309,9 +316,9 @@ void CompatComponent::StatusTimerHandler(void)
|
||||||
vector<string> sglist;
|
vector<string> sglist;
|
||||||
vector<Service>::iterator vt;
|
vector<Service>::iterator vt;
|
||||||
|
|
||||||
for (vt = sgt->second.begin(); vt != sgt->second.end(); vt++) {
|
BOOST_FOREACH(const Service& service, services) {
|
||||||
sglist.push_back(vt->GetHost().GetName());
|
sglist.push_back(service.GetHost().GetName());
|
||||||
sglist.push_back(vt->GetAlias());
|
sglist.push_back(service.GetAlias());
|
||||||
}
|
}
|
||||||
|
|
||||||
DumpStringList(objectfp, sglist);
|
DumpStringList(objectfp, sglist);
|
||||||
|
|
|
@ -40,9 +40,7 @@ void ConfigFileComponent::Start(void)
|
||||||
|
|
||||||
Logger::Write(LogInformation, "configfile", "Executing config items...");
|
Logger::Write(LogInformation, "configfile", "Executing config items...");
|
||||||
|
|
||||||
vector<ConfigItem::Ptr>::iterator it;
|
BOOST_FOREACH(const ConfigItem::Ptr& item, configItems) {
|
||||||
for (it = configItems.begin(); it != configItems.end(); it++) {
|
|
||||||
ConfigItem::Ptr item = *it;
|
|
||||||
item->Commit();
|
item->Commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,11 +111,9 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
|
||||||
host->GetProperty("services", &serviceDescs);
|
host->GetProperty("services", &serviceDescs);
|
||||||
|
|
||||||
if (serviceDescs) {
|
if (serviceDescs) {
|
||||||
Dictionary::Iterator it;
|
string svcname;
|
||||||
for (it = serviceDescs->Begin(); it != serviceDescs->End(); it++) {
|
Variant svcdesc;
|
||||||
string svcname = it->first;
|
BOOST_FOREACH(tie(svcname, svcdesc), serviceDescs) {
|
||||||
Variant svcdesc = it->second;
|
|
||||||
|
|
||||||
stringstream namebuf;
|
stringstream namebuf;
|
||||||
namebuf << item->GetName() << "-" << svcname;
|
namebuf << item->GetName() << "-" << svcname;
|
||||||
string name = namebuf.str();
|
string name = namebuf.str();
|
||||||
|
@ -152,10 +150,8 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldServices) {
|
if (oldServices) {
|
||||||
Dictionary::Iterator it;
|
ConfigItem::Ptr service;
|
||||||
for (it = oldServices->Begin(); it != oldServices->End(); it++) {
|
BOOST_FOREACH(tie(tuples::ignore, service), oldServices) {
|
||||||
ConfigItem::Ptr service = it->second;
|
|
||||||
|
|
||||||
if (!newServices->Contains(service->GetName()))
|
if (!newServices->Contains(service->GetName()))
|
||||||
service->Unregister();
|
service->Unregister();
|
||||||
}
|
}
|
||||||
|
@ -180,9 +176,8 @@ void ConvenienceComponent::HostRemovedHandler(const ConfigItem::Ptr& item)
|
||||||
if (!services)
|
if (!services)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Dictionary::Iterator it;
|
ConfigItem::Ptr service;
|
||||||
for (it = services->Begin(); it != services->End(); it++) {
|
BOOST_FOREACH(tie(tuples::ignore, service), services) {
|
||||||
ConfigItem::Ptr service = it->second;
|
|
||||||
service->Unregister();
|
service->Unregister();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,9 +161,8 @@ void DelegationComponent::SessionEstablishedHandler(const Endpoint::Ptr& endpoin
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* locally clear checker for all services that previously belonged to this endpoint */
|
/* locally clear checker for all services that previously belonged to this endpoint */
|
||||||
ConfigObject::Set::Iterator it;
|
BOOST_FOREACH(const ConfigObject::Ptr& object, m_AllServices) {
|
||||||
for (it = m_AllServices->Begin(); it != m_AllServices->End(); it++) {
|
Service service = object;
|
||||||
Service service = *it;
|
|
||||||
|
|
||||||
if (service.GetChecker() == endpoint->GetIdentity())
|
if (service.GetChecker() == endpoint->GetIdentity())
|
||||||
service.SetChecker("");
|
service.SetChecker("");
|
||||||
|
@ -184,9 +183,8 @@ void DelegationComponent::DelegationTimerHandler(void)
|
||||||
vector<Service> services;
|
vector<Service> services;
|
||||||
|
|
||||||
/* build "checker -> service count" histogram */
|
/* build "checker -> service count" histogram */
|
||||||
ConfigObject::Set::Iterator it;
|
BOOST_FOREACH(const ConfigObject::Ptr& object, m_AllServices) {
|
||||||
for (it = m_AllServices->Begin(); it != m_AllServices->End(); it++) {
|
Service service = object;
|
||||||
Service service = *it;
|
|
||||||
|
|
||||||
services.push_back(service);
|
services.push_back(service);
|
||||||
|
|
||||||
|
@ -207,10 +205,7 @@ void DelegationComponent::DelegationTimerHandler(void)
|
||||||
int delegated = 0;
|
int delegated = 0;
|
||||||
|
|
||||||
/* re-assign services */
|
/* re-assign services */
|
||||||
vector<Service>::iterator sit;
|
BOOST_FOREACH(Service& service, services) {
|
||||||
for (sit = services.begin(); sit != services.end(); sit++) {
|
|
||||||
Service service = *sit;
|
|
||||||
|
|
||||||
string checker = service.GetChecker();
|
string checker = service.GetChecker();
|
||||||
|
|
||||||
Endpoint::Ptr oldEndpoint;
|
Endpoint::Ptr oldEndpoint;
|
||||||
|
@ -229,8 +224,9 @@ void DelegationComponent::DelegationTimerHandler(void)
|
||||||
msgbuf << "Service: " << service.GetName() << ", candidates: " << candidates.size();
|
msgbuf << "Service: " << service.GetName() << ", candidates: " << candidates.size();
|
||||||
Logger::Write(LogDebug, "delegation", msgbuf.str());
|
Logger::Write(LogDebug, "delegation", msgbuf.str());
|
||||||
|
|
||||||
for (cit = candidates.begin(); cit != candidates.end(); cit++)
|
BOOST_FOREACH(const Endpoint::Ptr& candidate, candidates) {
|
||||||
avg_services += histogram[*cit];
|
avg_services += histogram[candidate];
|
||||||
|
}
|
||||||
|
|
||||||
avg_services /= candidates.size();
|
avg_services /= candidates.size();
|
||||||
overflow_tolerance = candidates.size() * 2;
|
overflow_tolerance = candidates.size() * 2;
|
||||||
|
@ -253,15 +249,13 @@ void DelegationComponent::DelegationTimerHandler(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find a new checker for the service */
|
/* find a new checker for the service */
|
||||||
for (cit = candidates.begin(); cit != candidates.end(); cit++) {
|
BOOST_FOREACH(const Endpoint::Ptr& candidate, candidates) {
|
||||||
Endpoint::Ptr newEndpoint = *cit;
|
|
||||||
|
|
||||||
/* does this checker already have too many services */
|
/* does this checker already have too many services */
|
||||||
if (histogram[newEndpoint] > avg_services)
|
if (histogram[candidate] > avg_services)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
service.SetChecker(newEndpoint->GetIdentity());
|
service.SetChecker(candidate->GetIdentity());
|
||||||
histogram[newEndpoint]++;
|
histogram[candidate]++;
|
||||||
|
|
||||||
delegated++;
|
delegated++;
|
||||||
|
|
||||||
|
@ -271,29 +265,30 @@ void DelegationComponent::DelegationTimerHandler(void)
|
||||||
assert(candidates.size() == 0 || !service.GetChecker().empty());
|
assert(candidates.size() == 0 || !service.GetChecker().empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
map<Endpoint::Ptr, int>::iterator hit;
|
Endpoint::Ptr endpoint;
|
||||||
for (hit = histogram.begin(); hit != histogram.end(); hit++) {
|
int count;
|
||||||
|
BOOST_FOREACH(tie(endpoint, count), histogram) {
|
||||||
stringstream msgbuf;
|
stringstream msgbuf;
|
||||||
msgbuf << "histogram: " << hit->first->GetIdentity() << " - " << hit->second;
|
msgbuf << "histogram: " << endpoint->GetIdentity() << " - " << count;
|
||||||
Logger::Write(LogInformation, "delegation", msgbuf.str());
|
Logger::Write(LogInformation, "delegation", msgbuf.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delegated > 0) {
|
if (delegated > 0) {
|
||||||
if (need_clear) {
|
if (need_clear) {
|
||||||
map<Endpoint::Ptr, int>::iterator hit;
|
Endpoint::Ptr endpoint;
|
||||||
for (hit = histogram.begin(); hit != histogram.end(); hit++) {
|
BOOST_FOREACH(tie(endpoint, tuples::ignore), histogram) {
|
||||||
ClearServices(hit->first);
|
ClearServices(endpoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (sit = services.begin(); sit != services.end(); sit++) {
|
BOOST_FOREACH(Service& service, services) {
|
||||||
string checker = sit->GetChecker();
|
string checker = service.GetChecker();
|
||||||
Endpoint::Ptr endpoint = EndpointManager::GetInstance()->GetEndpointByIdentity(checker);
|
Endpoint::Ptr endpoint = EndpointManager::GetInstance()->GetEndpointByIdentity(checker);
|
||||||
|
|
||||||
if (!endpoint)
|
if (!endpoint)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
AssignService(endpoint, *sit);
|
AssignService(endpoint, service);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,12 +168,13 @@ void DiscoveryComponent::NewEndpointHandler(const Endpoint::Ptr& endpoint)
|
||||||
|
|
||||||
// register published/subscribed topics for this endpoint
|
// register published/subscribed topics for this endpoint
|
||||||
ComponentDiscoveryInfo::Ptr info = ic->second;
|
ComponentDiscoveryInfo::Ptr info = ic->second;
|
||||||
set<string>::iterator it;
|
BOOST_FOREACH(string publication, info->Publications) {
|
||||||
for (it = info->Publications.begin(); it != info->Publications.end(); it++)
|
endpoint->RegisterPublication(publication);
|
||||||
endpoint->RegisterPublication(*it);
|
}
|
||||||
|
|
||||||
for (it = info->Subscriptions.begin(); it != info->Subscriptions.end(); it++)
|
BOOST_FOREACH(string subscription, info->Subscriptions) {
|
||||||
endpoint->RegisterSubscription(*it);
|
endpoint->RegisterSubscription(subscription);
|
||||||
|
}
|
||||||
|
|
||||||
FinishDiscoverySetup(endpoint);
|
FinishDiscoverySetup(endpoint);
|
||||||
}
|
}
|
||||||
|
@ -299,15 +300,17 @@ void DiscoveryComponent::SendDiscoveryMessage(const string& method, const string
|
||||||
}
|
}
|
||||||
|
|
||||||
set<string>::iterator i;
|
set<string>::iterator i;
|
||||||
MessagePart subscriptions;
|
Dictionary::Ptr subscriptions = boost::make_shared<Dictionary>();
|
||||||
for (i = info->Subscriptions.begin(); i != info->Subscriptions.end(); i++)
|
BOOST_FOREACH(string subscription, info->Subscriptions) {
|
||||||
subscriptions.Add(*i);
|
subscriptions->Add(subscription);
|
||||||
|
}
|
||||||
|
|
||||||
params.SetSubscriptions(subscriptions);
|
params.SetSubscriptions(subscriptions);
|
||||||
|
|
||||||
MessagePart publications;
|
Dictionary::Ptr publications = boost::make_shared<Dictionary>();
|
||||||
for (i = info->Publications.begin(); i != info->Publications.end(); i++)
|
BOOST_FOREACH(string publication, info->Publications) {
|
||||||
publications.Add(*i);
|
publications->Add(publication);
|
||||||
|
}
|
||||||
|
|
||||||
params.SetPublications(publications);
|
params.SetPublications(publications);
|
||||||
|
|
||||||
|
@ -324,15 +327,15 @@ bool DiscoveryComponent::HasMessagePermission(const Dictionary::Ptr& roles, cons
|
||||||
|
|
||||||
ConfigObject::TMap::Range range = ConfigObject::GetObjects("role");
|
ConfigObject::TMap::Range range = ConfigObject::GetObjects("role");
|
||||||
|
|
||||||
for (ConfigObject::TMap::Iterator ip = range.first; ip != range.second; ip++) {
|
ConfigObject::Ptr role;
|
||||||
ConfigObject::Ptr role = ip->second;
|
BOOST_FOREACH(tie(tuples::ignore, role), range) {
|
||||||
|
|
||||||
Dictionary::Ptr permissions;
|
Dictionary::Ptr permissions;
|
||||||
if (!role->GetProperty(messageType, &permissions))
|
if (!role->GetProperty(messageType, &permissions))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (Dictionary::Iterator is = permissions->Begin(); is != permissions->End(); is++) {
|
string permission;
|
||||||
if (Utility::Match(is->second, message))
|
BOOST_FOREACH(tie(tuples::ignore, permission), permissions) {
|
||||||
|
if (Utility::Match(permission, message))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -373,26 +376,26 @@ void DiscoveryComponent::ProcessDiscoveryMessage(const string& identity, const D
|
||||||
|
|
||||||
Endpoint::Ptr endpoint = EndpointManager::GetInstance()->GetEndpointByIdentity(identity);
|
Endpoint::Ptr endpoint = EndpointManager::GetInstance()->GetEndpointByIdentity(identity);
|
||||||
|
|
||||||
MessagePart publications;
|
Dictionary::Ptr publications;
|
||||||
if (message.GetPublications(&publications)) {
|
if (message.GetPublications(&publications)) {
|
||||||
Dictionary::Iterator i;
|
string publication;
|
||||||
for (i = publications.Begin(); i != publications.End(); i++) {
|
BOOST_FOREACH(tie(tuples::ignore, publication), publications) {
|
||||||
if (trusted || HasMessagePermission(roles, "publications", i->second)) {
|
if (trusted || HasMessagePermission(roles, "publications", publication)) {
|
||||||
info->Publications.insert(i->second);
|
info->Publications.insert(publication);
|
||||||
if (endpoint)
|
if (endpoint)
|
||||||
endpoint->RegisterPublication(i->second);
|
endpoint->RegisterPublication(publication);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MessagePart subscriptions;
|
Dictionary::Ptr subscriptions;
|
||||||
if (message.GetSubscriptions(&subscriptions)) {
|
if (message.GetSubscriptions(&subscriptions)) {
|
||||||
Dictionary::Iterator i;
|
string subscription;
|
||||||
for (i = subscriptions.Begin(); i != subscriptions.End(); i++) {
|
BOOST_FOREACH(tie(tuples::ignore, subscription), subscriptions) {
|
||||||
if (trusted || HasMessagePermission(roles, "subscriptions", i->second)) {
|
if (trusted || HasMessagePermission(roles, "subscriptions", subscription)) {
|
||||||
info->Subscriptions.insert(i->second);
|
info->Subscriptions.insert(subscription);
|
||||||
if (endpoint)
|
if (endpoint)
|
||||||
endpoint->RegisterSubscription(i->second);
|
endpoint->RegisterSubscription(subscription);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -456,9 +459,8 @@ void DiscoveryComponent::DiscoveryTimerHandler(void)
|
||||||
/* check whether we have to reconnect to one of our upstream endpoints */
|
/* check whether we have to reconnect to one of our upstream endpoints */
|
||||||
ConfigObject::TMap::Range range = ConfigObject::GetObjects("endpoint");
|
ConfigObject::TMap::Range range = ConfigObject::GetObjects("endpoint");
|
||||||
|
|
||||||
for (ConfigObject::TMap::Iterator it = range.first; it != range.second; it++) {
|
ConfigObject::Ptr object;
|
||||||
ConfigObject::Ptr object = it->second;
|
BOOST_FOREACH(tie(tuples::ignore, object), range) {
|
||||||
|
|
||||||
/* Check if we're already connected to this endpoint. */
|
/* Check if we're already connected to this endpoint. */
|
||||||
if (endpointManager->GetEndpointByIdentity(object->GetName()))
|
if (endpointManager->GetEndpointByIdentity(object->GetName()))
|
||||||
continue;
|
continue;
|
||||||
|
@ -472,8 +474,8 @@ void DiscoveryComponent::DiscoveryTimerHandler(void)
|
||||||
|
|
||||||
map<string, ComponentDiscoveryInfo::Ptr>::iterator curr, i;
|
map<string, ComponentDiscoveryInfo::Ptr>::iterator curr, i;
|
||||||
for (i = m_Components.begin(); i != m_Components.end(); ) {
|
for (i = m_Components.begin(); i != m_Components.end(); ) {
|
||||||
string identity = i->first;
|
const string& identity = i->first;
|
||||||
ComponentDiscoveryInfo::Ptr info = i->second;
|
const ComponentDiscoveryInfo::Ptr& info = i->second;
|
||||||
|
|
||||||
curr = i;
|
curr = i;
|
||||||
i++;
|
i++;
|
||||||
|
|
|
@ -59,22 +59,22 @@ void DiscoveryMessage::SetService(const string& value)
|
||||||
Set("service", value);
|
Set("service", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DiscoveryMessage::GetSubscriptions(MessagePart *value) const
|
bool DiscoveryMessage::GetSubscriptions(Dictionary::Ptr *value) const
|
||||||
{
|
{
|
||||||
return Get("subscriptions", value);
|
return Get("subscriptions", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiscoveryMessage::SetSubscriptions(MessagePart value)
|
void DiscoveryMessage::SetSubscriptions(const Dictionary::Ptr& value)
|
||||||
{
|
{
|
||||||
Set("subscriptions", value);
|
Set("subscriptions", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DiscoveryMessage::GetPublications(MessagePart *value) const
|
bool DiscoveryMessage::GetPublications(Dictionary::Ptr *value) const
|
||||||
{
|
{
|
||||||
return Get("publications", value);
|
return Get("publications", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiscoveryMessage::SetPublications(MessagePart value)
|
void DiscoveryMessage::SetPublications(const Dictionary::Ptr& value)
|
||||||
{
|
{
|
||||||
Set("publications", value);
|
Set("publications", value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,11 +41,11 @@ public:
|
||||||
bool GetService(string *value) const;
|
bool GetService(string *value) const;
|
||||||
void SetService(const string& value);
|
void SetService(const string& value);
|
||||||
|
|
||||||
bool GetSubscriptions(MessagePart *value) const;
|
bool GetSubscriptions(Dictionary::Ptr *value) const;
|
||||||
void SetSubscriptions(MessagePart value);
|
void SetSubscriptions(const Dictionary::Ptr& value);
|
||||||
|
|
||||||
bool GetPublications(MessagePart *value) const;
|
bool GetPublications(Dictionary::Ptr *value) const;
|
||||||
void SetPublications(MessagePart value);
|
void SetPublications(const Dictionary::Ptr& value);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ void *ConfigCompiler::GetScanner(void) const
|
||||||
|
|
||||||
vector<ConfigItem::Ptr> ConfigCompiler::GetResult(void) const
|
vector<ConfigItem::Ptr> ConfigCompiler::GetResult(void) const
|
||||||
{
|
{
|
||||||
return m_Result;
|
return m_Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string ConfigCompiler::GetPath(void) const
|
string ConfigCompiler::GetPath(void) const
|
||||||
|
|
|
@ -56,13 +56,12 @@ vector<string> ConfigItem::GetParents(void) const
|
||||||
|
|
||||||
void ConfigItem::CalculateProperties(Dictionary::Ptr dictionary) const
|
void ConfigItem::CalculateProperties(Dictionary::Ptr dictionary) const
|
||||||
{
|
{
|
||||||
vector<string>::const_iterator it;
|
BOOST_FOREACH(const string& name, m_Parents) {
|
||||||
for (it = m_Parents.begin(); it != m_Parents.end(); it++) {
|
ConfigItem::Ptr parent = ConfigItem::GetObject(GetType(), name);
|
||||||
ConfigItem::Ptr parent = ConfigItem::GetObject(GetType(), *it);
|
|
||||||
|
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << "Parent object '" << *it << "' does not exist (" << m_DebugInfo << ")";
|
message << "Parent object '" << name << "' does not exist (" << m_DebugInfo << ")";
|
||||||
throw domain_error(message.str());
|
throw domain_error(message.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,12 +75,12 @@ ConfigItem::Set::Ptr ConfigItem::GetAllObjects(void)
|
||||||
{
|
{
|
||||||
static ObjectSet<ConfigItem::Ptr>::Ptr allObjects;
|
static ObjectSet<ConfigItem::Ptr>::Ptr allObjects;
|
||||||
|
|
||||||
if (!allObjects) {
|
if (!allObjects) {
|
||||||
allObjects = boost::make_shared<ObjectSet<ConfigItem::Ptr> >();
|
allObjects = boost::make_shared<ObjectSet<ConfigItem::Ptr> >();
|
||||||
allObjects->Start();
|
allObjects->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
return allObjects;
|
return allObjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigItem::GetTypeAndName(const ConfigItem::Ptr& object, pair<string, string> *key)
|
bool ConfigItem::GetTypeAndName(const ConfigItem::Ptr& object, pair<string, string> *key)
|
||||||
|
|
|
@ -81,9 +81,10 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const
|
||||||
if (valueExprl) {
|
if (valueExprl) {
|
||||||
valueExprl->Execute(dict);
|
valueExprl->Execute(dict);
|
||||||
} else if (valueDict) {
|
} else if (valueDict) {
|
||||||
Dictionary::Iterator it;
|
string key;
|
||||||
for (it = valueDict->Begin(); it != valueDict->End(); it++) {
|
Variant value;
|
||||||
dict->Set(it->first, it->second);
|
BOOST_FOREACH(tie(key, value), valueDict) {
|
||||||
|
dict->Set(key, value);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stringstream message;
|
stringstream message;
|
||||||
|
|
|
@ -21,10 +21,6 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
ExpressionList::ExpressionList(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExpressionList::AddExpression(const Expression& expression)
|
void ExpressionList::AddExpression(const Expression& expression)
|
||||||
{
|
{
|
||||||
m_Expressions.push_back(expression);
|
m_Expressions.push_back(expression);
|
||||||
|
@ -37,9 +33,7 @@ size_t ExpressionList::GetLength(void) const
|
||||||
|
|
||||||
void ExpressionList::Execute(const Dictionary::Ptr& dictionary) const
|
void ExpressionList::Execute(const Dictionary::Ptr& dictionary) const
|
||||||
{
|
{
|
||||||
vector<Expression>::const_iterator it;
|
BOOST_FOREACH(const Expression& expression, m_Expressions) {
|
||||||
|
expression.Execute(dictionary);
|
||||||
for (it = m_Expressions.begin(); it != m_Expressions.end(); it++) {
|
|
||||||
it->Execute(dictionary);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,17 +29,12 @@ public:
|
||||||
typedef shared_ptr<ExpressionList> Ptr;
|
typedef shared_ptr<ExpressionList> Ptr;
|
||||||
typedef weak_ptr<ExpressionList> WeakPtr;
|
typedef weak_ptr<ExpressionList> WeakPtr;
|
||||||
|
|
||||||
ExpressionList(void);
|
|
||||||
// ExpressionList(Dictionary::Ptr serializedDictionary);
|
|
||||||
|
|
||||||
void AddExpression(const Expression& expression);
|
void AddExpression(const Expression& expression);
|
||||||
|
|
||||||
void Execute(const Dictionary::Ptr& dictionary) const;
|
void Execute(const Dictionary::Ptr& dictionary) const;
|
||||||
|
|
||||||
size_t GetLength(void) const;
|
size_t GetLength(void) const;
|
||||||
|
|
||||||
// Dictionary::Ptr Serialize(void);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vector<Expression> m_Expressions;
|
vector<Expression> m_Expressions;
|
||||||
};
|
};
|
||||||
|
|
|
@ -240,10 +240,8 @@ void EndpointManager::SendAnycastMessage(Endpoint::Ptr sender,
|
||||||
throw invalid_argument("Message is missing the 'method' property.");
|
throw invalid_argument("Message is missing the 'method' property.");
|
||||||
|
|
||||||
vector<Endpoint::Ptr> candidates;
|
vector<Endpoint::Ptr> candidates;
|
||||||
for (map<string, Endpoint::Ptr>::iterator i = m_Endpoints.begin(); i != m_Endpoints.end(); i++)
|
Endpoint::Ptr endpoint;
|
||||||
{
|
BOOST_FOREACH(tie(tuples::ignore, endpoint), m_Endpoints) {
|
||||||
Endpoint::Ptr endpoint = i->second;
|
|
||||||
|
|
||||||
/* don't forward messages between non-local endpoints */
|
/* don't forward messages between non-local endpoints */
|
||||||
if (!sender->IsLocal() && !endpoint->IsLocal())
|
if (!sender->IsLocal() && !endpoint->IsLocal())
|
||||||
continue;
|
continue;
|
||||||
|
@ -277,11 +275,8 @@ void EndpointManager::SendMulticastMessage(Endpoint::Ptr sender,
|
||||||
if (!message.GetMethod(&method))
|
if (!message.GetMethod(&method))
|
||||||
throw invalid_argument("Message is missing the 'method' property.");
|
throw invalid_argument("Message is missing the 'method' property.");
|
||||||
|
|
||||||
map<string, Endpoint::Ptr>::iterator i;
|
Endpoint::Ptr recipient;
|
||||||
for (i = m_Endpoints.begin(); i != m_Endpoints.end(); i++)
|
BOOST_FOREACH(tie(tuples::ignore, recipient), m_Endpoints) {
|
||||||
{
|
|
||||||
Endpoint::Ptr recipient = i->second;
|
|
||||||
|
|
||||||
/* don't forward messages back to the sender */
|
/* don't forward messages back to the sender */
|
||||||
if (sender == recipient)
|
if (sender == recipient)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -48,16 +48,11 @@ void JsonRpcClient::SendMessage(const MessagePart& message)
|
||||||
*/
|
*/
|
||||||
void JsonRpcClient::DataAvailableHandler(void)
|
void JsonRpcClient::DataAvailableHandler(void)
|
||||||
{
|
{
|
||||||
for (;;) {
|
string jsonString;
|
||||||
string jsonString;
|
|
||||||
MessagePart message;
|
|
||||||
|
|
||||||
if (!Netstring::ReadStringFromIOQueue(this, &jsonString))
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
while (Netstring::ReadStringFromIOQueue(this, &jsonString)) {
|
||||||
try {
|
try {
|
||||||
message = MessagePart(jsonString);
|
OnNewMessage(GetSelf(), MessagePart(jsonString));
|
||||||
OnNewMessage(GetSelf(), message);
|
|
||||||
} catch (const exception& ex) {
|
} catch (const exception& ex) {
|
||||||
Logger::Write(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + string(ex.what()));
|
Logger::Write(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + string(ex.what()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue