Esempio n. 1
0
  @Override
  public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) {

    try {
      VelocityContext context = createVelocityContext(check, subscription, alerts);

      StringWriter w = new StringWriter();
      Velocity.evaluate(context, w, "EmailNotificationService", getTemplateAsString());

      Email email =
          new Email()
              .withTo(subscription.getTarget())
              .withFrom(seyrenConfig.getFromEmail())
              .withSubject(createSubject(check))
              .withMessage(w.getBuffer().toString());

      mailSender.send(createMimeMessage(email));

    } catch (Exception e) {
      throw new NotificationFailedException(
          "Failed to send notification to "
              + subscription.getTarget()
              + " from "
              + seyrenConfig.getFromEmail(),
          e);
    }
  }
Esempio n. 2
0
  @Inject
  public SeyrenMailSender(SeyrenConfig seyrenConfig) {

    int port = seyrenConfig.getSmtpPort();
    String host = seyrenConfig.getSmtpHost();
    String username = seyrenConfig.getSmtpUsername();
    String password = seyrenConfig.getSmtpPassword();
    String protocol = seyrenConfig.getSmtpProtocol();

    setPort(port);
    setHost(host);

    Properties props = new Properties();
    if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) {
      props.setProperty("mail.smtp.auth", "true");
      setUsername(username);
      setPassword(password);
    }

    if (getPort() == 587) {
      props.put("mail.smtp.starttls.enable", "true");
    }

    if (props.size() > 0) {
      setJavaMailProperties(props);
    }

    setProtocol(protocol);

    LOGGER.info("{}:{}@{}", username, password, host);
  }
Esempio n. 3
0
 private VelocityContext createVelocityContext(
     Check check, Subscription subscription, List<Alert> alerts) {
   VelocityContext result = new VelocityContext();
   result.put("CHECK", check);
   result.put("ALERTS", alerts);
   result.put("SEYREN_URL", seyrenConfig.getBaseUrl());
   return result;
 }
 private Map<String, String> details(Check check, List<Alert> alerts)
     throws JsonProcessingException {
   ObjectMapper mapper = new ObjectMapper();
   mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
   mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
   mapper.setPropertyNamingStrategy(new PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy());
   return ImmutableMap.<String, String>builder()
       .put("CHECK", mapper.writeValueAsString(check))
       .put("STATE", check.getState().name())
       .put("ALERTS", mapper.writeValueAsString(alerts))
       .put("SEYREN_URL", seyrenConfig.getBaseUrl())
       .build();
 }
Esempio n. 5
0
 @Inject
 public MongoStore(SeyrenConfig seyrenConfig) {
   try {
     String uri = seyrenConfig.getMongoUrl();
     MongoURI mongoUri = new MongoURI(uri);
     DB mongo = mongoUri.connectDB();
     if (mongoUri.getUsername() != null) {
       mongo.authenticate(mongoUri.getUsername(), mongoUri.getPassword());
     }
     this.mongo = mongo;
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
 @Override
 public void sendNotification(Check check, Subscription subscription, List<Alert> alerts)
     throws NotificationFailedException {
   LOGGER.info("Script Location: {}", seyrenConfig.getScriptPath());
   ProcessBuilder pb =
       new ProcessBuilder(
           seyrenConfig.getScriptType(),
           seyrenConfig.getScriptPath(),
           subscription.getTarget(),
           new Gson().toJson(check));
   try {
     LOGGER.info("Script Start");
     Process p = pb.start();
     BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
     String line;
     while ((line = reader.readLine()) != null) {
       LOGGER.info(line);
     }
     LOGGER.info("Script End");
   } catch (IOException e) {
     LOGGER.info("Script could not be sent: {}", e.getMessage());
     throw new NotificationFailedException("Could not send message through the script");
   }
 }
Esempio n. 7
0
 @Test
 public void defaultGraphiteTrustStoreIsCorrect() {
   assertThat(config.getGraphiteTrustStore(), is(""));
 }
Esempio n. 8
0
 @Test
 public void defaultGraphiteKeyStorePasswordIsCorrect() {
   assertThat(config.getGraphiteKeyStorePassword(), is(""));
 }
Esempio n. 9
0
 @Test
 public void defaultGraphitePathIsCorrect() {
   assertThat(config.getGraphitePath(), is(""));
 }
Esempio n. 10
0
 @Test
 public void defaultHipChatUsernameIsCorrect() {
   assertThat(config.getHipChatUsername(), is("Seyren Alert"));
 }
Esempio n. 11
0
 @Test
 public void defaultSmtpPortIsCorrect() {
   assertThat(config.getSmtpPort(), is(25));
 }
Esempio n. 12
0
 @Test
 public void defaultMongoUrlIsCorrect() {
   assertThat(config.getMongoUrl(), is("mongodb://localhost:27017/seyren"));
 }
Esempio n. 13
0
 @Test
 public void defaultSmtpPasswordIsCorrect() {
   assertThat(config.getSmtpPassword(), is(""));
 }
Esempio n. 14
0
 @Test
 public void defaultFlowdockEmojisIsCorrect() {
   assertThat(config.getFlowdockEmojis(), is(""));
 }
Esempio n. 15
0
 @Test
 public void defaultBaseUrlIsCorrect() {
   if (config.isBaseUrlSetToDefault()) {
     assertThat(config.getBaseUrl(), is("http://localhost:8080/seyren"));
   }
 }
Esempio n. 16
0
 @Test
 public void defaultFlowdockExternalUsernameIsCorrect() {
   assertThat(config.getFlowdockExternalUsername(), is("Seyren"));
 }
Esempio n. 17
0
 @Test
 public void defaultHubotUrlIsCorrect() {
   assertThat(config.getHubotUrl(), is(""));
 }
Esempio n. 18
0
 @Test
 public void defaultPagerDutyDomainIsCorrect() {
   assertThat(config.getPagerDutyDomain(), is(""));
 }
Esempio n. 19
0
 @Test
 public void defaultSmtpFromIsCorrect() {
   assertThat(config.getSmtpFrom(), is("alert@seyren"));
 }
Esempio n. 20
0
 @Test
 public void defaultGraphiteUrlIsCorrect() {
   assertThat(config.getGraphiteUrl(), is("http://localhost:80"));
 }
Esempio n. 21
0
 @Test
 public void defaultSmtpUsernameIsCorrect() {
   assertThat(config.getSmtpUsername(), is(""));
 }
 private String url(Check check) {
   return seyrenConfig.getBaseUrl() + "/#/checks/" + check.getId();
 }
Esempio n. 23
0
 @Test
 public void defaultSmtpHostIsCorrect() {
   assertThat(config.getSmtpHost(), is("localhost"));
 }
Esempio n. 24
0
 @Test
 public void defaultGraphiteSchemeIsCorrect() {
   assertThat(config.getGraphiteScheme(), is("http"));
 }
Esempio n. 25
0
 @Test
 public void defaultSmtpProtocolIsCorrect() {
   assertThat(config.getSmtpProtocol(), is("smtp"));
 }
Esempio n. 26
0
 @Test
 public void defaultGraphiteHostIsCorrect() {
   assertThat(config.getGraphiteHost(), is("localhost:80"));
 }
Esempio n. 27
0
 @Test
 public void defaultGraphiteUsernameIsCorrect() {
   assertThat(config.getGraphiteUsername(), is(""));
 }
Esempio n. 28
0
 @Test
 public void defaultHipChatAuthTokenIsCorrect() {
   assertThat(config.getHipChatAuthToken(), is(""));
 }