use of com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient in project camel by apache.
the class SesEndpoint method createSESClient.
private AmazonSimpleEmailService createSESClient() {
AmazonSimpleEmailService client = null;
ClientConfiguration clientConfiguration = null;
boolean isClientConfigFound = false;
if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
clientConfiguration = new ClientConfiguration();
clientConfiguration.setProxyHost(configuration.getProxyHost());
clientConfiguration.setProxyPort(configuration.getProxyPort());
isClientConfigFound = true;
}
if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) {
AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
if (isClientConfigFound) {
client = new AmazonSimpleEmailServiceClient(credentials, clientConfiguration);
} else {
client = new AmazonSimpleEmailServiceClient(credentials);
}
} else {
if (isClientConfigFound) {
client = new AmazonSimpleEmailServiceClient();
} else {
client = new AmazonSimpleEmailServiceClient(clientConfiguration);
}
}
return client;
}
use of com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient in project ice by Netflix.
the class BasicWeeklyCostEmailService method trigger.
public synchronized void trigger(boolean test) {
try {
headerNote = getHeaderNote();
throughputMetrics = getThroughputMetrics();
AmazonSimpleEmailServiceClient emailService = AwsUtils.getAmazonSimpleEmailServiceClient();
Map<String, ApplicationGroup> appgroups = applicationGroupService.getApplicationGroups();
Map<String, List<ApplicationGroup>> appgroupsByEmail = collectEmails(appgroups);
for (String email : appgroupsByEmail.keySet()) {
try {
if (!StringUtils.isEmpty(email))
sendEmail(test, emailService, email, appgroupsByEmail.get(email));
} catch (Exception e) {
logger.error("error in sending email to " + email, e);
}
}
} catch (Exception e) {
logger.error("error sending cost emails", e);
}
}
use of com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient in project ice by Netflix.
the class BillingFileProcessor method sendOndemandCostAlert.
private void sendOndemandCostAlert() {
if (ondemandThreshold == null || StringUtils.isEmpty(fromEmail) || StringUtils.isEmpty(alertEmails) || endMilli < lastAlertMillis() + AwsUtils.hourMillis * 24)
return;
Map<Long, Map<Ec2InstanceReservationPrice.Key, Double>> ondemandCosts = getOndemandCosts(lastAlertMillis() + AwsUtils.hourMillis);
Long maxHour = null;
double maxTotal = ondemandThreshold;
for (Long hour : ondemandCosts.keySet()) {
double total = 0;
for (Double value : ondemandCosts.get(hour).values()) total += value;
if (total > maxTotal) {
maxHour = hour;
maxTotal = total;
}
}
if (maxHour != null) {
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
String subject = String.format("Alert: Ondemand cost per hour reached $%s at %s", numberFormat.format(maxTotal), AwsUtils.dateFormatter.print(maxHour));
StringBuilder body = new StringBuilder();
body.append(String.format("Total ondemand cost $%s at %s:<br><br>", numberFormat.format(maxTotal), AwsUtils.dateFormatter.print(maxHour)));
TreeMap<Double, String> costs = Maps.newTreeMap();
for (Map.Entry<Ec2InstanceReservationPrice.Key, Double> entry : ondemandCosts.get(maxHour).entrySet()) {
costs.put(entry.getValue(), entry.getKey().region + " " + entry.getKey().usageType + ": ");
}
for (Double cost : costs.descendingKeySet()) {
if (cost > 0)
body.append(costs.get(cost)).append("$" + numberFormat.format(cost)).append("<br>");
}
body.append("<br>Please go to <a href=\"" + urlPrefix + "dashboard/reservation#usage_cost=cost&groupBy=UsageType&product=ec2_instance&operation=OndemandInstances\">Ice</a> for details.");
SendEmailRequest request = new SendEmailRequest();
request.withSource(fromEmail);
List<String> emails = Lists.newArrayList(alertEmails.split(","));
request.withDestination(new Destination(emails));
request.withMessage(new Message(new Content(subject), new Body().withHtml(new Content(body.toString()))));
AmazonSimpleEmailServiceClient emailService = AwsUtils.getAmazonSimpleEmailServiceClient();
try {
emailService.sendEmail(request);
updateLastAlertMillis(endMilli);
logger.info("updateLastAlertMillis " + endMilli);
} catch (Exception e) {
logger.error("Error in sending alert emails", e);
}
}
}
Aggregations