2012-03-31 16:29:53 +02:00
|
|
|
#include <cstdio>
|
|
|
|
#include <iostream>
|
|
|
|
#include "i2-icinga.h"
|
|
|
|
|
2012-04-01 20:04:30 +02:00
|
|
|
#ifndef _WIN32
|
2012-04-01 19:45:30 +02:00
|
|
|
# include "icinga-version.h"
|
|
|
|
# define ICINGA_VERSION GIT_MESSAGE
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
2012-03-31 16:29:53 +02:00
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
using std::cout;
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
IcingaApplication::IcingaApplication(void)
|
|
|
|
{
|
|
|
|
m_ConnectionManager = new_object<ConnectionManager>();
|
|
|
|
}
|
|
|
|
|
|
|
|
int IcingaApplication::Main(const vector<string>& args)
|
|
|
|
{
|
2012-04-01 20:04:30 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
cout << "Icinga component loader" << endl;
|
|
|
|
#else /* _WIN32 */
|
|
|
|
cout << "Icinga component loader (version: " << ICINGA_VERSION << ")" << endl;
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
2012-04-01 09:30:38 +02:00
|
|
|
GetConfigHive()->OnObjectCreated.bind(bind_weak(&IcingaApplication::ConfigObjectCreatedHandler, shared_from_this()));
|
|
|
|
GetConfigHive()->OnObjectRemoved.bind(bind_weak(&IcingaApplication::ConfigObjectRemovedHandler, shared_from_this()));
|
|
|
|
|
2012-03-31 16:29:53 +02:00
|
|
|
ConfigObject::RefType fileComponentConfig = new_object<ConfigObject>();
|
|
|
|
fileComponentConfig->SetName("configfilecomponent");
|
|
|
|
fileComponentConfig->SetType("component");
|
2012-04-01 20:04:30 +02:00
|
|
|
fileComponentConfig->SetProperty("path", "libconfigfilecomponent.la");
|
2012-03-31 16:29:53 +02:00
|
|
|
fileComponentConfig->SetProperty("filename", "icinga.conf");
|
|
|
|
GetConfigHive()->AddObject(fileComponentConfig);
|
|
|
|
|
|
|
|
RunEventLoop();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionManager::RefType IcingaApplication::GetConnectionManager(void)
|
|
|
|
{
|
|
|
|
return m_ConnectionManager;
|
|
|
|
}
|
|
|
|
|
2012-04-01 09:30:38 +02:00
|
|
|
int IcingaApplication::ConfigObjectCreatedHandler(ConfigHiveEventArgs::RefType ea)
|
|
|
|
{
|
2012-04-01 09:48:52 +02:00
|
|
|
if (ea->Object->GetType() == "component") {
|
2012-04-01 19:32:41 +02:00
|
|
|
string path;
|
|
|
|
|
|
|
|
if (!ea->Object->GetProperty("path", &path))
|
|
|
|
throw exception(/*"Missing path property"*/);
|
|
|
|
|
|
|
|
LoadComponent(path, ea->Object);
|
2012-04-01 09:30:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int IcingaApplication::ConfigObjectRemovedHandler(ConfigHiveEventArgs::RefType ea)
|
|
|
|
{
|
2012-04-01 09:48:52 +02:00
|
|
|
if (ea->Object->GetType() == "component") {
|
|
|
|
UnloadComponent(ea->Object->GetName());
|
2012-04-01 09:30:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-31 16:29:53 +02:00
|
|
|
SET_START_CLASS(icinga::IcingaApplication);
|