Exemple #1
0
  private void processRule(Rule rule) {
    String id = rule.getId();
    int index1 = id.indexOf(":");
    int index2 = id.indexOf(":", index1 + 1);
    String conditions = id.substring(0, index1);
    String type = id.substring(index1 + 1, index2);
    String name = id.substring(index2 + 1);
    int command = Integer.valueOf(conditions.split(";")[0]);
    Pair<Integer, List<Condition>> pair = queryCheckMinuteAndConditions(rule.getConfigs());
    double[] datas = fetchDatas(conditions, type, pair.getKey());

    if (datas != null && datas.length > 0) {
      List<Condition> checkedConditions = pair.getValue();
      List<AlertResultEntity> alertResults =
          m_dataChecker.checkDataForApp(datas, checkedConditions);

      for (AlertResultEntity alertResult : alertResults) {
        Map<String, Object> par = new HashMap<String, Object>();
        par.put("name", name);
        AlertEntity entity = new AlertEntity();

        entity
            .setDate(alertResult.getAlertTime())
            .setContent(alertResult.getContent())
            .setLevel(alertResult.getAlertLevel());
        entity
            .setMetric(queryType(type))
            .setType(getName())
            .setGroup(queryCommand(command))
            .setParas(par);
        m_sendManager.addAlert(entity);
      }
    }
  }
Exemple #2
0
  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);
  }
Exemple #3
0
  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);
  }