Пример #1
0
  private void showAlarms(Long minDuration, int minutes) {
    final DateTime now = new DateTime();
    final DateTime start = now.minusMinutes(minutes);
    final List<PollResult> alarms =
        pollService.listAlarms(start.toDate(), now.toDate(), minDuration);
    final List<PollResult> problems = pollService.listProblems(start.toDate(), now.toDate());

    System.out.println("\nListing events over last " + minutes + " minutes");
    System.out.println(" ALARMS (duration > " + minDuration + ")");
    TextTable table =
        new TextTable(
            "  ",
            TextTable.ALIGN.LEFT,
            TextTable.ALIGN.LEFT,
            TextTable.ALIGN.LEFT,
            TextTable.ALIGN.RIGHT,
            TextTable.ALIGN.CENTER);
    if (!alarms.isEmpty()) {
      for (PollResult pollResult : alarms) {
        table.add(format2(pollResult));
      }
      System.out.println(table.toString());
    } else {
      System.out.println("  No alarms");
    }
    table.clear();
    System.out.println(" PROBLEMS (non-successful events)");
    if (!problems.isEmpty()) {
      for (PollResult pollResult : problems) {
        table.add(format2(pollResult));
      }
      System.out.println(table.toString());
    } else {
      System.out.println("  No problems");
    }
  }
Пример #2
0
  public void process(String[] params) {
    CommandLine cmd;

    try {
      cmd = parser.parse(options, params);
    } catch (org.apache.commons.cli.ParseException ex) {
      throw new RuntimeException(ex);
    }

    if (cmd.hasOption(LIST)) {
      list();
    }

    if (cmd.hasOption(DELETE)) {
      delete(cmd.getOptionValue(DELETE));
    }

    if (cmd.hasOption(START)) {
      long timeout = 10000;
      long wait = 120000;
      if (cmd.hasOption(WAIT)) {
        wait = Long.parseLong(cmd.getOptionValue(WAIT));
      }
      if (cmd.hasOption(TIMEOUT)) {
        timeout = Long.parseLong(cmd.getOptionValue(TIMEOUT));
      }
      pollService.start(wait, timeout);
    }

    if (cmd.hasOption(ALARMS)) {
      Long threshold = 20L;
      Integer minutes = 20;

      if (cmd.hasOption(THRESHOLD)) {
        threshold = Long.parseLong(cmd.getOptionValue(THRESHOLD));
      }
      if (cmd.hasOption(PERIOD)) {
        minutes = Integer.parseInt(cmd.getOptionValue(PERIOD));
      }

      showAlarms(threshold, minutes);
    }
  }