logger.info(results.size() + " check results succesfully sent to Nagios");
}
private CheckSubmissionResult parseResponseXML(String xml) throws ParserConfigurationException, SAXException, IOException {
final CheckSubmissionResult res = new CheckSubmissionResult();
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
DefaultHandler handler = new DefaultHandler() {
boolean statusTag = false;
boolean messageTag = false;
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (qName.equalsIgnoreCase("status")) {
statusTag = true;
}
if (qName.equalsIgnoreCase("message")) {
messageTag = true;
}
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (statusTag) {
res.setStatus(new String(ch, start, length));
statusTag = false;
}
if (messageTag) {
res.setMessage(new String(ch, start, length));
messageTag = false;
}
}
};
saxParser.parse(new InputSource(new StringReader(xml)), handler);
if (res.getStatus() == null || res.getMessage() == null) {
throw new SAXException("Failed to get response status and message");
}
return res;
}