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

Method GetVariable

lib/cli/variableutility.cpp:16–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14using namespace icinga;
15
16Value VariableUtility::GetVariable(const String& name)
17{
18 String varsfile = Configuration::VarsPath;
19
20 std::fstream fp;
21 fp.open(varsfile.CStr(), std::ios_base::in);
22
23 StdioStream::Ptr sfp = new StdioStream(&fp, false);
24
25 String message;
26 StreamReadContext src;
27 for (;;) {
28 StreamReadStatus srs = NetString::ReadStringFromStream(sfp, &message, src);
29
30 if (srs == StatusEof)
31 break;
32
33 if (srs != StatusNewItem)
34 continue;
35
36 Dictionary::Ptr variable = JsonDecode(message);
37
38 if (variable->Get("name") == name) {
39 return variable->Get("value");
40 }
41 }
42
43 return Empty;
44}
45
46void VariableUtility::PrintVariables(std::ostream& outfp)
47{

Callers 4

IsNameIndexerMethod · 0.80
GetConstMethod · 0.80
BindToScopeMethod · 0.80

Calls 2

CStrMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected