Skip to content

Commit

Permalink
PagerDuty skeleton plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tsegismont authored and jshaughn committed May 22, 2015
1 parent ebd4d00 commit 06c29fe
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 0 deletions.
69 changes: 69 additions & 0 deletions hawkular-actions-plugins/hawkular-actions-pagerduty/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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-actions-plugins</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>hawkular-actions-pagerduty</artifactId>
<packaging>war</packaging>

<name>Hawkular Action PagerDuty Plugin</name>

<dependencies>
<!-- TODO PagderDuty Java Client or HTTP client? -->
</dependencies>

<profiles>
<profile>
<id>dev</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>deploy</id>
<phase>install</phase>
<configuration>
<target>
<copy file="${project.build.directory}/${project.build.finalName}.war"
todir="${org.hawkular.wildfly.deployments}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.actions.pagerduty.listener;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.MessageListener;

import org.hawkular.actions.api.log.MsgLogger;
import org.hawkular.actions.api.model.ActionMessage;
import org.hawkular.bus.common.consumer.BasicMessageListener;

/**
* Listens to pagerduty bus notifications and interacts with PagerDuty REST API.
*
* @author Thomas Segismont
*/
@MessageDriven(messageListenerInterface = MessageListener.class, activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "HawkularAlertsActionsTopic"),
@ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "actionPlugin like 'pagerduty'") })
public class PagerDutyListener extends BasicMessageListener<ActionMessage> {

private final MsgLogger msgLog = MsgLogger.LOGGER;

@PostConstruct
void setup() {
// TODO initialize REST client
}

protected void onBasicMessage(ActionMessage msg) {
msgLog.infoActionReceived("pagerduty", msg.toString());

// TODO implement
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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.actions.pagerduty.registration;

import org.hawkular.bus.common.ConnectionContextFactory;
import org.hawkular.bus.common.Endpoint;
import org.hawkular.bus.common.MessageId;
import org.hawkular.bus.common.MessageProcessor;
import org.hawkular.bus.common.producer.ProducerConnectionContext;
import org.hawkular.actions.api.log.MsgLogger;
import org.hawkular.actions.api.model.ActionPluginMessage;
import org.jboss.logging.Logger;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.jms.JMSException;
import javax.jms.QueueConnectionFactory;
import java.util.HashSet;
import java.util.Set;

/**
* A initialization class to init the pagerduty plugin
*
* @author Thomas Segismont
*/
@Startup
@Singleton
public class RegistrationInit {
private final MsgLogger msgLog = MsgLogger.LOGGER;
private final Logger log = Logger.getLogger(RegistrationInit.class);
private static final String ACTION_PLUGIN_REGISTER = "HawkularAlertsPluginsQueue";

@Resource(mappedName = "java:/HawkularBusConnectionFactory")
private QueueConnectionFactory conFactory;
private ConnectionContextFactory ccf;
private ProducerConnectionContext pcc;

@PostConstruct
public void init() {
try {
ccf = new ConnectionContextFactory(conFactory);
pcc = ccf.createProducerConnectionContext(new Endpoint(Endpoint.Type.QUEUE, ACTION_PLUGIN_REGISTER));

ActionPluginMessage apMsg = new ActionPluginMessage();
apMsg.setOp("init");
apMsg.setActionPlugin("pagerduty");
Set<String> properties = new HashSet<String>();
// TODO describe plugin properties
properties.add("description");
apMsg.setProperties(properties);

MessageId mid = new MessageProcessor().send(pcc, apMsg);

msgLog.infoPluginRegistration("pagerduty", mid.toString());
} catch (JMSException e) {
log.debug(e.getMessage(), e);
msgLog.errorCannotSendMessage("pagerduty", e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<!--
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.
-->
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.hawkular.nest" />
</dependencies>
</deployment>
</jboss-deployment-structure>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<!--
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.
-->
<jboss-web>
<context-root>/hawkular/actions/pagerduty</context-root>
</jboss-web>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--
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.
-->
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

</web-app>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.actions.pagerduty.listener;

import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import java.util.List;

import org.hawkular.actions.api.model.ActionMessage;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

/**
* @author Thomas Segismont
*/
@RunWith(MockitoJUnitRunner.class)
public class PagerDutyListenerTest {

@BeforeClass
public static void configureListener() {
// TODO configure listener with system properties
}

private PagerDutyListener pagerDutyListener;

@Before
public void setup() {
pagerDutyListener = new PagerDutyListener();
}

@Test
public void testSend() throws Exception {
// TODO test
}
}

0 comments on commit 06c29fe

Please sign in to comment.