Skip to content

Commit

Permalink
Merge pull request #13 from GDATASoftwareAG/feature/migrate_to_graylog_3
Browse files Browse the repository at this point in the history
Dependency upgrades and usage within Graylog 3.3.5
  • Loading branch information
StefanHufschmidt authored Aug 20, 2020
2 parents fa55cc8 + 77eef55 commit c4bfdbb
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 37 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
V 1.2.2
-----------
* Upgraded dependencies
* Target changed to Graylog 3.3.5 (as legacy alarm callback)

V 1.2.1
-----------
* Fixed alerts with zero grace time
Expand Down
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
# Graylog AlertManager Notification Plugin
This plugin can be used for connecting [Graylog](https://www.graylog.org/) alerts to the [Prometheus](https://prometheus.io/) [AlertManager](https://prometheus.io/docs/alerting/alertmanager/).

The plugin development is based on [Graylog2/graylog-plugin-sample](https://github.com/Graylog2/graylog-plugin-sample) which is mentioned in the [Graylog plugin documentation](http://docs.graylog.org/en/2.4/pages/plugins.html).
The plugin development is based on [Graylog2/graylog-plugin-sample](https://github.com/Graylog2/graylog-plugin-sample) which is mentioned in the [Graylog plugin documentation](http://docs.graylog.org/en/3.3/pages/plugins.html).

**Note:** this plugin is currently only available as "Legacy Alarm Callbacks" item after adding it to Graylog
![Legacy Alarm Callback](images/Legacy_Plugin.png)

The current plugin version 1.2.2 has Graylog 3.3.5 as target. The plugin version 1.2.1 (see releases) targets Graylog 2.5.0 and above.

## Use Case
You are using a Graylog for checking the logs for errors, a Prometheus for checking the service metrics and you would like to organize your alerts with a AlertManager you need to get your Graylog alerts into the AlertManager.
Expand Down Expand Up @@ -42,18 +47,20 @@ List of provided keys you can use inside JMTE Templates:
## How to deploy on Graylog
You can easily build the plugin by executing `./gradlew build -x check --no-daemon`.
Afterwards there should be a `.jar` file inside the `build/libs/` directory.
Follow the instructions mentioned [here](http://docs.graylog.org/en/2.4/pages/plugins.html#installing-and-loading-plugins) to deploy this `.jar` file.
Follow the instructions mentioned [here](http://docs.graylog.org/en/3.3/pages/plugins.html#installing-and-loading-plugins) to deploy this `.jar` file.

## How to develop locally
You can use Docker and Docker-Compose to test changes of this plugin locally by following these steps:
1. Build the JAR
2. Run `docker-compose up` inside the development directory
3. Access your local Graylog instance web-interface at http://localhost:9000/
4. You can configure an alert to be send to `http://alertmanager:9093/api/v1/alerts` and access the AlertManager via http://localhost:9093/

## Screenshots
![Configuration of Callback](images/New_AlertManager_Callback_Window.png)

## Planned Features
You would like to contribute anything? - Take a look at [CONTRIBUTING.md](CONTRIBUTING.md).

## Known Issues
* The test alert will not be shown in AlertManager
* When clicking on `Test` to test your callback configuration it will show a green ok bar when everything is fine but the alert will not be shown in the AlertManager
* You have to create a stream with a alert condition to test the callback alert in AlertManager
* Implementation of EventNotification for usage as non-legacy notification plugin

You would like to contribute anything? - Take a look at [CONTRIBUTING.md](CONTRIBUTING.md).

Expand All @@ -62,4 +69,4 @@ See [LICENSE](LICENSE)

## Copyright

Copyright (c) 2019 G DATA CyberDefense AG and other authors.
Copyright (c) 2019-2020 G DATA CyberDefense AG and other authors.
28 changes: 14 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ serviceLoader {
}

group = 'de.gdata.mobilelab'
version = "1.2.1"
version = "1.2.2"

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand All @@ -46,44 +46,44 @@ repositories {

dependencies {
// https://mvnrepository.com/artifact/org.graylog2/graylog2-server
compile group: 'org.graylog2', name: 'graylog2-server', version: '2.5.0'
implementation group: 'org.graylog2', name: 'graylog2-server', version: '3.3.5'

// https://mvnrepository.com/artifact/org.jboss.dashboard-builder/dashboard-builder-bom
compile group: 'org.jboss.dashboard-builder', name: 'dashboard-builder-bom', version: '6.5.0.Final', ext: 'pom'
implementation group: 'org.jboss.dashboard-builder', name: 'dashboard-builder-bom', version: '6.5.0.Final', ext: 'pom'

// https://mvnrepository.com/artifact/com.google.auto.value/auto-value
compileOnly group: 'com.google.auto.value', name: 'auto-value', version: '1.6.3'
compileOnly group: 'com.google.auto.value', name: 'auto-value', version: '1.7.4'

// https://mvnrepository.com/artifact/org.projectlombok/lombok
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.4'

implementation group: 'org.projectlombok', name: 'lombok', version: '1.18.12'
annotationProcessor('org.projectlombok:lombok:1.18.12')

// TESTS

// https://mvnrepository.com/artifact/org.springframework/spring-web
testCompile group: 'org.springframework', name: 'spring-web', version: '5.1.4.RELEASE'
testImplementation group: 'org.springframework', name: 'spring-web', version: '5.2.8.RELEASE'

// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
testCompile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.8'
testImplementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.11.2'

testCompile group: 'junit', name: 'junit', version: '4.12'
testImplementation group: 'junit', name: 'junit', version: '4.13'

// https://mvnrepository.com/artifact/org.mockito/mockito-core
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.7.13'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.5.0'

// https://mvnrepository.com/artifact/org.testcontainers/testcontainers
testCompile group: 'org.testcontainers', name: 'testcontainers', version: '1.10.5'
testImplementation group: 'org.testcontainers', name: 'testcontainers', version: '1.14.3'

}

jar {
archiveName = "graylog-plugin-alertmanagercallback-" + version + ".jar"
baseName = title
archiveFileName = "graylog-plugin-alertmanagercallback-" + version + ".jar"
archiveBaseName = title
group = "de.gdata.mobilelab.alertmanagercallback"
manifest {
attributes(
'Implementation-Title': title,
'Implementation-Version': version,
'Implementation-Version': archiveVersion,
'Build-Time': new Date().format("yyy-MM-dd HH:mm:ss"),
'Graylog-Plugin-Properties-Path': 'de.gdata.mobilelab.alertmanagercallback.graylog-plugin-alertmanagercallback'
)
Expand Down
67 changes: 67 additions & 0 deletions development/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
version: '2'
services:


mongodb:
image: mongo:3
volumes:
- mongo_data:/data/db


elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.8.10
volumes:
- es_data:/usr/share/elasticsearch/data
environment:
- http.host=0.0.0.0
- transport.host=localhost
- network.host=0.0.0.0
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
mem_limit: 1g


graylog:
image: graylog/graylog:3.3.5
volumes:
- graylog_journal:/usr/share/graylog/data/journal
- ../build/libs/graylog-plugin-alertmanagercallback-1.2.2.jar:/usr/share/graylog/plugin/graylog-plugin-alertmanagercallback.jar
environment:
# CHANGE ME (must be at least 16 characters)!
- GRAYLOG_PASSWORD_SECRET=somepasswordpepper
# Password: admin
- GRAYLOG_ROOT_PASSWORD_SHA2=8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918
- GRAYLOG_HTTP_EXTERNAL_URI=http://127.0.0.1:9000/
links:
- mongodb:mongo
- elasticsearch
depends_on:
- mongodb
- elasticsearch
ports:
# Graylog web interface and REST API
- 9000:9000
# Syslog TCP
- 1514:1514
# Syslog UDP
- 1514:1514/udp
# GELF TCP
- 12201:12201
# GELF UDP
- 12201:12201/udp

alertmanager:
image: prom/alertmanager:v0.20.0
ports:
- 9093:9093

volumes:
mongo_data:
driver: local
es_data:
driver: local
graylog_journal:
driver: local
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Wed Feb 06 13:03:44 CET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
Binary file added images/Legacy_Plugin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public URI getURL() {

@Override
public Version getVersion() {
return Version.from(1, 2, 1);
return Version.from(1, 2, 2);
}

@Override
Expand All @@ -42,7 +42,7 @@ public String getDescription() {

@Override
public Version getRequiredVersion() {
return Version.from(2, 5, 0);
return Version.from(3, 3, 5);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# The plugin version
version=0.1
version=1.2.2

# The required Graylog server version
graylog.version=2.5.0
graylog.version=3.3.5

# When set to true (the default) the plugin gets a separate class loader
# when loading the plugin. When set to false, the plugin shares a class loader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class AlertManagerAlarmCallbackIT {

@Rule
public GenericContainer alertManagerContainer = new GenericContainer("prom/alertmanager:v0.15.3")
public GenericContainer alertManagerContainer = new GenericContainer("prom/alertmanager:v0.20.0")
.withExposedPorts(9093)
.waitingFor(new HostPortWaitStrategy());

Expand Down Expand Up @@ -88,7 +86,7 @@ public void call() throws AlarmCallbackException {
// and: Alert has been triggered in AlertManager
String alertOverview = new RestTemplate().getForObject("http://" + alertManagerContainer.getContainerIpAddress()
+ ":" + alertManagerContainer.getMappedPort(9093)
+ "/api/v1/alerts/groups",
+ "/api/v2/alerts/groups",
String.class);
assertNotNull(alertOverview);
assertTrue(alertOverview.contains("TestAlert1"));
Expand Down Expand Up @@ -119,7 +117,7 @@ public void callWithNullValues() throws AlarmCallbackException {
// and: Alert has been triggered in AlertManager
String alertOverview = new RestTemplate().getForObject("http://" + alertManagerContainer.getContainerIpAddress()
+ ":" + alertManagerContainer.getMappedPort(9093)
+ "/api/v1/alerts/groups",
+ "/api/v2/alerts/groups",
String.class);
assertNotNull(alertOverview);
assertTrue(alertOverview.contains("TestAlert1"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void getURL() {

@Test
public void getVersion() {
assertEquals(Version.from(1, 2, 1), new AlertManagerPluginMetaData().getVersion());
assertEquals(Version.from(1, 2, 2), new AlertManagerPluginMetaData().getVersion());
}

@Test
Expand All @@ -48,7 +48,7 @@ public void getDescription() {

@Test
public void getRequiredVersion() {
assertEquals(Version.from(2, 5, 0), new AlertManagerPluginMetaData().getRequiredVersion());
assertEquals(Version.from(3, 3, 5), new AlertManagerPluginMetaData().getRequiredVersion());
}

@Test
Expand Down

0 comments on commit c4bfdbb

Please sign in to comment.