add_subdirectory(plugins-contrib.d)
install(
- FILES itl command.conf command-icinga.conf hangman timeperiod.conf plugins command-plugins.conf manubulon command-plugins-manubulon.conf windows-plugins command-plugins-windows.conf nscp command-nscp-local.conf plugins-contrib
+ FILES itl command.conf command-icinga.conf hangman plugins command-plugins.conf manubulon command-plugins-manubulon.conf windows-plugins command-plugins-windows.conf nscp command-nscp-local.conf plugins-contrib
DESTINATION ${CMAKE_INSTALL_DATADIR}/icinga2/include
)
include "command.conf"
include "command-icinga.conf"
-include "timeperiod.conf"
if (!object)
return;
- ASSERT(!object->IsActive());
#ifdef I2_DEBUG
Log(LogDebug, "ConfigObject")
<< "Restoring object '" << name << "' of type '" << type << "'.";
Function::Ptr sf = new icinga::Function(WrapFunction(callback)); \
ScriptGlobal::Set(#name, sf); \
} \
- INITIALIZE_ONCE(RegisterFunction); \
+ INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
+ } } }
+
+#define REGISTER_SCRIPTFUNCTION_NS(ns, name, callback) \
+ namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \
+ void RegisterFunction(void) { \
+ Function::Ptr sf = new icinga::Function(WrapFunction(callback)); \
+ ScriptGlobal::Set(#ns "." #name, sf); \
+ } \
+ INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
} } }
#define REGISTER_SAFE_SCRIPTFUNCTION(name, callback) \
Function::Ptr sf = new icinga::Function(WrapFunction(callback), true); \
ScriptGlobal::Set(#name, sf); \
} \
- INITIALIZE_ONCE(RegisterFunction); \
+ INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
} } }
+#define REGISTER_SAFE_SCRIPTFUNCTION_NS(ns, name, callback) \
+ namespace { namespace UNIQUE_NAME(sf) { namespace sf ## ns ## name { \
+ void RegisterFunction(void) { \
+ Function::Ptr sf = new icinga::Function(WrapFunction(callback), true); \
+ ScriptGlobal::Set(#ns "." #name, sf); \
+ } \
+ INITIALIZE_ONCE_WITH_PRIORITY(RegisterFunction, 10); \
+ } } }
}
#endif /* SCRIPTFUNCTION_H */
Loader(void);
static boost::thread_specific_ptr<std::priority_queue<DeferredInitializer> >& GetDeferredInitializers(void);
-
};
}
#include "base/objectlock.hpp"
#include "base/exception.hpp"
#include <boost/foreach.hpp>
+#include <boost/algorithm/string/split.hpp>
#include <fstream>
using namespace icinga;
void ScriptGlobal::Set(const String& name, const Value& value)
{
- m_Globals->Set(name, value);
+ std::vector<String> tokens;
+ boost::algorithm::split(tokens, name, boost::is_any_of("."));
+
+ if (tokens.empty())
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Name must not be empty"));
+
+ {
+ ObjectLock olock(m_Globals);
+
+ Dictionary::Ptr parent = m_Globals;
+
+ for (std::vector<String>::size_type i = 0; i < tokens.size(); i++) {
+ const String& token = tokens[i];
+
+ if (i + 1 != tokens.size()) {
+ if (!parent->Contains(token)) {
+ Dictionary::Ptr dict = new Dictionary();
+ parent->Set(token, dict);
+ parent = dict;
+ } else {
+ parent = parent->Get(token);
+ }
+ }
+ }
+
+ parent->Set(tokens[tokens.size() - 1], value);
+ }
}
bool ScriptGlobal::Exists(const String& name)
ConfigItem::ItemList ConfigItem::m_UnnamedItems;
ConfigItem::IgnoredItemList ConfigItem::m_IgnoredItems;
-#ifdef I2_DEBUG
-REGISTER_SCRIPTFUNCTION(__run_with_activation_context, &ConfigItem::RunWithActivationContext);
-#endif /* I2_DEBUG */
+REGISTER_SCRIPTFUNCTION_NS(Internal, run_with_activation_context, &ConfigItem::RunWithActivationContext);
/**
* Constructor for the ConfigItem class.
return true;
}
-bool ConfigItem::CommitItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector<ConfigItem::Ptr>& newItems)
+bool ConfigItem::CommitItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector<ConfigItem::Ptr>& newItems, bool silent)
{
- Log(LogInformation, "ConfigItem", "Committing config item(s).");
+ if (!silent)
+ Log(LogInformation, "ConfigItem", "Committing config item(s).");
if (!CommitNewItems(context, upq, newItems)) {
upq.ReportExceptions("config");
ApplyRule::CheckMatches();
- /* log stats for external parsers */
- typedef std::map<Type::Ptr, int> ItemCountMap;
- ItemCountMap itemCounts;
- BOOST_FOREACH(const ConfigItem::Ptr& item, newItems) {
- if (!item->m_Object)
- continue;
+ if (!silent) {
+ /* log stats for external parsers */
+ typedef std::map<Type::Ptr, int> ItemCountMap;
+ ItemCountMap itemCounts;
+ BOOST_FOREACH(const ConfigItem::Ptr& item, newItems) {
+ if (!item->m_Object)
+ continue;
- itemCounts[item->m_Object->GetReflectionType()]++;
- }
+ itemCounts[item->m_Object->GetReflectionType()]++;
+ }
- BOOST_FOREACH(const ItemCountMap::value_type& kv, itemCounts) {
- Log(LogInformation, "ConfigItem")
- << "Instantiated " << kv.second << " " << (kv.second != 1 ? kv.first->GetPluralName() : kv.first->GetName()) << ".";
+ BOOST_FOREACH(const ItemCountMap::value_type& kv, itemCounts) {
+ Log(LogInformation, "ConfigItem")
+ << "Instantiated " << kv.second << " " << (kv.second != 1 ? kv.first->GetPluralName() : kv.first->GetName()) << ".";
+ }
}
return true;
}
-bool ConfigItem::ActivateItems(WorkQueue& upq, const std::vector<ConfigItem::Ptr>& newItems, bool runtimeCreated)
+bool ConfigItem::ActivateItems(WorkQueue& upq, const std::vector<ConfigItem::Ptr>& newItems, bool runtimeCreated, bool silent)
{
static boost::mutex mtx;
boost::mutex::scoped_lock lock(mtx);
- Log(LogInformation, "ConfigItem", "Triggering Start signal for config items");
+ if (!silent)
+ Log(LogInformation, "ConfigItem", "Triggering Start signal for config items");
BOOST_FOREACH(const ConfigItem::Ptr& item, newItems) {
if (!item->m_Object)
}
#endif /* I2_DEBUG */
- Log(LogInformation, "ConfigItem", "Activated all objects.");
+ if (!silent)
+ Log(LogInformation, "ConfigItem", "Activated all objects.");
return true;
}
-#ifdef I2_DEBUG
bool ConfigItem::RunWithActivationContext(const Function::Ptr& function)
{
ActivationScope scope;
std::vector<ConfigItem::Ptr> newItems;
- if (!CommitItems(scope.GetContext(), upq, newItems))
+ if (!CommitItems(scope.GetContext(), upq, newItems, true))
return false;
- if (!ActivateItems(upq, newItems))
+ if (!ActivateItems(upq, newItems, false, true))
return false;
return true;
}
-#endif /* I2_DEBUG */
std::vector<ConfigItem::Ptr> ConfigItem::GetItems(const String& type)
{
static ConfigItem::Ptr GetByTypeAndName(const String& type,
const String& name);
- static bool CommitItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector<ConfigItem::Ptr>& newItems);
- static bool ActivateItems(WorkQueue& upq, const std::vector<ConfigItem::Ptr>& newItems, bool runtimeCreated = false);
+ static bool CommitItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector<ConfigItem::Ptr>& newItems, bool silent = false);
+ static bool ActivateItems(WorkQueue& upq, const std::vector<ConfigItem::Ptr>& newItems, bool runtimeCreated = false, bool silent = false);
-#ifdef I2_DEBUG
static bool RunWithActivationContext(const Function::Ptr& function);
-#endif /* I2_DEBUG */
static std::vector<ConfigItem::Ptr> GetItems(const String& type);
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-template CheckCommand "ido-check-command" {
- execute = IdoCheck
-}
+assert(Internal.run_with_activation_context(function() {
+ template CheckCommand "ido-check-command" {
+ execute = Internal.IdoCheck
+ }
-object CheckCommand "ido" {
- import "ido-check-command"
-}
+ object CheckCommand "ido" {
+ import "ido-check-command"
+ }
+}))
using namespace icinga;
-REGISTER_SCRIPTFUNCTION(IdoCheck, &IdoCheckTask::ScriptFunc);
+REGISTER_SCRIPTFUNCTION_NS(Internal, IdoCheck, &IdoCheckTask::ScriptFunc);
void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
mkclass_target(usergroup.ti usergroup.tcpp usergroup.thpp)
mkclass_target(user.ti user.tcpp user.thpp)
+mkembedconfig_target(icinga-itl.conf icinga-itl.cpp)
+
set(icinga_SOURCES
apiactions.cpp apievents.cpp checkable.cpp checkable.thpp checkable-dependency.cpp checkable-downtime.cpp checkable-event.cpp
checkable-flapping.cpp checkable-script.cpp checkcommand.cpp checkcommand.thpp checkresult.cpp checkresult.thpp
cib.cpp clusterevents.cpp command.cpp command.thpp comment.cpp comment.thpp compatutility.cpp dependency.cpp dependency.thpp
dependency-apply.cpp downtime.cpp downtime.thpp eventcommand.cpp eventcommand.thpp
externalcommandprocessor.cpp host.cpp host.thpp hostgroup.cpp hostgroup.thpp icingaapplication.cpp icingaapplication.thpp
- customvarobject.cpp customvarobject.thpp
+ icinga-itl.cpp customvarobject.cpp customvarobject.thpp
legacytimeperiod.cpp macroprocessor.cpp notificationcommand.cpp notificationcommand.thpp notification.cpp notification.thpp
notification-apply.cpp objectutils.cpp perfdatavalue.cpp perfdatavalue.thpp pluginutility.cpp scheduleddowntime.cpp scheduleddowntime.thpp
scheduleddowntime-apply.cpp service-apply.cpp checkable-check.cpp checkable-comment.cpp
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-template TimePeriod "legacy-timeperiod" {
- update = LegacyTimePeriod
-}
+assert(Internal.run_with_activation_context(function() {
+ template TimePeriod "legacy-timeperiod" {
+ update = Internal.LegacyTimePeriod
+ }
+}))
using namespace icinga;
-REGISTER_SCRIPTFUNCTION(LegacyTimePeriod, &LegacyTimePeriod::ScriptFunc);
+REGISTER_SCRIPTFUNCTION_NS(Internal, LegacyTimePeriod, &LegacyTimePeriod::ScriptFunc);
bool LegacyTimePeriod::IsInTimeRange(tm *begin, tm *end, int stride, tm *reference)
{
using namespace icinga;
-REGISTER_SCRIPTFUNCTION(ClrCheck, &ClrCheckTask::ScriptFunc);
+REGISTER_SCRIPTFUNCTION_NS(Internal, ClrCheck, &ClrCheckTask::ScriptFunc);
static boost::once_flag l_OnceFlag = BOOST_ONCE_INIT;
using namespace icinga;
-REGISTER_SCRIPTFUNCTION(ClusterCheck, &ClusterCheckTask::ScriptFunc);
+REGISTER_SCRIPTFUNCTION_NS(Internal, ClusterCheck, &ClusterCheckTask::ScriptFunc);
void ClusterCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
using namespace icinga;
-REGISTER_SCRIPTFUNCTION(ClusterZoneCheck, &ClusterZoneCheckTask::ScriptFunc);
+REGISTER_SCRIPTFUNCTION_NS(Internal, ClusterZoneCheck, &ClusterZoneCheckTask::ScriptFunc);
void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
using namespace icinga;
-REGISTER_SCRIPTFUNCTION(ExceptionCheck, &ExceptionCheckTask::ScriptFunc);
+REGISTER_SCRIPTFUNCTION_NS(Internal, ExceptionCheck, &ExceptionCheckTask::ScriptFunc);
void ExceptionCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
using namespace icinga;
-REGISTER_SCRIPTFUNCTION(IcingaCheck, &IcingaCheckTask::ScriptFunc);
+REGISTER_SCRIPTFUNCTION_NS(Internal, IcingaCheck, &IcingaCheckTask::ScriptFunc);
void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
-template CheckCommand "icinga-check-command" {
- execute = IcingaCheck
-}
-
-template CheckCommand "cluster-check-command" {
- execute = ClusterCheck
-}
-
-template CheckCommand "cluster-zone-check-command" {
- execute = ClusterZoneCheck
-}
-
-template CheckCommand "plugin-check-command" {
- execute = PluginCheck
-}
-
-template CheckCommand "clr-check-command" {
- execute = ClrCheck
-}
-
-template NotificationCommand "plugin-notification-command" {
- execute = PluginNotification
-}
-
-template EventCommand "plugin-event-command" {
- execute = PluginEvent
-}
-
-template CheckCommand "random-check-command" {
- execute = RandomCheck
-}
-
-template CheckCommand "exception-check-command" {
- execute = ExceptionCheck
-}
+assert(Internal.run_with_activation_context(function() {
+ template CheckCommand "icinga-check-command" {
+ execute = Internal.IcingaCheck
+ }
+
+ template CheckCommand "cluster-check-command" {
+ execute = Internal.ClusterCheck
+ }
+
+ template CheckCommand "cluster-zone-check-command" {
+ execute = Internal.ClusterZoneCheck
+ }
+
+ template CheckCommand "plugin-check-command" {
+ execute = Internal.PluginCheck
+ }
+
+ template CheckCommand "clr-check-command" {
+ execute = Internal.ClrCheck
+ }
+
+ template NotificationCommand "plugin-notification-command" {
+ execute = Internal.PluginNotification
+ }
+
+ template EventCommand "plugin-event-command" {
+ execute = Internal.PluginEvent
+ }
+
+ template CheckCommand "random-check-command" {
+ execute = Internal.RandomCheck
+ }
+
+ template CheckCommand "exception-check-command" {
+ execute = Internal.ExceptionCheck
+ }
+}))
using namespace icinga;
-REGISTER_SCRIPTFUNCTION(NullCheck, &NullCheckTask::ScriptFunc);
+REGISTER_SCRIPTFUNCTION_NS(Internal, NullCheck, &NullCheckTask::ScriptFunc);
void NullCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
using namespace icinga;
-REGISTER_SCRIPTFUNCTION(NullEvent, &NullEventTask::ScriptFunc);
+REGISTER_SCRIPTFUNCTION_NS(Internal, NullEvent, &NullEventTask::ScriptFunc);
void NullEventTask::ScriptFunc(const Checkable::Ptr&, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
{ }
using namespace icinga;
-REGISTER_SCRIPTFUNCTION(PluginCheck, &PluginCheckTask::ScriptFunc);
+REGISTER_SCRIPTFUNCTION_NS(Internal, PluginCheck, &PluginCheckTask::ScriptFunc);
void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
using namespace icinga;
-REGISTER_SCRIPTFUNCTION(PluginEvent, &PluginEventTask::ScriptFunc);
+REGISTER_SCRIPTFUNCTION_NS(Internal, PluginEvent, &PluginEventTask::ScriptFunc);
void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
using namespace icinga;
-REGISTER_SCRIPTFUNCTION(PluginNotification, &PluginNotificationTask::ScriptFunc);
+REGISTER_SCRIPTFUNCTION_NS(Internal, PluginNotification, &PluginNotificationTask::ScriptFunc);
void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification,
const User::Ptr& user, const CheckResult::Ptr& cr, int itype,
using namespace icinga;
-REGISTER_SCRIPTFUNCTION(RandomCheck, &RandomCheckTask::ScriptFunc);
+REGISTER_SCRIPTFUNCTION_NS(Internal, RandomCheck, &RandomCheckTask::ScriptFunc);
void RandomCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
using namespace icinga;
-REGISTER_SCRIPTFUNCTION(EmptyTimePeriod, &TimePeriodTask::EmptyTimePeriodUpdate);
-REGISTER_SCRIPTFUNCTION(EvenMinutesTimePeriod, &TimePeriodTask::EvenMinutesTimePeriodUpdate);
+REGISTER_SCRIPTFUNCTION_NS(Internal, EmptyTimePeriod, &TimePeriodTask::EmptyTimePeriodUpdate);
+REGISTER_SCRIPTFUNCTION_NS(Internal, EvenMinutesTimePeriod, &TimePeriodTask::EvenMinutesTimePeriodUpdate);
Array::Ptr TimePeriodTask::EmptyTimePeriodUpdate(const TimePeriod::Ptr&, double, double)
{