return parents;
}
+Dictionary::Ptr Host::GetMacros(void) const
+{
+ Dictionary::Ptr value;
+ GetProperty("macros", &value);
+ return value;
+}
+
bool Host::IsReachable(void) const
{
Dictionary::Ptr dependencies;
string GetAlias(void) const;
Dictionary::Ptr GetGroups(void) const;
set<string> GetParents(void) const;
+ Dictionary::Ptr GetMacros(void) const;
bool IsReachable(void) const;
bool IsUp(void) const;
using namespace icinga;
-string MacroProcessor::ResolveMacros(const string& str, const Dictionary::Ptr& macros)
+string MacroProcessor::ResolveMacros(const string& str, const vector<Dictionary::Ptr>& macroDicts)
{
string::size_type offset, pos_first, pos_second;
string name = result.substr(pos_first + 1, pos_second - pos_first - 1);
string value;
- if (!macros || !macros->Get(name, &value))
+ bool resolved = false;
+
+ vector<Dictionary::Ptr>::const_iterator it;
+ for (it = macroDicts.begin(); it != macroDicts.end(); it++) {
+ Dictionary::Ptr macros = *it;
+ if (macros && macros->Get(name, &value)) {
+ resolved = true;
+ break;
+ }
+ }
+
+ if (!resolved)
throw runtime_error("Macro '" + name + "' is not defined.");
result.replace(pos_first, pos_second - pos_first + 1, value);
class I2_CIB_API MacroProcessor
{
public:
- static string ResolveMacros(const string& str, const Dictionary::Ptr& macros);
+ static string ResolveMacros(const string& str, const vector<Dictionary::Ptr>& macroDicts);
};
}
-#endif /* MACROPROCESSOR_H */
\ No newline at end of file
+#endif /* MACROPROCESSOR_H */
: CheckTask(service), m_FP(NULL), m_UsePopen(false)
{
string checkCommand = service.GetCheckCommand();
- m_Command = MacroProcessor::ResolveMacros(checkCommand, service.GetMacros());
+
+ vector<Dictionary::Ptr> macroDicts;
+ macroDicts.push_back(service.GetMacros());
+ macroDicts.push_back(service.GetHost().GetMacros());
+ macroDicts.push_back(IcingaApplication::GetInstance()->GetMacros());
+ m_Command = MacroProcessor::ResolveMacros(checkCommand, macroDicts);
}
void NagiosCheckTask::Enqueue(void)
icingaConfig->GetProperty("node", &m_Node);
icingaConfig->GetProperty("service", &m_Service);
icingaConfig->GetProperty("pidpath", &m_PidPath);
+ icingaConfig->GetProperty("macros", &m_Macros);
string logpath;
if (icingaConfig->GetProperty("logpath", &logpath)) {
return m_PidPath;
}
+Dictionary::Ptr IcingaApplication::GetMacros(void) const
+{
+ return m_Macros;
+}
+
time_t IcingaApplication::GetStartTime(void) const
{
return m_StartTime;
string GetNode(void) const;
string GetService(void) const;
string GetPidPath(void) const;
+ Dictionary::Ptr GetMacros(void) const;
time_t GetStartTime(void) const;
string m_Node;
string m_Service;
string m_PidPath;
+ Dictionary::Ptr m_Macros;
time_t m_StartTime;