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

Method GenerateNodeIcingaConfig

lib/cli/nodeutility.cpp:43–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41 */
42
43int NodeUtility::GenerateNodeIcingaConfig(const String& endpointName, const String& zoneName,
44 const String& parentZoneName, const std::vector<std::string>& endpoints,
45 const std::vector<String>& globalZones)
46{
47 Array::Ptr config = new Array();
48
49 Array::Ptr myParentZoneMembers = new Array();
50
51 for (String endpoint : endpoints) {
52 /* extract all --endpoint arguments and store host,port info */
53 std::vector<String> tokens = endpoint.Split(",");
54
55 Dictionary::Ptr myParentEndpoint = new Dictionary();
56
57 if (tokens.size() > 1) {
58 String host = tokens[1].Trim();
59
60 if (!host.IsEmpty())
61 myParentEndpoint->Set("host", host);
62 }
63
64 if (tokens.size() > 2) {
65 String port = tokens[2].Trim();
66
67 if (!port.IsEmpty())
68 myParentEndpoint->Set("port", port);
69 }
70
71 String myEndpointName = tokens[0].Trim();
72 myParentEndpoint->Set("__name", myEndpointName);
73 myParentEndpoint->Set("__type", "Endpoint");
74
75 /* save endpoint in master zone */
76 myParentZoneMembers->Add(myEndpointName);
77
78 config->Add(myParentEndpoint);
79 }
80
81 /* add the parent zone to the config */
82 config->Add(new Dictionary({
83 { "__name", parentZoneName },
84 { "__type", "Zone" },
85 { "endpoints", myParentZoneMembers }
86 }));
87
88 /* store the local generated node configuration */
89 config->Add(new Dictionary({
90 { "__name", endpointName },
91 { "__type", "Endpoint" }
92 }));
93
94 config->Add(new Dictionary({
95 { "__name", zoneName },
96 { "__type", "Zone" },
97 { "parent", parentZoneName },
98 { "endpoints", new Array({ endpointName }) }
99 }));
100

Callers

nothing calls this directly

Calls 6

SplitMethod · 0.80
TrimMethod · 0.80
sizeMethod · 0.45
IsEmptyMethod · 0.45
SetMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected