@Override
  public void call(Stream stream, AlertCondition.CheckResult result) throws AlarmCallbackException {
    final TwilioRestClient twilioClient =
        new TwilioRestClient(
            configuration.getString(CK_ACCOUNT_SID), configuration.getString(CK_AUTH_TOKEN));

    call(stream, result, twilioClient);
  }
  protected TcpTransport(
      final Configuration configuration,
      final Executor bossPool,
      final Executor workerPool,
      final ThroughputCounter throughputCounter,
      final ConnectionCounter connectionCounter,
      final LocalMetricRegistry localRegistry) {
    super(configuration, throughputCounter, localRegistry, bossPool, workerPool, connectionCounter);

    final boolean nulDelimiter = configuration.getBoolean(CK_USE_NULL_DELIMITER);
    this.delimiter = nulDelimiter ? nulDelimiter() : lineDelimiter();
    this.tcpKeepalive = configuration.getBoolean(CK_TCP_KEEPALIVE);
    this.maxFrameLength =
        configuration.getInt(CK_MAX_MESSAGE_SIZE, Config.DEFAULT_MAX_FRAME_LENGTH);
  }
  private void send(
      final TwilioRestClient client, final Stream stream, final AlertCondition.CheckResult result)
      throws TwilioRestException {
    final Account mainAccount = client.getAccount();
    final SmsFactory smsFactory = mainAccount.getSmsFactory();

    final Map<String, String> smsParams =
        ImmutableMap.of(
            "To", configuration.getString(CK_TO_NUMBER),
            "From", configuration.getString(CK_FROM_NUMBER),
            "Body", buildMessage(result, stream));

    final Sms sms = smsFactory.create(smsParams);

    LOG.debug("Sent SMS with status {}: {}", sms.getStatus(), sms.getBody());
  }
  protected String buildDescription(
      Stream stream, AlertCondition.CheckResult checkResult, Configuration configuration) {
    StringBuilder sb = new StringBuilder();

    sb.append(checkResult.getResultDescription());
    sb.append("\n\n");
    sb.append("*Date:* ").append("\n").append(Tools.iso8601().toString()).append("\n\n");
    sb.append("*Stream ID:* ").append("\n").append(stream.getId()).append("\n\n");
    sb.append("*Stream title:* ").append("\n").append(stream.getTitle()).append("\n\n");
    sb.append("*Stream URL:* ")
        .append("\n")
        .append(buildStreamURL(configuration.getString(CK_GRAYLOG_URL), stream))
        .append("\n\n");
    sb.append("*Stream rules:* ").append("\n").append(buildStreamRules(stream)).append("\n\n");
    sb.append("*Alert triggered at:* ")
        .append("\n")
        .append(checkResult.getTriggeredAt())
        .append("\n\n");
    sb.append("*Triggered condition:* ")
        .append("\n")
        .append(checkResult.getTriggeredCondition())
        .append("\n\n");

    return sb.toString();
  }
 @Override
 public void checkConfiguration() throws ConfigurationException {
   for (String key : MANDATORY_CONFIGURATION_KEYS) {
     if (!configuration.stringIsSet(key)) {
       throw new ConfigurationException(key + " is mandatory and must not be empty.");
     }
   }
 }
  @Inject
  public JDBCOutput(@Assisted Stream stream, @Assisted Configuration conf) throws SQLException {
    url = conf.getString("url");
    username = conf.getString("username");
    password = conf.getString("password");
    driver = conf.getString("driver");
    String f = conf.getString("fields");
    if (f != null && !f.trim().equals("")) {
      List<String> l = new ArrayList<String>();
      StringTokenizer tk = new StringTokenizer(f, "\n;, ");
      while (tk.hasMoreTokens()) {
        l.add(tk.nextToken().trim());
      }
      fields = l.toArray(new String[l.size()]);
    }
    logInsertQuery = conf.getString("logInsertQuery");
    logInsertAttributeQuery = conf.getString("logInsertAttributeQuery");

    log.info("Creating JDBC output " + url);

    if (driver != null && !driver.trim().isEmpty()) {
      try {
        Class.forName(driver);
      } catch (Exception e) {
        log.log(
            Level.SEVERE, "Failed to find/register driver (" + driver + "): " + e.getMessage(), e);
        driverFailed = true;
      }
    }

    reconnect();
  }
 @Override
 public Map<String, Object> getAttributes() {
   return Maps.transformEntries(
       configuration.getSource(),
       new Maps.EntryTransformer<String, Object, Object>() {
         @Override
         public Object transformEntry(String key, Object value) {
           if (SENSITIVE_CONFIGURATION_KEYS.contains(key)) {
             return "****";
           }
           return value;
         }
       });
 }
  @Override
  public void doLaunch(final MessageInput input) throws MisfireException {
    reporter =
        Graylog2Reporter.forRegistry(metricRegistry)
            .useSource(configuration.getString(CK_SOURCE))
            .convertDurationsTo(TimeUnit.valueOf(configuration.getString(CK_DURATION_UNIT)))
            .convertRatesTo(TimeUnit.valueOf(configuration.getString(CK_RATE_UNIT)))
            .build(new RawGelfWriter(input));

    scheduledFuture =
        scheduler.schedule(
            new Runnable() {
              @Override
              public void run() {
                if (isThrottled()) {
                  // do not block, but simply skip this iteration
                  log.debug("Skipping metric report this iteration because we are throttled.");
                }
                reporter.report();
              }
            },
            configuration.getInt(CK_REPORT_INTERVAL),
            TimeUnit.valueOf(configuration.getString(CK_REPORT_UNIT)));
  }
  @Override
  public ChannelPipeline getPipeline() throws Exception {
    ChannelBuffer[] delimiter;

    if (config.getBoolean(SyslogTCPInput.CK_USE_NULL_DELIMITER)) {
      delimiter = Delimiters.nulDelimiter();
    } else {
      delimiter = Delimiters.lineDelimiter();
    }

    ChannelPipeline p = Channels.pipeline();
    p.addLast("connection-counter", connectionCounter);
    p.addLast("framer", new DelimiterBasedFrameDecoder(2 * 1024 * 1024, delimiter));
    p.addLast("traffic-counter", throughputCounter);
    p.addLast("handler", new SyslogDispatcher(server, config, sourceInput));
    return p;
  }
  public static void checkConfiguration(Configuration configuration) throws ConfigurationException {
    if (!configuration.stringIsSet(CK_INSTANCE_URL)) {
      throw new ConfigurationException(CK_INSTANCE_URL + " is mandatory and must not be empty.");
    }

    if (configuration.stringIsSet(CK_INSTANCE_URL)
        && !configuration.getString(CK_INSTANCE_URL).equals("null")) {
      try {
        final URI jiraUri = new URI(configuration.getString(CK_INSTANCE_URL));
        if (!"http".equals(jiraUri.getScheme()) && !"https".equals(jiraUri.getScheme())) {
          throw new ConfigurationException(CK_INSTANCE_URL + " must be a valid HTTP or HTTPS URL.");
        }
      } catch (URISyntaxException e) {
        throw new ConfigurationException("Couldn't parse " + CK_INSTANCE_URL + " correctly.", e);
      }
    }

    if (!configuration.stringIsSet(CK_USERNAME)) {
      throw new ConfigurationException(CK_USERNAME + " is mandatory and must not be empty.");
    }

    if (!configuration.stringIsSet(CK_PASSWORD)) {
      throw new ConfigurationException(CK_PASSWORD + " is mandatory and must not be empty.");
    }

    if (!configuration.stringIsSet(CK_PROJECT_KEY)) {
      throw new ConfigurationException(CK_PROJECT_KEY + " is mandatory and must not be empty.");
    }

    if (!configuration.stringIsSet(CK_ISSUE_TYPE)) {
      throw new ConfigurationException(CK_ISSUE_TYPE + " is mandatory and must not be empty.");
    }

    if (configuration.stringIsSet(CK_GRAYLOG_URL)
        && !configuration.getString(CK_GRAYLOG_URL).equals("null")) {
      try {
        final URI graylogUri = new URI(configuration.getString(CK_GRAYLOG_URL));
        if (!"http".equals(graylogUri.getScheme()) && !"https".equals(graylogUri.getScheme())) {
          throw new ConfigurationException(CK_GRAYLOG_URL + " must be a valid HTTP or HTTPS URL.");
        }
      } catch (URISyntaxException e) {
        throw new ConfigurationException("Couldn't parse " + CK_GRAYLOG_URL + " correctly.", e);
      }
    }
  }