Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions seyren-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,36 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.4.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.6</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.9</version>
<type>jar</type>
</dependency>
</dependencies>

</project>
22 changes: 9 additions & 13 deletions seyren-api/src/main/java/com/seyren/api/bean/ChartsBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,20 @@ public Response getChart(String checkId, int width, int height, String from, Str
if (check == null) {
return Response.status(Status.NOT_FOUND).build();
}

String target = check.getTarget();

if (hideThresholds) {
return getChart(target, width, height, from, to, null, null, hideLegend, hideAxes);
return getChart(check.getGraphiteSourceUrl(), target, width, height, from, to, null, null, hideLegend, hideAxes);
} else {
return getChart(target, width, height, from, to, check.getWarn(), check.getError(), hideLegend, hideAxes);
return getChart(check.getGraphiteSourceUrl(), target, width, height, from, to, check.getWarn(), check.getError(), hideLegend, hideAxes);
}

}

@Override
public Response getCustomChart(String target, int width, int height, String from, String to, String warnThreshold, String errorThreshold, boolean hideLegend,
public Response getCustomChart(String target, String graphiteSourceUrl, int width, int height, String from, String to, String warnThreshold, String errorThreshold, boolean hideLegend,
boolean hideAxes) {

BigDecimal warn;
if (StringUtils.isEmpty(warnThreshold)) {
warn = null;
Expand All @@ -77,11 +76,10 @@ public Response getCustomChart(String target, int width, int height, String from
error = new BigDecimal(errorThreshold);
}

return getChart(target, width, height, from, to, warn, error, hideLegend, hideAxes);

return getChart(graphiteSourceUrl, target, width, height, from, to, warn, error, hideLegend, hideAxes);
}

private Response getChart(String target, int width, int height, String from, String to, BigDecimal warnThreshold, BigDecimal errorThreshold, boolean hideLegend,
private Response getChart(String graphiteSource, String target, int width, int height, String from, String to, BigDecimal warnThreshold, BigDecimal errorThreshold, boolean hideLegend,
boolean hideAxes) {

LegendState legendState;
Expand All @@ -99,12 +97,10 @@ private Response getChart(String target, int width, int height, String from, Str
}

try {
byte[] bytes = graphiteHttpClient.getChart(target, width, height, from, to, legendState, axesState, warnThreshold, errorThreshold);
byte[] bytes = graphiteHttpClient.getChart(graphiteSource, target, width, height, from, to, legendState, axesState, warnThreshold, errorThreshold);
return Response.ok(bytes, "image/png").build();
} catch (Exception e) {
return Response.serverError().build();
}

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Response getChart(@PathParam("checkId") String checkId,
@Produces("image/png")
@Path("/chart/{target}")
Response getCustomChart(@PathParam("target") String target,
@QueryParam("graphiteSourceUrl") String graphiteSourceUrl,
@QueryParam("width") @DefaultValue("1200") int width,
@QueryParam("height") @DefaultValue("350") int height,
@QueryParam("from") @DefaultValue("-24hours") String from,
Expand Down
10 changes: 8 additions & 2 deletions seyren-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,16 @@
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>com.opsgenie.integration</groupId>
<artifactId>sdk</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>com.opsgenie.integration</groupId>
<artifactId>sdk</artifactId>
<version>2.2.0</version>
<type>jar</type>
</dependency>
</dependencies>
<repositories>
<repository>
Expand Down
13 changes: 13 additions & 0 deletions seyren-core/src/main/java/com/seyren/core/domain/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class Check {
private AlertType state;
private DateTime lastCheck;
private List<Subscription> subscriptions = new ArrayList<Subscription>();
private String graphiteSourceUrl;

public String getId() {
return id;
Expand Down Expand Up @@ -239,4 +240,16 @@ public Check withSubscriptions(List<Subscription> subscriptions) {
return this;
}

public String getGraphiteSourceUrl() {
return graphiteSourceUrl;
}

public void setGraphiteSourceUrl(String graphiteSourceUrl) {
this.graphiteSourceUrl = graphiteSourceUrl;
}

public Check withGraphiteSourceUrl(String graphiteSourceUrl) {
setGraphiteSourceUrl(graphiteSourceUrl);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public Map<String, Optional<BigDecimal>> check(Check check) throws Exception {
Map<String, Optional<BigDecimal>> targetValues = new HashMap<String, Optional<BigDecimal>>();

try {
JsonNode node = graphiteHttpClient.getTargetJson(check.getTarget(), check.getFrom(), check.getUntil());
JsonNode node = graphiteHttpClient.getTargetJson(check.getGraphiteSourceUrl(), check.getTarget(), check.getFrom(), check.getUntil());

for (JsonNode metric : node) {
String target = metric.path("target").asText();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class PickleHandler implements Runnable {
public PickleHandler(Socket socket, Executor executor, ChecksStore checksStore, CheckRunnerFactory checkRunnerFactory) {
this.socket = socket;
this.executor = executor;
this.executor = executor;
this.checksStore = checksStore;
this.checkRunnerFactory = checkRunnerFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,105 +11,105 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.seyren.core.service.notification;
package com.seyren.core.service.notification;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a white space at the beginning of every line?


import java.io.IOException;
import java.text.ParseException;
import java.util.List;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Inject;
import javax.inject.Named;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ifountain.opsgenie.client.OpsGenieClient;
import com.ifountain.opsgenie.client.OpsGenieClientException;
import com.ifountain.opsgenie.client.model.alert.CloseAlertRequest;
import com.ifountain.opsgenie.client.model.alert.CloseAlertResponse;
import com.ifountain.opsgenie.client.model.alert.CreateAlertRequest;
import com.ifountain.opsgenie.client.model.alert.CreateAlertResponse;
import com.ifountain.opsgenie.client.model.alert.ListAlertsRequest;
import com.ifountain.opsgenie.client.model.alert.ListAlertsResponse;
import com.seyren.core.domain.Alert;
import com.seyren.core.domain.AlertType;
import com.seyren.core.domain.Check;
import com.seyren.core.domain.Subscription;
import com.seyren.core.domain.SubscriptionType;
import com.seyren.core.exception.NotificationFailedException;
import com.seyren.core.util.config.SeyrenConfig;
import com.ifountain.opsgenie.client.OpsGenieClient;
import com.ifountain.opsgenie.client.OpsGenieClientException;
import com.ifountain.opsgenie.client.model.alert.CloseAlertRequest;
import com.ifountain.opsgenie.client.model.alert.CloseAlertResponse;
import com.ifountain.opsgenie.client.model.alert.CreateAlertRequest;
import com.ifountain.opsgenie.client.model.alert.CreateAlertResponse;
import com.ifountain.opsgenie.client.model.alert.ListAlertsRequest;
import com.ifountain.opsgenie.client.model.alert.ListAlertsResponse;
import com.seyren.core.domain.Alert;
import com.seyren.core.domain.AlertType;
import com.seyren.core.domain.Check;
import com.seyren.core.domain.Subscription;
import com.seyren.core.domain.SubscriptionType;
import com.seyren.core.exception.NotificationFailedException;
import com.seyren.core.util.config.SeyrenConfig;

@Named
public class OpsGenieNotificationService implements NotificationService {
private static final Logger LOGGER = LoggerFactory.getLogger(OpsGenieNotificationService.class);
private SeyrenConfig config;
@Named
public class OpsGenieNotificationService implements NotificationService {
private static final Logger LOGGER = LoggerFactory.getLogger(OpsGenieNotificationService.class);
private SeyrenConfig config;

@Inject
public OpsGenieNotificationService(SeyrenConfig config) {
this.config = config;
}
@Inject
public OpsGenieNotificationService(SeyrenConfig config) {
this.config = config;
}

@Override
public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException {
OpsGenieClient client = new OpsGenieClient();
@Override
public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException {
OpsGenieClient client = new OpsGenieClient();

try {
String apiKey = subscription.getTarget();
if (check.getState() == AlertType.ERROR || check.getState() == AlertType.WARN) {
CreateAlertRequest request = new CreateAlertRequest();
request.setApiKey(apiKey);
request.setMessage(getMessage(check));
request.setSource("Seyren");
request.setTeams(config.getOpsGenieTeams());
try {
String apiKey = subscription.getTarget();
if (check.getState() == AlertType.ERROR || check.getState() == AlertType.WARN) {
CreateAlertRequest request = new CreateAlertRequest();
request.setApiKey(apiKey);
request.setMessage(getMessage(check));
request.setSource("Seyren");
request.setTeams(config.getOpsGenieTeams());

CreateAlertResponse response = client.alert().createAlert(request);
assert response.isSuccess();
} else if (check.getState() == AlertType.OK) {
com.ifountain.opsgenie.client.model.beans.Alert alert = findAlert(client, apiKey, getMessage(check));
CreateAlertResponse response = client.alert().createAlert(request);
assert response.isSuccess();
} else if (check.getState() == AlertType.OK) {
com.ifountain.opsgenie.client.model.beans.Alert alert = findAlert(client, apiKey, getMessage(check));

CloseAlertRequest request = new CloseAlertRequest();
request.setId(alert.getId());
request.setApiKey(apiKey);
CloseAlertResponse response = client.alert().closeAlert(request);
assert response.isSuccess();
}
} catch (OpsGenieClientException e) {
LOGGER.warn(
"Did not send notification to OpsGenie for check in state: {}",
check.getState(), e);
} catch (IOException e) {
LOGGER.warn(
"Did not send notification to OpsGenie for check in state: {}",
check.getState(), e);
} catch (ParseException e) {
LOGGER.warn(
"Did not send notification to OpsGenie for check in state: {}",
check.getState(), e);
CloseAlertRequest request = new CloseAlertRequest();
request.setId(alert.getId());
request.setApiKey(apiKey);
CloseAlertResponse response = client.alert().closeAlert(request);
assert response.isSuccess();
}
} catch (OpsGenieClientException e) {
LOGGER.warn(
"Did not send notification to OpsGenie for check in state: {}",
check.getState(), e);
} catch (IOException e) {
LOGGER.warn(
"Did not send notification to OpsGenie for check in state: {}",
check.getState(), e);
} catch (ParseException e) {
LOGGER.warn(
"Did not send notification to OpsGenie for check in state: {}",
check.getState(), e);

}
}
}
}

private com.ifountain.opsgenie.client.model.beans.Alert findAlert(OpsGenieClient client, String apiKey, String message) throws OpsGenieClientException, IOException, ParseException {
ListAlertsRequest request = new ListAlertsRequest();
request.setApiKey(apiKey);
private com.ifountain.opsgenie.client.model.beans.Alert findAlert(OpsGenieClient client, String apiKey, String message) throws OpsGenieClientException, IOException, ParseException {
ListAlertsRequest request = new ListAlertsRequest();
request.setApiKey(apiKey);

ListAlertsResponse response = client.alert().listAlerts(request);
List<com.ifountain.opsgenie.client.model.beans.Alert> alerts = response.getAlerts();
for (com.ifountain.opsgenie.client.model.beans.Alert alert: alerts) {
if (alert.getMessage().equals(message)) {
return alert;
}
}
return null;
}
ListAlertsResponse response = client.alert().listAlerts(request);
List<com.ifountain.opsgenie.client.model.beans.Alert> alerts = response.getAlerts();
for (com.ifountain.opsgenie.client.model.beans.Alert alert: alerts) {
if (alert.getMessage().equals(message)) {
return alert;
}
}
return null;
}

private String getMessage(Check check) {
return "Check '" + check.getName() + "' has exceeded its threshold.";
}
private String getMessage(Check check) {
return "Check '" + check.getName() + "' has exceeded its threshold.";
}

@Override
public boolean canHandle(SubscriptionType subscriptionType) {
return subscriptionType == SubscriptionType.OPSGENIE;
}
@Override
public boolean canHandle(SubscriptionType subscriptionType) {
return subscriptionType == SubscriptionType.OPSGENIE;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ private OctetString octetString(String value) {
private String url(Check check) {
return String.format("%s/#/checks/%s", seyrenConfig.getBaseUrl(), check.getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class SeyrenConfig {
private final Integer snmpPort;
private final String snmpCommunity;
private final String snmpOID;
private final String snmpSource;
private final String victorOpsRestAPIEndpoint;
private final String emailTemplateFileName;
private final String emailSubjectTemplateFileName;
Expand Down Expand Up @@ -158,6 +159,7 @@ public SeyrenConfig() {
this.snmpPort = Integer.parseInt(configOrDefault("SNMP_PORT", "162"));
this.snmpCommunity = configOrDefault("SNMP_COMMUNITY", "public");
this.snmpOID = configOrDefault("SNMP_OID", "1.3.6.1.4.1.32473.1");
this.snmpSource = configOrDefault("SNMP_SOURCE", "localhost");

//VictorOps
this.victorOpsRestAPIEndpoint = configOrDefault("VICTOROPS_REST_ENDPOINT", "");
Expand Down Expand Up @@ -315,7 +317,12 @@ public String getSnmpCommunity() {
public String getSnmpOID() {
return snmpOID;
}


@JsonIgnore
public String getSnmpSource() {
return snmpSource;
}

@JsonIgnore
public String getGraphiteUrl() {
return graphiteUrl;
Expand Down
Loading