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

Method SplitPerfdata

lib/icinga/pluginutility.cpp:130–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128}
129
130Array::Ptr PluginUtility::SplitPerfdata(const String& perfdata)
131{
132 ArrayData result;
133
134 size_t begin = 0;
135 String multi_prefix;
136
137 for (;;) {
138 size_t eqp = perfdata.FindFirstOf('=', begin);
139
140 if (eqp == String::NPos)
141 break;
142
143 String label = perfdata.SubStr(begin, eqp - begin);
144 boost::algorithm::trim_left(label);
145
146 if (label.GetLength() > 2 && label[0] == '\'' && label[label.GetLength() - 1] == '\'')
147 label = label.SubStr(1, label.GetLength() - 2);
148
149 size_t multi_index = label.RFind("::");
150
151 if (multi_index != String::NPos)
152 multi_prefix = "";
153
154 size_t spq = perfdata.FindFirstOf(' ', eqp);
155
156 if (spq == String::NPos)
157 spq = perfdata.GetLength();
158
159 String value = perfdata.SubStr(eqp + 1, spq - eqp - 1);
160
161 if (!multi_prefix.IsEmpty())
162 label = multi_prefix + "::" + label;
163
164 String pdv;
165 if (label.FindFirstOf(" ") != String::NPos)
166 pdv = "'" + label + "'=" + value;
167 else
168 pdv = label + "=" + value;
169
170 result.emplace_back(std::move(pdv));
171
172 if (multi_index != String::NPos)
173 multi_prefix = label.SubStr(0, multi_index);
174
175 begin = spq + 1;
176 }
177
178 return new Array(std::move(result));
179}
180
181String PluginUtility::FormatPerfdata(const Array::Ptr& perfdata, bool normalize)
182{

Callers

nothing calls this directly

Calls 5

FindFirstOfMethod · 0.80
SubStrMethod · 0.80
RFindMethod · 0.80
GetLengthMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected