public boolean deleteRule(BaseRuleConfigManager manager, String key) { try { String xmlContent = manager.deleteRule(key); return manager.insert(xmlContent); } catch (Exception ex) { return false; } }
public boolean addSubmitRule( BaseRuleConfigManager manager, String id, String metrics, String configs) { try { String xmlContent = manager.updateRule(id, metrics, configs); return manager.insert(xmlContent); } catch (Exception ex) { Cat.logError(ex); return false; } }
public void generateRuleConfigContent(String key, BaseRuleConfigManager manager, Model model) { String configsStr = ""; String ruleId = ""; if (!StringUtils.isEmpty(key)) { Rule rule = manager.queryRule(key); if (rule != null) { ruleId = rule.getId(); configsStr = new DefaultJsonBuilder(true).buildArray(rule.getConfigs()); String configHeader = new DefaultJsonBuilder(true).buildArray(rule.getMetricItems()); model.setConfigHeader(configHeader); } } String content = m_ruleDecorator.generateConfigsHtml(configsStr); model.setContent(content); model.setId(ruleId); }
public void generateRuleItemList(BaseRuleConfigManager manager, Model model) { Collection<Rule> rules = manager.getMonitorRules().getRules().values(); List<RuleItem> ruleItems = new ArrayList<RuleItem>(); for (Rule rule : rules) { String id = rule.getId(); List<MetricItem> items = rule.getMetricItems(); if (items.size() > 0) { MetricItem item = items.get(0); String productText = item.getProductText(); String metricText = item.getMetricItemText(); RuleItem ruleItem = new RuleItem(id, productText, metricText); ruleItem.setMonitorCount(item.isMonitorCount()); ruleItem.setMonitorAvg(item.isMonitorAvg()); ruleItem.setMonitorSum(item.isMonitorSum()); ruleItems.add(ruleItem); } } model.setRuleItems(ruleItems); }
protected AlertResultEntity computeAlertInfo( int minute, String product, String metricKey, MetricType type) { double[] value = null; double[] baseline = null; List<Config> configs = m_ruleConfigManager.queryConfigs(product, metricKey, type); Pair<Integer, List<Condition>> resultPair = queryCheckMinuteAndConditions(configs); int maxMinute = resultPair.getKey(); List<Condition> conditions = resultPair.getValue(); if (minute >= maxMinute - 1) { MetricReport report = fetchMetricReport(product, ModelPeriod.CURRENT); if (report != null) { int start = minute + 1 - maxMinute; int end = minute; value = queryRealData(start, end, metricKey, report, type); baseline = queryBaseLine( start, end, metricKey, new Date(ModelPeriod.CURRENT.getStartTime()), type); return m_dataChecker.checkData(value, baseline, conditions); } } else if (minute < 0) { MetricReport lastReport = fetchMetricReport(product, ModelPeriod.LAST); if (lastReport != null) { int start = 60 + minute + 1 - (maxMinute); int end = 60 + minute; value = queryRealData(start, end, metricKey, lastReport, type); baseline = queryBaseLine(start, end, metricKey, new Date(ModelPeriod.LAST.getStartTime()), type); return m_dataChecker.checkData(value, baseline, conditions); } } else { MetricReport currentReport = fetchMetricReport(product, ModelPeriod.CURRENT); MetricReport lastReport = fetchMetricReport(product, ModelPeriod.LAST); if (currentReport != null && lastReport != null) { int currentStart = 0, currentEnd = minute; double[] currentValue = queryRealData(currentStart, currentEnd, metricKey, currentReport, type); double[] currentBaseline = queryBaseLine( currentStart, currentEnd, metricKey, new Date(ModelPeriod.CURRENT.getStartTime()), type); int lastStart = 60 + 1 - (maxMinute - minute); int lastEnd = 59; double[] lastValue = queryRealData(lastStart, lastEnd, metricKey, lastReport, type); double[] lastBaseline = queryBaseLine( lastStart, lastEnd, metricKey, new Date(ModelPeriod.LAST.getStartTime()), type); value = mergerArray(lastValue, currentValue); baseline = mergerArray(lastBaseline, currentBaseline); return m_dataChecker.checkData(value, baseline, conditions); } } return null; }