-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,033 additions
and
4 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
hawkular-alerts-actions-api/src/main/java/org/hawkular/alerts/actions/api/Global.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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.api; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Define a plugin as global. | ||
* Global plugins process all messages without filtering per plugin name. | ||
* Global annotation is used in combination with Plugin annotation. | ||
* | ||
* @author Lucas Ponce | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface Global { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
hawkular-alerts-actions-plugins/hawkular-alerts-actions-webhook/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.hawkular.alerts</groupId> | ||
<artifactId>hawkular-alerts-actions-plugins</artifactId> | ||
<version>0.6.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>hawkular-alerts-actions-webhook</artifactId> | ||
<packaging>war</packaging> | ||
|
||
<name>Hawkular Alerts Action Webhook Plugin</name> | ||
|
||
<profiles> | ||
|
||
<profile> | ||
<id>bus</id> | ||
<dependencies> | ||
|
||
<!-- Hawkular Accounts dependencies --> | ||
<dependency> | ||
<groupId>org.hawkular.accounts</groupId> | ||
<artifactId>hawkular-accounts-api</artifactId> | ||
<version>${version.org.hawkular.accounts}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
<activation> | ||
<activeByDefault>true</activeByDefault> | ||
</activation> | ||
</profile> | ||
|
||
<profile> | ||
<id>standalone</id> | ||
<build> | ||
<plugins> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>default-compile</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
<configuration> | ||
<excludes> | ||
<exclude>org/hawkular/alerts/actions/webhook/accounts/*.java</exclude> | ||
</excludes> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>bus-war-package</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>war</goal> | ||
</goals> | ||
<configuration> | ||
<warSourceDirectory>src/main/webapp-standalone</warSourceDirectory> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
</profile> | ||
|
||
</profiles> | ||
|
||
</project> |
69 changes: 69 additions & 0 deletions
69
...-alerts-actions-webhook/src/main/java/org/hawkular/alerts/actions/webhook/WebHookApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* 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.webhook; | ||
|
||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.ws.rs.ApplicationPath; | ||
import javax.ws.rs.core.Application; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.hawkular.alerts.actions.api.MsgLogger; | ||
import org.jboss.logging.Logger; | ||
|
||
/** | ||
* Base class for REST WebHook plugin | ||
* @author Jay Shaughnessy | ||
* @author Lucas Ponce | ||
*/ | ||
@ApplicationPath("/") | ||
public class WebHookApp extends Application { | ||
private final MsgLogger msgLog = MsgLogger.LOGGER; | ||
private static final Logger log = Logger.getLogger(WebHookApp.class); | ||
|
||
public static final String TENANT_HEADER_NAME = "Hawkular-Tenant"; | ||
|
||
public WebHookApp() { | ||
log.debugf("Hawkular Alerts WebHook starting..."); | ||
} | ||
|
||
public static Response internalError(String message) { | ||
Map<String, String> errors = new HashMap<>(); | ||
errors.put("errorMsg", "Internal error: " + message); | ||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR) | ||
.entity(errors).type(APPLICATION_JSON_TYPE).build(); | ||
} | ||
|
||
public static Response ok(Object entity) { | ||
return Response.status(Response.Status.OK).entity(entity).type(APPLICATION_JSON_TYPE).build(); | ||
} | ||
|
||
public static Response ok() { | ||
return Response.status(Response.Status.OK).type(APPLICATION_JSON_TYPE).build(); | ||
} | ||
|
||
public static Response badRequest(String message) { | ||
Map<String, String> errors = new HashMap<>(); | ||
errors.put("errorMsg", "Bad request: " + message); | ||
return Response.status(Response.Status.BAD_REQUEST) | ||
.entity(errors).type(APPLICATION_JSON_TYPE).build(); | ||
} | ||
|
||
} |
93 changes: 93 additions & 0 deletions
93
...rts-actions-webhook/src/main/java/org/hawkular/alerts/actions/webhook/WebHookHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* 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.webhook; | ||
|
||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON; | ||
|
||
import static org.hawkular.alerts.actions.webhook.WebHookApp.TENANT_HEADER_NAME; | ||
|
||
import java.util.Map; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.DELETE; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.HeaderParam; | ||
import javax.ws.rs.PUT; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
/** | ||
* @author Jay Shaughnessy | ||
* @author Lucas Ponce | ||
*/ | ||
@Path("/") | ||
public class WebHookHandler { | ||
private static final Logger log = Logger.getLogger(WebHookHandler.class); | ||
|
||
@HeaderParam(TENANT_HEADER_NAME) | ||
String tenantId; | ||
|
||
@GET | ||
@Path("/") | ||
@Produces(APPLICATION_JSON) | ||
public Response findWebHooks() { | ||
return WebHookApp.ok(WebHooks.getWebHooks(tenantId)); | ||
} | ||
|
||
@PUT | ||
@Path("/") | ||
@Consumes(APPLICATION_JSON) | ||
@Produces(APPLICATION_JSON) | ||
public Response registerWebHook(final Map<String, String> webhook) { | ||
if (webhook == null || webhook.isEmpty()) { | ||
return WebHookApp.badRequest("webhook must be not null"); | ||
} | ||
if (!webhook.containsKey("url")) { | ||
return WebHookApp.badRequest("webhook must contain an url"); | ||
} | ||
String url = webhook.get("url"); | ||
String filter = webhook.containsKey("filter") ? webhook.get("filter") : null; | ||
try { | ||
WebHooks.addWebHook(tenantId, filter, url); | ||
return WebHookApp.ok(); | ||
} catch (Exception e) { | ||
log.debugf(e.getMessage(), e); | ||
return WebHookApp.internalError(e.getMessage()); | ||
} | ||
} | ||
|
||
@DELETE | ||
@Path("/{url}") | ||
public Response unregisterWebHook( | ||
@PathParam("url") | ||
final String url) { | ||
if (url == null || url.isEmpty()) { | ||
return WebHookApp.badRequest("webhook url must be not null"); | ||
} | ||
try { | ||
WebHooks.removeWebHook(tenantId, url); | ||
return WebHookApp.ok(); | ||
} catch (Exception e) { | ||
log.debugf(e.getMessage(), e); | ||
return WebHookApp.internalError(e.getMessage()); | ||
} | ||
} | ||
} |
Oops, something went wrong.