@Test public void testParsePerfData() throws Exception { List<NagiosPerfData> perfData = NagiosPerfData.parsePerfData("load1=0.490;15.000;30.000;0; load5=0.760;10.000;25.000;0; load15=0.850;5.000;20.000;0;"); assertThat(perfData.size(), is(equalTo(3))); }
public static List<NagiosPerfData> parsePerfData(String perfData) throws IOException { List<NagiosPerfData> perfs = new LinkedList<NagiosPerfData>(); CharBuffer buffer = CharBuffer.wrap(perfData.toCharArray()); while (buffer.hasRemaining()) { skipWhitespace(buffer); String label = readLabel(buffer); String valueString = readValue(buffer); String[] values = valueString.split(";"); String valueUOM = values.length > 0 ? values[0] : null; String warn = values.length > 1 ? values[1] : null; String crit = values.length > 2 ? values[2] : null; String min = values.length > 3 ? values[3] : null; String max = values.length > 4 ? values[4] : null; Matcher matcher = VALUE_UOM_PATTERN.matcher(valueUOM); if (matcher.matches()) { String value = matcher.group(1); String unit = matcher.group(2); perfs.add(new NagiosPerfData(label, value, unit, warn, crit, min, max)); } else { throw new IOException("Malformed perfdata value: " + valueUOM); } } return perfs; }
NagiosPerfData { public static List<NagiosPerfData> parsePerfData(String perfData) throws IOException { List<NagiosPerfData> perfs = new LinkedList<NagiosPerfData>(); CharBuffer buffer = CharBuffer.wrap(perfData.toCharArray()); while (buffer.hasRemaining()) { skipWhitespace(buffer); String label = readLabel(buffer); String valueString = readValue(buffer); String[] values = valueString.split(";"); String valueUOM = values.length > 0 ? values[0] : null; String warn = values.length > 1 ? values[1] : null; String crit = values.length > 2 ? values[2] : null; String min = values.length > 3 ? values[3] : null; String max = values.length > 4 ? values[4] : null; Matcher matcher = VALUE_UOM_PATTERN.matcher(valueUOM); if (matcher.matches()) { String value = matcher.group(1); String unit = matcher.group(2); perfs.add(new NagiosPerfData(label, value, unit, warn, crit, min, max)); } else { throw new IOException("Malformed perfdata value: " + valueUOM); } } return perfs; } }
NagiosPerfData { public static List<NagiosPerfData> parsePerfData(String perfData) throws IOException { List<NagiosPerfData> perfs = new LinkedList<NagiosPerfData>(); CharBuffer buffer = CharBuffer.wrap(perfData.toCharArray()); while (buffer.hasRemaining()) { skipWhitespace(buffer); String label = readLabel(buffer); String valueString = readValue(buffer); String[] values = valueString.split(";"); String valueUOM = values.length > 0 ? values[0] : null; String warn = values.length > 1 ? values[1] : null; String crit = values.length > 2 ? values[2] : null; String min = values.length > 3 ? values[3] : null; String max = values.length > 4 ? values[4] : null; Matcher matcher = VALUE_UOM_PATTERN.matcher(valueUOM); if (matcher.matches()) { String value = matcher.group(1); String unit = matcher.group(2); perfs.add(new NagiosPerfData(label, value, unit, warn, crit, min, max)); } else { throw new IOException("Malformed perfdata value: " + valueUOM); } } return perfs; } NagiosPerfData();  NagiosPerfData(String label, String value, String unit, String warning, String critical, String min, String max); }
NagiosPerfData { public static List<NagiosPerfData> parsePerfData(String perfData) throws IOException { List<NagiosPerfData> perfs = new LinkedList<NagiosPerfData>(); CharBuffer buffer = CharBuffer.wrap(perfData.toCharArray()); while (buffer.hasRemaining()) { skipWhitespace(buffer); String label = readLabel(buffer); String valueString = readValue(buffer); String[] values = valueString.split(";"); String valueUOM = values.length > 0 ? values[0] : null; String warn = values.length > 1 ? values[1] : null; String crit = values.length > 2 ? values[2] : null; String min = values.length > 3 ? values[3] : null; String max = values.length > 4 ? values[4] : null; Matcher matcher = VALUE_UOM_PATTERN.matcher(valueUOM); if (matcher.matches()) { String value = matcher.group(1); String unit = matcher.group(2); perfs.add(new NagiosPerfData(label, value, unit, warn, crit, min, max)); } else { throw new IOException("Malformed perfdata value: " + valueUOM); } } return perfs; } NagiosPerfData();  NagiosPerfData(String label, String value, String unit, String warning, String critical, String min, String max); String getLabel(); void setLabel(String label); String getValue(); void setValue(String value); String getUnit(); void setUnit(String unit); String getWarning(); void setWarning(String warning); String getCritical(); void setCritical(String critical); String getMin(); void setMin(String min); String getMax(); void setMax(String max); String toString(); Reading toReading(); static List<NagiosPerfData> parsePerfData(String perfData); static void skipWhitespace(CharBuffer buffer); static String readValue(CharBuffer buffer); static String readLabel(CharBuffer buffer); }
NagiosPerfData { public static List<NagiosPerfData> parsePerfData(String perfData) throws IOException { List<NagiosPerfData> perfs = new LinkedList<NagiosPerfData>(); CharBuffer buffer = CharBuffer.wrap(perfData.toCharArray()); while (buffer.hasRemaining()) { skipWhitespace(buffer); String label = readLabel(buffer); String valueString = readValue(buffer); String[] values = valueString.split(";"); String valueUOM = values.length > 0 ? values[0] : null; String warn = values.length > 1 ? values[1] : null; String crit = values.length > 2 ? values[2] : null; String min = values.length > 3 ? values[3] : null; String max = values.length > 4 ? values[4] : null; Matcher matcher = VALUE_UOM_PATTERN.matcher(valueUOM); if (matcher.matches()) { String value = matcher.group(1); String unit = matcher.group(2); perfs.add(new NagiosPerfData(label, value, unit, warn, crit, min, max)); } else { throw new IOException("Malformed perfdata value: " + valueUOM); } } return perfs; } NagiosPerfData();  NagiosPerfData(String label, String value, String unit, String warning, String critical, String min, String max); String getLabel(); void setLabel(String label); String getValue(); void setValue(String value); String getUnit(); void setUnit(String unit); String getWarning(); void setWarning(String warning); String getCritical(); void setCritical(String critical); String getMin(); void setMin(String min); String getMax(); void setMax(String max); String toString(); Reading toReading(); static List<NagiosPerfData> parsePerfData(String perfData); static void skipWhitespace(CharBuffer buffer); static String readValue(CharBuffer buffer); static String readLabel(CharBuffer buffer);  }