libchecker_la_CPPFLAGS = \
$(BOOST_CPPFLAGS) \
- -I${top_srcdir}/lib/base \
- -I${top_srcdir}/lib/config \
- -I${top_srcdir}/lib/remoting \
- -I${top_srcdir}/lib/icinga
+ -I${top_srcdir}/lib \
+ -I${top_srcdir}/components
libchecker_la_LDFLAGS = \
$(BOOST_LDFLAGS) \
******************************************************************************/
#include "i2-checker.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
+#include <boost/exception/diagnostic_information.hpp>
using namespace icinga;
boost::mutex::scoped_lock lock(m_Mutex);
for (;;) {
- typedef nth_index<ServiceSet, 1>::type CheckTimeView;
+ typedef boost::multi_index::nth_index<ServiceSet, 1>::type CheckTimeView;
CheckTimeView& idx = boost::get<1>(m_IdleServices);
while (idx.begin() == idx.end() && !m_Stopped)
if (!service->GetForceNextCheck()) {
if (!service->GetEnableActiveChecks()) {
- Logger::Write(LogDebug, "checker", "Skipping check for service '" + service->GetName() + "': active checks are disabled");
+ Log(LogDebug, "checker", "Skipping check for service '" + service->GetName() + "': active checks are disabled");
check = false;
}
TimePeriod::Ptr tp = service->GetCheckPeriod();
if (tp && !tp->IsInside(Utility::GetTime())) {
- Logger::Write(LogDebug, "checker", "Skipping check for service '" + service->GetName() + "': not in check_period");
+ Log(LogDebug, "checker", "Skipping check for service '" + service->GetName() + "': not in check_period");
check = false;
}
}
if (!check) {
service->UpdateNextCheck();
- typedef nth_index<ServiceSet, 1>::type CheckTimeView;
+ typedef boost::multi_index::nth_index<ServiceSet, 1>::type CheckTimeView;
CheckTimeView& idx = boost::get<1>(m_IdleServices);
idx.insert(service);
service->SetForceNextCheck(false);
}
- Logger::Write(LogDebug, "checker", "Executing service check for '" + service->GetName() + "'");
+ Log(LogDebug, "checker", "Executing service check for '" + service->GetName() + "'");
try {
CheckerComponent::Ptr self = GetSelf();
service->BeginExecuteCheck(boost::bind(&CheckerComponent::CheckCompletedHandler, self, service));
- } catch (const exception& ex) {
- Logger::Write(LogCritical, "checker", "Exception occured while checking service '" + service->GetName() + "': " + diagnostic_information(ex));
+ } catch (const std::exception& ex) {
+ Log(LogCritical, "checker", "Exception occured while checking service '" + service->GetName() + "': " + boost::diagnostic_information(ex));
}
lock.lock();
m_CV.notify_all();
}
- Logger::Write(LogDebug, "checker", "Check finished for service '" + service->GetName() + "'");
+ Log(LogDebug, "checker", "Check finished for service '" + service->GetName() + "'");
}
void CheckerComponent::ResultTimerHandler(void)
{
- Logger::Write(LogDebug, "checker", "ResultTimerHandler entered.");
+ Log(LogDebug, "checker", "ResultTimerHandler entered.");
- stringstream msgbuf;
+ std::ostringstream msgbuf;
{
boost::mutex::scoped_lock lock(m_Mutex);
msgbuf << "Pending services: " << m_PendingServices.size() << "; Idle services: " << m_IdleServices.size();
}
- Logger::Write(LogInformation, "checker", msgbuf.str());
+ Log(LogInformation, "checker", msgbuf.str());
}
void CheckerComponent::CheckerChangedHandler(const Service::Ptr& service)
boost::mutex::scoped_lock lock(m_Mutex);
/* remove and re-insert the service from the set in order to force an index update */
- typedef nth_index<ServiceSet, 0>::type ServiceView;
+ typedef boost::multi_index::nth_index<ServiceSet, 0>::type ServiceView;
ServiceView& idx = boost::get<0>(m_IdleServices);
ServiceView::iterator it = idx.find(service);
#ifndef CHECKERCOMPONENT_H
#define CHECKERCOMPONENT_H
+#include "base/dynamicobject.h"
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/ordered_index.hpp>
+#include <boost/multi_index/key_extractors.hpp>
+
namespace icinga
{
typedef shared_ptr<CheckerComponent> Ptr;
typedef weak_ptr<CheckerComponent> WeakPtr;
- typedef multi_index_container<
+ typedef boost::multi_index_container<
Service::Ptr,
- indexed_by<
- ordered_unique<identity<Service::Ptr> >,
- ordered_non_unique<ServiceNextCheckExtractor>
+ boost::multi_index::indexed_by<
+ boost::multi_index::ordered_unique<boost::multi_index::identity<Service::Ptr> >,
+ boost::multi_index::ordered_non_unique<ServiceNextCheckExtractor>
>
> ServiceSet;
* The Checker component executes service checks.
*/
-#include <i2-base.h>
-#include <i2-icinga.h>
+#include "base/i2-base.h"
+#include "icinga/i2-icinga.h"
-#include "checkercomponent.h"
+#include "checker/checkercomponent.h"
#endif /* I2CHECKER_H */
libcompat_la_CPPFLAGS = \
$(BOOST_CPPFLAGS) \
- -I${top_srcdir}/lib/base \
- -I${top_srcdir}/lib/config \
- -I${top_srcdir}/lib/remoting \
- -I${top_srcdir}/lib/icinga
+ -I${top_srcdir}/lib \
+ -I${top_srcdir}/components
libcompat_la_LDFLAGS = \
$(BOOST_LDFLAGS) \
******************************************************************************/
#include "i2-compat.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
+#include "base/exception.h"
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
+#include <boost/exception/diagnostic_information.hpp>
using namespace icinga;
String command = line;
try {
- Logger::Write(LogInformation, "compat", "Executing external command: " + command);
+ Log(LogInformation, "compat", "Executing external command: " + command);
ExternalCommandProcessor::Execute(command);
- } catch (const exception& ex) {
- stringstream msgbuf;
- msgbuf << "External command failed: " << diagnostic_information(ex);
- Logger::Write(LogWarning, "compat", msgbuf.str());
+ } catch (const std::exception& ex) {
+ std::ostringstream msgbuf;
+ msgbuf << "External command failed: " << boost::diagnostic_information(ex);
+ Log(LogWarning, "compat", msgbuf.str());
}
}
<< "\t" << "host_name" << "\t" << host->GetName() << "\n"
<< "\t" << "display_name" << "\t" << host->GetDisplayName() << "\n";
- set<Host::Ptr> parents = host->GetParentHosts();
+ std::set<Host::Ptr> parents = host->GetParentHosts();
if (!parents.empty()) {
fp << "\t" << "parents" << "\t";
*/
void CompatComponent::StatusTimerHandler(void)
{
- Logger::Write(LogInformation, "compat", "Writing compat status information");
+ Log(LogInformation, "compat", "Writing compat status information");
String statuspath = GetStatusPath();
String objectspath = GetObjectsPath();
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) {
Host::Ptr host = static_pointer_cast<Host>(object);
- stringstream tempstatusfp;
+ std::ostringstream tempstatusfp;
tempstatusfp << std::fixed;
DumpHostStatus(tempstatusfp, host);
statusfp << tempstatusfp.str();
- stringstream tempobjectfp;
+ std::ostringstream tempobjectfp;
tempobjectfp << std::fixed;
DumpHostObject(tempobjectfp, host);
objectfp << tempobjectfp.str();
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("HostGroup")) {
HostGroup::Ptr hg = static_pointer_cast<HostGroup>(object);
- stringstream tempobjectfp;
+ std::ostringstream tempobjectfp;
tempobjectfp << std::fixed;
tempobjectfp << "define hostgroup {" << "\n"
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
Service::Ptr service = static_pointer_cast<Service>(object);
- stringstream tempstatusfp;
+ std::ostringstream tempstatusfp;
tempstatusfp << std::fixed;
DumpServiceStatus(tempstatusfp, service);
statusfp << tempstatusfp.str();
- stringstream tempobjectfp;
+ std::ostringstream tempobjectfp;
tempobjectfp << std::fixed;
DumpServiceObject(tempobjectfp, service);
objectfp << tempobjectfp.str();
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("ServiceGroup")) {
ServiceGroup::Ptr sg = static_pointer_cast<ServiceGroup>(object);
- stringstream tempobjectfp;
+ std::ostringstream tempobjectfp;
tempobjectfp << std::fixed;
tempobjectfp << "define servicegroup {" << "\n"
tempobjectfp << "\t" << "members" << "\t";
- vector<String> sglist;
+ std::vector<String> sglist;
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
Host::Ptr host = service->GetHost();
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("User")) {
User::Ptr user = static_pointer_cast<User>(object);
- stringstream tempobjectfp;
+ std::ostringstream tempobjectfp;
tempobjectfp << std::fixed;
tempobjectfp << "define contact {" << "\n"
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("UserGroup")) {
UserGroup::Ptr ug = static_pointer_cast<UserGroup>(object);
- stringstream tempobjectfp;
+ std::ostringstream tempobjectfp;
tempobjectfp << std::fixed;
tempobjectfp << "define contactgroup {" << "\n"
#ifndef COMPATCOMPONENT_H
#define COMPATCOMPONENT_H
+#include "base/objectlock.h"
+
namespace icinga
{
String GetLogPath(void) const;
String GetCommandPath(void) const;
- void DumpDowntimes(ostream& fp, const Service::Ptr& owner, CompatObjectType type);
- void DumpComments(ostream& fp, const Service::Ptr& owner, CompatObjectType type);
- void DumpHostStatus(ostream& fp, const Host::Ptr& host);
- void DumpHostObject(ostream& fp, const Host::Ptr& host);
+ void DumpDowntimes(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type);
+ void DumpComments(std::ostream& fp, const Service::Ptr& owner, CompatObjectType type);
+ void DumpHostStatus(std::ostream& fp, const Host::Ptr& host);
+ void DumpHostObject(std::ostream& fp, const Host::Ptr& host);
- void DumpServiceStatusAttrs(ostream& fp, const Service::Ptr& service, CompatObjectType type);
+ void DumpServiceStatusAttrs(std::ostream& fp, const Service::Ptr& service, CompatObjectType type);
template<typename T>
void DumpNameList(ostream& fp, const T& list)
}
}
- void DumpServiceStatus(ostream& fp, const Service::Ptr& service);
- void DumpServiceObject(ostream& fp, const Service::Ptr& service);
+ void DumpServiceStatus(std::ostream& fp, const Service::Ptr& service);
+ void DumpServiceObject(std::ostream& fp, const Service::Ptr& service);
void StatusTimerHandler(void);
};
* The compat component implements compatibility functionality for Icinga 1.x.
*/
-#include <i2-base.h>
-#include <i2-remoting.h>
-#include <i2-icinga.h>
+#include "base/i2-base.h"
+#include "remoting/i2-remoting.h"
+#include "icinga/i2-icinga.h"
#include <fstream>
libdelegation_la_CPPFLAGS = \
$(BOOST_CPPFLAGS) \
- -I${top_srcdir}/lib/base \
- -I${top_srcdir}/lib/config \
- -I${top_srcdir}/lib/remoting \
- -I${top_srcdir}/lib/icinga
+ -I${top_srcdir}/lib \
+ -I${top_srcdir}/components
libdelegation_la_LDFLAGS = \
$(BOOST_LDFLAGS) \
******************************************************************************/
#include "i2-delegation.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
#include <algorithm>
+#include "base/dynamictype.h"
+#include <boost/foreach.hpp>
using namespace icinga;
return (endpoint->HasSubscription("checker"));
}
-set<Endpoint::Ptr> DelegationComponent::GetCheckerCandidates(const Service::Ptr& service) const
+std::set<Endpoint::Ptr> DelegationComponent::GetCheckerCandidates(const Service::Ptr& service) const
{
- set<Endpoint::Ptr> candidates;
+ std::set<Endpoint::Ptr> candidates;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
Endpoint::Ptr endpoint = dynamic_pointer_cast<Endpoint>(object);
void DelegationComponent::DelegationTimerHandler(void)
{
- map<Endpoint::Ptr, int> histogram;
+ std::map<Endpoint::Ptr, int> histogram;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
Endpoint::Ptr endpoint = dynamic_pointer_cast<Endpoint>(object);
histogram[endpoint] = 0;
}
- vector<Service::Ptr> services;
+ std::vector<Service::Ptr> services;
/* build "checker -> service count" histogram */
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
Endpoint::Ptr oldEndpoint = Endpoint::GetByName(checker);
- set<Endpoint::Ptr> candidates = GetCheckerCandidates(service);
+ std::set<Endpoint::Ptr> candidates = GetCheckerCandidates(service);
int avg_services = 0, overflow_tolerance = 0;
- vector<Endpoint::Ptr>::iterator cit;
+ std::vector<Endpoint::Ptr>::iterator cit;
if (!candidates.empty()) {
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "Service: " << service->GetName() << ", candidates: " << candidates.size();
- Logger::Write(LogDebug, "delegation", msgbuf.str());
+ Log(LogDebug, "delegation", msgbuf.str());
BOOST_FOREACH(const Endpoint::Ptr& candidate, candidates) {
avg_services += histogram[candidate];
service->ProcessCheckResult(cr);
- Logger::Write(LogWarning, "delegation", "Can't delegate service: " + service->GetName());
+ Log(LogWarning, "delegation", "Can't delegate service: " + service->GetName());
}
continue;
Endpoint::Ptr endpoint;
int count;
BOOST_FOREACH(tie(endpoint, count), histogram) {
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "histogram: " << endpoint->GetName() << " - " << count;
- Logger::Write(LogInformation, "delegation", msgbuf.str());
+ Log(LogInformation, "delegation", msgbuf.str());
}
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "Updated delegations for " << delegated << " services";
- Logger::Write(LogInformation, "delegation", msgbuf.str());
+ Log(LogInformation, "delegation", msgbuf.str());
}
void DelegationTimerHandler(void);
- set<Endpoint::Ptr> GetCheckerCandidates(const Service::Ptr& service) const;
+ std::set<Endpoint::Ptr> GetCheckerCandidates(const Service::Ptr& service) const;
static bool IsEndpointChecker(const Endpoint::Ptr& endpoint);
};
* The Delegation component delegates service checks to the checker component.
*/
-#include <i2-base.h>
-#include <i2-icinga.h>
+#include "base/i2-base.h"
+#include "icinga/i2-icinga.h"
-#include "delegationcomponent.h"
+#include "delegation/delegationcomponent.h"
#endif /* I2DELEGATION_H */
libdemo_la_CPPFLAGS = \
$(BOOST_CPPFLAGS) \
- -I${top_srcdir}/lib/base \
- -I${top_srcdir}/lib/config \
- -I${top_srcdir}/lib/remoting \
- -I${top_srcdir}/lib/icinga
+ -I${top_srcdir}/lib \
+ -I${top_srcdir}/components
libdemo_la_LDFLAGS = \
$(BOOST_LDFLAGS) \
******************************************************************************/
#include "i2-demo.h"
+#include "base/dynamictype.h"
+#include "base/logger_fwd.h"
+#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
*/
void DemoComponent::DemoTimerHandler(void)
{
- Logger::Write(LogInformation, "demo", "Sending multicast 'hello world' message.");
+ Log(LogInformation, "demo", "Sending multicast 'hello world' message.");
RequestMessage request;
request.SetMethod("demo::HelloWorld");
void DemoComponent::HelloWorldRequestHandler(const Endpoint::Ptr& sender,
const RequestMessage&)
{
- Logger::Write(LogInformation, "demo", "Got 'hello world' from identity=" +
+ Log(LogInformation, "demo", "Got 'hello world' from identity=" +
(sender ? sender->GetName() : "(anonymous)"));
}
* The demo component periodically sends demo messages.
*/
-#include <i2-base.h>
-#include <i2-remoting.h>
-#include <i2-icinga.h>
+#include "base/i2-base.h"
+#include "remoting/i2-remoting.h"
+#include "icinga/i2-icinga.h"
-#include "democomponent.h"
+#include "demo/democomponent.h"
#endif /* I2DEMO_H */
liblivestatus_la_CPPFLAGS = \
$(BOOST_CPPFLAGS) \
- -I${top_srcdir}/lib/base \
- -I${top_srcdir}/lib/config \
- -I${top_srcdir}/lib/remoting \
- -I${top_srcdir}/lib/icinga
+ -I${top_srcdir}/lib \
+ -I${top_srcdir}/components
liblivestatus_la_LDFLAGS = \
$(BOOST_LDFLAGS) \
******************************************************************************/
#include "i2-livestatus.h"
+#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;
******************************************************************************/
#include "i2-livestatus.h"
+#include "base/convert.h"
+#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;
return false; /* Item not found in list. */
} else {
- BOOST_THROW_EXCEPTION(invalid_argument("Invalid operator for column '" + m_Column + "': " + m_Operator + " (expected '>=')."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid operator for column '" + m_Column + "': " + m_Operator + " (expected '>=')."));
}
} else {
if (m_Operator == "=") {
else
return (static_cast<String>(value) >= m_Operand);
} else {
- BOOST_THROW_EXCEPTION(invalid_argument("Unknown operator for column '" + m_Column + "': " + m_Operator));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Unknown operator for column '" + m_Column + "': " + m_Operator));
}
}
void CombinerFilter::AddSubFilter(const Filter::Ptr& filter)
{
m_Filters.push_back(filter);
-}
\ No newline at end of file
+}
void AddSubFilter(const Filter::Ptr& filter);
protected:
- vector<Filter::Ptr> m_Filters;
+ std::vector<Filter::Ptr> m_Filters;
};
}
******************************************************************************/
#include "i2-livestatus.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
#include <boost/tuple/tuple.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;
******************************************************************************/
#include "i2-livestatus.h"
+#include "base/dynamictype.h"
+#include "base/logger_fwd.h"
+#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
using namespace livestatus;
void LivestatusComponent::NewClientHandler(const Socket::Ptr& client)
{
- Logger::Write(LogInformation, "livestatus", "Client connected");
+ Log(LogInformation, "livestatus", "Client connected");
LivestatusConnection::Ptr lconnection = boost::make_shared<LivestatusConnection>(client);
lconnection->OnClosed.connect(boost::bind(&LivestatusComponent::ClientClosedHandler, this, _1));
{
LivestatusConnection::Ptr lconnection = static_pointer_cast<LivestatusConnection>(connection);
- Logger::Write(LogInformation, "livestatus", "Client disconnected");
+ Log(LogInformation, "livestatus", "Client disconnected");
m_Connections.erase(lconnection);
}
Attribute<String> m_SocketPath;
Socket::Ptr m_Listener;
- set<LivestatusConnection::Ptr> m_Connections;
+ std::set<LivestatusConnection::Ptr> m_Connections;
void NewClientHandler(const Socket::Ptr& client);
void ClientClosedHandler(const Connection::Ptr& connection);
******************************************************************************/
#include "i2-livestatus.h"
+#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
using namespace livestatus;
LivestatusConnection(const Stream::Ptr& stream);
protected:
- vector<String> m_Lines;
+ std::vector<String> m_Lines;
virtual void ProcessData(void);
};
******************************************************************************/
#include "i2-livestatus.h"
+#include "base/dynamictype.h"
+#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;
******************************************************************************/
#include "i2-livestatus.h"
+#include "base/dynamictype.h"
+#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;
******************************************************************************/
#include "i2-livestatus.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
#include <boost/tuple/tuple.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;
******************************************************************************/
#include "i2-livestatus.h"
+#include "base/dynamictype.h"
+#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;
* The livestatus component implements livestatus queries.
*/
-#include <i2-base.h>
-#include <i2-remoting.h>
-#include <i2-icinga.h>
+#include "base/i2-base.h"
+#include "remoting/i2-remoting.h"
+#include "icinga/i2-icinga.h"
using namespace icinga;
-#include "connection.h"
-#include "column.h"
-#include "table.h"
-#include "filter.h"
-#include "combinerfilter.h"
-#include "orfilter.h"
-#include "andfilter.h"
-#include "negatefilter.h"
-#include "attributefilter.h"
-#include "query.h"
-#include "statustable.h"
-#include "contactgroupstable.h"
-#include "contactstable.h"
-#include "hoststable.h"
-#include "servicestable.h"
-#include "commentstable.h"
-#include "downtimestable.h"
-#include "component.h"
+#include "livestatus/connection.h"
+#include "livestatus/column.h"
+#include "livestatus/table.h"
+#include "livestatus/filter.h"
+#include "livestatus/combinerfilter.h"
+#include "livestatus/orfilter.h"
+#include "livestatus/andfilter.h"
+#include "livestatus/negatefilter.h"
+#include "livestatus/attributefilter.h"
+#include "livestatus/query.h"
+#include "livestatus/statustable.h"
+#include "livestatus/contactgroupstable.h"
+#include "livestatus/contactstable.h"
+#include "livestatus/hoststable.h"
+#include "livestatus/servicestable.h"
+#include "livestatus/commentstable.h"
+#include "livestatus/downtimestable.h"
+#include "livestatus/component.h"
#endif /* I2LIVESTATUS_H */
******************************************************************************/
#include "i2-livestatus.h"
+#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;
******************************************************************************/
#include "i2-livestatus.h"
+#include "base/convert.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
#include <boost/algorithm/string/classification.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;
-Query::Query(const vector<String>& lines)
+Query::Query(const std::vector<String>& lines)
: m_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true), m_Limit(-1)
{
String line = lines[0];
size_t sp_index = line.FindFirstOf(" ");
if (sp_index == String::NPos)
- BOOST_THROW_EXCEPTION(runtime_error("Livestatus header must contain a verb."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Livestatus header must contain a verb."));
String verb = line.SubStr(0, sp_index);
String target = line.SubStr(sp_index + 1);
return;
}
- deque<Filter::Ptr> filters, stats;
+ std::deque<Filter::Ptr> filters, stats;
for (unsigned int i = 1; i < lines.size(); i++) {
line = lines[i];
else if (header == "ColumnHeaders")
m_ColumnHeaders = (params == "on");
else if (header == "Filter" || header == "Stats") {
- vector<String> tokens = params.Split(boost::is_any_of(" "));
+ std::vector<String> tokens = params.Split(boost::is_any_of(" "));
if (tokens.size() == 2)
tokens.push_back("");
if (negate)
filter = boost::make_shared<NegateFilter>(filter);
- deque<Filter::Ptr>& deq = (header == "Filter") ? filters : stats;
+ std::deque<Filter::Ptr>& deq = (header == "Filter") ? filters : stats;
deq.push_back(filter);
} else if (header == "Or" || header == "And") {
- deque<Filter::Ptr>& deq = (header == "Or" || header == "And") ? filters : stats;
+ std::deque<Filter::Ptr>& deq = (header == "Or" || header == "And") ? filters : stats;
int num = Convert::ToLong(params);
CombinerFilter::Ptr filter;
deq.push_back(filter);
} else if (header == "Negate" || header == "StatsNegate") {
- deque<Filter::Ptr>& deq = (header == "Negate") ? filters : stats;
+ std::deque<Filter::Ptr>& deq = (header == "Negate") ? filters : stats;
if (deq.empty()) {
m_Verb = "ERROR";
m_Stats.swap(stats);
}
-void Query::PrintResultSet(ostream& fp, const vector<String>& columns, const Array::Ptr& rs)
+void Query::PrintResultSet(ostream& fp, const std::vector<String>& columns, const Array::Ptr& rs)
{
if (m_OutputFormat == "csv" && m_Columns.size() == 0 && m_ColumnHeaders) {
bool first = true;
void Query::ExecuteGetHelper(const Stream::Ptr& stream)
{
- Logger::Write(LogInformation, "livestatus", "Table: " + m_Table);
+ Log(LogInformation, "livestatus", "Table: " + m_Table);
Table::Ptr table = Table::GetByName(m_Table);
return;
}
- vector<Object::Ptr> objects = table->FilterRows(m_Filter);
- vector<String> columns;
+ std::vector<Object::Ptr> objects = table->FilterRows(m_Filter);
+ std::vector<String> columns;
if (m_Columns.size() > 0)
columns = m_Columns;
rs->Add(row);
}
} else {
- vector<int> stats(m_Stats.size(), 0);
+ std::vector<int> stats(m_Stats.size(), 0);
BOOST_FOREACH(const Object::Ptr& object, objects) {
int index = 0;
m_ColumnHeaders = false;
}
- stringstream result;
+ std::ostringstream result;
PrintResultSet(result, columns, rs);
SendResponse(stream, 200, result.str());
void Query::ExecuteCommandHelper(const Stream::Ptr& stream)
{
- Logger::Write(LogInformation, "livestatus", "Executing command: " + m_Command);
+ Log(LogInformation, "livestatus", "Executing command: " + m_Command);
ExternalCommandProcessor::Execute(m_Command);
SendResponse(stream, 200, "");
}
void Query::Execute(const Stream::Ptr& stream)
{
try {
- Logger::Write(LogInformation, "livestatus", "Executing livestatus query: " + m_Verb);
+ Log(LogInformation, "livestatus", "Executing livestatus query: " + m_Verb);
if (m_Verb == "GET")
ExecuteGetHelper(stream);
else if (m_Verb == "ERROR")
ExecuteErrorHelper(stream);
else
- BOOST_THROW_EXCEPTION(runtime_error("Invalid livestatus query verb."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Invalid livestatus query verb."));
} catch (const std::exception& ex) {
SendResponse(stream, 452, boost::diagnostic_information(ex));
}
typedef shared_ptr<Query> Ptr;
typedef weak_ptr<Query> WeakPtr;
- Query(const vector<String>& lines);
+ Query(const std::vector<String>& lines);
void Execute(const Stream::Ptr& stream);
/* Parameters for GET queries. */
String m_Table;
- vector<String> m_Columns;
+ std::vector<String> m_Columns;
Filter::Ptr m_Filter;
- deque<Filter::Ptr> m_Stats;
+ std::deque<Filter::Ptr> m_Stats;
String m_OutputFormat;
bool m_ColumnHeaders;
int m_ErrorCode;
String m_ErrorMessage;
- void PrintResultSet(ostream& fp, const vector<String>& columns, const Array::Ptr& rs);
+ void PrintResultSet(ostream& fp, const std::vector<String>& columns, const Array::Ptr& rs);
void ExecuteGetHelper(const Stream::Ptr& stream);
void ExecuteCommandHelper(const Stream::Ptr& stream);
******************************************************************************/
#include "i2-livestatus.h"
+#include "base/dynamictype.h"
+#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;
******************************************************************************/
#include "i2-livestatus.h"
+#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
using namespace livestatus;
#include "i2-livestatus.h"
#include <boost/tuple/tuple.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
using namespace livestatus;
void Table::AddColumn(const String& name, const Column& column)
{
- pair<String, Column> item = make_pair(name, column);
+ std::pair<String, Column> item = std::make_pair(name, column);
- pair<map<String, Column>::iterator, bool> ret = m_Columns.insert(item);
+ std::pair<std::map<String, Column>::iterator, bool> ret = m_Columns.insert(item);
if (!ret.second)
ret.first->second = column;
Column Table::GetColumn(const String& name) const
{
- map<String, Column>::const_iterator it = m_Columns.find(name);
+ std::map<String, Column>::const_iterator it = m_Columns.find(name);
if (it == m_Columns.end())
- BOOST_THROW_EXCEPTION(invalid_argument("Column '" + name + "' does not exist."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Column '" + name + "' does not exist."));
return it->second;
}
-vector<String> Table::GetColumnNames(void) const
+std::vector<String> Table::GetColumnNames(void) const
{
- vector<String> names;
+ std::vector<String> names;
String name;
BOOST_FOREACH(boost::tie(name, boost::tuples::ignore), m_Columns) {
return names;
}
-vector<Object::Ptr> Table::FilterRows(const Filter::Ptr& filter)
+std::vector<Object::Ptr> Table::FilterRows(const Filter::Ptr& filter)
{
- vector<Object::Ptr> rs;
+ std::vector<Object::Ptr> rs;
FetchRows(boost::bind(&Table::FilteredAddRow, this, boost::ref(rs), filter, _1));
return rs;
}
-void Table::FilteredAddRow(vector<Object::Ptr>& rs, const Filter::Ptr& filter, const Object::Ptr& object)
+void Table::FilteredAddRow(std::vector<Object::Ptr>& rs, const Filter::Ptr& filter, const Object::Ptr& object)
{
if (!filter || filter->Apply(GetSelf(), object))
rs.push_back(object);
virtual String GetName(void) const = 0;
- vector<Object::Ptr> FilterRows(const shared_ptr<Filter>& filter);
+ std::vector<Object::Ptr> FilterRows(const shared_ptr<Filter>& filter);
void AddColumn(const String& name, const Column& column);
Column GetColumn(const String& name) const;
- vector<String> GetColumnNames(void) const;
+ std::vector<String> GetColumnNames(void) const;
protected:
Table(void);
static Value EmptyDictionaryAccessor(const Object::Ptr&);
private:
- map<String, Column> m_Columns;
+ std::map<String, Column> m_Columns;
- void FilteredAddRow(vector<Object::Ptr>& rs, const shared_ptr<Filter>& filter, const Object::Ptr& object);
+ void FilteredAddRow(std::vector<Object::Ptr>& rs, const shared_ptr<Filter>& filter, const Object::Ptr& object);
};
}
libnotification_la_CPPFLAGS = \
$(BOOST_CPPFLAGS) \
- -I${top_srcdir}/lib/base \
- -I${top_srcdir}/lib/config \
- -I${top_srcdir}/lib/remoting \
- -I${top_srcdir}/lib/icinga
+ -I${top_srcdir}/lib \
+ -I${top_srcdir}/components
libnotification_la_LDFLAGS = \
$(BOOST_LDFLAGS) \
* The notification component is in charge of sending downtime notifications.
*/
-#include <i2-base.h>
-#include <i2-remoting.h>
-#include <i2-icinga.h>
+#include "base/i2-base.h"
+#include "remoting/i2-remoting.h"
+#include "icinga/i2-icinga.h"
-#include "notificationcomponent.h"
+#include "notification/notificationcomponent.h"
#endif /* I2NOTIFICATION_H */
******************************************************************************/
#include "i2-notification.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
libreplication_la_CPPFLAGS = \
$(BOOST_CPPFLAGS) \
- -I${top_srcdir}/lib/base \
- -I${top_srcdir}/lib/config \
- -I${top_srcdir}/lib/remoting \
- -I${top_srcdir}/lib/icinga
+ -I${top_srcdir}/lib \
+ -I${top_srcdir}/components
libreplication_la_LDFLAGS = \
$(BOOST_LDFLAGS) \
* Replicates Icinga 2 objects to remote instances.
*/
-#include <i2-base.h>
-#include <i2-remoting.h>
-#include <i2-icinga.h>
+#include "base/i2-base.h"
+#include "remoting/i2-remoting.h"
+#include "icinga/i2-icinga.h"
-#include "replicationcomponent.h"
+#include "replication/replicationcomponent.h"
#endif /* I2REPLICATION_H */
******************************************************************************/
#include "i2-replication.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
+#include <boost/foreach.hpp>
using namespace icinga;
DynamicType::Ptr type;
BOOST_FOREACH(const DynamicType::Ptr& dt, DynamicType::GetTypes()) {
- set<DynamicObject::Ptr> objects;
+ std::set<DynamicObject::Ptr> objects;
{
ObjectLock olock(dt);
MakeObjectMessage(object, "config::ObjectRemoved", 0, false));
}
-void ReplicationComponent::TransactionClosingHandler(double tx, const set<DynamicObject::WeakPtr>& modifiedObjects)
+void ReplicationComponent::TransactionClosingHandler(double tx, const std::set<DynamicObject::WeakPtr>& modifiedObjects)
{
if (modifiedObjects.empty())
return;
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "Sending " << modifiedObjects.size() << " replication updates.";
- Logger::Write(LogDebug, "replication", msgbuf.str());
+ Log(LogDebug, "replication", msgbuf.str());
BOOST_FOREACH(const DynamicObject::WeakPtr& wobject, modifiedObjects) {
DynamicObject::Ptr object = wobject.lock();
return;
}
- Logger::Write(LogDebug, "replication", "Received object from source: " + source);
+ Log(LogDebug, "replication", "Received object from source: " + source);
object->SetSource(source);
object->Register();
} else {
if (object->IsLocal())
- BOOST_THROW_EXCEPTION(invalid_argument("Replicated remote object is marked as local."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Replicated remote object is marked as local."));
// TODO: disallow config updates depending on endpoint config
void LocalObjectRegisteredHandler(const DynamicObject::Ptr& object);
void LocalObjectUnregisteredHandler(const DynamicObject::Ptr& object);
- void TransactionClosingHandler(double tx, const set<DynamicObject::WeakPtr>& modifiedObjects);
+ void TransactionClosingHandler(double tx, const std::set<DynamicObject::WeakPtr>& modifiedObjects);
void FlushObjectHandler(double tx, const DynamicObject::Ptr& object);
void RemoteObjectUpdateHandler(const RequestMessage& request);
-DI2_ICINGALAUNCHER_BUILD \
$(LTDLINCL) \
$(BOOST_CPPFLAGS) \
- -I${top_srcdir}/lib/base \
- -I${top_srcdir}/lib/config \
- -I${top_srcdir}/lib/remoting \
- -I${top_srcdir}/lib/icinga \
- -I${top_srcdir}
+ -I${top_srcdir}/lib \
+ -I${top_srcdir}/components
icinga2_LDFLAGS = \
$(BOOST_LDFLAGS) \
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include <i2-icinga.h>
+#include "base/i2-base.h"
+#include "config/i2-config.h"
+#include "base/application.h"
+#include "base/logger_fwd.h"
#include <boost/program_options.hpp>
#include <boost/tuple/tuple.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
#ifndef _WIN32
# include "icinga-version.h"
ConfigCompilerContext::SetContext(&context);
- BOOST_FOREACH(const String& configPath, g_AppParams["config"].as<vector<String> >()) {
+ BOOST_FOREACH(const String& configPath, g_AppParams["config"].as<std::vector<String> >()) {
ConfigCompiler::CompileFile(configPath);
}
BOOST_FOREACH(const ConfigCompilerError& error, context.GetErrors()) {
if (error.Warning) {
- Logger::Write(LogWarning, "icinga-app", "Config warning: " + error.Message);
+ Log(LogWarning, "icinga-app", "Config warning: " + error.Message);
} else {
hasError = true;
- Logger::Write(LogCritical, "icinga-app", "Config error: " + error.Message);
+ Log(LogCritical, "icinga-app", "Config error: " + error.Message);
}
}
static void ReloadConfigTimerHandler(void)
{
if (g_ReloadConfig) {
- Logger::Write(LogInformation, "icinga-app", "Received SIGHUP. Reloading config files.");
+ Log(LogInformation, "icinga-app", "Received SIGHUP. Reloading config files.");
LoadConfigFiles(false);
g_ReloadConfig = false;
desc.add_options()
("help", "show this help message")
("version,V", "show version information")
- ("library,l", po::value<vector<String> >(), "load a library")
- ("include,I", po::value<vector<String> >(), "add include search directory")
- ("config,c", po::value<vector<String> >(), "parse a configuration file")
+ ("library,l", po::value<std::vector<String> >(), "load a library")
+ ("include,I", po::value<std::vector<String> >(), "add include search directory")
+ ("config,c", po::value<std::vector<String> >(), "parse a configuration file")
("validate,v", "exit after validating the configuration")
("debug,x", "enable debugging")
;
try {
po::store(po::parse_command_line(argc, argv, desc), g_AppParams);
- } catch (const exception& ex) {
- stringstream msgbuf;
+ } catch (const std::exception& ex) {
+ std::ostringstream msgbuf;
msgbuf << "Error while parsing command-line options: " << ex.what();
- Logger::Write(LogCritical, "icinga-app", msgbuf.str());
+ Log(LogCritical, "icinga-app", msgbuf.str());
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
- Logger::Write(LogInformation, "icinga-app", "Icinga application loader"
+ Log(LogInformation, "icinga-app", "Icinga application loader"
#ifndef _WIN32
" (version: " ICINGA_VERSION ")"
#endif /* _WIN32 */
);
String searchDir = Application::GetPkgLibDir();
- Logger::Write(LogInformation, "base", "Adding library search dir: " + searchDir);
+ Log(LogInformation, "base", "Adding library search dir: " + searchDir);
#ifdef _WIN32
SetDllDirectory(searchDir.CStr());
(void) Utility::LoadExtensionLibrary("icinga");
if (g_AppParams.count("library")) {
- BOOST_FOREACH(const String& libraryName, g_AppParams["library"].as<vector<String> >()) {
+ BOOST_FOREACH(const String& libraryName, g_AppParams["library"].as<std::vector<String> >()) {
(void) Utility::LoadExtensionLibrary(libraryName);
}
}
ConfigCompiler::AddIncludeSearchDir(Application::GetPkgDataDir());
if (g_AppParams.count("include")) {
- BOOST_FOREACH(const String& includePath, g_AppParams["include"].as<vector<String> >()) {
+ BOOST_FOREACH(const String& includePath, g_AppParams["include"].as<std::vector<String> >()) {
ConfigCompiler::AddIncludeSearchDir(includePath);
}
}
if (g_AppParams.count("config") == 0) {
- Logger::Write(LogCritical, "icinga-app", "You need to specify at least one config file (using the --config option).");
+ Log(LogCritical, "icinga-app", "You need to specify at least one config file (using the --config option).");
return EXIT_FAILURE;
}
return EXIT_FAILURE;
if (validateOnly) {
- Logger::Write(LogInformation, "icinga-app", "Finished validating the configuration file(s).");
+ Log(LogInformation, "icinga-app", "Finished validating the configuration file(s).");
return EXIT_SUCCESS;
}
Application::Ptr app = Application::GetInstance();
if (!app)
- BOOST_THROW_EXCEPTION(runtime_error("Configuration must create an Application object."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Configuration must create an Application object."));
#ifndef _WIN32
struct sigaction sa;
pkglib_LTLIBRARIES = \
libbase.la
+EXTRA_DIST = \
+ i2-base.cpp
+
libbase_la_SOURCES = \
application.cpp \
application.h \
exception.h \
fifo.cpp \
fifo.h \
- i2-base.cpp \
i2-base.h \
logger.cpp \
logger.h \
+ logger_fwd.h \
netstring.cpp \
netstring.h \
object.cpp \
$(LTDLINCL) \
$(BOOST_CPPFLAGS) \
$(OPENSSL_INCLUDES) \
+ -I${top_srcdir}/lib \
-I${top_srcdir}/third-party/execvpe \
-I${top_srcdir}/third-party/mmatch \
-I${top_srcdir}/third-party/cJSON
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/application.h"
+#include "base/stacktrace.h"
+#include "base/timer.h"
+#include "base/logger_fwd.h"
+#include "base/exception.h"
+#include "base/objectlock.h"
+#include <sstream>
#include <boost/algorithm/string/classification.hpp>
#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
+#include <boost/make_shared.hpp>
+#include <boost/foreach.hpp>
+#include <boost/exception/diagnostic_information.hpp>
using namespace icinga;
: DynamicObject(serializedUpdate), m_PidFile(NULL)
{
if (!IsLocal())
- BOOST_THROW_EXCEPTION(runtime_error("Application objects must be local."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Application objects must be local."));
#ifdef _WIN32
/* disable GUI-based error messages for LoadLibrary() */
void Application::ShutdownTimerHandler(void)
{
if (m_ShuttingDown) {
- Logger::Write(LogInformation, "base", "Shutting down Icinga...");
+ Log(LogInformation, "base", "Shutting down Icinga...");
Application::GetInstance()->OnShutdown();
DynamicObject::DeactivateObjects();
if (abs(timeDiff) > 15) {
/* We made a significant jump in time. */
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "We jumped "
<< (timeDiff < 0 ? "forward" : "backward")
<< " in time: " << abs(timeDiff) << " seconds";
- Logger::Write(LogInformation, "base", msgbuf.str());
+ Log(LogInformation, "base", msgbuf.str());
Timer::AdjustTimers(-timeDiff);
}
if (!foundSlash) {
const char *pathEnv = getenv("PATH");
if (pathEnv != NULL) {
- vector<String> paths;
+ std::vector<String> paths;
boost::algorithm::split(paths, pathEnv, boost::is_any_of(":"));
bool foundPath = false;
if (!foundPath) {
executablePath.Clear();
- BOOST_THROW_EXCEPTION(runtime_error("Could not determine executable path."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Could not determine executable path."));
}
}
}
throw;
} catch (const std::exception& ex) {
std::cerr << std::endl
- << diagnostic_information(ex)
+ << boost::diagnostic_information(ex)
<< std::endl;
has_trace = (boost::get_error_info<StackTraceErrorInfo>(ex) != NULL);
m_PidFile = fopen(filename.CStr(), "w");
if (m_PidFile == NULL)
- BOOST_THROW_EXCEPTION(runtime_error("Could not open PID file '" + filename + "'"));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Could not open PID file '" + filename + "'"));
#ifndef _WIN32
int fd = fileno(m_PidFile);
Utility::SetCloExec(fd);
if (flock(fd, LOCK_EX | LOCK_NB) < 0) {
- Logger::Write(LogCritical, "base", "Could not lock PID file. Make sure that only one instance of the application is running.");
+ Log(LogCritical, "base", "Could not lock PID file. Make sure that only one instance of the application is running.");
_exit(EXIT_FAILURE);
}
#ifndef APPLICATION_H
#define APPLICATION_H
+#include "base/i2-base.h"
+#include "base/eventqueue.h"
+#include "base/dynamicobject.h"
+
namespace icinga {
class Component;
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/array.h"
+#include "base/objectlock.h"
+#include "base/utility.h"
#include <cJSON.h>
+#include <boost/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
Array::Ptr array = boost::make_shared<Array>();
if (json->type != cJSON_Array)
- BOOST_THROW_EXCEPTION(invalid_argument("JSON type must be cJSON_Array."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("JSON type must be cJSON_Array."));
for (cJSON *i = json->child; i != NULL; i = i->next) {
array->Add(Value::FromJson(i));
#ifndef ARRAY_H
#define ARRAY_H
+#include "base/i2-base.h"
+#include "base/value.h"
+#include <vector>
+
namespace icinga
{
/**
* An iterator that can be used to iterate over array elements.
*/
- typedef vector<Value>::iterator Iterator;
+ typedef std::vector<Value>::iterator Iterator;
Array(void);
cJSON *ToJson(void) const;
private:
- vector<Value> m_Data; /**< The data for the array. */
+ std::vector<Value> m_Data; /**< The data for the array. */
bool m_Sealed; /**< Whether the array is read-only. */
};
#ifndef ASYNCTASK_H
#define ASYNCTASK_H
+#include "base/i2-base.h"
+#include "base/object.h"
+#include "base/utility.h"
#include <boost/function.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/bind.hpp>
+#include <boost/exception_ptr.hpp>
namespace icinga
{
m_CV.wait(lock);
if (m_ResultRetrieved)
- BOOST_THROW_EXCEPTION(runtime_error("GetResult called on an AsyncTask whose result was already retrieved."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("GetResult called on an AsyncTask whose result was already retrieved."));
m_ResultRetrieved = true;
{
try {
Run();
- } catch (const exception&) {
+ } catch (...) {
FinishException(boost::current_exception());
}
}
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/attribute.h"
+#include "base/utility.h"
using namespace icinga;
#ifndef ATTRIBUTE_H
#define ATTRIBUTE_H
+#include "base/value.h"
+
namespace icinga
{
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/connection.h"
#include <boost/bind.hpp>
using namespace icinga;
#ifndef CONNECTION_H
#define CONNECTION_H
+#include "base/i2-base.h"
+#include "base/stream.h"
+#include <boost/signals2.hpp>
+
namespace icinga
{
void Close(void);
- signals2::signal<void (const Connection::Ptr&)> OnClosed;
+ boost::signals2::signal<void (const Connection::Ptr&)> OnClosed;
protected:
virtual void ProcessData(void) = 0;
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/convert.h"
+#include <sstream>
#include <boost/lexical_cast.hpp>
using namespace icinga;
String Convert::ToString(long val)
{
- stringstream cs;
+ std::ostringstream cs;
cs << val;
return cs.str();
}
#ifndef CONVERT_H
#define CONVERT_H
+#include "base/i2-base.h"
+#include "base/value.h"
+
namespace icinga
{
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/dictionary.h"
+#include "base/objectlock.h"
+#include "base/utility.h"
#include <cJSON.h>
#include <boost/tuple/tuple.hpp>
+#include <boost/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
* @returns true if the first key is less than the second key, false
* otherwise
*/
- bool operator()(const pair<String, Value>& a, const char *b)
+ bool operator()(const std::pair<String, Value>& a, const char *b)
{
return a.first < b;
}
* @returns true if the first key is less than the second key, false
* otherwise
*/
- bool operator()(const char *a, const pair<String, Value>& b)
+ bool operator()(const char *a, const std::pair<String, Value>& b)
{
return a < b.first;
}
ASSERT(!OwnsLock());
ObjectLock olock(this);
- map<String, Value>::const_iterator it;
+ std::map<String, Value>::const_iterator it;
it = std::lower_bound(m_Data.begin(), m_Data.end(), key, DictionaryKeyLessComparer());
ASSERT(!m_Sealed);
- pair<map<String, Value>::iterator, bool> ret;
- ret = m_Data.insert(make_pair(key, value));
+ std::pair<std::map<String, Value>::iterator, bool> ret;
+ ret = m_Data.insert(std::make_pair(key, value));
if (!ret.second)
ret.first->second = value;
}
Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
if (json->type != cJSON_Object)
- BOOST_THROW_EXCEPTION(invalid_argument("JSON type must be cJSON_Object."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("JSON type must be cJSON_Object."));
for (cJSON *i = json->child; i != NULL; i = i->next) {
dictionary->Set(i->string, Value::FromJson(i));
#ifndef DICTIONARY_H
#define DICTIONARY_H
+#include "base/i2-base.h"
+#include "base/object.h"
+#include "base/value.h"
+#include <map>
+
namespace icinga
{
/**
* An iterator that can be used to iterate over dictionary elements.
*/
- typedef map<String, Value>::iterator Iterator;
+ typedef std::map<String, Value>::iterator Iterator;
Dictionary(void);
cJSON *ToJson(void) const;
private:
- map<String, Value> m_Data; /**< The data for the dictionary. */
+ std::map<String, Value> m_Data; /**< The data for the dictionary. */
bool m_Sealed; /**< Whether the dictionary is read-only. */
};
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/dynamicobject.h"
+#include "base/dynamictype.h"
+#include "base/netstring.h"
+#include "base/registry.h"
+#include "base/stdiostream.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
+#include "base/exception.h"
+#include <fstream>
+#include <boost/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
double DynamicObject::m_CurrentTx = 0;
-set<DynamicObject::WeakPtr> DynamicObject::m_ModifiedObjects;
+std::set<DynamicObject::WeakPtr> DynamicObject::m_ModifiedObjects;
boost::mutex DynamicObject::m_TransactionMutex;
boost::once_flag DynamicObject::m_TransactionOnce = BOOST_ONCE_INIT;
Timer::Ptr DynamicObject::m_TransactionTimer;
-signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnRegistered;
-signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnUnregistered;
-signals2::signal<void (double, const set<DynamicObject::WeakPtr>&)> DynamicObject::OnTransactionClosing;
-signals2::signal<void (double, const DynamicObject::Ptr&)> DynamicObject::OnFlushObject;
+boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnRegistered;
+boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnUnregistered;
+boost::signals2::signal<void (double, const std::set<DynamicObject::WeakPtr>&)> DynamicObject::OnTransactionClosing;
+boost::signals2::signal<void (double, const DynamicObject::Ptr&)> DynamicObject::OnFlushObject;
DynamicObject::DynamicObject(const Dictionary::Ptr& serializedObject)
: m_ConfigTx(0), m_Registered(false)
RegisterAttribute("methods", Attribute_Config, &m_Methods);
if (!serializedObject->Contains("configTx"))
- BOOST_THROW_EXCEPTION(invalid_argument("Serialized object must contain a config snapshot."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Serialized object must contain a config snapshot."));
/* apply config state from the config item/remote update;
* The DynamicType::CreateObject function takes care of restoring
AttributeHolder attr(type, boundAttribute);
- pair<DynamicObject::AttributeIterator, bool> tt;
- tt = m_Attributes.insert(make_pair(name, attr));
+ std::pair<DynamicObject::AttributeIterator, bool> tt;
+ tt = m_Attributes.insert(std::make_pair(name, attr));
if (!tt.second) {
tt.first->second.SetType(type);
AttributeIterator it = m_Attributes.find(name);
if (it == m_Attributes.end())
- BOOST_THROW_EXCEPTION(runtime_error("Touch() called for unknown attribute: " + name));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Touch() called for unknown attribute: " + name));
it->second.SetTx(GetCurrentTx());
AttributeHolder attr(Attribute_Transient);
attr.SetValue(tx, data);
- m_Attributes.insert(make_pair(name, attr));
+ m_Attributes.insert(std::make_pair(name, attr));
} else {
if (!allowEditConfig && (it->second.GetType() & Attribute_Config))
- BOOST_THROW_EXCEPTION(runtime_error("Config properties are immutable: '" + name + "'."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Config properties are immutable: '" + name + "'."));
it->second.SetValue(tx, data);
}
ScriptTask::Ptr DynamicObject::MakeMethodTask(const String& method,
- const vector<Value>& arguments)
+ const std::vector<Value>& arguments)
{
Dictionary::Ptr methods;
ScriptFunction::Ptr func = ScriptFunctionRegistry::GetInstance()->GetItem(funcName);
if (!func)
- BOOST_THROW_EXCEPTION(invalid_argument("Function '" + funcName + "' does not exist."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Function '" + funcName + "' does not exist."));
return boost::make_shared<ScriptTask>(func, arguments);
}
*/
void DynamicObject::DumpObjects(const String& filename)
{
- Logger::Write(LogInformation, "base", "Dumping program state to file '" + filename + "'");
+ Log(LogInformation, "base", "Dumping program state to file '" + filename + "'");
String tempFilename = filename + ".tmp";
- fstream fp;
+ std::fstream fp;
fp.open(tempFilename.CStr(), std::ios_base::out);
if (!fp)
- BOOST_THROW_EXCEPTION(runtime_error("Could not open '" + filename + "' file"));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Could not open '" + filename + "' file"));
StdioStream::Ptr sfp = boost::make_shared<StdioStream>(&fp, false);
sfp->Start();
*/
void DynamicObject::RestoreObjects(const String& filename)
{
- Logger::Write(LogInformation, "base", "Restoring program state from file '" + filename + "'");
+ Log(LogInformation, "base", "Restoring program state from file '" + filename + "'");
std::fstream fp;
fp.open(filename.CStr(), std::ios_base::in);
DynamicType::Ptr dt = DynamicType::GetByName(type);
if (!dt)
- BOOST_THROW_EXCEPTION(invalid_argument("Invalid type: " + type));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid type: " + type));
DynamicObject::Ptr object = dt->GetObject(name);
sfp->Close();
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "Restored " << restored << " objects";
- Logger::Write(LogInformation, "base", msgbuf.str());
+ Log(LogInformation, "base", msgbuf.str());
}
void DynamicObject::DeactivateObjects(void)
void DynamicObject::NewTx(void)
{
double tx;
- set<DynamicObject::WeakPtr> objects;
+ std::set<DynamicObject::WeakPtr> objects;
{
boost::mutex::scoped_lock lock(m_TransactionMutex);
if (!object || !object->IsRegistered())
continue;
- set<String, string_iless> attrs;
+ std::set<String, string_iless> attrs;
{
ObjectLock olock(object);
#ifndef DYNAMICOBJECT_H
#define DYNAMICOBJECT_H
+#include "base/i2-base.h"
+#include "base/timer.h"
+#include "base/attribute.h"
+#include "base/scripttask.h"
+#include "base/object.h"
+#include "base/dictionary.h"
+#include <map>
+#include <set>
#include <boost/thread/once.hpp>
namespace icinga
typedef shared_ptr<DynamicObject> Ptr;
typedef weak_ptr<DynamicObject> WeakPtr;
- typedef map<String, AttributeHolder, string_iless> AttributeMap;
+ typedef std::map<String, AttributeHolder, string_iless> AttributeMap;
typedef AttributeMap::iterator AttributeIterator;
typedef AttributeMap::const_iterator AttributeConstIterator;
void ClearAttributesByType(AttributeType type);
- static signals2::signal<void (const DynamicObject::Ptr&)> OnRegistered;
- static signals2::signal<void (const DynamicObject::Ptr&)> OnUnregistered;
- static signals2::signal<void (double, const set<DynamicObject::WeakPtr>&)> OnTransactionClosing;
- static signals2::signal<void (double, const DynamicObject::Ptr&)> OnFlushObject;
+ static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnRegistered;
+ static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnUnregistered;
+ static boost::signals2::signal<void (double, const std::set<DynamicObject::WeakPtr>&)> OnTransactionClosing;
+ static boost::signals2::signal<void (double, const DynamicObject::Ptr&)> OnFlushObject;
ScriptTask::Ptr MakeMethodTask(const String& method,
- const vector<Value>& arguments);
+ const std::vector<Value>& arguments);
shared_ptr<DynamicType> GetType(void) const;
String GetName(void) const;
mutable boost::mutex m_AttributeMutex;
AttributeMap m_Attributes;
- set<String, string_iless> m_ModifiedAttributes;
+ std::set<String, string_iless> m_ModifiedAttributes;
double m_ConfigTx;
Attribute<String> m_Name;
/* This has to be a set of raw pointers because the DynamicObject
* constructor has to be able to insert objects into this list. */
- static set<DynamicObject::WeakPtr> m_ModifiedObjects;
+ static std::set<DynamicObject::WeakPtr> m_ModifiedObjects;
static boost::mutex m_TransactionMutex;
static boost::once_flag m_TransactionOnce;
static Timer::Ptr m_TransactionTimer;
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
using namespace icinga;
return InternalGetTypeSet(); /* Making a copy of the set here. */
}
-set<DynamicObject::Ptr> DynamicType::GetObjects(const String& type)
+std::set<DynamicObject::Ptr> DynamicType::GetObjects(const String& type)
{
DynamicType::Ptr dt = GetByName(type);
return dt->GetObjects();
}
-set<DynamicObject::Ptr> DynamicType::GetObjects(void) const
+std::set<DynamicObject::Ptr> DynamicType::GetObjects(void) const
{
ObjectLock olock(this);
if (it->second == object)
return;
- BOOST_THROW_EXCEPTION(runtime_error("RegisterObject() found existing object with the same name: " + name));
+ BOOST_THROW_EXCEPTION(std::runtime_error("RegisterObject() found existing object with the same name: " + name));
}
m_ObjectMap[name] = object;
DynamicType::TypeMap::const_iterator tt = InternalGetTypeMap().find(type->GetName());
if (tt != InternalGetTypeMap().end())
- BOOST_THROW_EXCEPTION(runtime_error("Cannot register class for type '" +
+ BOOST_THROW_EXCEPTION(std::runtime_error("Cannot register class for type '" +
type->GetName() + "': Objects of this type already exist."));
InternalGetTypeMap()[type->GetName()] = type;
#ifndef DYNAMICTYPE_H
#define DYNAMICTYPE_H
+#include "base/i2-base.h"
+#include "base/registry.h"
+#include "base/dynamicobject.h"
+#include <map>
+#include <set>
#include <boost/function.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
namespace icinga
{
void RegisterObject(const DynamicObject::Ptr& object);
void UnregisterObject(const DynamicObject::Ptr& object);
- static set<DynamicType::Ptr> GetTypes(void);
- set<DynamicObject::Ptr> GetObjects(void) const;
+ static std::set<DynamicType::Ptr> GetTypes(void);
+ std::set<DynamicObject::Ptr> GetObjects(void) const;
- static set<DynamicObject::Ptr> GetObjects(const String& type);
+ static std::set<DynamicObject::Ptr> GetObjects(const String& type);
private:
String m_Name;
ObjectFactory m_ObjectFactory;
- typedef map<String, DynamicObject::Ptr, string_iless> ObjectMap;
- typedef set<DynamicObject::Ptr> ObjectSet;
+ typedef std::map<String, DynamicObject::Ptr, string_iless> ObjectMap;
+ typedef std::set<DynamicObject::Ptr> ObjectSet;
ObjectMap m_ObjectMap;
ObjectSet m_ObjectSet;
- typedef map<String, DynamicType::Ptr, string_iless> TypeMap;
- typedef set<DynamicType::Ptr> TypeSet;
+ typedef std::map<String, DynamicType::Ptr, string_iless> TypeMap;
+ typedef std::set<DynamicType::Ptr> TypeSet;
static TypeMap& InternalGetTypeMap(void);
static TypeSet& InternalGetTypeSet(void);
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/eventqueue.h"
+#include "base/logger_fwd.h"
+#include "base/convert.h"
+#include "base/utility.h"
+#include <sstream>
#include <boost/bind.hpp>
+#include <boost/exception/diagnostic_information.hpp>
using namespace icinga;
try {
event();
} catch (const std::exception& ex) {
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "Exception thrown in event handler: " << std::endl
- << diagnostic_information(ex);
+ << boost::diagnostic_information(ex);
- Logger::Write(LogCritical, "base", msgbuf.str());
+ Log(LogCritical, "base", msgbuf.str());
} catch (...) {
- Logger::Write(LogCritical, "base", "Exception of unknown type thrown in event handler.");
+ Log(LogCritical, "base", "Exception of unknown type thrown in event handler.");
}
#ifdef _DEBUG
msgbuf << "Event call took " << (et - st) << "s";
# endif /* RUSAGE_THREAD */
- Logger::Write(LogWarning, "base", msgbuf.str());
+ Log(LogWarning, "base", msgbuf.str());
}
#endif /* _DEBUG */
}
pending = m_Events.size();
}
- Logger::Write(LogInformation, "base", "Pending tasks: " + Convert::ToString(pending));
+ Log(LogInformation, "base", "Pending tasks: " + Convert::ToString(pending));
}
}
#ifndef EVENTQUEUE_H
#define EVENTQUEUE_H
+#include "base/i2-base.h"
+#include <stack>
#include <boost/function.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
namespace icinga
{
-class Timer;
-
/**
* An event queue.
*
boost::condition_variable m_CV;
bool m_Stopped;
- stack<Callback> m_Events;
+ std::stack<Callback> m_Events;
void QueueThreadProc(void);
void ReportThreadProc(void);
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/exception.h"
using namespace icinga;
#ifndef EXCEPTION_H
#define EXCEPTION_H
+#include "base/i2-base.h"
+#include "base/stacktrace.h"
+#include <sstream>
#include <boost/thread/tss.hpp>
+#ifdef _WIN32
+# include <boost/algorithm/string/trim.hpp>
+#endif /* _WIN32 */
+
namespace icinga
{
*
* @ingroup base
*/
-class I2_BASE_API Exception //: public virtual exception
+class I2_BASE_API Exception
{
public:
static StackTrace *GetLastStackTrace(void);
inline std::string to_string(const errinfo_win32_error& e)
{
- stringstream tmp;
+ std::ostringstream tmp;
int code = e.value();
char *message;
inline std::string to_string(const errinfo_openssl_error& e)
{
- stringstream tmp;
+ std::ostringstream tmp;
int code = e.value();
const char *message = ERR_error_string(code, NULL);
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
-
-using std::bad_alloc;
+#include "base/fifo.h"
+#include "base/utility.h"
using namespace icinga;
char *newBuffer = static_cast<char *>(realloc(m_Buffer, newSize));
if (newBuffer == NULL)
- BOOST_THROW_EXCEPTION(bad_alloc());
+ BOOST_THROW_EXCEPTION(std::bad_alloc());
m_Buffer = newBuffer;
#ifndef FIFO_H
#define FIFO_H
+#include "base/i2-base.h"
+#include "base/stream.h"
+
namespace icinga
{
#include <sys/stat.h>
#include <signal.h>
-#include <string>
#include <exception>
#include <stdexcept>
-#include <sstream>
-#include <vector>
-#include <set>
-#include <iostream>
-#include <fstream>
-#include <list>
-#include <typeinfo>
-#include <map>
-#include <list>
-#include <algorithm>
-#include <deque>
-#include <stack>
-#include <iterator>
-using std::vector;
-using std::map;
-using std::list;
-using std::set;
-using std::multimap;
-using std::multiset;
-using std::pair;
-using std::deque;
-using std::stack;
-using std::make_pair;
-
-using std::stringstream;
-using std::istream;
-using std::ostream;
-using std::fstream;
-using std::ifstream;
-using std::ofstream;
-using std::iostream;
-
-using std::exception;
-using std::bad_alloc;
-using std::bad_cast;
-using std::runtime_error;
-using std::logic_error;
-using std::invalid_argument;
-using std::domain_error;
-
-using std::type_info;
-
-#include <boost/smart_ptr.hpp>
-#include <boost/make_shared.hpp>
-#include <boost/bind.hpp>
-#include <boost/signals2.hpp>
-#include <boost/foreach.hpp>
-#include <boost/exception/diagnostic_information.hpp>
+#include <boost/smart_ptr/shared_ptr.hpp>
+#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/exception/error_info.hpp>
#include <boost/exception/errinfo_api_function.hpp>
#include <boost/exception/errinfo_errno.hpp>
#include <boost/exception/errinfo_file_name.hpp>
-#include <boost/multi_index_container.hpp>
-#include <boost/multi_index/ordered_index.hpp>
-#include <boost/multi_index/key_extractors.hpp>
using boost::shared_ptr;
using boost::weak_ptr;
using boost::dynamic_pointer_cast;
using boost::static_pointer_cast;
-using boost::diagnostic_information;
using boost::errinfo_api_function;
using boost::errinfo_errno;
using boost::errinfo_file_name;
-using boost::multi_index_container;
-using boost::multi_index::indexed_by;
-using boost::multi_index::identity;
-using boost::multi_index::ordered_unique;
-using boost::multi_index::ordered_non_unique;
-using boost::multi_index::nth_index;
-
-namespace signals2 = boost::signals2;
#if defined(__APPLE__) && defined(__MACH__)
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#include <openssl/ssl.h>
#include <openssl/err.h>
-#if HAVE_GCC_ABI_DEMANGLE
-# include <cxxabi.h>
-#endif /* HAVE_GCC_ABI_DEMANGLE */
-
#ifdef I2_BASE_BUILD
# define I2_BASE_API I2_EXPORT
#else /* I2_BASE_BUILD */
# define I2_BASE_API I2_IMPORT
#endif /* I2_BASE_BUILD */
-#include "qstring.h"
-#include "utility.h"
-#include "stacktrace.h"
-#include "object.h"
-#include "objectlock.h"
-#include "exception.h"
-#include "eventqueue.h"
-#include "value.h"
-#include "convert.h"
-#include "dictionary.h"
-#include "array.h"
-#include "ringbuffer.h"
-#include "timer.h"
-#include "stream.h"
-#include "stream_bio.h"
-#include "connection.h"
-#include "netstring.h"
-#include "fifo.h"
-#include "stdiostream.h"
-#include "socket.h"
-#include "tcpsocket.h"
-#include "unixsocket.h"
-#include "tlsstream.h"
-#include "asynctask.h"
-#include "process.h"
-#include "singleton.h"
-#include "registry.h"
-#include "scriptfunction.h"
-#include "scripttask.h"
-#include "attribute.h"
-#include "dynamicobject.h"
-#include "dynamictype.h"
-#include "script.h"
-#include "scriptinterpreter.h"
-#include "scriptlanguage.h"
-#include "logger.h"
-#include "application.h"
-#include "streamlogger.h"
-#include "sysloglogger.h"
-
#endif /* I2BASE_H */
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/application.h"
+#include "base/streamlogger.h"
+#include "base/sysloglogger.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include <boost/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
RegisterAttribute("severity", Attribute_Config, &m_Severity);
if (!IsLocal())
- BOOST_THROW_EXCEPTION(runtime_error("Logger objects must be local."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Logger objects must be local."));
}
void Logger::Start(void)
{
String type = m_Type;
if (type.IsEmpty())
- BOOST_THROW_EXCEPTION(runtime_error("Logger objects must have a 'type' property."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Logger objects must have a 'type' property."));
ILogger::Ptr impl;
#ifndef _WIN32
impl = boost::make_shared<SyslogLogger>();
#else /* _WIN32 */
- BOOST_THROW_EXCEPTION(invalid_argument("Syslog is not supported on Windows."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Syslog is not supported on Windows."));
#endif /* _WIN32 */
} else if (type == "file") {
String path = m_Path;
if (path.IsEmpty())
- BOOST_THROW_EXCEPTION(invalid_argument("'log' object of type 'file' must have a 'path' property"));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("'log' object of type 'file' must have a 'path' property"));
StreamLogger::Ptr slogger = boost::make_shared<StreamLogger>();
slogger->OpenFile(path);
} else if (type == "console") {
impl = boost::make_shared<StreamLogger>(&std::cout);
} else {
- BOOST_THROW_EXCEPTION(runtime_error("Unknown log type: " + type));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Unknown log type: " + type));
}
impl->m_Config = GetSelf();
* @param facility The log facility.
* @param message The message.
*/
-void Logger::Write(LogSeverity severity, const String& facility,
+void icinga::Log(LogSeverity severity, const String& facility,
const String& message)
{
LogEntry entry;
entry.Facility = facility;
entry.Message = message;
- ForwardLogEntry(entry);
+ Logger::ForwardLogEntry(entry);
}
/**
case LogCritical:
return "critical";
default:
- BOOST_THROW_EXCEPTION(invalid_argument("Invalid severity."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity."));
}
}
else if (severity == "critical")
return LogCritical;
else
- BOOST_THROW_EXCEPTION(invalid_argument("Invalid severity: " + severity));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity: " + severity));
}
/**
#ifndef LOGGER_H
#define LOGGER_H
-namespace icinga
-{
+#include "base/i2-base.h"
+#include "base/dynamicobject.h"
+#include "base/logger_fwd.h"
-/**
- * Log severity.
- *
- * @ingroup base
- */
-enum LogSeverity
+namespace icinga
{
- LogDebug,
- LogInformation,
- LogWarning,
- LogCritical
-};
/**
* A lot entry.
explicit Logger(const Dictionary::Ptr& serializedUpdate);
- static void Write(LogSeverity severity, const String& facility,
- const String& message);
-
static String SeverityToString(LogSeverity severity);
static LogSeverity StringToSeverity(const String& severity);
ILogger::Ptr m_Impl;
static void ForwardLogEntry(const LogEntry& entry);
+
+ friend void Log(LogSeverity severity, const String& facility,
+ const String& message);
};
}
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/netstring.h"
+#include <sstream>
using namespace icinga;
char *buffer = static_cast<char *>(malloc(buffer_length));
if (buffer == NULL)
- BOOST_THROW_EXCEPTION(bad_alloc());
+ BOOST_THROW_EXCEPTION(std::bad_alloc());
peek_length = stream->Peek(buffer, buffer_length);
/* no leading zeros allowed */
if (buffer[0] == '0' && isdigit(buffer[1])) {
free(buffer);
- BOOST_THROW_EXCEPTION(invalid_argument("Invalid netString (leading zero)"));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid netString (leading zero)"));
}
size_t len, i;
/* length specifier must have at most 9 characters */
if (i >= 9) {
free(buffer);
- BOOST_THROW_EXCEPTION(invalid_argument("Length specifier must not exceed 9 characters"));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Length specifier must not exceed 9 characters"));
}
len = len * 10 + (buffer[i] - '0');
if (new_buffer == NULL) {
free(buffer);
- BOOST_THROW_EXCEPTION(bad_alloc());
+ BOOST_THROW_EXCEPTION(std::bad_alloc());
}
buffer = new_buffer;
/* check for the colon delimiter */
if (buffer[i] != ':') {
free(buffer);
- BOOST_THROW_EXCEPTION(invalid_argument("Invalid NetString (missing :)"));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid NetString (missing :)"));
}
/* check for the comma delimiter after the String */
if (buffer[i + 1 + len] != ',') {
free(buffer);
- BOOST_THROW_EXCEPTION(invalid_argument("Invalid NetString (missing ,)"));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid NetString (missing ,)"));
}
*str = String(&buffer[i + 1], &buffer[i + 1 + len]);
*/
void NetString::WriteStringToStream(const Stream::Ptr& stream, const String& str)
{
- stringstream prefixbuf;
+ std::ostringstream prefixbuf;
prefixbuf << str.GetLength() << ":";
String prefix = prefixbuf.str();
#ifndef NETSTRING_H
#define NETSTRING_H
+#include "base/i2-base.h"
+#include "base/stream.h"
+
namespace icinga
{
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/object.h"
using namespace icinga;
#ifndef OBJECT_H
#define OBJECT_H
+#include "base/i2-base.h"
#include <boost/thread/mutex.hpp>
+#include <boost/smart_ptr/enable_shared_from_this.hpp>
namespace icinga
{
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/objectlock.h"
+#include "base/utility.h"
using namespace icinga;
#ifndef OBJECTLOCK_H
#define OBJECTLOCK_H
+#include "base/object.h"
+
namespace icinga
{
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/process.h"
+#include "base/exception.h"
+#include "base/convert.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
+#include <map>
#include <boost/bind.hpp>
#include <boost/tuple/tuple.hpp>
+#include <boost/make_shared.hpp>
+#include <boost/foreach.hpp>
#ifndef _WIN32
#include <execvpe.h>
void Process::WorkerThreadProc(int taskFd)
{
- map<int, Process::Ptr> tasks;
+ std::map<int, Process::Ptr> tasks;
pollfd *pfds = NULL;
for (;;) {
- map<int, Process::Ptr>::iterator it, prev;
+ std::map<int, Process::Ptr>::iterator it, prev;
pfds = (pollfd *)realloc(pfds, (1 + tasks.size()) * sizeof(pollfd));
continue;
if (pfds[i].fd == taskFd) {
- vector<Process::Ptr> new_tasks;
+ std::vector<Process::Ptr> new_tasks;
unsigned int want = MaxTasksPerThread - tasks.size();
if (WIFEXITED(status)) {
exitcode = WEXITSTATUS(status);
} else if (WIFSIGNALED(status)) {
- stringstream outputbuf;
+ std::ostringstream outputbuf;
outputbuf << "Process was terminated by signal " << WTERMSIG(status);
output = outputbuf.str();
exitcode = 128;
{
boost::mutex::scoped_lock lock(m_Mutex);
if (m_Tasks.size() > 50)
- Logger::Write(LogCritical, "base", "More than 50 waiting Process tasks: " +
+ Log(LogCritical, "base", "More than 50 waiting Process tasks: " +
Convert::ToString(m_Tasks.size()));
}
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/process.h"
#ifdef _WIN32
using namespace icinga;
******************************************************************************/
#include "i2-base.h"
+#include "base/process.h"
+#include "base/array.h"
+#include "base/objectlock.h"
+#include <boost/foreach.hpp>
using namespace icinga;
boost::once_flag Process::m_ThreadOnce = BOOST_ONCE_INIT;
boost::mutex Process::m_Mutex;
-deque<Process::Ptr> Process::m_Tasks;
+std::deque<Process::Ptr> Process::m_Tasks;
-Process::Process(const vector<String>& arguments, const Dictionary::Ptr& extraEnvironment)
+Process::Process(const std::vector<String>& arguments, const Dictionary::Ptr& extraEnvironment)
: AsyncTask<Process, ProcessResult>(), m_Arguments(arguments), m_ExtraEnvironment(extraEnvironment)
{
{
#endif /* _WIN32 */
}
-vector<String> Process::SplitCommand(const Value& command)
+std::vector<String> Process::SplitCommand(const Value& command)
{
- vector<String> args;
+ std::vector<String> args;
if (command.IsObjectType<Array>()) {
Array::Ptr arguments = command;
#ifndef PROCESS_H
#define PROCESS_H
+#include "base/i2-base.h"
+#include "base/timer.h"
+#include "base/asynctask.h"
+#include "base/dictionary.h"
+#include <sstream>
+#include <deque>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/once.hpp>
typedef shared_ptr<Process> Ptr;
typedef weak_ptr<Process> WeakPtr;
- static const deque<Process::Ptr>::size_type MaxTasksPerThread = 512;
+ static const std::deque<Process::Ptr>::size_type MaxTasksPerThread = 512;
- Process(const vector<String>& arguments, const Dictionary::Ptr& extraEnvironment = Dictionary::Ptr());
+ Process(const std::vector<String>& arguments, const Dictionary::Ptr& extraEnvironment = Dictionary::Ptr());
- static vector<String> SplitCommand(const Value& command);
+ static std::vector<String> SplitCommand(const Value& command);
private:
- vector<String> m_Arguments;
+ std::vector<String> m_Arguments;
Dictionary::Ptr m_ExtraEnvironment;
#ifndef _WIN32
int m_FD;
#endif /* _WIN32 */
- stringstream m_OutputStream;
+ std::ostringstream m_OutputStream;
ProcessResult m_Result;
virtual void Run(void);
static boost::mutex m_Mutex;
- static deque<Process::Ptr> m_Tasks;
+ static std::deque<Process::Ptr> m_Tasks;
#ifndef _WIN32
static boost::condition_variable m_CV;
static int m_TaskFd;
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/qstring.h"
#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/compare.hpp>
m_Data.replace(first, second, str);
}
-String Join(const vector<String>& strings, const char *delim)
+String Join(const std::vector<String>& strings, const char *delim)
{
return boost::algorithm::join(strings, delim);
}
return m_Data.end();
}
-ostream& icinga::operator<<(ostream& stream, const String& str)
+std::ostream& icinga::operator<<(std::ostream& stream, const String& str)
{
stream << static_cast<std::string>(str);
return stream;
}
-istream& icinga::operator>>(istream& stream, String& str)
+std::istream& icinga::operator>>(std::istream& stream, String& str)
{
std::string tstr;
stream >> tstr;
#ifndef STRING_H
#define STRING_H
+#include "base/i2-base.h"
+#include <ostream>
+#include <istream>
+#include <vector>
#include <boost/algorithm/string/split.hpp>
namespace icinga {
void Replace(size_t first, size_t second, const String& str);
template<typename Predicate>
- vector<String> Split(const Predicate& predicate) const
+ std::vector<String> Split(const Predicate& predicate) const
{
- vector<String> tokens;
+ std::vector<String> tokens;
boost::algorithm::split(tokens, m_Data, predicate);
return tokens;
}
- static String Join(const vector<String>& strings, const char *delim);
+ static String Join(const std::vector<String>& strings, const char *delim);
void Trim(void);
std::string m_Data;
};
-I2_BASE_API ostream& operator<<(ostream& stream, const String& str);
-I2_BASE_API istream& operator>>(istream& stream, String& str);
+I2_BASE_API std::ostream& operator<<(std::ostream& stream, const String& str);
+I2_BASE_API std::istream& operator>>(std::istream& stream, String& str);
I2_BASE_API String operator+(const String& lhs, const String& rhs);
I2_BASE_API String operator+(const String& lhs, const char *rhs);
#ifndef REGISTRY_H
#define REGISTRY_H
+#include "base/i2-base.h"
+#include "base/singleton.h"
+#include "base/qstring.h"
+#include <map>
+#include <boost/thread/mutex.hpp>
+#include <boost/signals2.hpp>
+
namespace icinga
{
class I2_BASE_API Registry
{
public:
- typedef map<String, T, string_iless> ItemMap;
+ typedef std::map<String, T, string_iless> ItemMap;
static Registry<T> *GetInstance(void)
{
return m_Items; /* Makes a copy of the map. */
}
- signals2::signal<void (const String&, const T&)> OnRegistered;
- signals2::signal<void (const String&)> OnUnregistered;
+ boost::signals2::signal<void (const String&, const T&)> OnRegistered;
+ boost::signals2::signal<void (const String&)> OnUnregistered;
private:
mutable boost::mutex m_Mutex;
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/ringbuffer.h"
+#include "base/objectlock.h"
using namespace icinga;
#ifndef RINGBUFFER_H
#define RINGBUFFER_H
+#include "base/i2-base.h"
+#include "base/object.h"
+#include <vector>
+
namespace icinga
{
typedef shared_ptr<RingBuffer> Ptr;
typedef weak_ptr<RingBuffer> WeakPtr;
- typedef vector<int>::size_type SizeType;
+ typedef std::vector<int>::size_type SizeType;
RingBuffer(SizeType slots);
int GetValues(SizeType span) const;
private:
- vector<int> m_Slots;
+ std::vector<int> m_Slots;
SizeType m_TimeValue;
};
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/script.h"
+#include "base/scriptlanguage.h"
+#include "base/dynamictype.h"
+#include "base/logger_fwd.h"
+#include "base/objectlock.h"
using namespace icinga;
*/
void Script::SpawnInterpreter(void)
{
- Logger::Write(LogInformation, "base", "Reloading script '" + GetName() + "'");
+ Log(LogInformation, "base", "Reloading script '" + GetName() + "'");
ScriptLanguage::Ptr language = ScriptLanguage::GetByName(GetLanguage());
m_Interpreter = language->CreateInterpreter(GetSelf());
#ifndef SCRIPT_H
#define SCRIPT_H
+#include "base/i2-base.h"
+#include "base/dynamicobject.h"
+
namespace icinga
{
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/registry.h"
+#include "base/scriptfunction.h"
+#include "base/scripttask.h"
+#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
/**
* @threadsafety Always.
*/
-void ScriptFunction::Invoke(const ScriptTask::Ptr& task, const vector<Value>& arguments)
+void ScriptFunction::Invoke(const ScriptTask::Ptr& task, const std::vector<Value>& arguments)
{
m_Callback(task, arguments);
}
+
+RegisterFunctionHelper::RegisterFunctionHelper(const String& name, const ScriptFunction::Callback& function)
+{
+ ScriptFunction::Ptr func = boost::make_shared<ScriptFunction>(function);
+ ScriptFunctionRegistry::GetInstance()->Register(name, func);
+}
#ifndef SCRIPTFUNCTION_H
#define SCRIPTFUNCTION_H
+#include "base/i2-base.h"
+#include "base/registry.h"
+#include "base/value.h"
+#include <vector>
#include <boost/function.hpp>
namespace icinga
typedef shared_ptr<ScriptFunction> Ptr;
typedef weak_ptr<ScriptFunction> WeakPtr;
- typedef boost::function<void (const shared_ptr<ScriptTask>&, const vector<Value>& arguments)> Callback;
+ typedef boost::function<void (const shared_ptr<ScriptTask>&, const std::vector<Value>& arguments)> Callback;
explicit ScriptFunction(const Callback& function);
private:
Callback m_Callback;
- void Invoke(const shared_ptr<ScriptTask>& task, const vector<Value>& arguments);
+ void Invoke(const shared_ptr<ScriptTask>& task, const std::vector<Value>& arguments);
friend class ScriptTask;
};
*
* @ingroup base
*/
-class RegisterFunctionHelper
+class I2_BASE_API RegisterFunctionHelper
{
public:
- RegisterFunctionHelper(const String& name, const ScriptFunction::Callback& function)
- {
- ScriptFunction::Ptr func = boost::make_shared<ScriptFunction>(function);
- ScriptFunctionRegistry::GetInstance()->Register(name, func);
- }
+ RegisterFunctionHelper(const String& name, const ScriptFunction::Callback& function);
};
#define REGISTER_SCRIPTFUNCTION(name, callback) \
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/scriptinterpreter.h"
+#include "base/objectlock.h"
+#include <boost/bind.hpp>
+#include <boost/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
#ifndef SCRIPTINTERPRETER_H
#define SCRIPTINTERPRETER_H
+#include "base/i2-base.h"
+#include "base/script.h"
+#include <vector>
+#include <set>
+
namespace icinga
{
ScriptInterpreter(const Script::Ptr& script);
virtual void ProcessCall(const ScriptTask::Ptr& task, const String& function,
- const vector<Value>& arguments) = 0;
+ const std::vector<Value>& arguments) = 0;
void SubscribeFunction(const String& name);
void UnsubscribeFunction(const String& name);
private:
- set<String> m_SubscribedFunctions;
+ std::set<String> m_SubscribedFunctions;
};
}
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/scriptlanguage.h"
using namespace icinga;
{
boost::mutex::scoped_lock lock(GetMutex());
- map<String, ScriptLanguage::Ptr>::iterator it;
+ std::map<String, ScriptLanguage::Ptr>::iterator it;
it = GetLanguages().find(name);
return mutex;
}
-map<String, ScriptLanguage::Ptr>& ScriptLanguage::GetLanguages(void)
+std::map<String, ScriptLanguage::Ptr>& ScriptLanguage::GetLanguages(void)
{
- static map<String, ScriptLanguage::Ptr> languages;
+ static std::map<String, ScriptLanguage::Ptr> languages;
return languages;
}
#ifndef SCRIPTLANGUAGE_H
#define SCRIPTLANGUAGE_H
+#include "base/i2-base.h"
+#include "base/scriptinterpreter.h"
+#include <map>
+
namespace icinga
{
private:
static boost::mutex& GetMutex(void);
- static map<String, ScriptLanguage::Ptr>& GetLanguages(void);
+ static std::map<String, ScriptLanguage::Ptr>& GetLanguages(void);
};
/**
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/scripttask.h"
using namespace icinga;
ScriptTask::ScriptTask(const ScriptFunction::Ptr& function,
- const vector<Value>& arguments)
+ const std::vector<Value>& arguments)
: AsyncTask<ScriptTask, Value>(), m_Function(function),
m_Arguments(arguments)
{ }
#ifndef SCRIPTTASK_H
#define SCRIPTTASK_H
+#include "base/i2-base.h"
+#include "base/asynctask.h"
+#include "base/scriptfunction.h"
+#include <vector>
+
namespace icinga
{
typedef shared_ptr<ScriptTask> Ptr;
typedef weak_ptr<ScriptTask> WeakPtr;
- ScriptTask(const ScriptFunction::Ptr& function, const vector<Value>& arguments);
+ ScriptTask(const ScriptFunction::Ptr& function, const std::vector<Value>& arguments);
protected:
virtual void Run(void);
private:
ScriptFunction::Ptr m_Function;
- vector<Value> m_Arguments;
+ std::vector<Value> m_Arguments;
};
}
#ifndef SINGLETON_H
#define SINGLETON_H
+#include "base/i2-base.h"
+#include <boost/thread/mutex.hpp>
+
namespace icinga
{
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/socket.h"
+#include "base/objectlock.h"
+#include "base/utility.h"
+#include <sstream>
#include <boost/bind.hpp>
+#include <boost/make_shared.hpp>
using namespace icinga;
#endif /* _WIN32 */
}
- stringstream s;
+ std::ostringstream s;
s << "[" << host << "]:" << service;
return s.str();
}
ObjectLock olock(this);
if (m_Listening)
- throw new logic_error("Socket does not support GetAvailableBytes().");
+ throw new std::logic_error("Socket does not support GetAvailableBytes().");
return m_RecvQueue->GetAvailableBytes();
}
ObjectLock olock(this);
if (m_Listening)
- throw new logic_error("Socket does not support Read().");
+ throw new std::logic_error("Socket does not support Read().");
}
if (m_RecvQueue->GetAvailableBytes() == 0)
ObjectLock olock(this);
if (m_Listening)
- throw new logic_error("Socket does not support Peek().");
+ throw new std::logic_error("Socket does not support Peek().");
}
if (m_RecvQueue->GetAvailableBytes() == 0)
ObjectLock olock(this);
if (m_Listening)
- throw new logic_error("Socket does not support Write().");
+ throw new std::logic_error("Socket does not support Write().");
}
m_SendQueue->Write(buffer, size);
void Socket::HandleWritableServer(void)
{
- throw logic_error("This should never happen.");
+ throw std::logic_error("This should never happen.");
}
/**
#ifndef SOCKET_H
#define SOCKET_H
+#include "base/i2-base.h"
+#include "base/fifo.h"
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
+#include <boost/signals2.hpp>
namespace icinga {
void Listen(void);
- signals2::signal<void (const Socket::Ptr&, const Socket::Ptr&)> OnNewClient;
+ boost::signals2::signal<void (const Socket::Ptr&, const Socket::Ptr&)> OnNewClient;
protected:
void SetFD(SOCKET fd);
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/stacktrace.h"
+#include "base/qstring.h"
+#include "base/utility.h"
+
#if HAVE_BACKTRACE_SYMBOLS
# include <execinfo.h>
#endif /* HAVE_BACKTRACE_SYMBOLS */
* the one this function is executing in).
* @returns true if the stacktrace was printed, false otherwise.
*/
-void StackTrace::Print(ostream& fp, int ignoreFrames) const
+void StackTrace::Print(std::ostream& fp, int ignoreFrames) const
{
fp << std::endl << "Stacktrace:" << std::endl;
#endif /* _WIN32 */
}
-ostream& icinga::operator<<(ostream& stream, const StackTrace& trace)
+std::ostream& icinga::operator<<(std::ostream& stream, const StackTrace& trace)
{
trace.Print(stream, 1);
#ifndef STACKTRACE_H
#define STACKTRACE_H
+#include "base/i2-base.h"
+#include <ostream>
#include <boost/thread/once.hpp>
namespace icinga
explicit StackTrace(PEXCEPTION_POINTERS exi);
#endif /* _WIN32 */
- void Print(ostream& fp, int ignoreFrames = 0) const;
+ void Print(std::ostream& fp, int ignoreFrames = 0) const;
private:
void *m_Frames[64];
static void Initialize(void);
};
-I2_BASE_API ostream& operator<<(ostream& stream, const StackTrace& trace);
+I2_BASE_API std::ostream& operator<<(std::ostream& stream, const StackTrace& trace);
}
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/stdiostream.h"
+#include "base/objectlock.h"
+#include <boost/make_shared.hpp>
using namespace icinga;
* @param ownsStream Whether the new object owns the inner stream. If true
* the stream's destructor deletes the inner stream.
*/
-StdioStream::StdioStream(iostream *innerStream, bool ownsStream)
+StdioStream::StdioStream(std::iostream *innerStream, bool ownsStream)
: m_InnerStream(innerStream), m_OwnsStream(ownsStream),
m_ReadAheadBuffer(boost::make_shared<FIFO>())
{
#ifndef STDIOSTREAM_H
#define STDIOSTREAM_H
+#include "base/i2-base.h"
+#include "base/fifo.h"
+#include <iostream>
+
namespace icinga {
class StdioStream : public Stream
typedef shared_ptr<StdioStream> Ptr;
typedef weak_ptr<StdioStream> WeakPtr;
- StdioStream(iostream *innerStream, bool ownsStream);
+ StdioStream(std::iostream *innerStream, bool ownsStream);
~StdioStream(void);
virtual void Start(void);
virtual void Close(void);
private:
- iostream *m_InnerStream;
+ std::iostream *m_InnerStream;
bool m_OwnsStream;
FIFO::Ptr m_ReadAheadBuffer;
};
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/stream.h"
+#include "base/objectlock.h"
+#include "base/utility.h"
#include <boost/algorithm/string/trim.hpp>
using namespace icinga;
#ifndef STREAM_H
#define STREAM_H
+#include "base/i2-base.h"
+#include "base/object.h"
+#include "base/qstring.h"
#include <boost/exception_ptr.hpp>
+#include <boost/signals2.hpp>
namespace icinga
{
boost::exception_ptr GetException(void);
void CheckException(void);
- signals2::signal<void (const Stream::Ptr&)> OnConnected;
- signals2::signal<void (const Stream::Ptr&)> OnDataAvailable;
- signals2::signal<void (const Stream::Ptr&)> OnClosed;
+ boost::signals2::signal<void (const Stream::Ptr&)> OnConnected;
+ boost::signals2::signal<void (const Stream::Ptr&)> OnDataAvailable;
+ boost::signals2::signal<void (const Stream::Ptr&)> OnClosed;
protected:
void SetConnected(bool connected);
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/stream_bio.h"
using namespace icinga;
#ifndef STREAMBIO_H
#define STREAMBIO_H
+#include "base/i2-base.h"
+#include "base/stream.h"
+
namespace icinga
{
}
-#endif /* STREAMBIO_H */
\ No newline at end of file
+#endif /* STREAMBIO_H */
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/streamlogger.h"
+#include "base/objectlock.h"
+#include <fstream>
using namespace icinga;
*
* @param stream The stream.
*/
-StreamLogger::StreamLogger(ostream *stream)
+StreamLogger::StreamLogger(std::ostream *stream)
: ILogger(), m_Stream(stream), m_OwnsStream(false), m_Tty(IsTty(*stream))
{ }
*/
void StreamLogger::OpenFile(const String& filename)
{
- ofstream *stream = new ofstream();
+ std::ofstream *stream = new std::ofstream();
try {
- stream->open(filename.CStr(), fstream::out | fstream::trunc);
+ stream->open(filename.CStr(), std::fstream::out | std::fstream::trunc);
if (!stream->good())
- BOOST_THROW_EXCEPTION(runtime_error("Could not open logfile '" + filename + "'"));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Could not open logfile '" + filename + "'"));
} catch (...) {
delete stream;
throw;
* @param entry The log entry.
* @threadsafety Always.
*/
-void StreamLogger::ProcessLogEntry(ostream& stream, bool tty, const LogEntry& entry)
+void StreamLogger::ProcessLogEntry(std::ostream& stream, bool tty, const LogEntry& entry)
{
String timestamp = Utility::FormatDateTime("%Y/%m/%d %H:%M:%S %z", entry.Timestamp);
/**
* @threadsafety Always.
*/
-bool StreamLogger::IsTty(ostream& stream)
+bool StreamLogger::IsTty(std::ostream& stream)
{
#ifndef _WIN32
/* Eww... */
#ifndef STREAMLOGGER_H
#define STREAMLOGGER_H
+#include "base/i2-base.h"
+#include "base/logger.h"
+#include <ostream>
+
namespace icinga
{
typedef weak_ptr<StreamLogger> WeakPtr;
StreamLogger(void);
- explicit StreamLogger(ostream *stream);
+ explicit StreamLogger(std::ostream *stream);
~StreamLogger(void);
void OpenFile(const String& filename);
- static void ProcessLogEntry(ostream& stream, bool tty, const LogEntry& entry);
- static bool IsTty(ostream& stream);
+ static void ProcessLogEntry(std::ostream& stream, bool tty, const LogEntry& entry);
+ static bool IsTty(std::ostream& stream);
protected:
virtual void ProcessLogEntry(const LogEntry& entry);
private:
static boost::mutex m_Mutex;
- ostream *m_Stream;
+ std::ostream *m_Stream;
bool m_OwnsStream;
bool m_Tty;
};
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/sysloglogger.h"
#ifndef _WIN32
using namespace icinga;
#ifndef SYSLOGLOGGER_H
#define SYSLOGLOGGER_H
+#include "base/i2-base.h"
+#include "base/logger.h"
+
#ifndef _WIN32
namespace icinga
{
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/tcpsocket.h"
using namespace icinga;
freeaddrinfo(result);
if (fd == INVALID_SOCKET)
- BOOST_THROW_EXCEPTION(runtime_error("Could not create a suitable socket."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Could not create a suitable socket."));
}
/**
freeaddrinfo(result);
if (fd == INVALID_SOCKET)
- BOOST_THROW_EXCEPTION(runtime_error("Could not create a suitable socket."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Could not create a suitable socket."));
}
#ifndef TCPSOCKET_H
#define TCPSOCKET_H
+#include "base/i2-base.h"
+#include "base/socket.h"
+
namespace icinga
{
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/timer.h"
+#include "base/application.h"
#include <boost/bind.hpp>
using namespace icinga;
double now = Utility::GetTime();
- typedef nth_index<TimerSet, 1>::type TimerView;
+ typedef boost::multi_index::nth_index<TimerSet, 1>::type TimerView;
TimerView& idx = boost::get<1>(m_Timers);
TimerView::iterator it;
for (;;) {
boost::mutex::scoped_lock lock(m_Mutex);
- typedef nth_index<TimerSet, 1>::type NextTimerView;
+ typedef boost::multi_index::nth_index<TimerSet, 1>::type NextTimerView;
NextTimerView& idx = boost::get<1>(m_Timers);
/* Wait until there is at least one timer. */
#ifndef TIMER_H
#define TIMER_H
+#include "base/i2-base.h"
+#include "base/object.h"
+#include <list>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/ordered_index.hpp>
+#include <boost/multi_index/key_extractors.hpp>
+#include <boost/signals2.hpp>
namespace icinga {
typedef shared_ptr<Timer> Ptr;
typedef weak_ptr<Timer> WeakPtr;
- typedef list<Timer::WeakPtr> CollectionType;
+ typedef std::list<Timer::WeakPtr> CollectionType;
Timer(void);
void Reschedule(double next = -1);
double GetNext(void) const;
- signals2::signal<void(const Timer::Ptr&)> OnTimerExpired;
+ boost::signals2::signal<void(const Timer::Ptr&)> OnTimerExpired;
static void Initialize(void);
static void Uninitialize(void);
double m_Next; /**< When the next event should happen. */
bool m_Started; /**< Whether the timer is enabled. */
- typedef multi_index_container<
+ typedef boost::multi_index_container<
Timer::WeakPtr,
- indexed_by<
- ordered_unique<identity<Timer::WeakPtr> >,
- ordered_non_unique<TimerNextExtractor>
+ boost::multi_index::indexed_by<
+ boost::multi_index::ordered_unique<boost::multi_index::identity<Timer::WeakPtr> >,
+ boost::multi_index::ordered_non_unique<TimerNextExtractor>
>
> TimerSet;
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/tlsstream.h"
+#include "base/stream_bio.h"
+#include "base/objectlock.h"
+#include "base/utility.h"
+#include "base/exception.h"
#include <boost/bind.hpp>
+#include <boost/make_shared.hpp>
using namespace icinga;
}
if (!m_SSL)
- BOOST_THROW_EXCEPTION(logic_error("No X509 client certificate was specified."));
+ BOOST_THROW_EXCEPTION(std::logic_error("No X509 client certificate was specified."));
if (!m_SSLIndexInitialized) {
m_SSLIndex = SSL_get_ex_new_index(0, const_cast<char *>("TlsStream"), NULL, NULL, NULL);
#ifndef TLSSTREAM_H
#define TLSSTREAM_H
+#include "base/i2-base.h"
+#include "base/stream.h"
+#include "base/fifo.h"
+
namespace icinga
{
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/unixsocket.h"
+#include "base/exception.h"
#ifndef _WIN32
using namespace icinga;
#ifndef UNIXSOCKET_H
#define UNIXSOCKET_H
+#include "base/i2-base.h"
+#include "base/socket.h"
+
#ifndef _WIN32
namespace icinga
{
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/utility.h"
+#include "base/application.h"
+#include "base/logger_fwd.h"
+#include "base/exception.h"
#include <mmatch.h>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/function.hpp>
+#include <boost/foreach.hpp>
+
+#if HAVE_GCC_ABI_DEMANGLE
+# include <cxxabi.h>
+#endif /* HAVE_GCC_ABI_DEMANGLE */
using namespace icinga;
* @param ti A type_info object.
* @returns The type name of the object.
*/
-String Utility::GetTypeName(const type_info& ti)
+String Utility::GetTypeName(const std::type_info& ti)
{
return DemangleSymbolName(ti.name());
}
#endif /* _WIN32 */
if (dir == NULL)
- BOOST_THROW_EXCEPTION(bad_alloc());
+ BOOST_THROW_EXCEPTION(std::bad_alloc());
String result;
String result;
if (dir == NULL)
- BOOST_THROW_EXCEPTION(bad_alloc());
+ BOOST_THROW_EXCEPTION(std::bad_alloc());
#ifndef _WIN32
result = basename(dir);
path = "lib" + library + ".la";
#endif /* _WIN32 */
- Logger::Write(LogInformation, "base", "Loading library '" + path + "'");
+ Log(LogInformation, "base", "Loading library '" + path + "'");
#ifdef _WIN32
HMODULE hModule = LoadLibrary(path.CStr());
lt_dlhandle hModule = lt_dlopen(path.CStr());
if (hModule == NULL) {
- BOOST_THROW_EXCEPTION(runtime_error("Could not load library '" + path + "': " + lt_dlerror()));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Could not load library '" + path + "': " + lt_dlerror()));
}
#endif /* _WIN32 */
#ifndef UTILITY_H
#define UTILITY_H
+#include "base/i2-base.h"
+#include "base/qstring.h"
+#include <typeinfo>
#include <boost/function.hpp>
namespace icinga
{
public:
static String DemangleSymbolName(const String& sym);
- static String GetTypeName(const type_info& ti);
+ static String GetTypeName(const std::type_info& ti);
static shared_ptr<SSL_CTX> MakeSSLContext(const String& pubkey, const String& privkey, const String& cakey);
static String GetCertificateCN(const shared_ptr<X509>& certificate);
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-#include "i2-base.h"
+#include "base/application.h"
+#include "base/array.h"
+#include "base/logger_fwd.h"
#include <cJSON.h>
#include <boost/lexical_cast.hpp>
object = boost::get<Object::Ptr>(m_Value).get();
return "Object of type '" + Utility::GetTypeName(typeid(*object)) + "'";
default:
- BOOST_THROW_EXCEPTION(runtime_error("Unknown value type."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Unknown value type."));
}
}
else if (json->type == cJSON_NULL)
return Value();
else
- BOOST_THROW_EXCEPTION(invalid_argument("Unsupported JSON type."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Unsupported JSON type."));
}
/**
Array::Ptr array = *this;
return array->ToJson();
} else {
- Logger::Write(LogDebug, "base", "Ignoring unknown object while converting variant to JSON.");
+ Log(LogDebug, "base", "Ignoring unknown object while converting variant to JSON.");
return cJSON_CreateNull();
}
return cJSON_CreateNull();
default:
- BOOST_THROW_EXCEPTION(runtime_error("Invalid variant type."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Invalid variant type."));
}
}
cJSON *json = cJSON_Parse(jsonString.CStr());
if (!json)
- BOOST_THROW_EXCEPTION(runtime_error("Invalid JSON String"));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Invalid JSON String"));
Value value = FromJson(json);
cJSON_Delete(json);
#ifndef VALUE_H
#define VALUE_H
+#include "base/object.h"
+#include "base/qstring.h"
#include <boost/variant.hpp>
struct cJSON;
Object::Ptr object = dynamic_pointer_cast<Object>(value);
if (!object)
- BOOST_THROW_EXCEPTION(invalid_argument("shared_ptr value type must inherit from Object class."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("shared_ptr value type must inherit from Object class."));
m_Value = object;
}
shared_ptr<T> object = dynamic_pointer_cast<T>(boost::get<Object::Ptr>(m_Value));
if (!object)
- BOOST_THROW_EXCEPTION(bad_cast());
+ BOOST_THROW_EXCEPTION(std::bad_cast());
return object;
}
AM_YFLAGS = -d
EXTRA_DIST = \
- base-type.conf
+ base-type.conf \
+ i2-config.cpp
.conf.cpp: $(top_builddir)/tools/mkembedconfig.c
$(top_builddir)/tools/mkembedconfig $< $@
configcompilercontext.h \
config_lexer.ll \
config_parser.yy \
- i2-config.cpp \
i2-config.h \
configitem.cpp \
configitem.h \
libconfig_la_CPPFLAGS = \
-DI2_CONFIG_BUILD \
$(BOOST_CPPFLAGS) \
- -I${top_srcdir}/lib/base
+ -I${top_srcdir}/lib
libconfig_la_LDFLAGS = \
$(BOOST_LDFLAGS) \
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5
-#define YY_FLEX_SUBMINOR_VERSION 35
+#define YY_FLEX_SUBMINOR_VERSION 37
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
/* Size of default input buffer. */
#ifndef YY_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k.
- * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
- * Ditto for the __ia64__ case accordingly.
- */
-#define YY_BUF_SIZE 32768
-#else
#define YY_BUF_SIZE 16384
-#endif /* __ia64__ */
#endif
/* The state buf must be large enough to hold one state per character in the main buffer.
typedef struct yy_buffer_state *YY_BUFFER_STATE;
#endif
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef size_t yy_size_t;
+#endif
+
#define EOB_ACT_CONTINUE_SCAN 0
#define EOB_ACT_END_OF_FILE 1
#define EOB_ACT_LAST_MATCH 2
#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
-#ifndef YY_TYPEDEF_YY_SIZE_T
-#define YY_TYPEDEF_YY_SIZE_T
-typedef size_t yy_size_t;
-#endif
-
#ifndef YY_STRUCT_YY_BUFFER_STATE
#define YY_STRUCT_YY_BUFFER_STATE
struct yy_buffer_state
/* Number of characters read into yy_ch_buf, not including EOB
* characters.
*/
- int yy_n_chars;
+ yy_size_t yy_n_chars;
/* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to
YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
-YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner );
void *yyalloc (yy_size_t ,yyscan_t yyscanner );
void *yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
/* Begin user sect3 */
-#define yywrap(n) 1
+#define yywrap(yyscanner) 1
#define YY_SKIP_YYWRAP
typedef unsigned char YY_CHAR;
#include "i2-config.h"
#include "config_parser.h"
+#include <sstream>
using namespace icinga;
char *new_buf = (char *)realloc(lb->buf, new_len);
if (new_buf == NULL && new_len > 0)
- throw bad_alloc();
+ throw std::bad_alloc();
lb->buf = new_buf;
lb->size++;
-#line 701 "config_lexer.cc"
+#line 694 "config_lexer.cc"
#define INITIAL 0
#define C_COMMENT 1
size_t yy_buffer_stack_max; /**< capacity of stack. */
YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
char yy_hold_char;
- int yy_n_chars;
- int yyleng_r;
+ yy_size_t yy_n_chars;
+ yy_size_t yyleng_r;
char *yy_c_buf_p;
int yy_init;
int yy_start;
void yyset_out (FILE * out_str ,yyscan_t yyscanner );
-int yyget_leng (yyscan_t yyscanner );
+yy_size_t yyget_leng (yyscan_t yyscanner );
char *yyget_text (yyscan_t yyscanner );
/* Amount of stuff to slurp up with each read. */
#ifndef YY_READ_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k */
-#define YY_READ_BUF_SIZE 16384
-#else
#define YY_READ_BUF_SIZE 8192
-#endif /* __ia64__ */
#endif
/* Copy whatever the last rule matched to the standard output. */
register int yy_act;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-#line 91 "config_lexer.ll"
+#line 92 "config_lexer.ll"
lex_buf string_buf;
-#line 958 "config_lexer.cc"
+#line 946 "config_lexer.cc"
yylval = yylval_param;
case 1:
YY_RULE_SETUP
-#line 94 "config_lexer.ll"
+#line 95 "config_lexer.ll"
{ lb_init(&string_buf); BEGIN(STRING); }
YY_BREAK
case 2:
YY_RULE_SETUP
-#line 96 "config_lexer.ll"
+#line 97 "config_lexer.ll"
{
BEGIN(INITIAL);
case 3:
/* rule 3 can match eol */
YY_RULE_SETUP
-#line 106 "config_lexer.ll"
+#line 107 "config_lexer.ll"
{
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "Unterminated string found: " << *yylloc;
ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
BEGIN(INITIAL);
YY_BREAK
case 4:
YY_RULE_SETUP
-#line 113 "config_lexer.ll"
+#line 114 "config_lexer.ll"
{
/* octal escape sequence */
int result;
if (result > 0xff) {
/* error, constant is out-of-bounds */
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "Constant is out-of-bounds: " << yytext << " " << *yylloc;
ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
}
YY_BREAK
case 5:
YY_RULE_SETUP
-#line 129 "config_lexer.ll"
+#line 130 "config_lexer.ll"
{
/* generate error - bad escape sequence; something
* like '\48' or '\0777777'
*/
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "Bad escape sequence found: " << yytext << " " << *yylloc;
ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
}
YY_BREAK
case 6:
YY_RULE_SETUP
-#line 138 "config_lexer.ll"
+#line 139 "config_lexer.ll"
{ lb_append_char(&string_buf, '\n'); }
YY_BREAK
case 7:
YY_RULE_SETUP
-#line 139 "config_lexer.ll"
+#line 140 "config_lexer.ll"
{ lb_append_char(&string_buf, '\t'); }
YY_BREAK
case 8:
YY_RULE_SETUP
-#line 140 "config_lexer.ll"
+#line 141 "config_lexer.ll"
{ lb_append_char(&string_buf, '\r'); }
YY_BREAK
case 9:
YY_RULE_SETUP
-#line 141 "config_lexer.ll"
+#line 142 "config_lexer.ll"
{ lb_append_char(&string_buf, '\b'); }
YY_BREAK
case 10:
YY_RULE_SETUP
-#line 142 "config_lexer.ll"
+#line 143 "config_lexer.ll"
{ lb_append_char(&string_buf, '\f'); }
YY_BREAK
case 11:
/* rule 11 can match eol */
YY_RULE_SETUP
-#line 143 "config_lexer.ll"
+#line 144 "config_lexer.ll"
{ lb_append_char(&string_buf, yytext[1]); }
YY_BREAK
case 12:
YY_RULE_SETUP
-#line 145 "config_lexer.ll"
+#line 146 "config_lexer.ll"
{
char *yptr = yytext;
YY_BREAK
case 13:
YY_RULE_SETUP
-#line 152 "config_lexer.ll"
+#line 153 "config_lexer.ll"
{ lb_init(&string_buf); BEGIN(HEREDOC); }
YY_BREAK
case 14:
YY_RULE_SETUP
-#line 154 "config_lexer.ll"
+#line 155 "config_lexer.ll"
{
BEGIN(INITIAL);
case 15:
/* rule 15 can match eol */
YY_RULE_SETUP
-#line 164 "config_lexer.ll"
+#line 165 "config_lexer.ll"
{ lb_append_char(&string_buf, yytext[0]); }
YY_BREAK
case 16:
YY_RULE_SETUP
-#line 167 "config_lexer.ll"
+#line 168 "config_lexer.ll"
BEGIN(C_COMMENT);
YY_BREAK
case 17:
YY_RULE_SETUP
-#line 171 "config_lexer.ll"
+#line 172 "config_lexer.ll"
BEGIN(INITIAL);
YY_BREAK
case 18:
/* rule 18 can match eol */
YY_RULE_SETUP
-#line 172 "config_lexer.ll"
+#line 173 "config_lexer.ll"
/* ignore comment */
YY_BREAK
case 19:
YY_RULE_SETUP
-#line 173 "config_lexer.ll"
+#line 174 "config_lexer.ll"
/* ignore star */
YY_BREAK
case 20:
YY_RULE_SETUP
-#line 176 "config_lexer.ll"
+#line 177 "config_lexer.ll"
/* ignore C++-style comments */
YY_BREAK
case 21:
/* rule 21 can match eol */
YY_RULE_SETUP
-#line 177 "config_lexer.ll"
+#line 178 "config_lexer.ll"
/* ignore whitespace */
YY_BREAK
case 22:
YY_RULE_SETUP
-#line 180 "config_lexer.ll"
+#line 181 "config_lexer.ll"
return T_TYPE;
YY_BREAK
case 23:
YY_RULE_SETUP
-#line 181 "config_lexer.ll"
+#line 182 "config_lexer.ll"
{ yylval->type = TypeDictionary; return T_TYPE_DICTIONARY; }
YY_BREAK
case 24:
YY_RULE_SETUP
-#line 182 "config_lexer.ll"
+#line 183 "config_lexer.ll"
{ yylval->type = TypeArray; return T_TYPE_ARRAY; }
YY_BREAK
case 25:
YY_RULE_SETUP
-#line 183 "config_lexer.ll"
+#line 184 "config_lexer.ll"
{ yylval->type = TypeNumber; return T_TYPE_NUMBER; }
YY_BREAK
case 26:
YY_RULE_SETUP
-#line 184 "config_lexer.ll"
+#line 185 "config_lexer.ll"
{ yylval->type = TypeString; return T_TYPE_STRING; }
YY_BREAK
case 27:
YY_RULE_SETUP
-#line 185 "config_lexer.ll"
+#line 186 "config_lexer.ll"
{ yylval->type = TypeScalar; return T_TYPE_SCALAR; }
YY_BREAK
case 28:
YY_RULE_SETUP
-#line 186 "config_lexer.ll"
+#line 187 "config_lexer.ll"
{ yylval->type = TypeAny; return T_TYPE_ANY; }
YY_BREAK
case 29:
YY_RULE_SETUP
-#line 187 "config_lexer.ll"
+#line 188 "config_lexer.ll"
{ return T_VALIDATOR; }
YY_BREAK
case 30:
YY_RULE_SETUP
-#line 188 "config_lexer.ll"
+#line 189 "config_lexer.ll"
{ return T_REQUIRE; }
YY_BREAK
case 31:
YY_RULE_SETUP
-#line 189 "config_lexer.ll"
+#line 190 "config_lexer.ll"
{ return T_ATTRIBUTE; }
YY_BREAK
case 32:
YY_RULE_SETUP
-#line 190 "config_lexer.ll"
+#line 191 "config_lexer.ll"
return T_ABSTRACT;
YY_BREAK
case 33:
YY_RULE_SETUP
-#line 191 "config_lexer.ll"
+#line 192 "config_lexer.ll"
return T_LOCAL;
YY_BREAK
case 34:
YY_RULE_SETUP
-#line 192 "config_lexer.ll"
+#line 193 "config_lexer.ll"
return T_OBJECT;
YY_BREAK
case 35:
YY_RULE_SETUP
-#line 193 "config_lexer.ll"
+#line 194 "config_lexer.ll"
return T_TEMPLATE;
YY_BREAK
case 36:
YY_RULE_SETUP
-#line 194 "config_lexer.ll"
+#line 195 "config_lexer.ll"
return T_INCLUDE;
YY_BREAK
case 37:
YY_RULE_SETUP
-#line 195 "config_lexer.ll"
+#line 196 "config_lexer.ll"
return T_LIBRARY;
YY_BREAK
case 38:
YY_RULE_SETUP
-#line 196 "config_lexer.ll"
+#line 197 "config_lexer.ll"
return T_INHERITS;
YY_BREAK
case 39:
YY_RULE_SETUP
-#line 197 "config_lexer.ll"
+#line 198 "config_lexer.ll"
return T_NULL;
YY_BREAK
case 40:
YY_RULE_SETUP
-#line 198 "config_lexer.ll"
+#line 199 "config_lexer.ll"
return T_PARTIAL;
YY_BREAK
case 41:
YY_RULE_SETUP
-#line 199 "config_lexer.ll"
+#line 200 "config_lexer.ll"
{ yylval->num = 1; return T_NUMBER; }
YY_BREAK
case 42:
YY_RULE_SETUP
-#line 200 "config_lexer.ll"
+#line 201 "config_lexer.ll"
{ yylval->num = 0; return T_NUMBER; }
YY_BREAK
case 43:
YY_RULE_SETUP
-#line 201 "config_lexer.ll"
+#line 202 "config_lexer.ll"
{ yylval->text = strdup(yytext); return T_IDENTIFIER; }
YY_BREAK
case 44:
/* rule 44 can match eol */
YY_RULE_SETUP
-#line 202 "config_lexer.ll"
+#line 203 "config_lexer.ll"
{ yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING_ANGLE; }
YY_BREAK
case 45:
YY_RULE_SETUP
-#line 203 "config_lexer.ll"
+#line 204 "config_lexer.ll"
{ yylval->num = strtod(yytext, NULL) / 1000; return T_NUMBER; }
YY_BREAK
case 46:
YY_RULE_SETUP
-#line 204 "config_lexer.ll"
+#line 205 "config_lexer.ll"
{ yylval->num = strtod(yytext, NULL) * 60 * 60; return T_NUMBER; }
YY_BREAK
case 47:
YY_RULE_SETUP
-#line 205 "config_lexer.ll"
+#line 206 "config_lexer.ll"
{ yylval->num = strtod(yytext, NULL) * 60; return T_NUMBER; }
YY_BREAK
case 48:
YY_RULE_SETUP
-#line 206 "config_lexer.ll"
+#line 207 "config_lexer.ll"
{ yylval->num = strtod(yytext, NULL); return T_NUMBER; }
YY_BREAK
case 49:
YY_RULE_SETUP
-#line 207 "config_lexer.ll"
+#line 208 "config_lexer.ll"
{ yylval->num = strtod(yytext, NULL); return T_NUMBER; }
YY_BREAK
case 50:
YY_RULE_SETUP
-#line 208 "config_lexer.ll"
+#line 209 "config_lexer.ll"
{ yylval->op = OperatorSet; return T_EQUAL; }
YY_BREAK
case 51:
YY_RULE_SETUP
-#line 209 "config_lexer.ll"
+#line 210 "config_lexer.ll"
{ yylval->op = OperatorPlus; return T_PLUS_EQUAL; }
YY_BREAK
case 52:
YY_RULE_SETUP
-#line 210 "config_lexer.ll"
+#line 211 "config_lexer.ll"
{ yylval->op = OperatorMinus; return T_MINUS_EQUAL; }
YY_BREAK
case 53:
YY_RULE_SETUP
-#line 211 "config_lexer.ll"
+#line 212 "config_lexer.ll"
{ yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; }
YY_BREAK
case 54:
YY_RULE_SETUP
-#line 212 "config_lexer.ll"
+#line 213 "config_lexer.ll"
{ yylval->op = OperatorDivide; return T_DIVIDE_EQUAL; }
YY_BREAK
case 55:
YY_RULE_SETUP
-#line 215 "config_lexer.ll"
+#line 216 "config_lexer.ll"
return yytext[0];
YY_BREAK
case 56:
YY_RULE_SETUP
-#line 217 "config_lexer.ll"
+#line 218 "config_lexer.ll"
ECHO;
YY_BREAK
-#line 1392 "config_lexer.cc"
+#line 1380 "config_lexer.cc"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(C_COMMENT):
case YY_STATE_EOF(STRING):
else
{
- int num_to_read =
+ yy_size_t num_to_read =
YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
while ( num_to_read <= 0 )
{ /* Not enough room in the buffer - grow it. */
/* just a shorter name for the current buffer */
- YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
+ YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
int yy_c_buf_p_offset =
(int) (yyg->yy_c_buf_p - b->yy_ch_buf);
if ( b->yy_is_our_buffer )
{
- int new_size = b->yy_buf_size * 2;
+ yy_size_t new_size = b->yy_buf_size * 2;
if ( new_size <= 0 )
b->yy_buf_size += b->yy_buf_size / 8;
/* Read in more data. */
YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
- yyg->yy_n_chars, (size_t) num_to_read );
+ yyg->yy_n_chars, num_to_read );
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 196);
+ (void)yyg;
return yy_is_jam ? 0 : yy_current_state;
}
if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
{ /* need to shift things up to make room */
/* +2 for EOB chars. */
- register int number_to_move = yyg->yy_n_chars + 2;
+ register yy_size_t number_to_move = yyg->yy_n_chars + 2;
register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
register char *source =
else
{ /* need more input */
- int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
+ yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
++yyg->yy_c_buf_p;
switch ( yy_get_next_buffer( yyscanner ) )
*/
static void yyensure_buffer_stack (yyscan_t yyscanner)
{
- int num_to_alloc;
+ yy_size_t num_to_alloc;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if (!yyg->yy_buffer_stack) {
* @param yyscanner The scanner object.
* @return the newly allocated buffer state object.
*/
-YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner)
+YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
char *buf;
/** Get the length of the current token.
* @param yyscanner The scanner object.
*/
-int yyget_leng (yyscan_t yyscanner)
+yy_size_t yyget_leng (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyleng;
/* lineno is only valid if an input buffer exists. */
if (! YY_CURRENT_BUFFER )
- yy_fatal_error( "yyset_lineno called with no buffer" , yyscanner);
+ YY_FATAL_ERROR( "yyset_lineno called with no buffer" );
yylineno = line_number;
}
/* column is only valid if an input buffer exists. */
if (! YY_CURRENT_BUFFER )
- yy_fatal_error( "yyset_column called with no buffer" , yyscanner);
+ YY_FATAL_ERROR( "yyset_column called with no buffer" );
yycolumn = column_no;
}
#define YYTABLES_NAME "yytables"
-#line 217 "config_lexer.ll"
+#line 218 "config_lexer.ll"
#include "i2-config.h"
#include "config_parser.h"
+#include <sstream>
using namespace icinga;
char *new_buf = (char *)realloc(lb->buf, new_len);
if (new_buf == NULL && new_len > 0)
- throw bad_alloc();
+ throw std::bad_alloc();
lb->buf = new_buf;
lb->size++;
}
<STRING>\n {
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "Unterminated string found: " << *yylloc;
ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
BEGIN(INITIAL);
if (result > 0xff) {
/* error, constant is out-of-bounds */
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "Constant is out-of-bounds: " << yytext << " " << *yylloc;
ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
}
/* generate error - bad escape sequence; something
* like '\48' or '\0777777'
*/
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "Bad escape sequence found: " << yytext << " " << *yylloc;
ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
}
-/* A Bison parser, made by GNU Bison 2.5. */
+/* A Bison parser, made by GNU Bison 2.7. */
/* Bison implementation for Yacc-like parsers in C
- Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc.
+ Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#define YYBISON 1
/* Bison version. */
-#define YYBISON_VERSION "2.5"
+#define YYBISON_VERSION "2.7"
/* Skeleton name. */
#define YYSKELETON_NAME "yacc.c"
/* Pull parsers. */
#define YYPULL 1
-/* Using locations. */
-#define YYLSP_NEEDED 1
/* Copy the first part of user declarations. */
+/* Line 371 of yacc.c */
+#line 68 "config_parser.cc"
-/* Line 268 of yacc.c */
-#line 71 "config_parser.cc"
-
-/* Enabling traces. */
-#ifndef YYDEBUG
-# define YYDEBUG 0
-#endif
+# ifndef YY_NULL
+# if defined __cplusplus && 201103L <= __cplusplus
+# define YY_NULL nullptr
+# else
+# define YY_NULL 0
+# endif
+# endif
/* Enabling verbose error messages. */
#ifdef YYERROR_VERBOSE
# define YYERROR_VERBOSE 1
#endif
-/* Enabling the token table. */
-#ifndef YYTOKEN_TABLE
-# define YYTOKEN_TABLE 0
+/* In a future release of Bison, this section will be replaced
+ by #include "y.tab.h". */
+#ifndef YY_YY_CONFIG_PARSER_HH_INCLUDED
+# define YY_YY_CONFIG_PARSER_HH_INCLUDED
+/* Enabling traces. */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+#if YYDEBUG
+extern int yydebug;
#endif
-
/* "%code requires" blocks. */
-
-/* Line 288 of yacc.c */
+/* Line 387 of yacc.c */
#line 1 "config_parser.yy"
/******************************************************************************
******************************************************************************/
#include "i2-config.h"
+#include <sstream>
+#include <stack>
+#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
-
-/* Line 288 of yacc.c */
-#line 125 "config_parser.cc"
+/* Line 387 of yacc.c */
+#line 132 "config_parser.cc"
/* Tokens. */
#ifndef YYTOKENTYPE
-
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
-
-/* Line 293 of yacc.c */
-#line 38 "config_parser.yy"
+/* Line 387 of yacc.c */
+#line 41 "config_parser.yy"
char *text;
double num;
icinga::TypeSpecifier type;
-
-/* Line 293 of yacc.c */
-#line 212 "config_parser.cc"
+/* Line 387 of yacc.c */
+#line 216 "config_parser.cc"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
#endif
-/* Copy the second part of user declarations. */
+#ifdef YYPARSE_PARAM
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void *YYPARSE_PARAM);
+#else
+int yyparse ();
+#endif
+#else /* ! YYPARSE_PARAM */
+#if defined __STDC__ || defined __cplusplus
+int yyparse (ConfigCompiler *context);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
+
+#endif /* !YY_YY_CONFIG_PARSER_HH_INCLUDED */
-/* Line 343 of yacc.c */
-#line 85 "config_parser.yy"
+/* Copy the second part of user declarations. */
+/* Line 390 of yacc.c */
+#line 88 "config_parser.yy"
int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
void yyerror(YYLTYPE *locp, ConfigCompiler *, const char *err)
{
- stringstream message;
+ std::ostringstream message;
message << *locp << ": " << err;
ConfigCompilerContext::GetContext()->AddError(false, message.str());
}
int yyparse(ConfigCompiler *context);
-static stack<ExpressionList::Ptr> m_ExpressionLists;
-static stack<Array::Ptr> m_Arrays;
+static std::stack<ExpressionList::Ptr> m_ExpressionLists;
+static std::stack<Array::Ptr> m_Arrays;
static ConfigItemBuilder::Ptr m_Item;
static bool m_Abstract;
static bool m_Local;
-static stack<TypeRuleList::Ptr> m_RuleLists;
+static std::stack<TypeRuleList::Ptr> m_RuleLists;
static ConfigType::Ptr m_Type;
void ConfigCompiler::Compile(void)
try {
yyparse(this);
- } catch (const exception& ex) {
+ } catch (const std::exception& ex) {
ConfigCompilerContext::GetContext()->AddError(false, boost::diagnostic_information(ex));
}
}
#define scanner (context->GetScanner())
-
-/* Line 343 of yacc.c */
-#line 275 "config_parser.cc"
+/* Line 390 of yacc.c */
+#line 293 "config_parser.cc"
#ifdef short
# undef short
# if defined YYENABLE_NLS && YYENABLE_NLS
# if ENABLE_NLS
# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
-# define YY_(msgid) dgettext ("bison-runtime", msgid)
+# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
# endif
# endif
# ifndef YY_
-# define YY_(msgid) msgid
+# define YY_(Msgid) Msgid
# endif
#endif
/* Suppress unused-variable warnings by "using" E. */
#if ! defined lint || defined __GNUC__
-# define YYUSE(e) ((void) (e))
+# define YYUSE(E) ((void) (E))
#else
-# define YYUSE(e) /* empty */
+# define YYUSE(E) /* empty */
#endif
/* Identity function, used to suppress warnings about constant conditions. */
#ifndef lint
-# define YYID(n) (n)
+# define YYID(N) (N)
#else
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+ /* Use EXIT_SUCCESS as a witness for stdlib.h. */
# ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
# endif
#endif
#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
-/* Copy COUNT objects from FROM to TO. The source and destination do
+/* Copy COUNT objects from SRC to DST. The source and destination do
not overlap. */
# ifndef YYCOPY
# if defined __GNUC__ && 1 < __GNUC__
-# define YYCOPY(To, From, Count) \
- __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
+# define YYCOPY(Dst, Src, Count) \
+ __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
# else
-# define YYCOPY(To, From, Count) \
- do \
- { \
- YYSIZE_T yyi; \
- for (yyi = 0; yyi < (Count); yyi++) \
- (To)[yyi] = (From)[yyi]; \
- } \
+# define YYCOPY(Dst, Src, Count) \
+ do \
+ { \
+ YYSIZE_T yyi; \
+ for (yyi = 0; yyi < (Count); yyi++) \
+ (Dst)[yyi] = (Src)[yyi]; \
+ } \
while (YYID (0))
# endif
# endif
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
- 0, 123, 123, 124, 127, 127, 127, 127, 130, 135,
- 141, 147, 148, 156, 155, 185, 188, 195, 194, 206,
- 207, 209, 210, 211, 214, 219, 224, 231, 240, 241,
- 248, 249, 250, 251, 252, 253, 260, 265, 260, 290,
- 291, 296, 297, 300, 304, 310, 311, 314, 321, 322,
- 326, 325, 337, 338, 340, 341, 342, 345, 353, 369,
- 370, 371, 372, 373, 380, 379, 391, 392, 394, 395,
- 399, 405, 410, 414, 418, 424, 425
+ 0, 126, 126, 127, 130, 130, 130, 130, 133, 138,
+ 144, 150, 151, 159, 158, 188, 191, 198, 197, 209,
+ 210, 212, 213, 214, 217, 222, 227, 234, 243, 244,
+ 251, 252, 253, 254, 255, 256, 263, 268, 263, 293,
+ 294, 299, 300, 303, 307, 313, 314, 317, 324, 325,
+ 329, 328, 340, 341, 343, 344, 345, 348, 356, 372,
+ 373, 374, 375, 376, 383, 382, 394, 395, 397, 398,
+ 402, 408, 413, 417, 421, 427, 428
};
#endif
-#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
+#if YYDEBUG || YYERROR_VERBOSE || 1
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
"object_inherits_item", "object_inherits_specifier", "expressionlist",
"$@5", "expressions", "expressions_inner", "expression", "operator",
"array", "$@6", "array_items", "array_items_inner", "simplevalue",
- "value", 0
+ "value", YY_NULL
};
#endif
49
};
-#define yypact_value_is_default(yystate) \
- ((yystate) == (-72))
+#define yypact_value_is_default(Yystate) \
+ (!!((Yystate) == (-72)))
-#define yytable_value_is_error(yytable_value) \
+#define yytable_value_is_error(Yytable_value) \
YYID (0)
static const yytype_int8 yycheck[] =
#define YYRECOVERING() (!!yyerrstatus)
-#define YYBACKUP(Token, Value) \
-do \
- if (yychar == YYEMPTY && yylen == 1) \
- { \
- yychar = (Token); \
- yylval = (Value); \
- YYPOPSTACK (1); \
- goto yybackup; \
- } \
- else \
- { \
+#define YYBACKUP(Token, Value) \
+do \
+ if (yychar == YYEMPTY) \
+ { \
+ yychar = (Token); \
+ yylval = (Value); \
+ YYPOPSTACK (yylen); \
+ yystate = *yyssp; \
+ goto yybackup; \
+ } \
+ else \
+ { \
yyerror (&yylloc, context, YY_("syntax error: cannot back up")); \
YYERROR; \
} \
while (YYID (0))
-
+/* Error token number */
#define YYTERROR 1
#define YYERRCODE 256
If N is 0, then set CURRENT to the empty location which ends
the previous symbol: RHS[0] (always defined). */
-#define YYRHSLOC(Rhs, K) ((Rhs)[K])
#ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N) \
- do \
- if (YYID (N)) \
- { \
- (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
- (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
- (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
- (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
- } \
- else \
- { \
- (Current).first_line = (Current).last_line = \
- YYRHSLOC (Rhs, 0).last_line; \
- (Current).first_column = (Current).last_column = \
- YYRHSLOC (Rhs, 0).last_column; \
- } \
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+ do \
+ if (YYID (N)) \
+ { \
+ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
+ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
+ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
+ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
+ } \
+ else \
+ { \
+ (Current).first_line = (Current).last_line = \
+ YYRHSLOC (Rhs, 0).last_line; \
+ (Current).first_column = (Current).last_column = \
+ YYRHSLOC (Rhs, 0).last_column; \
+ } \
while (YYID (0))
#endif
+#define YYRHSLOC(Rhs, K) ((Rhs)[K])
+
/* YY_LOCATION_PRINT -- Print the location on the stream.
This macro was not mandated originally: define only if we know
#ifndef YY_LOCATION_PRINT
# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
-# define YY_LOCATION_PRINT(File, Loc) \
- fprintf (File, "%d.%d-%d.%d", \
- (Loc).first_line, (Loc).first_column, \
- (Loc).last_line, (Loc).last_column)
+
+/* Print *YYLOCP on YYO. Private, do not rely on its existence. */
+
+__attribute__((__unused__))
+#if (defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)
+static unsigned
+yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
+#else
+static unsigned
+yy_location_print_ (yyo, yylocp)
+ FILE *yyo;
+ YYLTYPE const * const yylocp;
+#endif
+{
+ unsigned res = 0;
+ int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
+ if (0 <= yylocp->first_line)
+ {
+ res += fprintf (yyo, "%d", yylocp->first_line);
+ if (0 <= yylocp->first_column)
+ res += fprintf (yyo, ".%d", yylocp->first_column);
+ }
+ if (0 <= yylocp->last_line)
+ {
+ if (yylocp->first_line < yylocp->last_line)
+ {
+ res += fprintf (yyo, "-%d", yylocp->last_line);
+ if (0 <= end_col)
+ res += fprintf (yyo, ".%d", end_col);
+ }
+ else if (0 <= end_col && yylocp->first_column < end_col)
+ res += fprintf (yyo, "-%d", end_col);
+ }
+ return res;
+ }
+
+# define YY_LOCATION_PRINT(File, Loc) \
+ yy_location_print_ (File, &(Loc))
+
# else
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
# endif
/* YYLEX -- calling `yylex' with the right arguments. */
-
#ifdef YYLEX_PARAM
# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
#else
ConfigCompiler *context;
#endif
{
+ FILE *yyo = yyoutput;
+ YYUSE (yyo);
if (!yyvaluep)
return;
YYUSE (yylocationp);
switch (yytype)
{
default:
- break;
+ break;
}
}
yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
yytype_int16 *yyssp, int yytoken)
{
- YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]);
+ YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
YYSIZE_T yysize = yysize0;
- YYSIZE_T yysize1;
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
/* Internationalized format string. */
- const char *yyformat = 0;
+ const char *yyformat = YY_NULL;
/* Arguments of yyformat. */
char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
/* Number of reported tokens (one for the "unexpected", one per
break;
}
yyarg[yycount++] = yytname[yyx];
- yysize1 = yysize + yytnamerr (0, yytname[yyx]);
- if (! (yysize <= yysize1
- && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
- return 2;
- yysize = yysize1;
+ {
+ YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
+ if (! (yysize <= yysize1
+ && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
+ return 2;
+ yysize = yysize1;
+ }
}
}
}
# undef YYCASE_
}
- yysize1 = yysize + yystrlen (yyformat);
- if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
- return 2;
- yysize = yysize1;
+ {
+ YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
+ if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
+ return 2;
+ yysize = yysize1;
+ }
if (*yymsg_alloc < yysize)
{
{
default:
- break;
+ break;
}
}
-/* Prevent warnings from -Wmissing-prototypes. */
-#ifdef YYPARSE_PARAM
-#if defined __STDC__ || defined __cplusplus
-int yyparse (void *YYPARSE_PARAM);
-#else
-int yyparse ();
-#endif
-#else /* ! YYPARSE_PARAM */
-#if defined __STDC__ || defined __cplusplus
-int yyparse (ConfigCompiler *context);
-#else
-int yyparse ();
-#endif
-#endif /* ! YYPARSE_PARAM */
/*----------.
/* The lookahead symbol. */
int yychar;
+
+#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
+/* Suppress an incorrect diagnostic about yylval being uninitialized. */
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
+ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
+ _Pragma ("GCC diagnostic pop")
+#else
+/* Default value used for initialization, for pacifying older GCCs
+ or non-GCC compilers. */
+static YYSTYPE yyval_default;
+# define YY_INITIAL_VALUE(Value) = Value
+#endif
+static YYLTYPE yyloc_default
+# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
+ = { 1, 1, 1, 1 }
+# endif
+;
+#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END
+#endif
+#ifndef YY_INITIAL_VALUE
+# define YY_INITIAL_VALUE(Value) /* Nothing. */
+#endif
+
/* The semantic value of the lookahead symbol. */
-YYSTYPE yylval;
+YYSTYPE yylval YY_INITIAL_VALUE(yyval_default);
/* Location data for the lookahead symbol. */
-YYLTYPE yylloc;
+YYLTYPE yylloc = yyloc_default;
+
/* Number of syntax errors so far. */
int yynerrs;
`yyvs': related to semantic values.
`yyls': related to locations.
- Refer to the stacks thru separate pointers, to allow yyoverflow
+ Refer to the stacks through separate pointers, to allow yyoverflow
to reallocate them elsewhere. */
/* The state stack. */
int yyn;
int yyresult;
/* Lookahead token as an internal (translated) token number. */
- int yytoken;
+ int yytoken = 0;
/* The variables used to return semantic value and location from the
action routines. */
YYSTYPE yyval;
Keep to zero when no symbol should be popped. */
int yylen = 0;
- yytoken = 0;
- yyss = yyssa;
- yyvs = yyvsa;
- yyls = yylsa;
+ yyssp = yyss = yyssa;
+ yyvsp = yyvs = yyvsa;
+ yylsp = yyls = yylsa;
yystacksize = YYINITDEPTH;
YYDPRINTF ((stderr, "Starting parse\n"));
yyerrstatus = 0;
yynerrs = 0;
yychar = YYEMPTY; /* Cause a token to be read. */
-
- /* Initialize stack pointers.
- Waste one element of value and location stack
- so that they stay on the same level as the state stack.
- The wasted elements are never initialized. */
- yyssp = yyss;
- yyvsp = yyvs;
- yylsp = yyls;
-
-#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
- /* Initialize the default location before parsing starts. */
- yylloc.first_line = yylloc.last_line = 1;
- yylloc.first_column = yylloc.last_column = 1;
-#endif
-
+ yylsp[0] = yylloc;
goto yysetstate;
/*------------------------------------------------------------.
yychar = YYEMPTY;
yystate = yyn;
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
*++yyvsp = yylval;
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
*++yylsp = yylloc;
goto yynewstate;
switch (yyn)
{
case 8:
-
-/* Line 1806 of yacc.c */
-#line 131 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 134 "config_parser.yy"
{
context->HandleInclude((yyvsp[(2) - (2)].text), false, yylloc);
free((yyvsp[(2) - (2)].text));
break;
case 9:
-
-/* Line 1806 of yacc.c */
-#line 136 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 139 "config_parser.yy"
{
context->HandleInclude((yyvsp[(2) - (2)].text), true, yylloc);
free((yyvsp[(2) - (2)].text));
break;
case 10:
-
-/* Line 1806 of yacc.c */
-#line 142 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 145 "config_parser.yy"
{
context->HandleLibrary((yyvsp[(2) - (2)].text));
free((yyvsp[(2) - (2)].text));
break;
case 12:
-
-/* Line 1806 of yacc.c */
-#line 149 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 152 "config_parser.yy"
{
(yyval.text) = (yyvsp[(1) - (1)].text);
free((yyvsp[(1) - (1)].text));
break;
case 13:
-
-/* Line 1806 of yacc.c */
-#line 156 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 159 "config_parser.yy"
{
String name = String((yyvsp[(3) - (3)].text));
free((yyvsp[(3) - (3)].text));
if (!m_Type) {
if ((yyvsp[(1) - (3)].num))
- BOOST_THROW_EXCEPTION(invalid_argument("Partial type definition for unknown type '" + name + "'"));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Partial type definition for unknown type '" + name + "'"));
m_Type = boost::make_shared<ConfigType>(name, yylloc);
ConfigCompilerContext::GetContext()->AddType(m_Type);
break;
case 14:
-
-/* Line 1806 of yacc.c */
-#line 171 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 174 "config_parser.yy"
{
TypeRuleList::Ptr ruleList = *(yyvsp[(6) - (6)].variant);
m_Type->GetRuleList()->AddRules(ruleList);
break;
case 15:
-
-/* Line 1806 of yacc.c */
-#line 185 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 188 "config_parser.yy"
{
(yyval.num) = 0;
}
break;
case 16:
-
-/* Line 1806 of yacc.c */
-#line 189 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 192 "config_parser.yy"
{
(yyval.num) = 1;
}
break;
case 17:
-
-/* Line 1806 of yacc.c */
-#line 195 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 198 "config_parser.yy"
{
m_RuleLists.push(boost::make_shared<TypeRuleList>());
}
break;
case 18:
-
-/* Line 1806 of yacc.c */
-#line 200 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 203 "config_parser.yy"
{
(yyval.variant) = new Value(m_RuleLists.top());
m_RuleLists.pop();
break;
case 24:
-
-/* Line 1806 of yacc.c */
-#line 215 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 218 "config_parser.yy"
{
m_RuleLists.top()->AddRequire((yyvsp[(2) - (2)].text));
free((yyvsp[(2) - (2)].text));
break;
case 25:
-
-/* Line 1806 of yacc.c */
-#line 220 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 223 "config_parser.yy"
{
m_RuleLists.top()->SetValidator((yyvsp[(2) - (2)].text));
free((yyvsp[(2) - (2)].text));
break;
case 26:
-
-/* Line 1806 of yacc.c */
-#line 225 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 228 "config_parser.yy"
{
TypeRule rule((yyvsp[(2) - (3)].type), (yyvsp[(3) - (3)].text), TypeRuleList::Ptr(), yylloc);
free((yyvsp[(3) - (3)].text));
break;
case 27:
-
-/* Line 1806 of yacc.c */
-#line 232 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 235 "config_parser.yy"
{
TypeRule rule((yyvsp[(2) - (4)].type), (yyvsp[(3) - (4)].text), *(yyvsp[(4) - (4)].variant), yylloc);
free((yyvsp[(3) - (4)].text));
break;
case 29:
-
-/* Line 1806 of yacc.c */
-#line 242 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 245 "config_parser.yy"
{
m_Type->SetParent((yyvsp[(2) - (2)].text));
free((yyvsp[(2) - (2)].text));
break;
case 35:
-
-/* Line 1806 of yacc.c */
-#line 254 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 257 "config_parser.yy"
{
(yyval.type) = (yyvsp[(1) - (1)].type);
}
break;
case 36:
-
-/* Line 1806 of yacc.c */
-#line 260 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 263 "config_parser.yy"
{
m_Abstract = false;
m_Local = false;
break;
case 37:
-
-/* Line 1806 of yacc.c */
-#line 265 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 268 "config_parser.yy"
{
m_Item = boost::make_shared<ConfigItemBuilder>(yylloc);
break;
case 38:
-
-/* Line 1806 of yacc.c */
-#line 277 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 280 "config_parser.yy"
{
ExpressionList::Ptr exprl = *(yyvsp[(7) - (7)].variant);
delete (yyvsp[(7) - (7)].variant);
break;
case 40:
-
-/* Line 1806 of yacc.c */
-#line 292 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 295 "config_parser.yy"
{
m_Abstract = true;
}
break;
case 43:
-
-/* Line 1806 of yacc.c */
-#line 301 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 304 "config_parser.yy"
{
m_Abstract = true;
}
break;
case 44:
-
-/* Line 1806 of yacc.c */
-#line 305 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 308 "config_parser.yy"
{
m_Local = true;
}
break;
case 47:
-
-/* Line 1806 of yacc.c */
-#line 315 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 318 "config_parser.yy"
{
m_Item->AddParent((yyvsp[(1) - (1)].text));
free((yyvsp[(1) - (1)].text));
break;
case 50:
-
-/* Line 1806 of yacc.c */
-#line 326 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 329 "config_parser.yy"
{
m_ExpressionLists.push(boost::make_shared<ExpressionList>());
}
break;
case 51:
-
-/* Line 1806 of yacc.c */
-#line 331 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 334 "config_parser.yy"
{
(yyval.variant) = new Value(m_ExpressionLists.top());
m_ExpressionLists.pop();
break;
case 57:
-
-/* Line 1806 of yacc.c */
-#line 346 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 349 "config_parser.yy"
{
Expression expr((yyvsp[(1) - (3)].text), (yyvsp[(2) - (3)].op), *(yyvsp[(3) - (3)].variant), yylloc);
free((yyvsp[(1) - (3)].text));
break;
case 58:
-
-/* Line 1806 of yacc.c */
-#line 354 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 357 "config_parser.yy"
{
Expression subexpr((yyvsp[(3) - (6)].text), (yyvsp[(5) - (6)].op), *(yyvsp[(6) - (6)].variant), yylloc);
free((yyvsp[(3) - (6)].text));
break;
case 63:
-
-/* Line 1806 of yacc.c */
-#line 374 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 377 "config_parser.yy"
{
(yyval.op) = (yyvsp[(1) - (1)].op);
}
break;
case 64:
-
-/* Line 1806 of yacc.c */
-#line 380 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 383 "config_parser.yy"
{
m_Arrays.push(boost::make_shared<Array>());
}
break;
case 65:
-
-/* Line 1806 of yacc.c */
-#line 385 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 388 "config_parser.yy"
{
(yyval.variant) = new Value(m_Arrays.top());
m_Arrays.pop();
break;
case 69:
-
-/* Line 1806 of yacc.c */
-#line 396 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 399 "config_parser.yy"
{
m_Arrays.top()->Add(*(yyvsp[(1) - (1)].variant));
}
break;
case 70:
-
-/* Line 1806 of yacc.c */
-#line 400 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 403 "config_parser.yy"
{
m_Arrays.top()->Add(*(yyvsp[(3) - (3)].variant));
}
break;
case 71:
-
-/* Line 1806 of yacc.c */
-#line 406 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 409 "config_parser.yy"
{
(yyval.variant) = new Value((yyvsp[(1) - (1)].text));
free((yyvsp[(1) - (1)].text));
break;
case 72:
-
-/* Line 1806 of yacc.c */
-#line 411 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 414 "config_parser.yy"
{
(yyval.variant) = new Value((yyvsp[(1) - (1)].num));
}
break;
case 73:
-
-/* Line 1806 of yacc.c */
-#line 415 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 418 "config_parser.yy"
{
(yyval.variant) = new Value();
}
break;
case 74:
-
-/* Line 1806 of yacc.c */
-#line 419 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 422 "config_parser.yy"
{
(yyval.variant) = (yyvsp[(1) - (1)].variant);
}
break;
case 76:
-
-/* Line 1806 of yacc.c */
-#line 426 "config_parser.yy"
+/* Line 1792 of yacc.c */
+#line 429 "config_parser.yy"
{
(yyval.variant) = (yyvsp[(1) - (1)].variant);
}
break;
-
-/* Line 1806 of yacc.c */
-#line 2052 "config_parser.cc"
+/* Line 1792 of yacc.c */
+#line 2077 "config_parser.cc"
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
YY_STACK_PRINT (yyss, yyssp);
}
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
*++yyvsp = yylval;
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
yyerror_range[2] = yylloc;
/* Using YYLLOC is tempting, but would change the location of
yyresult = 1;
goto yyreturn;
-#if !defined(yyoverflow) || YYERROR_VERBOSE
+#if !defined yyoverflow || YYERROR_VERBOSE
/*-------------------------------------------------.
| yyexhaustedlab -- memory exhaustion comes here. |
`-------------------------------------------------*/
}
-
-/* Line 2067 of yacc.c */
-#line 430 "config_parser.yy"
-
+/* Line 2055 of yacc.c */
+#line 433 "config_parser.yy"
******************************************************************************/
#include "i2-config.h"
+#include <sstream>
+#include <stack>
+#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
void yyerror(YYLTYPE *locp, ConfigCompiler *, const char *err)
{
- stringstream message;
+ std::ostringstream message;
message << *locp << ": " << err;
ConfigCompilerContext::GetContext()->AddError(false, message.str());
}
int yyparse(ConfigCompiler *context);
-static stack<ExpressionList::Ptr> m_ExpressionLists;
-static stack<Array::Ptr> m_Arrays;
+static std::stack<ExpressionList::Ptr> m_ExpressionLists;
+static std::stack<Array::Ptr> m_Arrays;
static ConfigItemBuilder::Ptr m_Item;
static bool m_Abstract;
static bool m_Local;
-static stack<TypeRuleList::Ptr> m_RuleLists;
+static std::stack<TypeRuleList::Ptr> m_RuleLists;
static ConfigType::Ptr m_Type;
void ConfigCompiler::Compile(void)
try {
yyparse(this);
- } catch (const exception& ex) {
+ } catch (const std::exception& ex) {
ConfigCompilerContext::GetContext()->AddError(false, boost::diagnostic_information(ex));
}
}
if (!m_Type) {
if ($1)
- BOOST_THROW_EXCEPTION(invalid_argument("Partial type definition for unknown type '" + name + "'"));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Partial type definition for unknown type '" + name + "'"));
m_Type = boost::make_shared<ConfigType>(name, yylloc);
ConfigCompilerContext::GetContext()->AddType(m_Type);
******************************************************************************/
#include "i2-config.h"
+#include "base/logger_fwd.h"
+#include <sstream>
+#include <fstream>
+#include <boost/foreach.hpp>
using std::ifstream;
using namespace icinga;
-vector<String> ConfigCompiler::m_IncludeSearchDirs;
+std::vector<String> ConfigCompiler::m_IncludeSearchDirs;
/**
* Constructor for the ConfigCompiler class.
* @param input Input stream for the configuration file.
* @param includeHandler Handler function for #include directives.
*/
-ConfigCompiler::ConfigCompiler(const String& path, istream *input,
+ConfigCompiler::ConfigCompiler(const String& path, std::istream *input,
HandleIncludeFunc includeHandler)
: m_Path(path), m_Input(input), m_HandleInclude(includeHandler)
{
* @param stream The input stream.
* @returns Configuration items.
*/
-void ConfigCompiler::CompileStream(const String& path, istream *stream)
+void ConfigCompiler::CompileStream(const String& path, std::istream *stream)
{
- stream->exceptions(istream::badbit);
+ stream->exceptions(std::istream::badbit);
ConfigCompiler ctx(path, stream);
ctx.Compile();
*/
void ConfigCompiler::CompileFile(const String& path)
{
- ifstream stream;
- stream.open(path.CStr(), ifstream::in);
+ std::ifstream stream;
+ stream.open(path.CStr(), std::ifstream::in);
if (!stream)
- BOOST_THROW_EXCEPTION(invalid_argument("Could not open config file: " + path));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Could not open config file: " + path));
- Logger::Write(LogInformation, "config", "Compiling config file: " + path);
+ Log(LogInformation, "config", "Compiling config file: " + path);
return CompileStream(path, &stream);
}
*/
void ConfigCompiler::CompileText(const String& path, const String& text)
{
- stringstream stream(text);
+ std::stringstream stream(text);
return CompileStream(path, &stream);
}
}
}
- vector<ConfigItem::Ptr> items;
+ std::vector<ConfigItem::Ptr> items;
if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CompileFile, _1))) {
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "Include file '" + include + "' does not exist (or no files found for pattern): " << debuginfo;
- BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str()));
+ BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str()));
}
}
*/
void ConfigCompiler::AddIncludeSearchDir(const String& dir)
{
- Logger::Write(LogInformation, "config", "Adding include search dir: " + dir);
+ Log(LogInformation, "config", "Adding include search dir: " + dir);
m_IncludeSearchDirs.push_back(dir);
}
#ifndef CONFIGCOMPILER_H
#define CONFIGCOMPILER_H
+#include "base/registry.h"
+#include <iostream>
+
namespace icinga
{
public:
typedef boost::function<void (const String&, bool, const DebugInfo&)> HandleIncludeFunc;
- explicit ConfigCompiler(const String& path, istream *input = &cin,
+ explicit ConfigCompiler(const String& path, std::istream *input,
HandleIncludeFunc includeHandler = &ConfigCompiler::HandleFileInclude);
virtual ~ConfigCompiler(void);
void Compile(void);
- static void CompileStream(const String& path, istream *stream);
+ static void CompileStream(const String& path, std::istream *stream);
static void CompileFile(const String& path);
static void CompileText(const String& path, const String& text);
private:
String m_Path;
- istream *m_Input;
+ std::istream *m_Input;
HandleIncludeFunc m_HandleInclude;
void *m_Scanner;
- static vector<String> m_IncludeSearchDirs;
+ static std::vector<String> m_IncludeSearchDirs;
void InitializeScanner(void);
void DestroyScanner(void);
******************************************************************************/
#include "i2-config.h"
+#include "base/logger_fwd.h"
+#include <boost/foreach.hpp>
using std::ifstream;
void ConfigCompilerContext::AddItem(const ConfigItem::Ptr& item)
{
m_Items.push_back(item);
- m_ItemsMap[make_pair(item->GetType(), item->GetName())] = item;
+ m_ItemsMap[std::make_pair(item->GetType(), item->GetName())] = item;
}
ConfigItem::Ptr ConfigCompilerContext::GetItem(const String& type, const String& name) const
{
- map<pair<String, String>, ConfigItem::Ptr>::const_iterator it;
+ std::map<std::pair<String, String>, ConfigItem::Ptr>::const_iterator it;
- it = m_ItemsMap.find(make_pair(type, name));
+ it = m_ItemsMap.find(std::make_pair(type, name));
if (it == m_ItemsMap.end())
return ConfigItem::Ptr();
return it->second;
}
-vector<ConfigItem::Ptr> ConfigCompilerContext::GetItems(void) const
+std::vector<ConfigItem::Ptr> ConfigCompilerContext::GetItems(void) const
{
return m_Items;
}
ConfigType::Ptr ConfigCompilerContext::GetType(const String& name) const
{
- map<String, ConfigType::Ptr>::const_iterator it;
+ std::map<String, ConfigType::Ptr>::const_iterator it;
it = m_Types.find(name);
m_Errors.push_back(ConfigCompilerError(warning, message));
}
-vector<ConfigCompilerError> ConfigCompilerContext::GetErrors(void) const
+std::vector<ConfigCompilerError> ConfigCompilerContext::GetErrors(void) const
{
return m_Errors;
}
{
ASSERT(m_Context == NULL);
- Logger::Write(LogInformation, "config", "Activating config items in compilation unit '" + m_Unit + "'");
+ Log(LogInformation, "config", "Activating config items in compilation unit '" + m_Unit + "'");
BOOST_FOREACH(const ConfigItem::Ptr& item, m_Items) {
item->Commit();
}
void AddItem(const ConfigItem::Ptr& item);
ConfigItem::Ptr GetItem(const String& type, const String& name) const;
- vector<ConfigItem::Ptr> GetItems(void) const;
+ std::vector<ConfigItem::Ptr> GetItems(void) const;
void AddType(const ConfigType::Ptr& type);
ConfigType::Ptr GetType(const String& name) const;
void AddError(bool warning, const String& message);
- vector<ConfigCompilerError> GetErrors(void) const;
+ std::vector<ConfigCompilerError> GetErrors(void) const;
void SetFlags(int flags);
int GetFlags(void) const;
int m_Flags;
- vector<shared_ptr<ConfigItem> > m_Items;
- map<pair<String, String>, shared_ptr<ConfigItem> > m_ItemsMap;
+ std::vector<shared_ptr<ConfigItem> > m_Items;
+ std::map<std::pair<String, String>, shared_ptr<ConfigItem> > m_ItemsMap;
- map<String, shared_ptr<ConfigType> > m_Types;
+ std::map<String, shared_ptr<ConfigType> > m_Types;
- vector<ConfigCompilerError> m_Errors;
+ std::vector<ConfigCompilerError> m_Errors;
static ConfigCompilerContext *m_Context;
};
******************************************************************************/
#include "i2-config.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
+#include <sstream>
#include <boost/tuple/tuple.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
boost::mutex ConfigItem::m_Mutex;
ConfigItem::ItemMap ConfigItem::m_Items;
-signals2::signal<void (const ConfigItem::Ptr&)> ConfigItem::OnCommitted;
-signals2::signal<void (const ConfigItem::Ptr&)> ConfigItem::OnRemoved;
+boost::signals2::signal<void (const ConfigItem::Ptr&)> ConfigItem::OnCommitted;
+boost::signals2::signal<void (const ConfigItem::Ptr&)> ConfigItem::OnRemoved;
/**
* Constructor for the ConfigItem class.
*/
ConfigItem::ConfigItem(const String& type, const String& name,
const String& unit, bool abstract, const ExpressionList::Ptr& exprl,
- const vector<String>& parents, const DebugInfo& debuginfo)
+ const std::vector<String>& parents, const DebugInfo& debuginfo)
: m_Type(type), m_Name(name), m_Unit(unit), m_Abstract(abstract),
m_ExpressionList(exprl), m_Parents(parents), m_DebugInfo(debuginfo)
{
*
* @returns The list of parents.
*/
-vector<String> ConfigItem::GetParents(void) const
+std::vector<String> ConfigItem::GetParents(void) const
{
return m_Parents;
}
parent = ConfigItem::GetObject(m_Type, name);
if (!parent) {
- stringstream message;
+ std::ostringstream message;
message << "Parent object '" << name << "' does not"
" exist (" << m_DebugInfo << ")";
- BOOST_THROW_EXCEPTION(domain_error(message.str()));
+ BOOST_THROW_EXCEPTION(std::invalid_argument(message.str()));
}
parent->InternalLink(dictionary);
String type, name;
- Logger::Write(LogDebug, "base", "Commit called for ConfigItem Type=" + GetType() + ", Name=" + GetName());
+ Log(LogDebug, "base", "Commit called for ConfigItem Type=" + GetType() + ", Name=" + GetName());
/* Make sure the type is valid. */
DynamicType::Ptr dtype = DynamicType::GetByName(GetType());
if (!dtype)
- BOOST_THROW_EXCEPTION(runtime_error("Type '" + GetType() + "' does not exist."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Type '" + GetType() + "' does not exist."));
/* Try to find an existing item with the same type and name. */
- pair<String, String> ikey = make_pair(GetType(), GetName());
+ std::pair<String, String> ikey = std::make_pair(GetType(), GetName());
ConfigItem::Ptr oldItem;
{
oldItem = it->second;
}
- set<ConfigItem::WeakPtr> children;
+ std::set<ConfigItem::WeakPtr> children;
if (oldItem) {
ObjectLock olock(oldItem);
ObjectLock olock(this);
ConfigItem::ItemMap::iterator it;
- it = m_Items.find(make_pair(m_Type, m_Name));
+ it = m_Items.find(std::make_pair(m_Type, m_Name));
if (it != m_Items.end())
m_Items.erase(it);
ConfigItem::ItemMap::iterator it;
- it = m_Items.find(make_pair(type, name));
+ it = m_Items.find(std::make_pair(type, name));
if (it != m_Items.end())
return it->second;
*
* @param fp The stream.
*/
-void ConfigItem::Dump(ostream& fp) const
+void ConfigItem::Dump(std::ostream& fp) const
{
ObjectLock olock(this);
*/
void ConfigItem::UnloadUnit(const String& unit)
{
- vector<ConfigItem::Ptr> obsoleteItems;
+ std::vector<ConfigItem::Ptr> obsoleteItems;
{
boost::mutex::scoped_lock lock(m_Mutex);
- Logger::Write(LogInformation, "config", "Unloading config items from compilation unit '" + unit + "'");
+ Log(LogInformation, "config", "Unloading config items from compilation unit '" + unit + "'");
ConfigItem::Ptr item;
BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) {
#ifndef CONFIGITEM_H
#define CONFIGITEM_H
+#include "base/dynamicobject.h"
+
namespace icinga
{
typedef weak_ptr<ConfigItem> WeakPtr;
ConfigItem(const String& type, const String& name, const String& unit,
- bool abstract, const ExpressionList::Ptr& exprl, const vector<String>& parents,
+ bool abstract, const ExpressionList::Ptr& exprl, const std::vector<String>& parents,
const DebugInfo& debuginfo);
String GetType(void) const;
String GetUnit(void) const;
bool IsAbstract(void) const;
- vector<String> GetParents(void) const;
+ std::vector<String> GetParents(void) const;
ExpressionList::Ptr GetExpressionList(void) const;
DynamicObject::Ptr Commit(void);
void Unregister(void);
- void Dump(ostream& fp) const;
+ void Dump(std::ostream& fp) const;
DynamicObject::Ptr GetDynamicObject(void) const;
static void UnloadUnit(const String& unit);
- static signals2::signal<void (const ConfigItem::Ptr&)> OnCommitted;
- static signals2::signal<void (const ConfigItem::Ptr&)> OnRemoved;
+ static boost::signals2::signal<void (const ConfigItem::Ptr&)> OnCommitted;
+ static boost::signals2::signal<void (const ConfigItem::Ptr&)> OnRemoved;
private:
void InternalLink(const Dictionary::Ptr& dictionary) const;
bool m_Abstract; /**< Whether this is a template. */
ExpressionList::Ptr m_ExpressionList;
- vector<String> m_Parents; /**< The names of parent configuration
+ std::vector<String> m_Parents; /**< The names of parent configuration
items. */
DebugInfo m_DebugInfo; /**< Debug information. */
DynamicObject::WeakPtr m_DynamicObject; /**< The instantiated version
* of this configuration
* item */
- set<ConfigItem::WeakPtr> m_ChildObjects; /**< Instantiated items
+ std::set<ConfigItem::WeakPtr> m_ChildObjects; /**< Instantiated items
* that inherit from this item */
static boost::mutex m_Mutex;
- typedef map<pair<String, String>, ConfigItem::Ptr> ItemMap;
+ typedef std::map<std::pair<String, String>, ConfigItem::Ptr> ItemMap;
static ItemMap m_Items; /**< All registered configuration items. */
static ConfigItem::Ptr GetObjectUnlocked(const String& type,
******************************************************************************/
#include "i2-config.h"
+#include "base/dynamictype.h"
+#include <boost/smart_ptr/make_shared.hpp>
+#include <sstream>
+#include <boost/foreach.hpp>
using namespace icinga;
ConfigItem::Ptr ConfigItemBuilder::Compile(void)
{
if (m_Type.IsEmpty()) {
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "The type name of an object may not be empty: " << m_DebugInfo;
- BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str()));
+ BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str()));
}
if (!DynamicType::GetByName(m_Type)) {
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "The type '" + m_Type + "' is unknown: " << m_DebugInfo;
- BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str()));
+ BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str()));
}
if (m_Name.IsEmpty()) {
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "The name of an object may not be empty: " << m_DebugInfo;
- BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str()));
+ BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str()));
}
BOOST_FOREACH(const String& parent, m_Parents) {
item = ConfigItem::GetObject(m_Type, parent);
if (!item) {
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "The parent config item '" + parent + "' does not exist: " << m_DebugInfo;
- BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str()));
+ BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str()));
}
}
String m_Unit; /**< The compilation unit. */
bool m_Local; /**< Whether the item is local. */
bool m_Abstract; /**< Whether the item is abstract. */
- vector<String> m_Parents; /**< The names of parent configuration
+ std::vector<String> m_Parents; /**< The names of parent configuration
items. */
ExpressionList::Ptr m_ExpressionList; /**< Expressions for this item. */
DebugInfo m_DebugInfo; /**< Debug information. */
******************************************************************************/
#include "i2-config.h"
+#include "base/objectlock.h"
+#include "base/convert.h"
#include <boost/tuple/tuple.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
if (item->IsAbstract())
return;
- vector<String> locations;
+ std::vector<String> locations;
locations.push_back("Object '" + item->GetName() + "' (Type: '" + item->GetType() + "')");
ConfigType::Ptr parent;
parent = ConfigCompilerContext::GetContext()->GetType(m_Parent);
}
- vector<TypeRuleList::Ptr> ruleLists;
+ std::vector<TypeRuleList::Ptr> ruleLists;
if (parent) {
ObjectLock plock(parent);
ruleLists.push_back(parent->m_RuleList);
/**
* @threadsafety Always.
*/
-String ConfigType::LocationToString(const vector<String>& locations)
+String ConfigType::LocationToString(const std::vector<String>& locations)
{
bool first = true;
String stack;
* @threadsafety Always.
*/
void ConfigType::ValidateDictionary(const Dictionary::Ptr& dictionary,
- const vector<TypeRuleList::Ptr>& ruleLists, vector<String>& locations)
+ const std::vector<TypeRuleList::Ptr>& ruleLists, std::vector<String>& locations)
{
BOOST_FOREACH(const TypeRuleList::Ptr& ruleList, ruleLists) {
BOOST_FOREACH(const String& require, ruleList->GetRequires()) {
ScriptFunction::Ptr func = ScriptFunctionRegistry::GetInstance()->GetItem(validator);
if (!func)
- BOOST_THROW_EXCEPTION(invalid_argument("Validator function '" + validator + "' does not exist."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Validator function '" + validator + "' does not exist."));
- vector<Value> arguments;
+ std::vector<Value> arguments;
arguments.push_back(LocationToString(locations));
arguments.push_back(dictionary);
Value value;
BOOST_FOREACH(boost::tie(key, value), dictionary) {
TypeValidationResult overallResult = ValidationUnknownField;
- vector<TypeRuleList::Ptr> subRuleLists;
+ std::vector<TypeRuleList::Ptr> subRuleLists;
locations.push_back("Attribute '" + key + "'");
* @threadsafety Always.
*/
void ConfigType::ValidateArray(const Array::Ptr& array,
- const vector<TypeRuleList::Ptr>& ruleLists, vector<String>& locations)
+ const std::vector<TypeRuleList::Ptr>& ruleLists, std::vector<String>& locations)
{
BOOST_FOREACH(const TypeRuleList::Ptr& ruleList, ruleLists) {
BOOST_FOREACH(const String& require, ruleList->GetRequires()) {
ScriptFunction::Ptr func = ScriptFunctionRegistry::GetInstance()->GetItem(validator);
if (!func)
- BOOST_THROW_EXCEPTION(invalid_argument("Validator function '" + validator + "' does not exist."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Validator function '" + validator + "' does not exist."));
- vector<Value> arguments;
+ std::vector<Value> arguments;
arguments.push_back(LocationToString(locations));
arguments.push_back(array);
index++;
TypeValidationResult overallResult = ValidationUnknownField;
- vector<TypeRuleList::Ptr> subRuleLists;
+ std::vector<TypeRuleList::Ptr> subRuleLists;
locations.push_back("Attribute '" + key + "'");
#ifndef CONFIGTYPE_H\r
#define CONFIGTYPE_H\r
\r
+#include "base/array.h"\r
+\r
namespace icinga\r
{\r
\r
DebugInfo m_DebugInfo; /**< Debug information. */\r
\r
static void ValidateDictionary(const Dictionary::Ptr& dictionary,\r
- const vector<TypeRuleList::Ptr>& ruleLists, vector<String>& locations);\r
+ const std::vector<TypeRuleList::Ptr>& ruleLists, std::vector<String>& locations);\r
static void ValidateArray(const Array::Ptr& array,\r
- const vector<TypeRuleList::Ptr>& ruleLists, vector<String>& locations);\r
+ const std::vector<TypeRuleList::Ptr>& ruleLists, std::vector<String>& locations);\r
\r
- static String LocationToString(const vector<String>& locations);\r
+ static String LocationToString(const std::vector<String>& locations);\r
};\r
\r
}\r
#ifndef DEBUGINFO_H
#define DEBUGINFO_H
+#include "base/qstring.h"
+
namespace icinga
{
* @param val The DebugInfo struct.
* @returns The output stream.
*/
-inline ostream& operator<<(ostream& out, const DebugInfo& val)
+inline std::ostream& operator<<(std::ostream& out, const DebugInfo& val)
{
out << "in " << val.Path << ": "
<< val.FirstLine << ":" << val.FirstColumn
******************************************************************************/
#include "i2-config.h"
+#include "base/objectlock.h"
+#include <sstream>
#include <boost/tuple/tuple.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
switch (m_Operator) {
case OperatorExecute:
if (!valueExprl)
- BOOST_THROW_EXCEPTION(invalid_argument("Operand for OperatorExecute must be an ExpressionList."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Operand for OperatorExecute must be an ExpressionList."));
valueExprl->Execute(dictionary);
if (!dict) {
if (!oldValue.IsEmpty()) {
- stringstream message;
+ std::ostringstream message;
message << "Wrong argument types for"
" += (non-dictionary and"
" dictionary) ("
<< m_DebugInfo << ")";
- BOOST_THROW_EXCEPTION(domain_error(message.str()));
+ BOOST_THROW_EXCEPTION(std::invalid_argument(message.str()));
}
dict = boost::make_shared<Dictionary>();
dict->Set(key, value);
}
} else {
- stringstream message;
+ std::ostringstream message;
message << "+= only works for dictionaries ("
<< m_DebugInfo << ")";
- BOOST_THROW_EXCEPTION(domain_error(message.str()));
+ BOOST_THROW_EXCEPTION(std::invalid_argument(message.str()));
}
break;
default:
- BOOST_THROW_EXCEPTION(runtime_error("Not yet implemented."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Not yet implemented."));
}
dictionary->Set(m_Key, newValue);
}
-void Expression::DumpValue(ostream& fp, int indent, const Value& value, bool inlineDict)
+void Expression::DumpValue(std::ostream& fp, int indent, const Value& value, bool inlineDict)
{
ExpressionList::Ptr valueExprl;
Dictionary::Ptr valueDict;
return;
}
- BOOST_THROW_EXCEPTION(runtime_error("Encountered unknown type while dumping value."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Encountered unknown type while dumping value."));
}
/**
* @threadsafety Always.
*/
-void Expression::Dump(ostream& fp, int indent) const
+void Expression::Dump(std::ostream& fp, int indent) const
{
if (m_Operator == OperatorExecute) {
DumpValue(fp, indent, m_Value, true);
fp << "+=";
break;
default:
- BOOST_THROW_EXCEPTION(runtime_error("Not yet implemented."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Not yet implemented."));
}
fp << " ";
#ifndef EXPRESSION_H
#define EXPRESSION_H
+#include "base/dictionary.h"
+
namespace icinga
{
const DebugInfo& debuginfo);
void Execute(const Dictionary::Ptr& dictionary) const;
- void Dump(ostream& fp, int indent = 0) const;
+ void Dump(std::ostream& fp, int indent = 0) const;
private:
String m_Key;
Value m_Value;
DebugInfo m_DebugInfo;
- static void DumpValue(ostream& fp, int indent, const Value& value, bool inlineDict = false);
+ static void DumpValue(std::ostream& fp, int indent, const Value& value, bool inlineDict = false);
};
}
******************************************************************************/
#include "i2-config.h"
+#include <boost/foreach.hpp>
using namespace icinga;
* @param fp The stream.
* @param indent The indentation level.
*/
-void ExpressionList::Dump(ostream& fp, int indent) const
+void ExpressionList::Dump(std::ostream& fp, int indent) const
{
BOOST_FOREACH(const Expression& expression, m_Expressions) {
expression.Dump(fp, indent);
}
-}
\ No newline at end of file
+}
#ifndef EXPRESSIONLIST_H
#define EXPRESSIONLIST_H
+#include "base/dictionary.h"
+
namespace icinga
{
void AddExpression(const Expression& expression);
void Execute(const Dictionary::Ptr& dictionary) const;
- void Dump(ostream& fp, int indent) const;
+ void Dump(std::ostream& fp, int indent) const;
size_t GetLength(void) const;
private:
- vector<Expression> m_Expressions;
+ std::vector<Expression> m_Expressions;
};
}
* at runtime.
*/
-#include <i2-base.h>
-
-#include <stack>
-#include <fstream>
-
-using std::stack;
-using std::istream;
-using std::ostream;
-using std::cin;
-using std::endl;
+//#include "base/i2-base.h"
#ifdef I2_CONFIG_BUILD
# define I2_CONFIG_API I2_EXPORT
# define I2_CONFIG_API I2_IMPORT
#endif /* I2_CONFIG_BUILD */
-#include "debuginfo.h"
+/*#include "debuginfo.h"
#include "typerulelist.h"
#include "typerule.h"
#include "expression.h"
#include "configtype.h"
#include "configitembuilder.h"
#include "configcompiler.h"
-#include "configcompilercontext.h"
+#include "configcompilercontext.h"*/
#endif /* I2CONFIG_H */
******************************************************************************/
#include "i2-config.h"
+#include "base/convert.h"
using namespace icinga;
******************************************************************************/\r
\r
#include "i2-config.h"\r
+#include <boost/foreach.hpp>\r
\r
using namespace icinga;\r
\r
*\r
* @returns The list of required attributes.\r
*/\r
-vector<String> TypeRuleList::GetRequires(void) const\r
+std::vector<String> TypeRuleList::GetRequires(void) const\r
{\r
return m_Requires;\r
}\r
#ifndef TYPERULELIST_H\r
#define TYPERULELIST_H\r
\r
+#include "base/value.h"\r
+\r
namespace icinga\r
{\r
\r
\r
void AddRequire(const String& attr);\r
void AddRequires(const TypeRuleList::Ptr& ruleList);\r
- vector<String> GetRequires(void) const;\r
+ std::vector<String> GetRequires(void) const;\r
\r
void AddRule(const TypeRule& rule);\r
void AddRules(const TypeRuleList::Ptr& ruleList);\r
\r
private:\r
String m_Validator;\r
- vector<String> m_Requires;\r
- vector<TypeRule> m_Rules;\r
+ std::vector<String> m_Requires;\r
+ std::vector<TypeRule> m_Rules;\r
};\r
\r
}\r
libicinga.la
EXTRA_DIST = \
- icinga-type.conf
+ icinga-type.conf \
+ i2-icinga.cpp
.conf.cpp: $(top_builddir)/tools/mkembedconfig.c
$(top_builddir)/tools/mkembedconfig $< $@
hostgroup.cpp \
hostgroup.h \
host.h \
- i2-icinga.cpp \
i2-icinga.h \
icinga-type.cpp \
icingaapplication.cpp \
libicinga_la_CPPFLAGS = \
-DI2_ICINGA_BUILD \
$(BOOST_CPPFLAGS) \
- -I${top_srcdir}/lib/base \
- -I${top_srcdir}/lib/config \
- -I${top_srcdir}/lib/remoting \
- -I${top_srcdir}
+ -I${top_srcdir}/lib
libicinga_la_LDFLAGS = \
$(BOOST_LDFLAGS) \
******************************************************************************/
#include "i2-icinga.h"
+#include "base/logger_fwd.h"
using namespace icinga;
/**
* @threadsafety Always.
*/
-void API::GetAnswerToEverything(const ScriptTask::Ptr& task, const vector<Value>& arguments)
+void API::GetAnswerToEverything(const ScriptTask::Ptr& task, const std::vector<Value>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Text argument required."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Text argument required."));
String text = arguments[0];
- Logger::Write(LogInformation, "icinga", "Hello from the Icinga 2 API: " + text);
+ Log(LogInformation, "icinga", "Hello from the Icinga 2 API: " + text);
task->FinishResult(42);
}
class I2_ICINGA_API API
{
public:
- static void GetAnswerToEverything(const ScriptTask::Ptr& task, const vector<Value>& arguments);
+ static void GetAnswerToEverything(const ScriptTask::Ptr& task, const std::vector<Value>& arguments);
private:
API(void);
#ifndef CIB_H
#define CIB_H
+#include "base/ringbuffer.h"
+
namespace icinga
{
******************************************************************************/
#include "i2-icinga.h"
+#include "base/convert.h"
+#include "base/logger_fwd.h"
+#include "base/objectlock.h"
#include <boost/algorithm/string/classification.hpp>
+#include <boost/foreach.hpp>
+#include <boost/exception/diagnostic_information.hpp>
using namespace icinga;
boost::once_flag ExternalCommandProcessor::m_InitializeOnce = BOOST_ONCE_INIT;
boost::mutex ExternalCommandProcessor::m_Mutex;
-map<String, ExternalCommandProcessor::Callback> ExternalCommandProcessor::m_Commands;
+std::map<String, ExternalCommandProcessor::Callback> ExternalCommandProcessor::m_Commands;
/**
* @threadsafety Always.
return;
if (line[0] != '[')
- BOOST_THROW_EXCEPTION(invalid_argument("Missing timestamp in command: " + line));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Missing timestamp in command: " + line));
size_t pos = line.FindFirstOf("]");
if (pos == String::NPos)
- BOOST_THROW_EXCEPTION(invalid_argument("Missing timestamp in command: " + line));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Missing timestamp in command: " + line));
String timestamp = line.SubStr(1, pos - 1);
String args = line.SubStr(pos + 2, String::NPos);
double ts = Convert::ToDouble(timestamp);
if (ts == 0)
- BOOST_THROW_EXCEPTION(invalid_argument("Invalid timestamp in command: " + line));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid timestamp in command: " + line));
- vector<String> argv = args.Split(boost::is_any_of(";"));
+ std::vector<String> argv = args.Split(boost::is_any_of(";"));
if (argv.empty())
- BOOST_THROW_EXCEPTION(invalid_argument("Missing arguments in command: " + line));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Missing arguments in command: " + line));
- vector<String> argvExtra(argv.begin() + 1, argv.end());
+ std::vector<String> argvExtra(argv.begin() + 1, argv.end());
Execute(ts, argv[0], argvExtra);
}
/**
* @threadsafety Always.
*/
-void ExternalCommandProcessor::Execute(double time, const String& command, const vector<String>& arguments)
+void ExternalCommandProcessor::Execute(double time, const String& command, const std::vector<String>& arguments)
{
boost::call_once(m_InitializeOnce, &ExternalCommandProcessor::Initialize);
{
boost::mutex::scoped_lock lock(m_Mutex);
- map<String, ExternalCommandProcessor::Callback>::iterator it;
+ std::map<String, ExternalCommandProcessor::Callback>::iterator it;
it = m_Commands.find(command);
if (it == m_Commands.end())
- BOOST_THROW_EXCEPTION(invalid_argument("The external command '" + command + "' does not exist."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("The external command '" + command + "' does not exist."));
callback = it->second;
}
m_Commands[command] = callback;
}
-void ExternalCommandProcessor::ProcessHostCheckResult(double time, const vector<String>& arguments)
+void ExternalCommandProcessor::ProcessHostCheckResult(double time, const std::vector<String>& arguments)
{
if (arguments.size() < 3)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 3 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 3 arguments."));
Host::Ptr host = Host::GetByName(arguments[0]);
Service::Ptr hc = host->GetHostCheckService();
if (!hc->GetEnablePassiveChecks())
- BOOST_THROW_EXCEPTION(invalid_argument("Got passive check result for host '" + arguments[0] + "' which has passive checks disabled."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Got passive check result for host '" + arguments[0] + "' which has passive checks disabled."));
int exitStatus = Convert::ToDouble(arguments[1]);
Dictionary::Ptr result = PluginCheckTask::ParseCheckOutput(arguments[2]);
result->Set("execution_end", time);
result->Set("active", 0);
- Logger::Write(LogInformation, "icinga", "Processing passive check result for host '" + arguments[0] + "'");
+ Log(LogInformation, "icinga", "Processing passive check result for host '" + arguments[0] + "'");
hc->ProcessCheckResult(result);
{
}
}
-void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const vector<String>& arguments)
+void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const std::vector<String>& arguments)
{
if (arguments.size() < 4)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 4 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 4 arguments."));
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
if (!service->GetEnablePassiveChecks())
- BOOST_THROW_EXCEPTION(invalid_argument("Got passive check result for service '" + arguments[1] + "' which has passive checks disabled."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Got passive check result for service '" + arguments[1] + "' which has passive checks disabled."));
int exitStatus = Convert::ToDouble(arguments[2]);
Dictionary::Ptr result = PluginCheckTask::ParseCheckOutput(arguments[3]);
result->Set("execution_end", time);
result->Set("active", 0);
- Logger::Write(LogInformation, "icinga", "Processing passive check result for service '" + arguments[1] + "'");
+ Log(LogInformation, "icinga", "Processing passive check result for service '" + arguments[1] + "'");
service->ProcessCheckResult(result);
{
}
}
-void ExternalCommandProcessor::ScheduleHostCheck(double, const vector<String>& arguments)
+void ExternalCommandProcessor::ScheduleHostCheck(double, const std::vector<String>& arguments)
{
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
Host::Ptr host = Host::GetByName(arguments[0]);
double planned_check = Convert::ToDouble(arguments[1]);
if (planned_check > hc->GetNextCheck()) {
- Logger::Write(LogInformation, "icinga", "Ignoring reschedule request for host '" +
+ Log(LogInformation, "icinga", "Ignoring reschedule request for host '" +
arguments[0] + "' (next check is already sooner than requested check time)");
return;
}
- Logger::Write(LogInformation, "icinga", "Rescheduling next check for host '" + arguments[0] + "'");
+ Log(LogInformation, "icinga", "Rescheduling next check for host '" + arguments[0] + "'");
{
ObjectLock olock(hc);
}
}
-void ExternalCommandProcessor::ScheduleForcedHostCheck(double, const vector<String>& arguments)
+void ExternalCommandProcessor::ScheduleForcedHostCheck(double, const std::vector<String>& arguments)
{
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
Host::Ptr host = Host::GetByName(arguments[0]);
Service::Ptr hc = host->GetHostCheckService();
- Logger::Write(LogInformation, "icinga", "Rescheduling next check for host '" + arguments[0] + "'");
+ Log(LogInformation, "icinga", "Rescheduling next check for host '" + arguments[0] + "'");
{
ObjectLock olock(hc);
}
}
-void ExternalCommandProcessor::ScheduleSvcCheck(double, const vector<String>& arguments)
+void ExternalCommandProcessor::ScheduleSvcCheck(double, const std::vector<String>& arguments)
{
if (arguments.size() < 3)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 3 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 3 arguments."));
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
double planned_check = Convert::ToDouble(arguments[2]);
if (planned_check > service->GetNextCheck()) {
- Logger::Write(LogInformation, "icinga", "Ignoring reschedule request for service '" +
+ Log(LogInformation, "icinga", "Ignoring reschedule request for service '" +
arguments[1] + "' (next check is already sooner than requested check time)");
return;
}
- Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + arguments[1] + "'");
+ Log(LogInformation, "icinga", "Rescheduling next check for service '" + arguments[1] + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::ScheduleForcedSvcCheck(double, const vector<String>& arguments)
+void ExternalCommandProcessor::ScheduleForcedSvcCheck(double, const std::vector<String>& arguments)
{
if (arguments.size() < 3)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 3 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 3 arguments."));
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
- Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + arguments[1] + "'");
+ Log(LogInformation, "icinga", "Rescheduling next check for service '" + arguments[1] + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::EnableHostCheck(double, const vector<String>& arguments)
+void ExternalCommandProcessor::EnableHostCheck(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
Host::Ptr host = Host::GetByName(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Enabling active checks for host '" + arguments[0] + "'");
+ Log(LogInformation, "icinga", "Enabling active checks for host '" + arguments[0] + "'");
Service::Ptr hc = host->GetHostCheckService();
if (!hc)
}
}
-void ExternalCommandProcessor::DisableHostCheck(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DisableHostCheck(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
Host::Ptr host = Host::GetByName(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Disabling active checks for host '" + arguments[0] + "'");
+ Log(LogInformation, "icinga", "Disabling active checks for host '" + arguments[0] + "'");
Service::Ptr hc = host->GetHostCheckService();
if (!hc)
}
}
-void ExternalCommandProcessor::EnableSvcCheck(double, const vector<String>& arguments)
+void ExternalCommandProcessor::EnableSvcCheck(double, const std::vector<String>& arguments)
{
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
- Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + arguments[1] + "'");
+ Log(LogInformation, "icinga", "Enabling active checks for service '" + arguments[1] + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::DisableSvcCheck(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DisableSvcCheck(double, const std::vector<String>& arguments)
{
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
- Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + arguments[1] + "'");
+ Log(LogInformation, "icinga", "Disabling active checks for service '" + arguments[1] + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::ShutdownProcess(double, const vector<String>&)
+void ExternalCommandProcessor::ShutdownProcess(double, const std::vector<String>&)
{
- Logger::Write(LogInformation, "icinga", "Shutting down Icinga via external command.");
+ Log(LogInformation, "icinga", "Shutting down Icinga via external command.");
Application::RequestShutdown();
}
-void ExternalCommandProcessor::ScheduleForcedHostSvcChecks(double, const vector<String>& arguments)
+void ExternalCommandProcessor::ScheduleForcedHostSvcChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
double planned_check = Convert::ToDouble(arguments[1]);
Host::Ptr host = Host::GetByName(arguments[0]);
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
- Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + service->GetName() + "'");
+ Log(LogInformation, "icinga", "Rescheduling next check for service '" + service->GetName() + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::ScheduleHostSvcChecks(double, const vector<String>& arguments)
+void ExternalCommandProcessor::ScheduleHostSvcChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
double planned_check = Convert::ToDouble(arguments[1]);
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
if (planned_check > service->GetNextCheck()) {
- Logger::Write(LogInformation, "icinga", "Ignoring reschedule request for service '" +
+ Log(LogInformation, "icinga", "Ignoring reschedule request for service '" +
service->GetName() + "' (next check is already sooner than requested check time)");
continue;
}
- Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + service->GetName() + "'");
+ Log(LogInformation, "icinga", "Rescheduling next check for service '" + service->GetName() + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::EnableHostSvcChecks(double, const vector<String>& arguments)
+void ExternalCommandProcessor::EnableHostSvcChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
Host::Ptr host = Host::GetByName(arguments[0]);
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
- Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'");
+ Log(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'");
service->SetEnableActiveChecks(true);
}
}
-void ExternalCommandProcessor::DisableHostSvcChecks(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DisableHostSvcChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments."));
Host::Ptr host = Host::GetByName(arguments[0]);
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
- Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'");
+ Log(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const vector<String>& arguments)
+void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const std::vector<String>& arguments)
{
if (arguments.size() < 7)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 7 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 7 arguments."));
bool sticky = Convert::ToBool(arguments[2]);
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
if (service->GetState() == StateOK)
- BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' is OK."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("The service '" + arguments[1] + "' is OK."));
- Logger::Write(LogInformation, "icinga", "Setting acknowledgement for service '" + service->GetName() + "'");
+ Log(LogInformation, "icinga", "Setting acknowledgement for service '" + service->GetName() + "'");
service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal);
}
-void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const vector<String>& arguments)
+void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const std::vector<String>& arguments)
{
if (arguments.size() < 8)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments."));
bool sticky = Convert::ToBool(arguments[2]);
double timestamp = Convert::ToDouble(arguments[5]);
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
if (service->GetState() == StateOK)
- BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' is OK."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("The service '" + arguments[1] + "' is OK."));
- Logger::Write(LogInformation, "icinga", "Setting timed acknowledgement for service '" + service->GetName() + "'");
+ Log(LogInformation, "icinga", "Setting timed acknowledgement for service '" + service->GetName() + "'");
service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal, timestamp);
}
-void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const vector<String>& arguments)
+void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const std::vector<String>& arguments)
{
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
- Logger::Write(LogInformation, "icinga", "Removing acknowledgement for service '" + service->GetName() + "'");
+ Log(LogInformation, "icinga", "Removing acknowledgement for service '" + service->GetName() + "'");
service->ClearAcknowledgement();
}
-void ExternalCommandProcessor::AcknowledgeHostProblem(double, const vector<String>& arguments)
+void ExternalCommandProcessor::AcknowledgeHostProblem(double, const std::vector<String>& arguments)
{
if (arguments.size() < 6)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 6 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 6 arguments."));
bool sticky = Convert::ToBool(arguments[1]);
Host::Ptr host = Host::GetByName(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Setting acknowledgement for host '" + host->GetName() + "'");
+ Log(LogInformation, "icinga", "Setting acknowledgement for host '" + host->GetName() + "'");
Service::Ptr service = host->GetHostCheckService();
if (service) {
if (service->GetState() == StateOK)
- BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' is OK."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK."));
service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal);
}
}
-void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const vector<String>& arguments)
+void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const std::vector<String>& arguments)
{
if (arguments.size() < 7)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 7 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 7 arguments."));
bool sticky = Convert::ToBool(arguments[1]);
double timestamp = Convert::ToDouble(arguments[4]);
Host::Ptr host = Host::GetByName(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Setting timed acknowledgement for host '" + host->GetName() + "'");
+ Log(LogInformation, "icinga", "Setting timed acknowledgement for host '" + host->GetName() + "'");
Service::Ptr service = host->GetHostCheckService();
if (service) {
if (service->GetState() == StateOK)
- BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' is OK."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("The host '" + arguments[0] + "' is OK."));
service->AcknowledgeProblem(sticky ? AcknowledgementSticky : AcknowledgementNormal, timestamp);
}
}
-void ExternalCommandProcessor::RemoveHostAcknowledgement(double, const vector<String>& arguments)
+void ExternalCommandProcessor::RemoveHostAcknowledgement(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
Host::Ptr host = Host::GetByName(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Removing acknowledgement for host '" + host->GetName() + "'");
+ Log(LogInformation, "icinga", "Removing acknowledgement for host '" + host->GetName() + "'");
Service::Ptr service = host->GetHostCheckService();
if (service)
service->ClearAcknowledgement();
}
-void ExternalCommandProcessor::EnableHostgroupSvcChecks(double, const vector<String>& arguments)
+void ExternalCommandProcessor::EnableHostgroupSvcChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
- Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'");
+ Log(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::DisableHostgroupSvcChecks(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DisableHostgroupSvcChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
- Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'");
+ Log(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::EnableServicegroupSvcChecks(double, const vector<String>& arguments)
+void ExternalCommandProcessor::EnableServicegroupSvcChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
- Logger::Write(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'");
+ Log(LogInformation, "icinga", "Enabling active checks for service '" + service->GetName() + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::DisableServicegroupSvcChecks(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DisableServicegroupSvcChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
- Logger::Write(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'");
+ Log(LogInformation, "icinga", "Disabling active checks for service '" + service->GetName() + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::EnablePassiveHostChecks(double, const vector<String>& arguments)
+void ExternalCommandProcessor::EnablePassiveHostChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
Host::Ptr host = Host::GetByName(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Enabling passive checks for host '" + arguments[0] + "'");
+ Log(LogInformation, "icinga", "Enabling passive checks for host '" + arguments[0] + "'");
Service::Ptr hc = host->GetHostCheckService();
if (!hc)
}
}
-void ExternalCommandProcessor::DisablePassiveHostChecks(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DisablePassiveHostChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 arguments."));
Host::Ptr host = Host::GetByName(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Disabling passive checks for host '" + arguments[0] + "'");
+ Log(LogInformation, "icinga", "Disabling passive checks for host '" + arguments[0] + "'");
Service::Ptr hc = host->GetHostCheckService();
if (!hc)
}
}
-void ExternalCommandProcessor::EnablePassiveSvcChecks(double, const vector<String>& arguments)
+void ExternalCommandProcessor::EnablePassiveSvcChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
- Logger::Write(LogInformation, "icinga", "Enabling passive checks for service '" + arguments[1] + "'");
+ Log(LogInformation, "icinga", "Enabling passive checks for service '" + arguments[1] + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::DisablePassiveSvcChecks(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DisablePassiveSvcChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
- Logger::Write(LogInformation, "icinga", "Disabling passive checks for service '" + arguments[1] + "'");
+ Log(LogInformation, "icinga", "Disabling passive checks for service '" + arguments[1] + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::EnableServicegroupPassiveSvcChecks(double, const vector<String>& arguments)
+void ExternalCommandProcessor::EnableServicegroupPassiveSvcChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
- Logger::Write(LogInformation, "icinga", "Enabling passive checks for service '" + service->GetName() + "'");
+ Log(LogInformation, "icinga", "Enabling passive checks for service '" + service->GetName() + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::DisableServicegroupPassiveSvcChecks(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DisableServicegroupPassiveSvcChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
- Logger::Write(LogInformation, "icinga", "Disabling passive checks for service '" + service->GetName() + "'");
+ Log(LogInformation, "icinga", "Disabling passive checks for service '" + service->GetName() + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::EnableHostgroupPassiveSvcChecks(double, const vector<String>& arguments)
+void ExternalCommandProcessor::EnableHostgroupPassiveSvcChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
- Logger::Write(LogInformation, "icinga", "Enabling passive checks for service '" + service->GetName() + "'");
+ Log(LogInformation, "icinga", "Enabling passive checks for service '" + service->GetName() + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::DisableHostgroupPassiveSvcChecks(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DisableHostgroupPassiveSvcChecks(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
- Logger::Write(LogInformation, "icinga", "Disabling passive checks for service '" + service->GetName() + "'");
+ Log(LogInformation, "icinga", "Disabling passive checks for service '" + service->GetName() + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::ProcessFile(double, const vector<String>& arguments)
+void ExternalCommandProcessor::ProcessFile(double, const std::vector<String>& arguments)
{
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
String file = arguments[0];
bool del = Convert::ToBool(arguments[1]);
- ifstream ifp;
- ifp.exceptions(ifstream::badbit);
+ std::ifstream ifp;
+ ifp.exceptions(std::ifstream::badbit);
- ifp.open(file.CStr(), ifstream::in);
+ ifp.open(file.CStr(), std::ifstream::in);
while(ifp.good()) {
std::string line;
std::getline(ifp, line);
try {
- Logger::Write(LogInformation, "compat", "Executing external command: " + line);
+ Log(LogInformation, "compat", "Executing external command: " + line);
Execute(line);
- } catch (const exception& ex) {
- stringstream msgbuf;
- msgbuf << "External command failed: " << diagnostic_information(ex);
- Logger::Write(LogWarning, "icinga", msgbuf.str());
+ } catch (const std::exception& ex) {
+ std::ostringstream msgbuf;
+ msgbuf << "External command failed: " << boost::diagnostic_information(ex);
+ Log(LogWarning, "icinga", msgbuf.str());
}
}
(void) unlink(file.CStr());
}
-void ExternalCommandProcessor::ScheduleSvcDowntime(double, const vector<String>& arguments)
+void ExternalCommandProcessor::ScheduleSvcDowntime(double, const std::vector<String>& arguments)
{
if (arguments.size() < 9)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 9 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 9 arguments."));
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
if (triggeredByLegacy != 0)
triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
- Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
+ Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
(void) service->AddDowntime(arguments[7], arguments[8],
Convert::ToDouble(arguments[2]), Convert::ToDouble(arguments[3]),
Convert::ToBool(arguments[4]), triggeredBy, Convert::ToDouble(arguments[6]));
}
-void ExternalCommandProcessor::DelSvcDowntime(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DelSvcDowntime(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
int id = Convert::ToLong(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
+ Log(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
String rid = Service::GetDowntimeIDFromLegacyID(id);
Service::RemoveDowntime(rid);
}
-void ExternalCommandProcessor::ScheduleHostDowntime(double, const vector<String>& arguments)
+void ExternalCommandProcessor::ScheduleHostDowntime(double, const std::vector<String>& arguments)
{
if (arguments.size() < 8)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments."));
Host::Ptr host = Host::GetByName(arguments[0]);
if (triggeredByLegacy != 0)
triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
- Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
+ Log(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
Service::Ptr service = host->GetHostCheckService();
if (service) {
(void) service->AddDowntime(arguments[6], arguments[7],
}
}
-void ExternalCommandProcessor::DelHostDowntime(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DelHostDowntime(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
int id = Convert::ToLong(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
+ Log(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
String rid = Service::GetDowntimeIDFromLegacyID(id);
Service::RemoveDowntime(rid);
}
-void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const vector<String>& arguments)
+void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const std::vector<String>& arguments)
{
if (arguments.size() < 8)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 argument."));
Host::Ptr host = Host::GetByName(arguments[0]);
triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
- Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
+ Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
(void) service->AddDowntime(arguments[6], arguments[7],
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
}
-void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double, const vector<String>& arguments)
+void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double, const std::vector<String>& arguments)
{
if (arguments.size() < 8)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments."));
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
- Logger::Write(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
+ Log(LogInformation, "icinga", "Creating downtime for host " + host->GetName());
Service::Ptr service = host->GetHostCheckService();
if (service) {
(void) service->AddDowntime(arguments[6], arguments[7],
}
}
-void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const vector<String>& arguments)
+void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const std::vector<String>& arguments)
{
if (arguments.size() < 8)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments."));
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
* over all hosts in the host group - otherwise we might end up creating multiple
* downtimes for some services. */
- set<Service::Ptr> services;
+ std::set<Service::Ptr> services;
BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
}
BOOST_FOREACH(const Service::Ptr& service, services) {
- Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
+ Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
(void) service->AddDowntime(arguments[6], arguments[7],
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
}
-void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const vector<String>& arguments)
+void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const std::vector<String>& arguments)
{
if (arguments.size() < 8)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments."));
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
* over all services in the service group - otherwise we might end up creating multiple
* downtimes for some hosts. */
- set<Service::Ptr> services;
+ std::set<Service::Ptr> services;
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
Host::Ptr host = service->GetHost();
}
BOOST_FOREACH(const Service::Ptr& service, services) {
- Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
+ Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
(void) service->AddDowntime(arguments[6], arguments[7],
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
}
-void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double, const vector<String>& arguments)
+void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double, const std::vector<String>& arguments)
{
if (arguments.size() < 8)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 8 arguments."));
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
- Logger::Write(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
+ Log(LogInformation, "icinga", "Creating downtime for service " + service->GetName());
(void) service->AddDowntime(arguments[6], arguments[7],
Convert::ToDouble(arguments[1]), Convert::ToDouble(arguments[2]),
Convert::ToBool(arguments[3]), triggeredBy, Convert::ToDouble(arguments[5]));
}
}
-void ExternalCommandProcessor::AddHostComment(double, const vector<String>& arguments)
+void ExternalCommandProcessor::AddHostComment(double, const std::vector<String>& arguments)
{
if (arguments.size() < 4)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 4 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 4 arguments."));
Host::Ptr host = Host::GetByName(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Creating comment for host " + host->GetName());
+ Log(LogInformation, "icinga", "Creating comment for host " + host->GetName());
Service::Ptr service = host->GetHostCheckService();
if (service)
(void) service->AddComment(CommentUser, arguments[2], arguments[3], 0);
}
-void ExternalCommandProcessor::DelHostComment(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DelHostComment(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
int id = Convert::ToLong(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Removing comment ID " + arguments[0]);
+ Log(LogInformation, "icinga", "Removing comment ID " + arguments[0]);
String rid = Service::GetCommentIDFromLegacyID(id);
Service::RemoveComment(rid);
}
-void ExternalCommandProcessor::AddSvcComment(double, const vector<String>& arguments)
+void ExternalCommandProcessor::AddSvcComment(double, const std::vector<String>& arguments)
{
if (arguments.size() < 5)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 5 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 5 arguments."));
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
- Logger::Write(LogInformation, "icinga", "Creating comment for service " + service->GetName());
+ Log(LogInformation, "icinga", "Creating comment for service " + service->GetName());
(void) service->AddComment(CommentUser, arguments[3], arguments[4], 0);
}
-void ExternalCommandProcessor::DelSvcComment(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DelSvcComment(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
int id = Convert::ToLong(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Removing comment ID " + arguments[0]);
+ Log(LogInformation, "icinga", "Removing comment ID " + arguments[0]);
String rid = Service::GetCommentIDFromLegacyID(id);
Service::RemoveComment(rid);
}
-void ExternalCommandProcessor::DelAllHostComments(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DelAllHostComments(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
Host::Ptr host = Host::GetByName(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Removing all comments for host " + host->GetName());
+ Log(LogInformation, "icinga", "Removing all comments for host " + host->GetName());
Service::Ptr service = host->GetHostCheckService();
if (service)
service->RemoveAllComments();
}
-void ExternalCommandProcessor::DelAllSvcComments(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DelAllSvcComments(double, const std::vector<String>& arguments)
{
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
- Logger::Write(LogInformation, "icinga", "Removing all comments for service " + service->GetName());
+ Log(LogInformation, "icinga", "Removing all comments for service " + service->GetName());
service->RemoveAllComments();
}
-void ExternalCommandProcessor::SendCustomHostNotification(double, const vector<String>& arguments)
+void ExternalCommandProcessor::SendCustomHostNotification(double, const std::vector<String>& arguments)
{
if (arguments.size() < 4)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 4 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 4 arguments."));
Host::Ptr host = Host::GetByName(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Sending custom notification for host " + host->GetName());
+ Log(LogInformation, "icinga", "Sending custom notification for host " + host->GetName());
Service::Ptr service = host->GetHostCheckService();
if (service)
service->RequestNotifications(NotificationCustom, service->GetLastCheckResult());
}
-void ExternalCommandProcessor::SendCustomSvcNotification(double, const vector<String>& arguments)
+void ExternalCommandProcessor::SendCustomSvcNotification(double, const std::vector<String>& arguments)
{
if (arguments.size() < 5)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 5 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 5 arguments."));
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
- Logger::Write(LogInformation, "icinga", "Sending custom notification for service " + service->GetName());
+ Log(LogInformation, "icinga", "Sending custom notification for service " + service->GetName());
service->RequestNotifications(NotificationCustom, service->GetLastCheckResult());
}
-void ExternalCommandProcessor::DelayHostNotification(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DelayHostNotification(double, const std::vector<String>& arguments)
{
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
Host::Ptr host = Host::GetByName(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Delaying notifications for host " + host->GetName());
+ Log(LogInformation, "icinga", "Delaying notifications for host " + host->GetName());
Service::Ptr hc = host->GetHostCheckService();
if (!hc)
return;
}
}
-void ExternalCommandProcessor::DelaySvcNotification(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DelaySvcNotification(double, const std::vector<String>& arguments)
{
if (arguments.size() < 3)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 3 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 3 arguments."));
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
- Logger::Write(LogInformation, "icinga", "Delaying notifications for service " + service->GetName());
+ Log(LogInformation, "icinga", "Delaying notifications for service " + service->GetName());
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::EnableHostNotifications(double, const vector<String>& arguments)
+void ExternalCommandProcessor::EnableHostNotifications(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
Host::Ptr host = Host::GetByName(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Enabling notifications for host '" + arguments[0] + "'");
+ Log(LogInformation, "icinga", "Enabling notifications for host '" + arguments[0] + "'");
Service::Ptr hc = host->GetHostCheckService();
if (!hc)
}
}
-void ExternalCommandProcessor::DisableHostNotifications(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DisableHostNotifications(double, const std::vector<String>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 1 argument."));
Host::Ptr host = Host::GetByName(arguments[0]);
- Logger::Write(LogInformation, "icinga", "Disabling notifications for host '" + arguments[0] + "'");
+ Log(LogInformation, "icinga", "Disabling notifications for host '" + arguments[0] + "'");
Service::Ptr hc = host->GetHostCheckService();
if (!hc)
}
}
-void ExternalCommandProcessor::EnableSvcNotifications(double, const vector<String>& arguments)
+void ExternalCommandProcessor::EnableSvcNotifications(double, const std::vector<String>& arguments)
{
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
- Logger::Write(LogInformation, "icinga", "Enabling notifications for service '" + arguments[1] + "'");
+ Log(LogInformation, "icinga", "Enabling notifications for service '" + arguments[1] + "'");
{
ObjectLock olock(service);
}
}
-void ExternalCommandProcessor::DisableSvcNotifications(double, const vector<String>& arguments)
+void ExternalCommandProcessor::DisableSvcNotifications(double, const std::vector<String>& arguments)
{
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 2 arguments."));
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
- Logger::Write(LogInformation, "icinga", "Disabling notifications for service '" + arguments[1] + "'");
+ Log(LogInformation, "icinga", "Disabling notifications for service '" + arguments[1] + "'");
{
ObjectLock olock(service);
class I2_ICINGA_API ExternalCommandProcessor {
public:
static void Execute(const String& line);
- static void Execute(double time, const String& command, const vector<String>& arguments);
+ static void Execute(double time, const String& command, const std::vector<String>& arguments);
private:
- typedef boost::function<void (double time, const vector<String>& arguments)> Callback;
+ typedef boost::function<void (double time, const std::vector<String>& arguments)> Callback;
static boost::once_flag m_InitializeOnce;
static boost::mutex m_Mutex;
- static map<String, Callback> m_Commands;
+ static std::map<String, Callback> m_Commands;
ExternalCommandProcessor(void);
static void RegisterCommand(const String& command, const Callback& callback);
- static void ProcessHostCheckResult(double time, const vector<String>& arguments);
- static void ProcessServiceCheckResult(double time, const vector<String>& arguments);
- static void ScheduleHostCheck(double time, const vector<String>& arguments);
- static void ScheduleForcedHostCheck(double time, const vector<String>& arguments);
- static void ScheduleSvcCheck(double time, const vector<String>& arguments);
- static void ScheduleForcedSvcCheck(double time, const vector<String>& arguments);
- static void EnableHostCheck(double time, const vector<String>& arguments);
- static void DisableHostCheck(double time, const vector<String>& arguments);
- static void EnableSvcCheck(double time, const vector<String>& arguments);
- static void DisableSvcCheck(double time, const vector<String>& arguments);
- static void ShutdownProcess(double time, const vector<String>& arguments);
- static void ScheduleForcedHostSvcChecks(double time, const vector<String>& arguments);
- static void ScheduleHostSvcChecks(double time, const vector<String>& arguments);
- static void EnableHostSvcChecks(double time, const vector<String>& arguments);
- static void DisableHostSvcChecks(double time, const vector<String>& arguments);
- static void AcknowledgeSvcProblem(double time, const vector<String>& arguments);
- static void AcknowledgeSvcProblemExpire(double time, const vector<String>& arguments);
- static void RemoveSvcAcknowledgement(double time, const vector<String>& arguments);
- static void AcknowledgeHostProblem(double time, const vector<String>& arguments);
- static void AcknowledgeHostProblemExpire(double time, const vector<String>& arguments);
- static void RemoveHostAcknowledgement(double time, const vector<String>& arguments);
- static void EnableHostgroupSvcChecks(double time, const vector<String>& arguments);
- static void DisableHostgroupSvcChecks(double time, const vector<String>& arguments);
- static void EnableServicegroupSvcChecks(double time, const vector<String>& arguments);
- static void DisableServicegroupSvcChecks(double time, const vector<String>& arguments);
- static void EnablePassiveHostChecks(double time, const vector<String>& arguments);
- static void DisablePassiveHostChecks(double time, const vector<String>& arguments);
- static void EnablePassiveSvcChecks(double time, const vector<String>& arguments);
- static void DisablePassiveSvcChecks(double time, const vector<String>& arguments);
- static void EnableServicegroupPassiveSvcChecks(double time, const vector<String>& arguments);
- static void DisableServicegroupPassiveSvcChecks(double time, const vector<String>& arguments);
- static void EnableHostgroupPassiveSvcChecks(double time, const vector<String>& arguments);
- static void DisableHostgroupPassiveSvcChecks(double time, const vector<String>& arguments);
- static void ProcessFile(double time, const vector<String>& arguments);
- static void ScheduleSvcDowntime(double time, const vector<String>& arguments);
- static void DelSvcDowntime(double time, const vector<String>& arguments);
- static void ScheduleHostDowntime(double time, const vector<String>& arguments);
- static void DelHostDowntime(double time, const vector<String>& arguments);
- static void ScheduleHostSvcDowntime(double time, const vector<String>& arguments);
- static void ScheduleHostgroupHostDowntime(double time, const vector<String>& arguments);
- static void ScheduleHostgroupSvcDowntime(double time, const vector<String>& arguments);
- static void ScheduleServicegroupHostDowntime(double time, const vector<String>& arguments);
- static void ScheduleServicegroupSvcDowntime(double time, const vector<String>& arguments);
- static void AddHostComment(double time, const vector<String>& arguments);
- static void DelHostComment(double time, const vector<String>& arguments);
- static void AddSvcComment(double time, const vector<String>& arguments);
- static void DelSvcComment(double time, const vector<String>& arguments);
- static void DelAllHostComments(double time, const vector<String>& arguments);
- static void DelAllSvcComments(double time, const vector<String>& arguments);
- static void SendCustomHostNotification(double time, const vector<String>& arguments);
- static void SendCustomSvcNotification(double time, const vector<String>& arguments);
- static void DelayHostNotification(double time, const vector<String>& arguments);
- static void DelaySvcNotification(double time, const vector<String>& arguments);
- static void EnableHostNotifications(double time, const vector<String>& arguments);
- static void DisableHostNotifications(double time, const vector<String>& arguments);
- static void EnableSvcNotifications(double time, const vector<String>& arguments);
- static void DisableSvcNotifications(double time, const vector<String>& arguments);
+ static void ProcessHostCheckResult(double time, const std::vector<String>& arguments);
+ static void ProcessServiceCheckResult(double time, const std::vector<String>& arguments);
+ static void ScheduleHostCheck(double time, const std::vector<String>& arguments);
+ static void ScheduleForcedHostCheck(double time, const std::vector<String>& arguments);
+ static void ScheduleSvcCheck(double time, const std::vector<String>& arguments);
+ static void ScheduleForcedSvcCheck(double time, const std::vector<String>& arguments);
+ static void EnableHostCheck(double time, const std::vector<String>& arguments);
+ static void DisableHostCheck(double time, const std::vector<String>& arguments);
+ static void EnableSvcCheck(double time, const std::vector<String>& arguments);
+ static void DisableSvcCheck(double time, const std::vector<String>& arguments);
+ static void ShutdownProcess(double time, const std::vector<String>& arguments);
+ static void ScheduleForcedHostSvcChecks(double time, const std::vector<String>& arguments);
+ static void ScheduleHostSvcChecks(double time, const std::vector<String>& arguments);
+ static void EnableHostSvcChecks(double time, const std::vector<String>& arguments);
+ static void DisableHostSvcChecks(double time, const std::vector<String>& arguments);
+ static void AcknowledgeSvcProblem(double time, const std::vector<String>& arguments);
+ static void AcknowledgeSvcProblemExpire(double time, const std::vector<String>& arguments);
+ static void RemoveSvcAcknowledgement(double time, const std::vector<String>& arguments);
+ static void AcknowledgeHostProblem(double time, const std::vector<String>& arguments);
+ static void AcknowledgeHostProblemExpire(double time, const std::vector<String>& arguments);
+ static void RemoveHostAcknowledgement(double time, const std::vector<String>& arguments);
+ static void EnableHostgroupSvcChecks(double time, const std::vector<String>& arguments);
+ static void DisableHostgroupSvcChecks(double time, const std::vector<String>& arguments);
+ static void EnableServicegroupSvcChecks(double time, const std::vector<String>& arguments);
+ static void DisableServicegroupSvcChecks(double time, const std::vector<String>& arguments);
+ static void EnablePassiveHostChecks(double time, const std::vector<String>& arguments);
+ static void DisablePassiveHostChecks(double time, const std::vector<String>& arguments);
+ static void EnablePassiveSvcChecks(double time, const std::vector<String>& arguments);
+ static void DisablePassiveSvcChecks(double time, const std::vector<String>& arguments);
+ static void EnableServicegroupPassiveSvcChecks(double time, const std::vector<String>& arguments);
+ static void DisableServicegroupPassiveSvcChecks(double time, const std::vector<String>& arguments);
+ static void EnableHostgroupPassiveSvcChecks(double time, const std::vector<String>& arguments);
+ static void DisableHostgroupPassiveSvcChecks(double time, const std::vector<String>& arguments);
+ static void ProcessFile(double time, const std::vector<String>& arguments);
+ static void ScheduleSvcDowntime(double time, const std::vector<String>& arguments);
+ static void DelSvcDowntime(double time, const std::vector<String>& arguments);
+ static void ScheduleHostDowntime(double time, const std::vector<String>& arguments);
+ static void DelHostDowntime(double time, const std::vector<String>& arguments);
+ static void ScheduleHostSvcDowntime(double time, const std::vector<String>& arguments);
+ static void ScheduleHostgroupHostDowntime(double time, const std::vector<String>& arguments);
+ static void ScheduleHostgroupSvcDowntime(double time, const std::vector<String>& arguments);
+ static void ScheduleServicegroupHostDowntime(double time, const std::vector<String>& arguments);
+ static void ScheduleServicegroupSvcDowntime(double time, const std::vector<String>& arguments);
+ static void AddHostComment(double time, const std::vector<String>& arguments);
+ static void DelHostComment(double time, const std::vector<String>& arguments);
+ static void AddSvcComment(double time, const std::vector<String>& arguments);
+ static void DelSvcComment(double time, const std::vector<String>& arguments);
+ static void DelAllHostComments(double time, const std::vector<String>& arguments);
+ static void DelAllSvcComments(double time, const std::vector<String>& arguments);
+ static void SendCustomHostNotification(double time, const std::vector<String>& arguments);
+ static void SendCustomSvcNotification(double time, const std::vector<String>& arguments);
+ static void DelayHostNotification(double time, const std::vector<String>& arguments);
+ static void DelaySvcNotification(double time, const std::vector<String>& arguments);
+ static void EnableHostNotifications(double time, const std::vector<String>& arguments);
+ static void DisableHostNotifications(double time, const std::vector<String>& arguments);
+ static void EnableSvcNotifications(double time, const std::vector<String>& arguments);
+ static void DisableSvcNotifications(double time, const std::vector<String>& arguments);
};
}
******************************************************************************/
#include "i2-icinga.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
#include <boost/tuple/tuple.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
boost::mutex Host::m_ServiceMutex;
-map<String, map<String, Service::WeakPtr> > Host::m_ServicesCache;
+std::map<String, std::map<String, Service::WeakPtr> > Host::m_ServicesCache;
bool Host::m_ServicesCacheNeedsUpdate = false;
Timer::Ptr Host::m_ServicesCacheTimer;
{
ASSERT(!OwnsLock());
- set<Service::Ptr> parentServices = GetParentServices();
+ std::set<Service::Ptr> parentServices = GetParentServices();
BOOST_FOREACH(const Service::Ptr& service, parentServices) {
ObjectLock olock(service);
return false;
}
- set<Host::Ptr> parentHosts = GetParentHosts();
+ std::set<Host::Ptr> parentHosts = GetParentHosts();
BOOST_FOREACH(const Host::Ptr& host, parentHosts) {
Service::Ptr hc = host->GetHostCheckService();
if (svcdesc.IsScalar())
svcname = svcdesc;
- stringstream namebuf;
+ std::ostringstream namebuf;
namebuf << GetName() << "-" << svcname;
String name = namebuf.str();
CopyServiceAttributes<false>(this, builder);
if (!svcdesc.IsObjectType<Dictionary>())
- BOOST_THROW_EXCEPTION(invalid_argument("Service description must be either a string or a dictionary."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Service description must be either a string or a dictionary."));
Dictionary::Ptr service = svcdesc;
}
}
-set<Service::Ptr> Host::GetServices(void) const
+std::set<Service::Ptr> Host::GetServices(void) const
{
- set<Service::Ptr> services;
+ std::set<Service::Ptr> services;
boost::mutex::scoped_lock lock(m_ServiceMutex);
m_ServicesCacheNeedsUpdate = false;
}
- Logger::Write(LogDebug, "icinga", "Updating Host services cache.");
+ Log(LogDebug, "icinga", "Updating Host services cache.");
- map<String, map<String, Service::WeakPtr> > newServicesCache;
+ std::map<String, std::map<String, Service::WeakPtr> > newServicesCache;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
const Service::Ptr& service = static_pointer_cast<Service>(object);
m_ServicesCache.swap(newServicesCache);
}
-void Host::ValidateServiceDictionary(const ScriptTask::Ptr& task, const vector<Value>& arguments)
+void Host::ValidateServiceDictionary(const ScriptTask::Ptr& task, const std::vector<Value>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Location must be specified."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Location must be specified."));
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Attribute dictionary must be specified."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Attribute dictionary must be specified."));
String location = arguments[0];
Dictionary::Ptr attrs = arguments[1];
String key;
Value value;
BOOST_FOREACH(boost::tie(key, value), attrs) {
- vector<String> templates;
+ std::vector<String> templates;
if (!value.IsObjectType<Dictionary>())
- BOOST_THROW_EXCEPTION(invalid_argument("Service description must be a dictionary."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Service description must be a dictionary."));
Dictionary::Ptr serviceDesc = value;
{
boost::mutex::scoped_lock lock(m_ServiceMutex);
- map<String, Service::WeakPtr>& services = m_ServicesCache[GetName()];
- map<String, Service::WeakPtr>::iterator it = services.find(name);
+ std::map<String, Service::WeakPtr>& services = m_ServicesCache[GetName()];
+ std::map<String, Service::WeakPtr>::iterator it = services.find(name);
if (it != services.end()) {
Service::Ptr service = it->second.lock();
return Service::GetByNamePair(dict->Get("host"), dict->Get("service"));
} else {
- BOOST_THROW_EXCEPTION(invalid_argument("Host/Service name pair is invalid."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Host/Service name pair is invalid."));
}
}
-set<Host::Ptr> Host::GetParentHosts(void) const
+std::set<Host::Ptr> Host::GetParentHosts(void) const
{
- set<Host::Ptr> parents;
+ std::set<Host::Ptr> parents;
Array::Ptr dependencies = GetHostDependencies();
return GetServiceByShortName(host_check);
}
-set<Service::Ptr> Host::GetParentServices(void) const
+std::set<Service::Ptr> Host::GetParentServices(void) const
{
- set<Service::Ptr> parents;
+ std::set<Service::Ptr> parents;
Array::Ptr dependencies = GetServiceDependencies();
Dictionary::Ptr CalculateDynamicMacros(void) const;
shared_ptr<Service> GetHostCheckService(void) const;
- set<Host::Ptr> GetParentHosts(void) const;
- set<shared_ptr<Service> > GetParentServices(void) const;
+ std::set<Host::Ptr> GetParentHosts(void) const;
+ std::set<shared_ptr<Service> > GetParentServices(void) const;
bool IsReachable() const;
shared_ptr<Service> GetServiceByShortName(const Value& name) const;
- set<shared_ptr<Service> > GetServices(void) const;
+ std::set<shared_ptr<Service> > GetServices(void) const;
static void InvalidateServicesCache(void);
static void ValidateServiceDictionary(const ScriptTask::Ptr& task,
Dictionary::Ptr m_SlaveServices;
static boost::mutex m_ServiceMutex;
- static map<String, map<String, weak_ptr<Service> > > m_ServicesCache;
+ static std::map<String, std::map<String, weak_ptr<Service> > > m_ServicesCache;
static bool m_ServicesCacheNeedsUpdate;
static Timer::Ptr m_ServicesCacheTimer;
******************************************************************************/
#include "i2-icinga.h"
+#include "base/dynamictype.h"
+#include "base/logger_fwd.h"
+#include "base/objectlock.h"
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
boost::mutex HostGroup::m_Mutex;
-map<String, vector<Host::WeakPtr> > HostGroup::m_MembersCache;
+std::map<String, std::vector<Host::WeakPtr> > HostGroup::m_MembersCache;
bool HostGroup::m_MembersCacheNeedsUpdate = false;
Timer::Ptr HostGroup::m_MembersCacheTimer;
DynamicObject::Ptr configObject = DynamicObject::GetObject("HostGroup", name);
if (!configObject)
- BOOST_THROW_EXCEPTION(invalid_argument("HostGroup '" + name + "' does not exist."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("HostGroup '" + name + "' does not exist."));
return dynamic_pointer_cast<HostGroup>(configObject);
}
/**
* @threadsafety Always.
*/
-set<Host::Ptr> HostGroup::GetMembers(void) const
+std::set<Host::Ptr> HostGroup::GetMembers(void) const
{
- set<Host::Ptr> hosts;
+ std::set<Host::Ptr> hosts;
{
boost::mutex::scoped_lock lock(m_Mutex);
m_MembersCacheNeedsUpdate = false;
}
- Logger::Write(LogDebug, "icinga", "Updating HostGroup members cache.");
+ Log(LogDebug, "icinga", "Updating HostGroup members cache.");
- map<String, vector<Host::WeakPtr> > newMembersCache;
+ std::map<String, std::vector<Host::WeakPtr> > newMembersCache;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) {
const Host::Ptr& host = static_pointer_cast<Host>(object);
String GetNotesUrl(void) const;
String GetActionUrl(void) const;
- set<Host::Ptr> GetMembers(void) const;
+ std::set<Host::Ptr> GetMembers(void) const;
static void InvalidateMembersCache(void);
Attribute<String> m_ActionUrl;
static boost::mutex m_Mutex;
- static map<String, vector<Host::WeakPtr> > m_MembersCache;
+ static std::map<String, std::vector<Host::WeakPtr> > m_MembersCache;
static bool m_MembersCacheNeedsUpdate;
static Timer::Ptr m_MembersCacheTimer;
* common to all components (e.g. hosts, services, etc.).
*/
-#include <i2-base.h>
-#include <i2-config.h>
-#include <i2-remoting.h>
+#include "base/i2-base.h"
+#include "config/i2-config.h"
+#include "remoting/i2-remoting.h"
#ifdef I2_ICINGA_BUILD
# define I2_ICINGA_API I2_EXPORT
******************************************************************************/
#include "i2-icinga.h"
+#include "base/dynamictype.h"
+#include "base/logger_fwd.h"
+#include "base/objectlock.h"
+#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
*/
int IcingaApplication::Main(void)
{
- Logger::Write(LogDebug, "icinga", "In IcingaApplication::Main()");
+ Log(LogDebug, "icinga", "In IcingaApplication::Main()");
m_StartTime = Utility::GetTime();
/* set up SSL context */
shared_ptr<X509> cert = Utility::GetX509Certificate(GetCertificateFile());
String identity = Utility::GetCertificateCN(cert);
- Logger::Write(LogInformation, "icinga", "My identity: " + identity);
+ Log(LogInformation, "icinga", "My identity: " + identity);
EndpointManager::GetInstance()->SetIdentity(identity);
m_SSLContext = Utility::MakeSSLContext(GetCertificateFile(), GetCertificateFile(), GetCAFile());
RunEventLoop();
- Logger::Write(LogInformation, "icinga", "Icinga has shut down.");
+ Log(LogInformation, "icinga", "Icinga has shut down.");
return EXIT_SUCCESS;
}
#ifndef ICINGAAPPLICATION_H
#define ICINGAAPPLICATION_H
+#include "base/application.h"
+
namespace icinga
{
******************************************************************************/
#include "i2-icinga.h"
+#include "base/objectlock.h"
#include <boost/tuple/tuple.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
result = resultArr;
} else {
- BOOST_THROW_EXCEPTION(invalid_argument("Command is not a string or array."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Command is not a string or array."));
}
return result;
pos_second = result.FindFirstOf("$", pos_first + 1);
if (pos_second == String::NPos)
- BOOST_THROW_EXCEPTION(runtime_error("Closing $ not found in macro format string."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Closing $ not found in macro format string."));
String name = result.SubStr(pos_first + 1, pos_second - pos_first - 1);
if (!macros || !macros->Contains(name))
- BOOST_THROW_EXCEPTION(runtime_error("Macro '" + name + "' is not defined."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Macro '" + name + "' is not defined."));
String value = macros->Get(name);
result.Replace(pos_first, pos_second - pos_first + 1, value);
/**
* @threadsafety Always.
*/
-Dictionary::Ptr MacroProcessor::MergeMacroDicts(const vector<Dictionary::Ptr>& dicts)
+Dictionary::Ptr MacroProcessor::MergeMacroDicts(const std::vector<Dictionary::Ptr>& dicts)
{
Dictionary::Ptr result = boost::make_shared<Dictionary>();
{
public:
static Value ResolveMacros(const Value& str, const Dictionary::Ptr& macros);
- static Dictionary::Ptr MergeMacroDicts(const vector<Dictionary::Ptr>& macroDicts);
+ static Dictionary::Ptr MergeMacroDicts(const std::vector<Dictionary::Ptr>& macroDicts);
private:
MacroProcessor(void);
******************************************************************************/
#include "i2-icinga.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
#include <boost/tuple/tuple.hpp>
+#include <boost/foreach.hpp>
+#include <boost/exception/diagnostic_information.hpp>
using namespace icinga;
/**
* @threadsafety Always.
*/
-set<User::Ptr> Notification::GetUsers(void) const
+std::set<User::Ptr> Notification::GetUsers(void) const
{
- set<User::Ptr> result;
+ std::set<User::Ptr> result;
Array::Ptr users = m_Users;
/**
* @threadsafety Always.
*/
-set<UserGroup::Ptr> Notification::GetGroups(void) const
+std::set<UserGroup::Ptr> Notification::GetGroups(void) const
{
- set<UserGroup::Ptr> result;
+ std::set<UserGroup::Ptr> result;
Array::Ptr groups = m_Groups;
Dictionary::Ptr macros = cr->Get("macros");
- set<User::Ptr> allUsers;
+ std::set<User::Ptr> allUsers;
- set<User::Ptr> users = GetUsers();
+ std::set<User::Ptr> users = GetUsers();
std::copy(users.begin(), users.end(), std::inserter(allUsers, allUsers.begin()));
BOOST_FOREACH(const UserGroup::Ptr& ug, GetGroups()) {
- set<User::Ptr> members = ug->GetMembers();
+ std::set<User::Ptr> members = ug->GetMembers();
std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin()));
}
BOOST_FOREACH(const User::Ptr& user, allUsers) {
- Logger::Write(LogDebug, "icinga", "Sending notification for user " + user->GetName());
+ Log(LogDebug, "icinga", "Sending notification for user " + user->GetName());
BeginExecuteNotificationHelper(macros, type, user);
}
{
ASSERT(!OwnsLock());
- vector<Dictionary::Ptr> macroDicts;
+ std::vector<Dictionary::Ptr> macroDicts;
if (user) {
macroDicts.push_back(user->GetMacros());
Notification::Ptr self = GetSelf();
- vector<Value> arguments;
+ std::vector<Value> arguments;
arguments.push_back(self);
arguments.push_back(macros);
arguments.push_back(type);
ScriptTask::Ptr task = MakeMethodTask("notify", arguments);
if (!task) {
- Logger::Write(LogWarning, "icinga", "Notification object '" + GetName() + "' doesn't have a 'notify' method.");
+ Log(LogWarning, "icinga", "Notification object '" + GetName() + "' doesn't have a 'notify' method.");
return;
}
try {
task->GetResult();
- Logger::Write(LogInformation, "icinga", "Completed sending notification for service '" + GetService()->GetName() + "'");
- } catch (const exception& ex) {
- stringstream msgbuf;
+ Log(LogInformation, "icinga", "Completed sending notification for service '" + GetService()->GetName() + "'");
+ } catch (const std::exception& ex) {
+ std::ostringstream msgbuf;
msgbuf << "Exception occured during notification for service '"
- << GetService()->GetName() << "': " << diagnostic_information(ex);
+ << GetService()->GetName() << "': " << boost::diagnostic_information(ex);
String message = msgbuf.str();
- Logger::Write(LogWarning, "icinga", message);
+ Log(LogWarning, "icinga", message);
}
}
shared_ptr<Service> GetService(void) const;
Value GetNotificationCommand(void) const;
Dictionary::Ptr GetMacros(void) const;
- set<User::Ptr> GetUsers(void) const;
- set<UserGroup::Ptr> GetGroups(void) const;
+ std::set<User::Ptr> GetUsers(void) const;
+ std::set<UserGroup::Ptr> GetGroups(void) const;
void BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr);
Attribute<String> m_HostName;
Attribute<String> m_Service;
- set<ScriptTask::Ptr> m_Tasks;
+ std::set<ScriptTask::Ptr> m_Tasks;
void NotificationCompletedHandler(const ScriptTask::Ptr& task);
******************************************************************************/
#include "i2-icinga.h"
+#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
/**
* @threadsafety Always.
*/
-void NullCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments)
+void NullCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const std::vector<Value>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Service must be specified."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Service must be specified."));
Dictionary::Ptr cr = boost::make_shared<Dictionary>();
cr->Set("state", StateUnknown);
#ifndef NULLCHECKTASK_H
#define NULLCHECKTASK_H
+#include "base/scripttask.h"
+
namespace icinga
{
class I2_ICINGA_API NullCheckTask
{
public:
- static void ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments);
+ static void ScriptFunc(const ScriptTask::Ptr& task, const std::vector<Value>& arguments);
private:
NullCheckTask(void);
******************************************************************************/
#include "i2-icinga.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
+#include "base/convert.h"
+#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
m_OutputFile.open(tempFile.CStr());
if (!m_OutputFile.good())
- Logger::Write(LogWarning, "icinga", "Could not open perfdata file '" + tempFile + "' for writing. Perfdata will be lost.");
+ Log(LogWarning, "icinga", "Could not open perfdata file '" + tempFile + "' for writing. Perfdata will be lost.");
}
/**
#ifndef PERFDATAWRITER_H
#define PERFDATAWRITER_H
+#include "base/dynamicobject.h"
+#include <fstream>
+
namespace icinga
{
Timer::Ptr m_RotationTimer;
void RotationTimerHandler(void);
- ofstream m_OutputFile;
+ std::ofstream m_OutputFile;
void RotateFile(void);
};
#include "i2-icinga.h"
#include <boost/algorithm/string/classification.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
/**
* @threadsafety Always.
*/
-void PluginCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments)
+void PluginCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const std::vector<Value>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Service must be specified."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Service must be specified."));
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Macros must be specified."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Macros must be specified."));
Service::Ptr service = arguments[0];
Dictionary::Ptr macros = arguments[1];
String text;
String perfdata;
- vector<String> lines = output.Split(boost::is_any_of("\r\n"));
+ std::vector<String> lines = output.Split(boost::is_any_of("\r\n"));
BOOST_FOREACH (const String& line, lines) {
size_t delim = line.FindFirstOf("|");
#ifndef PLUGINCHECKTASK_H
#define PLUGINCHECKTASK_H
+#include "base/scripttask.h"
+#include "base/process.h"
+
namespace icinga
{
class I2_ICINGA_API PluginCheckTask
{
public:
- static void ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments);
+ static void ScriptFunc(const ScriptTask::Ptr& task, const std::vector<Value>& arguments);
static ServiceState ExitStatusToState(int exitStatus);
static Dictionary::Ptr ParseCheckOutput(const String& output);
******************************************************************************/
#include "i2-icinga.h"
+#include "base/logger_fwd.h"
+#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
/**
* @threadsafety Always.
*/
-void PluginNotificationTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments)
+void PluginNotificationTask::ScriptFunc(const ScriptTask::Ptr& task, const std::vector<Value>& arguments)
{
if (arguments.size() < 1)
- BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Notification target must be specified."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Notification target must be specified."));
if (arguments.size() < 2)
- BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Macros must be specified."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Macros must be specified."));
if (arguments.size() < 3)
- BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Notification type must be specified."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Missing argument: Notification type must be specified."));
Notification::Ptr notification = arguments[0];
Dictionary::Ptr macros = arguments[1];
pr = ct.m_Process->GetResult();
if (pr.ExitStatus != 0) {
- stringstream msgbuf;
+ std::ostringstream msgbuf;
msgbuf << "Notification command '" << ct.m_Command << "' for service '"
<< ct.m_ServiceName << "' failed; exit status: "
<< pr.ExitStatus << ", output: " << pr.Output;
- Logger::Write(LogWarning, "icinga", msgbuf.str());
+ Log(LogWarning, "icinga", msgbuf.str());
}
ct.m_Task->FinishResult(Empty);
#ifndef PLUGINNOTIFICATIONTASK_H
#define PLUGINNOTIFICATIONTASK_H
+#include "base/scripttask.h"
+#include "base/process.h"
+
namespace icinga
{
class I2_ICINGA_API PluginNotificationTask
{
public:
- static void ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments);
+ static void ScriptFunc(const ScriptTask::Ptr& task, const std::vector<Value>& arguments);
private:
static void ProcessFinishedHandler(PluginNotificationTask ct);
******************************************************************************/
#include "i2-icinga.h"
+#include "icinga/service.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
+#include <boost/exception/diagnostic_information.hpp>
using namespace icinga;
const double Service::DefaultCheckInterval = 5 * 60;
const double Service::CheckIntervalDivisor = 5.0;
-signals2::signal<void (const Service::Ptr&)> Service::OnCheckerChanged;
-signals2::signal<void (const Service::Ptr&)> Service::OnNextCheckChanged;
+boost::signals2::signal<void (const Service::Ptr&)> Service::OnCheckerChanged;
+boost::signals2::signal<void (const Service::Ptr&)> Service::OnNextCheckChanged;
/**
* @threadsafety Always.
Service::Ptr self = GetSelf();
- vector<Value> arguments;
+ std::vector<Value> arguments;
arguments.push_back(self);
arguments.push_back(macros);
if (vresult.IsObjectType<Dictionary>())
result = vresult;
- } catch (const exception& ex) {
- stringstream msgbuf;
+ } catch (const std::exception& ex) {
+ std::ostringstream msgbuf;
msgbuf << "Exception occured during check for service '"
- << GetName() << "': " << diagnostic_information(ex);
+ << GetName() << "': " << boost::diagnostic_information(ex);
String message = msgbuf.str();
- Logger::Write(LogWarning, "icinga", message);
+ Log(LogWarning, "icinga", message);
result = boost::make_shared<Dictionary>();
result->Set("state", StateUnknown);
******************************************************************************/
#include "i2-icinga.h"
+#include "icinga/service.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
int Service::m_NextCommentID = 1;
boost::mutex Service::m_CommentMutex;
-map<int, String> Service::m_LegacyCommentsCache;
-map<String, Service::WeakPtr> Service::m_CommentsCache;
+std::map<int, String> Service::m_LegacyCommentsCache;
+std::map<String, Service::WeakPtr> Service::m_CommentsCache;
bool Service::m_CommentsCacheNeedsUpdate = false;
Timer::Ptr Service::m_CommentsCacheTimer;
Timer::Ptr Service::m_CommentsExpireTimer;
{
boost::mutex::scoped_lock lock(m_CommentMutex);
- map<int, String>::iterator it = m_LegacyCommentsCache.find(id);
+ std::map<int, String>::iterator it = m_LegacyCommentsCache.find(id);
if (it == m_LegacyCommentsCache.end())
return Empty;
m_CommentsCacheNeedsUpdate = false;
}
- Logger::Write(LogDebug, "icinga", "Updating Service comments cache.");
+ Log(LogDebug, "icinga", "Updating Service comments cache.");
- map<int, String> newLegacyCommentsCache;
- map<String, Service::WeakPtr> newCommentsCache;
+ std::map<int, String> newLegacyCommentsCache;
+ std::map<String, Service::WeakPtr> newCommentsCache;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
Service::Ptr service = dynamic_pointer_cast<Service>(object);
if (!comments)
return;
- vector<String> expiredComments;
+ std::vector<String> expiredComments;
{
ObjectLock olock(comments);
******************************************************************************/
#include "i2-icinga.h"
+#include "icinga/service.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
#include <boost/tuple/tuple.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
int Service::m_NextDowntimeID = 1;
boost::mutex Service::m_DowntimeMutex;
-map<int, String> Service::m_LegacyDowntimesCache;
-map<String, Service::WeakPtr> Service::m_DowntimesCache;
+std::map<int, String> Service::m_LegacyDowntimesCache;
+std::map<String, Service::WeakPtr> Service::m_DowntimesCache;
bool Service::m_DowntimesCacheNeedsUpdate = false;
Timer::Ptr Service::m_DowntimesCacheTimer;
Timer::Ptr Service::m_DowntimesExpireTimer;
{
boost::mutex::scoped_lock lock(m_DowntimeMutex);
- map<int, String>::iterator it = m_LegacyDowntimesCache.find(id);
+ std::map<int, String>::iterator it = m_LegacyDowntimesCache.find(id);
if (it == m_LegacyDowntimesCache.end())
return Empty;
m_DowntimesCacheNeedsUpdate = false;
}
- Logger::Write(LogDebug, "icinga", "Updating Service downtimes cache.");
+ Log(LogDebug, "icinga", "Updating Service downtimes cache.");
- map<int, String> newLegacyDowntimesCache;
- map<String, Service::WeakPtr> newDowntimesCache;
+ std::map<int, String> newLegacyDowntimesCache;
+ std::map<String, Service::WeakPtr> newDowntimesCache;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
Service::Ptr service = dynamic_pointer_cast<Service>(object);
if (!downtimes)
return;
- vector<String> expiredDowntimes;
+ std::vector<String> expiredDowntimes;
{
ObjectLock olock(downtimes);
******************************************************************************/
#include "i2-icinga.h"
+#include "icinga/service.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
#include <boost/tuple/tuple.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
+#include <boost/exception/diagnostic_information.hpp>
using namespace icinga;
boost::mutex Service::m_NotificationMutex;
-map<String, set<Notification::WeakPtr> > Service::m_NotificationsCache;
+std::map<String, std::set<Notification::WeakPtr> > Service::m_NotificationsCache;
bool Service::m_NotificationsCacheNeedsUpdate = false;
Timer::Ptr Service::m_NotificationsCacheTimer;
params.SetType(type);
params.SetCheckResult(cr);
- Logger::Write(LogDebug, "icinga", "Sending notification anycast request for service '" + GetName() + "'");
+ Log(LogDebug, "icinga", "Sending notification anycast request for service '" + GetName() + "'");
EndpointManager::GetInstance()->SendAnycastMessage(Endpoint::Ptr(), msg);
}
void Service::SendNotifications(NotificationType type, const Dictionary::Ptr& cr)
{
if (!GetEnableNotifications()) {
- Logger::Write(LogInformation, "icinga", "Notifications are disabled for service '" + GetName() + "'.");
+ Log(LogInformation, "icinga", "Notifications are disabled for service '" + GetName() + "'.");
return;
}
- Logger::Write(LogInformation, "icinga", "Sending notifications for service '" + GetName() + "'");
+ Log(LogInformation, "icinga", "Sending notifications for service '" + GetName() + "'");
- set<Notification::Ptr> notifications = GetNotifications();
+ std::set<Notification::Ptr> notifications = GetNotifications();
if (notifications.empty())
- Logger::Write(LogInformation, "icinga", "Service '" + GetName() + "' does not have any notifications.");
+ Log(LogInformation, "icinga", "Service '" + GetName() + "' does not have any notifications.");
BOOST_FOREACH(const Notification::Ptr& notification, notifications) {
try {
notification->BeginExecuteNotification(type, cr);
- } catch (const exception& ex) {
- stringstream msgbuf;
+ } catch (const std::exception& ex) {
+ std::ostringstream msgbuf;
msgbuf << "Exception occured during notification for service '"
- << GetName() << "': " << diagnostic_information(ex);
+ << GetName() << "': " << boost::diagnostic_information(ex);
String message = msgbuf.str();
- Logger::Write(LogWarning, "icinga", message);
+ Log(LogWarning, "icinga", message);
}
}
}
m_NotificationsCacheNeedsUpdate = false;
}
- Logger::Write(LogDebug, "icinga", "Updating Service notifications cache.");
+ Log(LogDebug, "icinga", "Updating Service notifications cache.");
- map<String, set<Notification::WeakPtr> > newNotificationsCache;
+ std::map<String, std::set<Notification::WeakPtr> > newNotificationsCache;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Notification")) {
const Notification::Ptr& notification = static_pointer_cast<Notification>(object);
/**
* @threadsafety Always.
*/
-set<Notification::Ptr> Service::GetNotifications(void) const
+std::set<Notification::Ptr> Service::GetNotifications(void) const
{
- set<Notification::Ptr> notifications;
+ std::set<Notification::Ptr> notifications;
{
boost::mutex::scoped_lock lock(m_NotificationMutex);
void Service::UpdateSlaveNotifications(void)
{
Dictionary::Ptr oldNotifications;
- vector<Dictionary::Ptr> notificationDescsList;
+ std::vector<Dictionary::Ptr> notificationDescsList;
ConfigItem::Ptr item;
item = ConfigItem::GetObject("Service", GetName());
String nfcname;
Value nfcdesc;
BOOST_FOREACH(boost::tie(nfcname, nfcdesc), notificationDescs) {
- stringstream namebuf;
+ std::ostringstream namebuf;
namebuf << GetName() << "-" << nfcname;
String name = namebuf.str();
CopyNotificationAttributes(this, builder);
if (!nfcdesc.IsObjectType<Dictionary>())
- BOOST_THROW_EXCEPTION(invalid_argument("Notification description must be a dictionary."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Notification description must be a dictionary."));
Dictionary::Ptr notification = nfcdesc;
******************************************************************************/
#include "i2-icinga.h"
+#include "icinga/service.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
/**
* @threadsafety Always.
*/
-set<Host::Ptr> Service::GetParentHosts(void) const
+std::set<Host::Ptr> Service::GetParentHosts(void) const
{
- set<Host::Ptr> parents;
+ std::set<Host::Ptr> parents;
Host::Ptr host = GetHost();
/**
* @threadsafety Always.
*/
-set<Service::Ptr> Service::GetParentServices(void) const
+std::set<Service::Ptr> Service::GetParentServices(void) const
{
- set<Service::Ptr> parents;
+ std::set<Service::Ptr> parents;
Host::Ptr host = GetHost();
Array::Ptr dependencies = GetServiceDependencies();
Dictionary::Ptr Service::CalculateAllMacros(const Dictionary::Ptr& crOverride) const
{
- vector<Dictionary::Ptr> macroDicts;
+ std::vector<Dictionary::Ptr> macroDicts;
macroDicts.push_back(GetMacros());
Host::Ptr host = GetHost();
#ifndef SERVICE_H
#define SERVICE_H
+#include "base/dynamictype.h"
+#include <boost/signals2.hpp>
+
namespace icinga
{
Dictionary::Ptr CalculateDynamicMacros(const Dictionary::Ptr& crOverride = Dictionary::Ptr()) const;
Dictionary::Ptr CalculateAllMacros(const Dictionary::Ptr& crOverride = Dictionary::Ptr()) const;
- set<Host::Ptr> GetParentHosts(void) const;
- set<Service::Ptr> GetParentServices(void) const;
+ std::set<Host::Ptr> GetParentHosts(void) const;
+ std::set<Service::Ptr> GetParentServices(void) const;
bool IsReachable(void) const;
static StateType StateTypeFromString(const String& state);
static String StateTypeToString(StateType state);
- static signals2::signal<void (const Service::Ptr&)> OnCheckerChanged;
- static signals2::signal<void (const Service::Ptr&)> OnNextCheckChanged;
+ static boost::signals2::signal<void (const Service::Ptr&)> OnCheckerChanged;
+ static boost::signals2::signal<void (const Service::Ptr&)> OnNextCheckChanged;
/* Downtimes */
static int GetNextDowntimeID(void);
void RequestNotifications(NotificationType type, const Dictionary::Ptr& cr);
void SendNotifications(NotificationType type, const Dictionary::Ptr& cr);
- set<Notification::Ptr> GetNotifications(void) const;
+ std::set<Notification::Ptr> GetNotifications(void) const;
static void InvalidateNotificationsCache(void);
static int m_NextDowntimeID;
static boost::mutex m_DowntimeMutex;
- static map<int, String> m_LegacyDowntimesCache;
- static map<String, Service::WeakPtr> m_DowntimesCache;
+ static std::map<int, String> m_LegacyDowntimesCache;
+ static std::map<String, Service::WeakPtr> m_DowntimesCache;
static bool m_DowntimesCacheNeedsUpdate;
static Timer::Ptr m_DowntimesCacheTimer;
static Timer::Ptr m_DowntimesExpireTimer;
static int m_NextCommentID;
static boost::mutex m_CommentMutex;
- static map<int, String> m_LegacyCommentsCache;
- static map<String, Service::WeakPtr> m_CommentsCache;
+ static std::map<int, String> m_LegacyCommentsCache;
+ static std::map<String, Service::WeakPtr> m_CommentsCache;
static bool m_CommentsCacheNeedsUpdate;
static Timer::Ptr m_CommentsCacheTimer;
static Timer::Ptr m_CommentsExpireTimer;
Attribute<double> m_NotificationInterval;
static boost::mutex m_NotificationMutex;
- static map<String, set<Notification::WeakPtr> > m_NotificationsCache;
+ static std::map<String, std::set<Notification::WeakPtr> > m_NotificationsCache;
static bool m_NotificationsCacheNeedsUpdate;
static Timer::Ptr m_NotificationsCacheTimer;
******************************************************************************/
#include "i2-icinga.h"
+#include "icinga/servicegroup.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
boost::mutex ServiceGroup::m_Mutex;
-map<String, vector<Service::WeakPtr> > ServiceGroup::m_MembersCache;
+std::map<String, std::vector<Service::WeakPtr> > ServiceGroup::m_MembersCache;
bool ServiceGroup::m_MembersCacheNeedsUpdate = false;
Timer::Ptr ServiceGroup::m_MembersCacheTimer;
DynamicObject::Ptr configObject = DynamicObject::GetObject("ServiceGroup", name);
if (!configObject)
- BOOST_THROW_EXCEPTION(invalid_argument("ServiceGroup '" + name + "' does not exist."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("ServiceGroup '" + name + "' does not exist."));
return dynamic_pointer_cast<ServiceGroup>(configObject);
}
/**
* @threadsafety Always.
*/
-set<Service::Ptr> ServiceGroup::GetMembers(void) const
+std::set<Service::Ptr> ServiceGroup::GetMembers(void) const
{
- set<Service::Ptr> services;
+ std::set<Service::Ptr> services;
{
boost::mutex::scoped_lock lock(m_Mutex);
m_MembersCacheNeedsUpdate = false;
}
- Logger::Write(LogDebug, "icinga", "Updating ServiceGroup members cache.");
+ Log(LogDebug, "icinga", "Updating ServiceGroup members cache.");
- map<String, vector<Service::WeakPtr> > newMembersCache;
+ std::map<String, std::vector<Service::WeakPtr> > newMembersCache;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
const Service::Ptr& service = static_pointer_cast<Service>(object);
#ifndef SERVICEGROUP_H
#define SERVICEGROUP_H
+#include "base/dynamictype.h"
+
namespace icinga
{
String GetNotesUrl(void) const;
String GetActionUrl(void) const;
- set<Service::Ptr> GetMembers(void) const;
+ std::set<Service::Ptr> GetMembers(void) const;
static void InvalidateMembersCache(void);
Attribute<String> m_ActionUrl;
static boost::mutex m_Mutex;
- static map<String, vector<Service::WeakPtr> > m_MembersCache;
+ static std::map<String, std::vector<Service::WeakPtr> > m_MembersCache;
static bool m_MembersCacheNeedsUpdate;
static Timer::Ptr m_MembersCacheTimer;
******************************************************************************/
#include "i2-icinga.h"
+#include "base/dynamictype.h"
+#include "base/scriptfunction.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
TimePeriod::Ptr self = GetSelf();
- vector<Value> arguments;
+ std::vector<Value> arguments;
arguments.push_back(self);
arguments.push_back(begin);
arguments.push_back(end);
ScriptTask::Ptr task = MakeMethodTask("update", arguments);
if (!task) {
- Logger::Write(LogWarning, "icinga", "TimePeriod object '" + GetName() + "' doesn't have an 'update' method.");
+ Log(LogWarning, "icinga", "TimePeriod object '" + GetName() + "' doesn't have an 'update' method.");
return;
}
}
}
-void TimePeriod::EmptyTimePeriodUpdate(const ScriptTask::Ptr& task, const vector<Value>& arguments)
+void TimePeriod::EmptyTimePeriodUpdate(const ScriptTask::Ptr& task, const std::vector<Value>& arguments)
{
if (arguments.size() < 3)
- BOOST_THROW_EXCEPTION(runtime_error("Expected 3 arguments."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Expected 3 arguments."));
// TimePeriod::Ptr tp = arguments[0];
// double begin = arguments[1];
task->FinishResult(segments);
}
-void TimePeriod::EvenMinutesTimePeriodUpdate(const ScriptTask::Ptr& task, const vector<Value>& arguments)
+void TimePeriod::EvenMinutesTimePeriodUpdate(const ScriptTask::Ptr& task, const std::vector<Value>& arguments)
{
if (arguments.size() < 3)
- BOOST_THROW_EXCEPTION(runtime_error("Expected 3 arguments."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Expected 3 arguments."));
TimePeriod::Ptr tp = arguments[0];
double begin = arguments[1];
bool IsInside(double ts) const;
double FindNextTransition(double begin);
- static void EmptyTimePeriodUpdate(const ScriptTask::Ptr& task, const vector<Value>& arguments);
- static void EvenMinutesTimePeriodUpdate(const ScriptTask::Ptr& task, const vector<Value>& arguments);
+ static void EmptyTimePeriodUpdate(const ScriptTask::Ptr& task, const std::vector<Value>& arguments);
+ static void EvenMinutesTimePeriodUpdate(const ScriptTask::Ptr& task, const std::vector<Value>& arguments);
private:
Attribute<double> m_ValidBegin;
******************************************************************************/
#include "i2-icinga.h"
+#include "base/dynamictype.h"
+#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
******************************************************************************/
#include "i2-icinga.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
boost::mutex UserGroup::m_Mutex;
-map<String, vector<User::WeakPtr> > UserGroup::m_MembersCache;
+std::map<String, std::vector<User::WeakPtr> > UserGroup::m_MembersCache;
bool UserGroup::m_MembersCacheNeedsUpdate = false;
Timer::Ptr UserGroup::m_MembersCacheTimer;
DynamicObject::Ptr configObject = DynamicObject::GetObject("UserGroup", name);
if (!configObject)
- BOOST_THROW_EXCEPTION(invalid_argument("UserGroup '" + name + "' does not exist."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("UserGroup '" + name + "' does not exist."));
return dynamic_pointer_cast<UserGroup>(configObject);
}
/**
* @threadsafety Always.
*/
-set<User::Ptr> UserGroup::GetMembers(void) const
+std::set<User::Ptr> UserGroup::GetMembers(void) const
{
- set<User::Ptr> users;
+ std::set<User::Ptr> users;
{
boost::mutex::scoped_lock lock(m_Mutex);
m_MembersCacheNeedsUpdate = false;
}
- Logger::Write(LogDebug, "icinga", "Updating UserGroup members cache.");
+ Log(LogDebug, "icinga", "Updating UserGroup members cache.");
- map<String, vector<User::WeakPtr> > newMembersCache;
+ std::map<String, std::vector<User::WeakPtr> > newMembersCache;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("User")) {
const User::Ptr& user = static_pointer_cast<User>(object);
#ifndef USERGROUP_H
#define USERGROUP_H
+#include "base/dynamicobject.h"
+
namespace icinga
{
String GetDisplayName(void) const;
- set<User::Ptr> GetMembers(void) const;
+ std::set<User::Ptr> GetMembers(void) const;
static void InvalidateMembersCache(void);
Attribute<String> m_DisplayName;
static boost::mutex m_Mutex;
- static map<String, vector<User::WeakPtr> > m_MembersCache;
+ static std::map<String, std::vector<User::WeakPtr> > m_MembersCache;
static bool m_MembersCacheNeedsUpdate;
static Timer::Ptr m_MembersCacheTimer;
-DI2_PYTHON_BUILD \
$(BOOST_CPPFLAGS) \
@PYTHON_CSPEC@ \
- -I${top_srcdir}/lib/base \
- -I${top_srcdir}/lib/config \
- -I${top_srcdir}/lib/remoting \
- -I${top_srcdir}
+ -I${top_srcdir}/lib
libpython_la_LDFLAGS = \
$(BOOST_LDFLAGS) \
libremoting_la_CPPFLAGS = \
-DI2_REMOTING_BUILD \
$(BOOST_CPPFLAGS) \
- -I${top_srcdir}/lib/base \
- -I${top_srcdir}/lib/config
+ -I${top_srcdir}/lib
libremoting_la_LDFLAGS = \
$(BOOST_LDFLAGS) \
******************************************************************************/
#include "i2-remoting.h"
+#include "base/application.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
+#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
REGISTER_TYPE(Endpoint);
-signals2::signal<void (const Endpoint::Ptr&)> Endpoint::OnConnected;
-signals2::signal<void (const Endpoint::Ptr&)> Endpoint::OnDisconnected;
+boost::signals2::signal<void (const Endpoint::Ptr&)> Endpoint::OnConnected;
+boost::signals2::signal<void (const Endpoint::Ptr&)> Endpoint::OnDisconnected;
/**
* Constructor for the Endpoint class.
{
ObjectLock olock(this);
- map<String, shared_ptr<signals2::signal<Endpoint::Callback> > >::iterator it;
+ std::map<String, shared_ptr<boost::signals2::signal<Endpoint::Callback> > >::iterator it;
it = m_TopicHandlers.find(topic);
- shared_ptr<signals2::signal<Endpoint::Callback> > sig;
+ shared_ptr<boost::signals2::signal<Endpoint::Callback> > sig;
if (it == m_TopicHandlers.end()) {
- sig = boost::make_shared<signals2::signal<Endpoint::Callback> >();
+ sig = boost::make_shared<boost::signals2::signal<Endpoint::Callback> >();
m_TopicHandlers.insert(make_pair(topic, sig));
} else {
sig = it->second;
//m_TopicHandlers[method] -= callback;
//UnregisterSubscription(method);
- BOOST_THROW_EXCEPTION(runtime_error("Not implemented."));
+ BOOST_THROW_EXCEPTION(std::runtime_error("Not implemented."));
}
void Endpoint::ProcessRequest(const Endpoint::Ptr& sender, const RequestMessage& request)
if (!request.GetMethod(&method))
return;
- map<String, shared_ptr<signals2::signal<Endpoint::Callback> > >::iterator it;
+ std::map<String, shared_ptr<boost::signals2::signal<Endpoint::Callback> > >::iterator it;
it = m_TopicHandlers.find(method);
if (it == m_TopicHandlers.end())
stringstream message;
message << "Error occured for JSON-RPC socket: Message=" << diagnostic_information(ex);
- Logger::Write(LogWarning, "jsonrpc", message.str());
+ Log(LogWarning, "jsonrpc", message.str());
}*/
- Logger::Write(LogWarning, "jsonrpc", "Lost connection to endpoint: identity=" + GetName());
+ Log(LogWarning, "jsonrpc", "Lost connection to endpoint: identity=" + GetName());
{
ObjectLock olock(this);
#ifndef ENDPOINT_H
#define ENDPOINT_H
+#include "base/dynamicobject.h"
+#include <boost/signals2.hpp>
+
namespace icinga
{
static Endpoint::Ptr MakeEndpoint(const String& name, bool replicated, bool local = true);
- static signals2::signal<void (const Endpoint::Ptr&)> OnConnected;
- static signals2::signal<void (const Endpoint::Ptr&)> OnDisconnected;
+ static boost::signals2::signal<void (const Endpoint::Ptr&)> OnConnected;
+ static boost::signals2::signal<void (const Endpoint::Ptr&)> OnDisconnected;
private:
Attribute<bool> m_Local;
bool m_SentWelcome; /**< Have we sent a welcome message to this
endpoint? */
- map<String, shared_ptr<signals2::signal<Callback> > > m_TopicHandlers;
+ std::map<String, shared_ptr<boost::signals2::signal<Callback> > > m_TopicHandlers;
void NewMessageHandler(const MessagePart& message);
void ClientClosedHandler(void);
******************************************************************************/
#include "i2-remoting.h"
+#include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
+#include "base/convert.h"
#include <boost/tuple/tuple.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
shared_ptr<SSL_CTX> sslContext = m_SSLContext;
if (!sslContext)
- BOOST_THROW_EXCEPTION(logic_error("SSL context is required for AddListener()"));
+ BOOST_THROW_EXCEPTION(std::logic_error("SSL context is required for AddListener()"));
- stringstream s;
+ std::ostringstream s;
s << "Adding new listener: port " << service;
- Logger::Write(LogInformation, "icinga", s.str());
+ Log(LogInformation, "icinga", s.str());
TcpSocket::Ptr server = boost::make_shared<TcpSocket>();
shared_ptr<SSL_CTX> sslContext = m_SSLContext;
if (!sslContext)
- BOOST_THROW_EXCEPTION(logic_error("SSL context is required for AddConnection()"));
+ BOOST_THROW_EXCEPTION(std::logic_error("SSL context is required for AddConnection()"));
TcpSocket::Ptr client = boost::make_shared<TcpSocket>();
client->Connect(node, service);
shared_ptr<X509> cert = tlsStream->GetPeerCertificate();
String identity = Utility::GetCertificateCN(cert);
- Logger::Write(LogInformation, "icinga", "New client connection at " + peerAddress + " for identity '" + identity + "'");
+ Log(LogInformation, "icinga", "New client connection at " + peerAddress + " for identity '" + identity + "'");
Endpoint::Ptr endpoint = Endpoint::GetByName(identity);
{
String method;
if (!message.GetMethod(&method))
- BOOST_THROW_EXCEPTION(invalid_argument("Message is missing the 'method' property."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Message is missing the 'method' property."));
- vector<Endpoint::Ptr> candidates;
+ std::vector<Endpoint::Ptr> candidates;
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
Endpoint::Ptr endpoint = dynamic_pointer_cast<Endpoint>(object);
{
String id;
if (message.GetID(&id))
- BOOST_THROW_EXCEPTION(invalid_argument("Multicast requests must not have an ID."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Multicast requests must not have an ID."));
String method;
if (!message.GetMethod(&method))
- BOOST_THROW_EXCEPTION(invalid_argument("Message is missing the 'method' property."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Message is missing the 'method' property."));
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
Endpoint::Ptr recipient = dynamic_pointer_cast<Endpoint>(object);
m_NextMessageID++;
- stringstream idstream;
- idstream << m_NextMessageID;
-
- String id = idstream.str();
+ String id = Convert::ToString(m_NextMessageID);
message.SetID(id);
PendingRequest pr;
SendUnicastMessage(sender, recipient, message);
}
-bool EndpointManager::RequestTimeoutLessComparer(const pair<String, PendingRequest>& a,
- const pair<String, PendingRequest>& b)
+bool EndpointManager::RequestTimeoutLessComparer(const std::pair<String, PendingRequest>& a,
+ const std::pair<String, PendingRequest>& b)
{
return a.second.Timeout < b.second.Timeout;
}
service = endpoint->GetService();
if (node.IsEmpty() || service.IsEmpty()) {
- Logger::Write(LogWarning, "icinga", "Can't reconnect "
+ Log(LogWarning, "icinga", "Can't reconnect "
"to endpoint '" + endpoint->GetName() + "': No "
"node/service information.");
continue;
{
ObjectLock olock(this);
- map<String, PendingRequest>::iterator it;
+ std::map<String, PendingRequest>::iterator it;
for (it = m_Requests.begin(); it != m_Requests.end(); ++it) {
if (it->second.HasTimedOut()) {
it->second.Callback(Endpoint::Ptr(), it->second.Request,
String id;
if (!message.GetID(&id))
- BOOST_THROW_EXCEPTION(invalid_argument("Response message must have a message ID."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Response message must have a message ID."));
- map<String, PendingRequest>::iterator it;
+ std::map<String, PendingRequest>::iterator it;
it = m_Requests.find(id);
if (it == m_Requests.end())
#ifndef ENDPOINTMANAGER_H
#define ENDPOINTMANAGER_H
+#include "base/tcpsocket.h"
+#include "base/tlsstream.h"
+#include <boost/signals2.hpp>
+
namespace icinga
{
void ProcessResponseMessage(const Endpoint::Ptr& sender, const ResponseMessage& message);
- signals2::signal<void (const Endpoint::Ptr&)> OnNewEndpoint;
+ boost::signals2::signal<void (const Endpoint::Ptr&)> OnNewEndpoint;
private:
String m_Identity;
Timer::Ptr m_ReconnectTimer;
- set<TcpSocket::Ptr> m_Servers;
- set<TlsStream::Ptr> m_PendingClients;
+ std::set<TcpSocket::Ptr> m_Servers;
+ std::set<TlsStream::Ptr> m_PendingClients;
/**
* Information about a pending API request.
};
long m_NextMessageID;
- map<String, PendingRequest> m_Requests;
+ std::map<String, PendingRequest> m_Requests;
Timer::Ptr m_RequestTimer;
- static bool RequestTimeoutLessComparer(const pair<String, PendingRequest>& a, const pair<String, PendingRequest>& b);
+ static bool RequestTimeoutLessComparer(const std::pair<String, PendingRequest>& a, const std::pair<String, PendingRequest>& b);
void RequestTimerHandler(void);
void SubscriptionTimerHandler(void);
* supports endpoint-based communication using messages.
*/
-#include <i2-base.h>
-#include <i2-config.h>
+#include "base/i2-base.h"
+#include "config/i2-config.h"
#ifdef I2_REMOTING_BUILD
# define I2_REMOTING_API I2_EXPORT
******************************************************************************/
#include "i2-remoting.h"
+#include "base/netstring.h"
+#include "base/objectlock.h"
+#include "base/logger_fwd.h"
+#include <boost/exception/diagnostic_information.hpp>
using namespace icinga;
Value value = Value::Deserialize(jsonString);
if (!value.IsObjectType<Dictionary>()) {
- BOOST_THROW_EXCEPTION(invalid_argument("JSON-RPC"
+ BOOST_THROW_EXCEPTION(std::invalid_argument("JSON-RPC"
" message must be a dictionary."));
}
MessagePart mp(value);
OnNewMessage(GetSelf(), mp);
- } catch (const exception& ex) {
- Logger::Write(LogCritical, "remoting", "Exception"
+ } catch (const std::exception& ex) {
+ Log(LogCritical, "remoting", "Exception"
" while processing message from JSON-RPC client: " +
- diagnostic_information(ex));
+ boost::diagnostic_information(ex));
}
}
}
#ifndef JSONRPCCONNECTION_H
#define JSONRPCCONNECTION_H
+#include "base/connection.h"
+#include <boost/signals2.hpp>
+
namespace icinga
{
void SendMessage(const MessagePart& message);
- signals2::signal<void (const JsonRpcConnection::Ptr&, const MessagePart&)> OnNewMessage;
+ boost::signals2::signal<void (const JsonRpcConnection::Ptr&, const MessagePart&)> OnNewMessage;
protected:
virtual void ProcessData(void);
******************************************************************************/
#include "i2-remoting.h"
+#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
fprintf(outfp, "/* This file has been automatically generated\n"
" from the input file \"%s\". */\n\n", argv[1]);
- fputs("#include \"i2-config.h\"\n\nstatic const char g_ConfigFragment[] = {\n", outfp);
+ fputs("#include \"config/configcompiler.h\"\n\nstatic const char g_ConfigFragment[] = {\n", outfp);
fputc('\t', outfp);
cols = 0;