use of org.onebusaway.enterprise.webapp.actions.status.model.IcingaResponse in project onebusaway-application-modules by camsys.
the class StatusProviderImpl method getIcingaStatus.
@Override
public StatusGroup getIcingaStatus() {
StatusGroup group = new StatusGroup();
group.setTitle("System Monitoring");
group.setScope("Monitoring and Infrastructure notices");
group.setSource("Monitoring subsystem -- automated notifications");
IcingaResponse response = null;
// fail if not configured!
String baseUrl = _config.getConfigurationValueAsString("icinga.baseUrl", null);
String command = _config.getConfigurationValueAsString("icinga.command", null);
// be careful -- by default we aren't configured to do anything!
if (baseUrl == null || command == null) {
_log.info("missing required configuration for status group: baseUrl=" + baseUrl + ", command=" + command);
return group;
}
try {
HttpClient client = new HttpClient();
String url = baseUrl + encode(command);
HttpMethod method = new GetMethod(url);
client.executeMethod(method);
InputStream result = method.getResponseBodyAsStream();
ObjectMapper mapper = new ObjectMapper();
response = mapper.readValue(result, IcingaResponse.class);
} catch (IOException e) {
_log.error("Exception getting Icinga data " + e);
group.addItem(exceptionStatus(e));
return group;
}
if (response == null) {
group.addItem(exceptionStatus());
return group;
}
for (IcingaItem bean : response.getResult()) {
StatusItem item = new StatusItem();
item.setDescription(bean.getServiceName());
item.setTitle(bean.getServiceDisplayName());
int state = bean.getServiceCurrentState();
StatusItem.Status status;
if (state == 0) {
status = StatusItem.Status.OK;
} else if (state == 1) {
status = StatusItem.Status.WARNING;
} else {
// 2 (or something even weirder!)
status = StatusItem.Status.ERROR;
}
item.setStatus(status);
group.addItem(item);
}
return group;
}
Aggregations