Search in sources :

Example 6 with StatusItem

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);
        }
    }
}
Also used : StatusItem(org.onebusaway.enterprise.webapp.actions.status.model.StatusItem) SyndContent(com.rometools.rome.feed.synd.SyndContent) StatusGroup(org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl)

Example 7 with StatusItem

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;
}
Also used : IcingaItem(org.onebusaway.enterprise.webapp.actions.status.model.IcingaItem) InputStream(java.io.InputStream) IOException(java.io.IOException) IcingaResponse(org.onebusaway.enterprise.webapp.actions.status.model.IcingaResponse) StatusItem(org.onebusaway.enterprise.webapp.actions.status.model.StatusItem) StatusGroup(org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpMethod(org.apache.commons.httpclient.HttpMethod) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 8 with StatusItem

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;
}
Also used : AffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean.AffectsBean) StatusItem(org.onebusaway.enterprise.webapp.actions.status.model.StatusItem) StatusGroup(org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup) SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean) AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 9 with StatusItem

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;
}
Also used : StatusItem(org.onebusaway.enterprise.webapp.actions.status.model.StatusItem)

Example 10 with StatusItem

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;
}
Also used : StatusItem(org.onebusaway.enterprise.webapp.actions.status.model.StatusItem) StatusGroup(org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup) InputStream(java.io.InputStream) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) AgencyMetadata(org.onebusaway.agency_metadata.model.AgencyMetadata) HttpMethod(org.apache.commons.httpclient.HttpMethod) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

StatusItem (org.onebusaway.enterprise.webapp.actions.status.model.StatusItem)11 StatusGroup (org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup)10 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)6 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)6 SyndContent (com.rometools.rome.feed.synd.SyndContent)4 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)4 ArrayList (java.util.ArrayList)4 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HttpClient (org.apache.commons.httpclient.HttpClient)2 HttpMethod (org.apache.commons.httpclient.HttpMethod)2 GetMethod (org.apache.commons.httpclient.methods.GetMethod)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 JsonNode (org.codehaus.jackson.JsonNode)1 AgencyMetadata (org.onebusaway.agency_metadata.model.AgencyMetadata)1 IcingaItem (org.onebusaway.enterprise.webapp.actions.status.model.IcingaItem)1 IcingaResponse (org.onebusaway.enterprise.webapp.actions.status.model.IcingaResponse)1 AgencyWithCoverageBean (org.onebusaway.transit_data.model.AgencyWithCoverageBean)1