| 179 | } |
| 180 | |
| 181 | String 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 | } |