/** Instantiates a new basic context. */
 public BasicChaosMonkeyContext() {
   super("simianarmy.properties", "client.properties", "chaos.properties");
   setChaosCrawler(new ASGChaosCrawler(awsClient()));
   setChaosInstanceSelector(new BasicChaosInstanceSelector());
   MonkeyConfiguration cfg = configuration();
   AmazonSimpleEmailServiceClient sesClient = new AmazonSimpleEmailServiceClient();
   if (configuration().getStr("simianarmy.aws.email.region") != null) {
     sesClient.setRegion(
         Region.getRegion(
             Regions.fromName(configuration().getStr("simianarmy.aws.email.region"))));
   }
   setChaosEmailNotifier(new BasicChaosEmailNotifier(cfg, sesClient, null));
 }
Exemplo n.º 2
0
  @Override
  public void sendEmail(EmailBean emailBean) {

    if (emailBean == null) {
      return;
    }

    if (CollectionUtils.isEmpty(emailBean.getRecipients())) {
      return;
    }

    final Destination destination = new Destination().withToAddresses(emailBean.getRecipients());
    final Content subjectContent = new Content().withData(emailBean.getSubject());
    final Content bodyContent = new Content().withData(emailBean.getBody());
    final Body body = new Body().withText(bodyContent);

    if (StringUtils.hasText(emailBean.getRecordsAsHtml())) {
      body.withHtml(new Content().withData(emailBean.getRecordsAsHtml()));
    }

    final Message message = new Message().withSubject(subjectContent).withBody(body);

    final SendEmailRequest request =
        new SendEmailRequest()
            .withSource(emailBean.getFrom())
            .withDestination(destination)
            .withMessage(message);

    final AmazonSimpleEmailServiceClient emailClient = new AmazonSimpleEmailServiceClient();
    final Region region = Region.getRegion(Regions.DEFAULT_REGION);
    emailClient.setRegion(region);

    SendEmailResult sendEmailResult = emailClient.sendEmail(request);

    //        TODO handle email result (Log, store state to db, etc..)
  }