mirror of https://github.com/Icinga/icinga2.git
Implemented global macros.
This commit is contained in:
parent
eebd660d4f
commit
530819d658
|
@ -86,6 +86,13 @@ set<string> Host::GetParents(void) const
|
|||
return parents;
|
||||
}
|
||||
|
||||
Dictionary::Ptr Host::GetMacros(void) const
|
||||
{
|
||||
Dictionary::Ptr value;
|
||||
GetProperty("macros", &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Host::IsReachable(void) const
|
||||
{
|
||||
Dictionary::Ptr dependencies;
|
||||
|
|
|
@ -34,6 +34,7 @@ public:
|
|||
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;
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
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;
|
||||
|
||||
|
@ -36,7 +36,18 @@ string MacroProcessor::ResolveMacros(const string& str, const Dictionary::Ptr& m
|
|||
|
||||
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);
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace icinga
|
|||
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);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,12 @@ NagiosCheckTask::NagiosCheckTask(const Service& service)
|
|||
: 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)
|
||||
|
|
Binary file not shown.
|
@ -170,6 +170,7 @@ int IcingaApplication::Main(const vector<string>& args)
|
|||
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)) {
|
||||
|
@ -314,6 +315,11 @@ string IcingaApplication::GetPidPath(void) const
|
|||
return m_PidPath;
|
||||
}
|
||||
|
||||
Dictionary::Ptr IcingaApplication::GetMacros(void) const
|
||||
{
|
||||
return m_Macros;
|
||||
}
|
||||
|
||||
time_t IcingaApplication::GetStartTime(void) const
|
||||
{
|
||||
return m_StartTime;
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
string GetNode(void) const;
|
||||
string GetService(void) const;
|
||||
string GetPidPath(void) const;
|
||||
Dictionary::Ptr GetMacros(void) const;
|
||||
|
||||
time_t GetStartTime(void) const;
|
||||
|
||||
|
@ -56,6 +57,7 @@ private:
|
|||
string m_Node;
|
||||
string m_Service;
|
||||
string m_PidPath;
|
||||
Dictionary::Ptr m_Macros;
|
||||
|
||||
time_t m_StartTime;
|
||||
|
||||
|
|
Loading…
Reference in New Issue