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

Method FormatPerfdata

lib/icinga/pluginutility.cpp:181–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179}
180
181String PluginUtility::FormatPerfdata(const Array::Ptr& perfdata, bool normalize)
182{
183 if (!perfdata)
184 return "";
185
186 std::ostringstream result;
187
188 ObjectLock olock(perfdata);
189
190 bool first = true;
191 for (const Value& pdv : perfdata) {
192 if (!first)
193 result << " ";
194 else
195 first = false;
196
197 if (pdv.IsObjectType<PerfdataValue>()) {
198 result << static_cast<PerfdataValue::Ptr>(pdv)->Format();
199 } else if (normalize) {
200 PerfdataValue::Ptr normalized;
201
202 try {
203 normalized = PerfdataValue::Parse(pdv);
204 } catch (const std::invalid_argument& ex) {
205 Log(LogDebug, "PerfdataValue") << ex.what();
206 }
207
208 if (normalized) {
209 result << normalized->Format();
210 } else {
211 result << pdv;
212 }
213 } else {
214 result << pdv;
215 }
216 }
217
218 return result.str();
219}

Callers

nothing calls this directly

Calls 3

LogClass · 0.85
FormatMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected