use of org.onebusaway.enterprise.webapp.actions.status.model.StatusItem in project onebusaway-application-modules by camsys.
the class StatusUpdateAction method setIcingaAlerts.
private void setIcingaAlerts(List<SyndEntry> entries, String baseUrl) {
// Add Icinga Alerts
SyndEntry icingaEntry = new SyndEntryImpl();
SyndContent icingaContent = new SyndContentImpl();
icingaEntry.setTitle("System Monitoring");
icingaEntry.setLink(baseUrl + "/rss/monitoring-alerts-update");
entries.add(icingaEntry);
StatusGroup icingaGroup = _statusProvider.getIcingaStatus();
StatusGroup icingaProblems = new StatusGroup();
icingaProblems.setTitle(icingaGroup.getTitle());
// Only report items where status is not "OK"
for (StatusItem icingaItem : icingaGroup.getItems()) {
if (icingaItem.getStatus() != StatusItem.Status.OK) {
icingaProblems.addItem(icingaItem);
}
}
if (icingaProblems.getItems().size() == 0) {
icingaEntry = new SyndEntryImpl();
icingaEntry.setTitle("All systems operational");
entries.add(icingaEntry);
} else {
for (StatusItem icingaItem : icingaProblems.getItems()) {
icingaEntry = new SyndEntryImpl();
icingaEntry.setTitle(icingaItem.getTitle());
icingaContent = new SyndContentImpl();
icingaContent.setValue(icingaItem.getStatus() + ": " + icingaItem.getDescription());
icingaEntry.setDescription(icingaContent);
entries.add(icingaEntry);
}
}
}
use of org.onebusaway.enterprise.webapp.actions.status.model.StatusItem 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;
}
use of org.onebusaway.enterprise.webapp.actions.status.model.StatusItem in project onebusaway-application-modules by camsys.
the class StatusProviderImpl method getAgencyServiceAlertStatus.
@Override
public StatusGroup getAgencyServiceAlertStatus() {
StatusGroup group = new StatusGroup();
group.setTitle("Agency Advisories");
group.setScope("Schedule and real-time availability at the agency level");
group.setSource("Sound Transit administrators -- manual entry");
List<AgencyWithCoverageBean> agencies = _transitDataService.getAgenciesWithCoverage();
for (AgencyWithCoverageBean agency : agencies) {
String agencyId = agency.getAgency().getId();
String agencyName = agency.getAgency().getName();
// Use query to limit to agency and no other parameters
SituationQueryBean query = new SituationQueryBean();
AffectsBean ab = new AffectsBean();
ab.setAgencyId(agencyId);
query.setAffects(Collections.singletonList(ab));
ListBean<ServiceAlertBean> alerts = _transitDataService.getServiceAlerts(query);
List<ServiceAlertBean> beans = filterByTime(alerts.getList(), System.currentTimeMillis());
for (ServiceAlertBean bean : beans) {
StatusItem item = new StatusItem();
item.setDescription(bean.getDescriptions().get(0).getValue());
item.setTitle(agencyName + ": " + bean.getSummaries().get(0).getValue());
item.setStatus(StatusItem.Status.ALERT);
group.addItem(item);
}
}
return group;
}
use of org.onebusaway.enterprise.webapp.actions.status.model.StatusItem in project onebusaway-application-modules by camsys.
the class StatusProviderImpl method exceptionStatus.
private static StatusItem exceptionStatus(Exception e) {
StatusItem item = new StatusItem();
item.setStatus(StatusItem.Status.WARNING);
item.setTitle("Unable to load status group.");
if (e != null) {
item.setDescription(e.toString());
}
return item;
}
use of org.onebusaway.enterprise.webapp.actions.status.model.StatusItem in project onebusaway-application-modules by camsys.
the class StatusProviderImpl method getAgencyMetadataStatus.
@Override
public StatusGroup getAgencyMetadataStatus() {
StatusGroup group = new StatusGroup();
group.setTitle("General Notices");
group.setScope("Informational updates about holiday and schedule changes");
group.setSource("Agency Providers -- manual entry");
AgencyMetadata[] response = new AgencyMetadata[0];
String api = _config.getConfigurationValueAsString("status.obaApi", "http://localhost:8080/onebusaway-api-webapp/");
String endpoint = _config.getConfigurationValueAsString("status.obaApiAgencyMetadata", "api/where/agency-metadata/list.json");
String apikey = _config.getConfigurationValueAsString("display.obaApiKey", "OBAKEY");
String url = api + endpoint + "?key=" + apikey;
try {
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(url);
client.executeMethod(method);
InputStream result = method.getResponseBodyAsStream();
ObjectMapper mapper = new ObjectMapper();
JsonNode tree = mapper.readTree(result);
JsonNode value = tree.findValue("data");
response = mapper.readValue(value, AgencyMetadata[].class);
} catch (IOException e) {
_log.error("Exception getting AgencyMetadata" + e);
group.addItem(exceptionStatus(e));
return group;
}
if (response == null) {
group.addItem(exceptionStatus());
return group;
}
for (AgencyMetadata bean : response) {
if (!StringUtils.isEmpty(bean.getAgencyMessage())) {
StatusItem item = new StatusItem();
item.setTitle(bean.getName() + ": " + bean.getAgencyMessage());
item.setStatus(StatusItem.Status.INFO);
group.addItem(item);
}
}
return group;
}
Aggregations