MCPcopy Create free account
hub / github.com/Icinga/icinga2 / GetCheckableCommandArgs

Method GetCheckableCommandArgs

lib/icinga/compatutility.cpp:69–132  ·  view source on GitHub ↗

Used in DB IDO and Livestatus. */

Source from the content-addressed store, hash-verified

67
68/* Used in DB IDO and Livestatus. */
69String CompatUtility::GetCheckableCommandArgs(const Checkable::Ptr& checkable)
70{
71 CheckCommand::Ptr command = checkable->GetCheckCommand();
72
73 Dictionary::Ptr args = new Dictionary();
74
75 if (command) {
76 Host::Ptr host;
77 Service::Ptr service;
78 tie(host, service) = GetHostService(checkable);
79 String command_line = GetCommandLine(command);
80
81 Dictionary::Ptr command_vars = command->GetVars();
82
83 if (command_vars) {
84 ObjectLock olock(command_vars);
85 for (const Dictionary::Pair& kv : command_vars) {
86 String macro = "$" + kv.first + "$"; // this is too simple
87 if (command_line.Contains(macro))
88 args->Set(kv.first, kv.second);
89
90 }
91 }
92
93 Dictionary::Ptr host_vars = host->GetVars();
94
95 if (host_vars) {
96 ObjectLock olock(host_vars);
97 for (const Dictionary::Pair& kv : host_vars) {
98 String macro = "$" + kv.first + "$"; // this is too simple
99 if (command_line.Contains(macro))
100 args->Set(kv.first, kv.second);
101 macro = "$host.vars." + kv.first + "$";
102 if (command_line.Contains(macro))
103 args->Set(kv.first, kv.second);
104 }
105 }
106
107 if (service) {
108 Dictionary::Ptr service_vars = service->GetVars();
109
110 if (service_vars) {
111 ObjectLock olock(service_vars);
112 for (const Dictionary::Pair& kv : service_vars) {
113 String macro = "$" + kv.first + "$"; // this is too simple
114 if (command_line.Contains(macro))
115 args->Set(kv.first, kv.second);
116 macro = "$service.vars." + kv.first + "$";
117 if (command_line.Contains(macro))
118 args->Set(kv.first, kv.second);
119 }
120 }
121 }
122
123 String arg_string;
124 ObjectLock olock(args);
125 for (const Dictionary::Pair& kv : args) {
126 arg_string += Convert::ToString(kv.first) + "=" + Convert::ToString(kv.second) + "!";

Callers

nothing calls this directly

Calls 3

GetCheckCommandMethod · 0.80
ContainsMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected