Bugfixes.

This commit is contained in:
Gunnar Beutner 2012-06-12 10:49:30 +02:00
parent d45bcf99b1
commit 0270d9cf52
6 changed files with 60 additions and 62 deletions

View File

@ -74,13 +74,12 @@ public:
*/ */
void operator()(const TArgs& args) void operator()(const TArgs& args)
{ {
typename vector<ObserverType>::iterator i; vector<ObserverType>::size_type i = 0;
for (i = 0; i < m_Observers.size(); i++) {
for (i = m_Observers.begin(); i != m_Observers.end(); ) { int result = m_Observers[i](args);
int result = (*i)(args);
if (result == -1) if (result == -1)
i = m_Observers.erase(i); m_Observers.erase(m_Observers.begin() + i);
else else
i++; i++;
} }

View File

@ -63,6 +63,7 @@ vector<ConfigItem::Ptr> ConfigCompiler::CompileStream(istream *stream)
vector<ConfigItem::Ptr> ConfigCompiler::CompileFile(const string& filename) vector<ConfigItem::Ptr> ConfigCompiler::CompileFile(const string& filename)
{ {
ifstream stream; ifstream stream;
stream.exceptions(ifstream::badbit);
stream.open(filename, ifstream::in); stream.open(filename, ifstream::in);
return CompileStream(&stream); return CompileStream(&stream);
} }

View File

@ -1,39 +1,36 @@
{ local object application "icinga" {
"icinga": { privkey = "icinga-c1.key",
"icinga": { pubkey = "icinga-c1.crt",
"replicate": "0", cakey = "ca.crt",
"privkey": "icinga-c1.key",
"pubkey": "icinga-c1.crt", node = "10.0.10.14",
"cakey": "ca.crt", service = 7777
"node": "10.0.10.14", }
"service": "7777"
} local object component "configrpc" {
}, configSource = 1
"component": { }
"configrpc": { "replicate": "0", "configSource": "1" },
"demo": { "replicate": "0" }, local object component "demo" {
"discovery": { "replicate": "0", "broker": "1" } }
},
"host": { local object component "discovery" {
"localhost": { "node": "127.0.0.1" } broker = 1
}, }
"endpoint": {
"icinga-c2": { local object endpoint "icinga-c2" {
"replicate": "0", roles = { "demo" }
"roles": [ "demo" ] }
},
"icinga-c3": { local object endpoint "icinga-c3" {
"replicate": "0", roles = { "demo" }
"roles": [ "demo" ] }
}
}, local object role "broker" {
"role": { publications = { "discovery::NewComponent" }
"broker": { }
"publications": [ "discovery::NewComponent" ]
}, local object role "demo" {
"demo": { publications = { "demo::*" },
"publications": [ "demo::*" ], subscriptions = { "demo::*" }
"subscriptions": [ "demo::*" ]
}
}
} }

View File

@ -29,7 +29,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "icinga-app", "icinga-app\ic
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "configfile", "components\configfile\configfile.vcxproj", "{E58F1DA7-B723-412B-B2B7-7FF58E2A944E}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "configfile", "components\configfile\configfile.vcxproj", "{E58F1DA7-B723-412B-B2B7-7FF58E2A944E}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} {9C92DA90-FD53-43A9-A244-90F2E8AF9677} = {9C92DA90-FD53-43A9-A244-90F2E8AF9677}
{B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7} = {B26AFFA6-2BDF-42E6-A224-2591FFD9BFB7}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "configrpc", "components\configrpc\configrpc.vcxproj", "{697C6D7E-3109-484C-A7AF-384D28711610}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "configrpc", "components\configrpc\configrpc.vcxproj", "{697C6D7E-3109-484C-A7AF-384D28711610}"

View File

@ -52,6 +52,19 @@ int IcingaApplication::Main(const vector<string>& args)
string componentDirectory = GetExeDirectory() + "/../lib/icinga2"; string componentDirectory = GetExeDirectory() + "/../lib/icinga2";
AddComponentSearchDir(componentDirectory); AddComponentSearchDir(componentDirectory);
/* register handler for 'component' config objects */
static ConfigObject::Set::Ptr componentObjects = make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("component"));
function<int (const ObjectSetEventArgs<ConfigObject::Ptr>&)> NewComponentHandler = bind_weak(&IcingaApplication::NewComponentHandler, shared_from_this());
componentObjects->OnObjectAdded += NewComponentHandler;
componentObjects->OnObjectCommitted += NewComponentHandler;
componentObjects->OnObjectRemoved += bind_weak(&IcingaApplication::DeletedComponentHandler, shared_from_this());
componentObjects->Start();
/* load config file */
ConfigObject::Ptr fileComponentConfig = make_shared<ConfigObject>("component", "configfile");
fileComponentConfig->SetProperty("configFilename", args[1]);
fileComponentConfig->Commit();
ConfigObject::Ptr icingaConfig = ConfigObject::GetObject("application", "icinga"); ConfigObject::Ptr icingaConfig = ConfigObject::GetObject("application", "icinga");
if (!icingaConfig) if (!icingaConfig)
@ -66,19 +79,6 @@ int IcingaApplication::Main(const vector<string>& args)
icingaConfig->GetProperty("node", &m_Node); icingaConfig->GetProperty("node", &m_Node);
icingaConfig->GetProperty("service", &m_Service); icingaConfig->GetProperty("service", &m_Service);
/* register handler for 'component' config objects */
static ConfigObject::Set::Ptr componentObjects = make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("component"));
function<int (const ObjectSetEventArgs<ConfigObject::Ptr>&)> NewComponentHandler = bind_weak(&IcingaApplication::NewComponentHandler, shared_from_this());
componentObjects->OnObjectAdded += NewComponentHandler;
componentObjects->OnObjectCommitted += NewComponentHandler;
componentObjects->OnObjectRemoved += bind_weak(&IcingaApplication::DeletedComponentHandler, shared_from_this());
componentObjects->Start();
/* load config file */
ConfigObject::Ptr fileComponentConfig = make_shared<ConfigObject>("component", "configfile");
fileComponentConfig->GetProperties()->SetProperty("configFilename", args[1]);
fileComponentConfig->Commit();
if (!GetPrivateKeyFile().empty() && !GetPublicKeyFile().empty() && !GetCAKeyFile().empty()) { if (!GetPrivateKeyFile().empty() && !GetPublicKeyFile().empty() && !GetCAKeyFile().empty()) {
/* set up SSL context */ /* set up SSL context */
shared_ptr<X509> cert = Utility::GetX509Certificate(GetPublicKeyFile()); shared_ptr<X509> cert = Utility::GetX509Certificate(GetPublicKeyFile());