Skip to content

Commit

Permalink
Merge pull request #89 from lucasponce/HWKALERTS-85
Browse files Browse the repository at this point in the history
HWKALERTS-85 Improve email plugin to support context
  • Loading branch information
lucasponce committed Sep 9, 2015
2 parents 2c598c8 + 500589b commit 8be8be0
Show file tree
Hide file tree
Showing 38 changed files with 2,278 additions and 1,230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
*/
@ActionPlugin(name = "aerogear")
public class AerogearPlugin implements ActionPluginListener {
static final String ROOT_SERVER_URL_PROPERTY = "org.hawkular.actions.aerogear.root.server.url";
static final String ROOT_SERVER_URL_PROPERTY = "org.hawkular.alerts.actions.aerogear.root.server.url";
static final String ROOT_SERVER_URL = System.getProperty(ROOT_SERVER_URL_PROPERTY);
static final String APPLICATION_ID_PROPERTY = "org.hawkular.actions.aerogear.application.id";
static final String APPLICATION_ID_PROPERTY = "org.hawkular.alerts.actions.aerogear.application.id";
static final String APPLICATION_ID = System.getProperty(APPLICATION_ID_PROPERTY);
static final String MASTER_SECRET_PROPERTY = "org.hawkular.actions.aerogear.master.secret";
static final String MASTER_SECRET_PROPERTY = "org.hawkular.alerts.actions.aerogear.master.secret";
static final String MASTER_SECRET = System.getProperty(MASTER_SECRET_PROPERTY);

private final MsgLogger msgLog = MsgLogger.LOGGER;
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<table width="540" cellspacing="0" cellpadding="0" border="0" class="flexible-container" style="margin:0 auto;">
<tr>
<td align="center" style="padding-bottom:25px;">
<#if alert?? && alert.status?? && alert.status == 'RESOLVED'>
<#if status?? && status == 'resolved'>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAABoCAYAAAA6sjRJAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2hpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tld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4Xyrsit9jJCi7jalcBP4W9fjJpkMHjvdQZ/m7cQJm7isc44J93ELj1oTtWR2G6A5y6AK+O/SvAAIXWqzTI5/FPAAAAAElFTkSuQmCC
" alt="Icon: alert resolved flag" border="0" width="60"
height="52" />
Expand All @@ -112,18 +112,25 @@
</#if>
</td>
</tr>
<tr>
<td align="center" style="color:#333333; font-family:Open sans,sans-serif; font-size:15px; font-weight:bold; line-height:24px;">
<#if htmlSubject??>
${htmlSubject}
</#if>
</td>
</tr>
<#list conditions as condition>
<tr>
<td align="center" style="color:#333333; font-family:Open sans,sans-serif; font-size:15px; font-weight:bold; line-height:24px;">
${condition.description}
</td>
</tr>
<#if condition.averageDescription??>
<tr>
<td align="center" style="color:#999999; font-family:Open sans,sans-serif; font-size:13px; line-height:21px; padding-bottom:7px;">
(Average ${condition.averageDescription})
</td>
</tr>
</#if>
</#list>
<tr>
<td align="center" style="line-height:24px; padding-bottom:15px;">
<a class="link" href="<#if url??>${url}<#else>http://www.hawkular.org</#if>" target="_blank"
<a class="link" href="<#if baseUrl??>${baseUrl}<#else>http://www.hawkular.org</#if>" target="_blank"
style="color:#0099d3; font-family:Open sans,sans-serif;
font-size:15px; text-decoration: none;"><#if alert?? && alert.trigger?? && alert.trigger.name??>${alert.trigger.name}</#if></a>
font-size:15px; text-decoration: none;"><#if triggerDescription??>${triggerDescription}</#if></a>
</td>
</tr>
<tr>
Expand All @@ -133,35 +140,9 @@
</tr>
<tr>
<td align="center" style="color:#999999; font-family:Open sans,sans-serif; font-size:13px; line-height:21px; padding-bottom:7px;">
<#if alert?? && alert.dampening?? && alert.dampening.type == 'STRICT_TIME'>alert triggered after ${alert.dampening.evalTimeSetting/1000} seconds </#if>
<#if dampeningDescription??>${dampeningDescription}</#if>
</td>
</tr>
<#if condition?? && condition.type == 'THRESHOLD' && average??>
<tr>
<td align="center" style="color:#333333; font-family:Open sans,sans-serif; font-size:13px; line-height:21px;">
Average response time: <span style="font-size:15px;">${average}</span> ms
</td>
</tr>
<tr>
<td align="center" style="color:#999999; font-family:Open sans,sans-serif; font-size:13px; line-height:21px; padding-bottom:7px;">
threshold is ${condition.threshold} ms
</td>
</tr>
</#if>
<#if (numConditions > 1)>
<tr>
<td align="center" style="color:#333333; font-family:Open sans,sans-serif; font-size:13px; line-height:21px;">
Conditions:
</td>
</tr>
<#list condDescs as condDesc>
<tr>
<td align="center" style="color:#999999; font-family:Open sans,sans-serif; font-size:13px; line-height:21px; padding-bottom:7px;">
${condDesc.type}: ${condDesc.description}
</td>
</tr>
</#list>
</#if>
<#if alert?? && alert.status?? && alert.status == 'ACKNOWLEDGED'>
<tr>
<td align="center" style="color:#333333; font-family:Open sans,sans-serif; font-size:13px; line-height:21px;">
Expand Down Expand Up @@ -216,7 +197,7 @@
</tr>

<!-- View -->
<#if url??>
<#if baseUrl??>
<tr>
<td>
<table width="600" cellspacing="0" cellpadding="0" border="0" class="flexible-container" style="margin:0 auto;">
Expand All @@ -230,7 +211,7 @@
</tr>
<tr>
<td align="center" style="padding-bottom:50px;">
<a class="btn-primary" href="${url}" target="_blank" style="display:block; background-color:#0085cf; border:1px solid #006e9c; border-radius:1px; color:#ffffff; font-family:Open sans,sans-serif; font-size:14px; font-weight:600; line-height:1.3333333; padding:6px 10px; text-decoration:none; width: 100px;">
<a class="btn-primary" href="${baseUrl}" target="_blank" style="display:block; background-color:#0085cf; border:1px solid #006e9c; border-radius:1px; color:#ffffff; font-family:Open sans,sans-serif; font-size:14px; font-weight:600; line-height:1.3333333; padding:6px 10px; text-decoration:none; width: 100px;">
View Metrics
</a>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@ HAWKULAR

--

<#if plainSubject??>
${plainSubject}
${emailSubject}

</#if>
Start time:
<#if alert??>
${alert.ctime?number_to_datetime} <#if alert.dampening?? && alert.dampening.type == 'STRICT_TIME'>(Alert triggered after ${alert.dampening.evalTimeSetting/1000} seconds )</#if>

</#if>
<#if type?? && type == 'THRESHOLD' && average?? && condition??>
Average response time:
${average} ms (threshold is ${condition.threshold} ms)
${alert.ctime?number_to_datetime}
<#if dampeningDescription??>(${dampeningDescription})</#if>

</#if>
<#if (numConditions > 1)>
Conditions:
<#list condDescs as condDesc>
${condDesc.type}: ${condDesc.description}
<#list conditions as condition>
${condition.description} <#if condition.averageDescription??>(Average ${condition.averageDescription}) </#if>

</#list>
</#if>
<#if alert?? && alert.status?? && alert.status == 'ACKNOWLEDGED'>
Expand Down Expand Up @@ -48,7 +43,7 @@ ${alert.resolvedNotes}
</#if>
</#if>

<#if url??>
<#if baseUrl??>
To view metrics of this alert, access your Hawkular account:
${url}
${baseUrl}
</#if>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.alerts.actions.email;

import java.io.File;
import java.io.FileOutputStream;

import javax.mail.Message;

import org.junit.BeforeClass;

/**
* Helper methods for tests
*
* @author Jay Shaughnessy
* @author Lucas Ponce
*/
public class CommonTest {

@BeforeClass
public static void setUnitTest() {
System.setProperty(EmailPlugin.MAIL_SESSION_OFFLINE, "true");
}

protected void writeEmailFile(Message msg, String fileName) throws Exception {
File dir = new File("target/test-emails");
if (!dir.exists()) {
dir.mkdirs();
}
File file = new File(dir, fileName);
FileOutputStream fos = new FileOutputStream(file);
msg.writeTo(fos);
fos.close();
}

}

0 comments on commit 8be8be0

Please sign in to comment.