Examples of AlertCriteria


Examples of org.rhq.core.domain.criteria.AlertCriteria

            return result.size();
        }

        @Override
        protected AlertCriteria getFetchCriteria(DSRequest request) {
            AlertCriteria criteria = new AlertCriteria();
           
            // name filter
            String currentSetting = this.configuration.getSimpleValue(Constant.ALERT_NAME, "");
            criteria.addFilterName(currentSetting);

            // result count
            currentSetting = this.configuration.getSimpleValue(Constant.RESULT_COUNT,
                Constant.RESULT_COUNT_DEFAULT);

            // We have to set a PageControl override here, or RPCDataSource will apply default paging based on the
            // request. But, once setting a paging override the CriteriaQueryGenerator will use it for
            // paging *and* sorting, so we need to also ensure our desired sorting is included in the override. So,
            // to get the most recent alerts, apply a descending ordering on create time.
            int pageNumber = 0;
            int pageSize = Integer.valueOf(currentSetting);
            OrderingField orderingField = new OrderingField("ctime", PageOrdering.DESC);
            criteria.setPageControl(new PageControl(pageNumber, pageSize, orderingField));

            // filter priority
            currentSetting = this.configuration
                .getSimpleValue(Constant.ALERT_PRIORITY, Constant.ALERT_PRIORITY_DEFAULT);
            String[] parsedValues = currentSetting.trim().split(",");
            if (!(currentSetting.trim().isEmpty() || parsedValues.length == AlertPriority.values().length)) {
                AlertPriority[] filterPriorities = new AlertPriority[parsedValues.length];
                int indx = 0;
                for (String priority : parsedValues) {
                    AlertPriority p = AlertPriority.valueOf(priority);
                    filterPriorities[indx++] = p;
                }
                criteria.addFilterPriorities(filterPriorities);
            }

            //result timeframe if enabled
            PropertySimple property = configuration.getSimple(Constant.METRIC_RANGE_ENABLE);
            if (null != property && Boolean.valueOf(property.getBooleanValue())) {//then proceed setting

                boolean isAdvanced = Boolean.valueOf(configuration.getSimpleValue(Constant.METRIC_RANGE_BEGIN_END_FLAG,
                    Constant.METRIC_RANGE_BEGIN_END_FLAG_DEFAULT));
                if (isAdvanced) {
                    //Advanced time settings
                    currentSetting = configuration.getSimpleValue(Constant.METRIC_RANGE, Constant.METRIC_RANGE_DEFAULT);
                    String[] range = currentSetting.split(",");
                    if (range.length == 2) {
                        criteria.addFilterStartTime(Long.valueOf(range[0]));
                        criteria.addFilterEndTime(Long.valueOf(range[1]));
                    }
                } else {
                    //Simple time settings
                    property = configuration.getSimple(Constant.METRIC_RANGE_LASTN);
                    if (property != null) {
                        Integer lastN = Integer.valueOf(configuration.getSimpleValue(Constant.METRIC_RANGE_LASTN,
                            Constant.METRIC_RANGE_LASTN_DEFAULT));
                        Integer units = Integer.valueOf(configuration.getSimpleValue(Constant.METRIC_RANGE_UNIT,
                            Constant.METRIC_RANGE_UNIT_DEFAULT));
                        ArrayList<Long> beginEnd = MeasurementUtility.calculateTimeFrame(lastN, units);
                        criteria.addFilterStartTime(Long.valueOf(beginEnd.get(0)));
                        criteria.addFilterEndTime(Long.valueOf(beginEnd.get(1)));
                    }
                }
            }
            String filters = this.configuration.getSimpleValue(Constant.ALERT_FILTER, Constant.ALERT_FILTER_DEFAULT);
            if(filters != null && filters.length() > 0) {
                String[] filterArray = filters.trim().split(",");
                for(String filter : filterArray) {
                    if(filter.equals(AlertFilter.ACKNOWLEDGED_STATUS.name())) {
                        criteria.addFilterUnacknowledgedOnly(true);
                    } else if(filter.equals(AlertFilter.RECOVERY_TYPE.name())) {
                        criteria.addFilterRecoveryIds(Integer.valueOf(0)); // Filter all alerts with recoveryId = 0 (
                    } else if(filter.equals(AlertFilter.RECOVERED_STATUS.name())) {
                        criteria.addFilterRecovered(true);
                    }
                }
            }

            // add any context related filters
            switch (getEntityContext().type) {
            case Resource:
                criteria.addFilterResourceIds(getEntityContext().getResourceId());
                break;

            case ResourceGroup:
                criteria.addFilterResourceGroupIds(getEntityContext().getGroupId());
                break;
            default:
                // no default
                break;
            }

            criteria.fetchAlertDefinition(true);
            criteria.fetchRecoveryAlertDefinition(true);
            criteria.fetchConditionLogs(true);

            return criteria;
        }
View Full Code Here

Examples of org.rhq.core.domain.criteria.AlertCriteria

        assert alerts.size() == 1 : "1 alert should have fired: " + alerts;
    }

    private PageList<Alert> getAlerts(int resourceId) {
        AlertManagerLocal alertManager = LookupUtil.getAlertManager();
        AlertCriteria alertCriteria = new AlertCriteria();
        alertCriteria.addFilterResourceIds(resourceId);
        alertCriteria.fetchConditionLogs(true);
        return alertManager.findAlertsByCriteria(getOverlord(), alertCriteria);
    }
View Full Code Here

Examples of org.rhq.core.domain.criteria.AlertCriteria

        // wait for our JMS messages to process and see if we get any alerts
        Thread.sleep(3000);

        //check that the alert fired when going from DOWN to UP
        AlertCriteria aCrit = new AlertCriteria();
        aCrit.addFilterResourceIds(newResource.getId());

        List<Alert> alerts = LookupUtil.getAlertManager().findAlertsByCriteria(getOverlord(), aCrit);
        assertEquals("Unexpected number of alerts on the resource.", 1, alerts.size());
    }
View Full Code Here

Examples of org.rhq.core.domain.criteria.AlertCriteria

            AlertsPortletPreferences prefs = user.getWebPreferences().getAlertsPortletPreferences();

            PageControl pageControl = new PageControl(0, prefs.count);

            AlertCriteria criteria = new AlertCriteria();
            criteria.addFilterPriorities(AlertPriority.getByLegacyIndex(prefs.priority));
            criteria.addFilterStartTime(prefs.timeRange);
            criteria.addFilterResourceIds(("all".equals(prefs.displayAll) ? null : ArrayUtils.wrapInArray(prefs
                .asArray())));
            criteria.setPageControl(pageControl);

            PageList<Alert> alerts = alertManager.findAlertsByCriteria(user.getSubject(), criteria);

            if ((alerts != null) && (alerts.size() > 0)) {
                for (Alert alert : alerts) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.