diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fe5d84d --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +.idea/ +*.iml +*.ipr +*.iws +.classpath +.project +.settings/ +target/ +dependency-reduced-pom.xml +node_modules +node +build +build.config.js.sample + diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..574c2ec --- /dev/null +++ b/.travis.yml @@ -0,0 +1,27 @@ +sudo: required +dist: trusty +language: java +jdk: + - oraclejdk8 +addons: + apt: + packages: + - rpm +before_deploy: + - mvn jdeb:jdeb && export RELEASE_DEB_FILE=$(ls target/*.deb) + - mvn rpm:rpm && export RELEASE_RPM_FILE=$(find target/ -name '*.rpm' | tail -1) + - rm -f target/original-*.jar + - export RELEASE_PKG_FILE=$(ls target/*.jar) + - echo "Deploying release to GitHub releases" +deploy: + provider: releases + api_key: + secure: + file: + - "${RELEASE_PKG_FILE}" + - "${RELEASE_DEB_FILE}" + - "${RELEASE_RPM_FILE}" + skip_cleanup: true + on: + tags: true + jdk: oraclejdk8 diff --git a/GETTING-STARTED.md b/GETTING-STARTED.md new file mode 100644 index 0000000..dd82c9d --- /dev/null +++ b/GETTING-STARTED.md @@ -0,0 +1,26 @@ +Getting started with your new Graylog plugin +============================================ + +Welcome to your new Graylog plugin! + +Please refer to http://docs.graylog.org/en/latest/pages/plugins.html for documentation on how to write +plugins for Graylog. + +Travis CI +--------- + +There is a `.travis.yml` template in this project which is prepared to automatically +deploy the plugin artifacts (JAR, DEB, RPM) to GitHub releases. + +You just have to add your encrypted GitHub access token to the `.travis.yml`. +The token can be generated in your [GitHub personal access token settings](https://github.com/settings/tokens). + +Before Travis CI works, you have to enable it. Install the Travis CI command line +application and execute `travis enable`. + +To encrypt your GitHub access token you can use `travis encrypt`. + +Alternatively you can use `travis setup -f releases` to automatically create a GitHub +access token and add it to the `.travis.yml` file. **Attention:** doing this +will replace some parts of the `.travis.yml` file and you have to restore previous +settings. diff --git a/README.md b/README.md new file mode 100644 index 0000000..007d9b3 --- /dev/null +++ b/README.md @@ -0,0 +1,58 @@ +# Teams Plugin for Graylog + +[![Build Status](https://travis-ci.org/https://github.com/hidapple/graylog-plugin-teams.git.svg?branch=master)](https://travis-ci.org/https://github.com/hidapple/graylog-plugin-teams.git) + +__Use this paragraph to enter a description of your plugin.__ + +**Required Graylog version:** 2.0 and later + +Installation +------------ + +[Download the plugin](https://github.com/https://github.com/hidapple/graylog-plugin-teams.git/releases) +and place the `.jar` file in your Graylog plugin directory. The plugin directory +is the `plugins/` folder relative from your `graylog-server` directory by default +and can be configured in your `graylog.conf` file. + +Restart `graylog-server` and you are done. + +Development +----------- + +You can improve your development experience for the web interface part of your plugin +dramatically by making use of hot reloading. To do this, do the following: + +* `git clone https://github.com/Graylog2/graylog2-server.git` +* `cd graylog2-server/graylog2-web-interface` +* `ln -s $YOURPLUGIN plugin/` +* `npm install && npm start` + +Usage +----- + +__Use this paragraph to document the usage of your plugin__ + + +Getting started +--------------- + +This project is using Maven 3 and requires Java 8 or higher. + +* Clone this repository. +* Run `mvn package` to build a JAR file. +* Optional: Run `mvn jdeb:jdeb` and `mvn rpm:rpm` to create a DEB and RPM package respectively. +* Copy generated JAR file in target directory to your Graylog plugin directory. +* Restart the Graylog. + +Plugin Release +-------------- + +We are using the maven release plugin: + +``` +$ mvn release:prepare +[...] +$ mvn release:perform +``` + +This sets the version numbers, creates a tag and pushes to GitHub. Travis CI will build the release artifacts and upload to GitHub automatically. diff --git a/build.config.js b/build.config.js new file mode 100644 index 0000000..500cf49 --- /dev/null +++ b/build.config.js @@ -0,0 +1,6 @@ +const path = require('path'); + +module.exports = { + // Make sure that this is the correct path to the web interface part of the Graylog server repository. + web_src_path: path.resolve(__dirname, '../graylog2-server', 'graylog2-web-interface'), +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..7709712 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "Teams", + "version": "1.0.0-SNAPSHOT", + "description": "", + "repository": { + "type": "git", + "url": "https://github.com/hidapple/graylog-plugin-teams.git" + }, + "scripts": { + "build": "webpack", + "lint": "eslint -c .eslintrc src/**/*", + "test": "jest" + }, + "keywords": [ + "graylog" + ], + "author": "Shohei Hida", + "license": "MIT", + "dependencies": { + }, + "devDependencies": { + "graylog-web-plugin": "file:../graylog2-server/graylog2-web-interface/packages/graylog-web-plugin" + } +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f8f5961 --- /dev/null +++ b/pom.xml @@ -0,0 +1,268 @@ + + + 4.0.0 + + + org.graylog.plugins + graylog-plugin-web-parent + 3.0.0-alpha.3-SNAPSHOT + ../graylog2-server/graylog-plugin-parent/graylog-plugin-web-parent + + + org.graylog.plugins + graylog-plugin-teams + 1.0.0-SNAPSHOT + jar + + ${project.artifactId} + Graylog ${project.artifactId} plugin. + https://www.graylog.org + + + + Shohei Hida + + + + + scm:git:git@github.com:https://github.com/hidapple/graylog-plugin-teams.git.git + scm:git:git@github.com:https://github.com/hidapple/graylog-plugin-teams.git.git + https://github.com/https://github.com/hidapple/graylog-plugin-teams.git + HEAD + + + + UTF-8 + 1.8 + 1.8 + + + true + + ${project.parent.version} + /usr/share/graylog-server/plugin + + + + + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots + + + sonatype-nexus-staging + Nexus Release Repository + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + sonatype-nexus-releases + Sonatype Nexus Releases + https://oss.sonatype.org/content/repositories/releases + + true + + + false + + + + + + + org.graylog2 + graylog2-server + ${graylog.version} + provided + + + + + + build + + src/main/resources + true + + + + + maven-assembly-plugin + + true + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.6 + + + + ${project.groupId}.${project.artifactId} + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 2.4.1 + + false + + + + package + + shade + + + + + + + + + + + + org.apache.maven.plugins + maven-release-plugin + 2.5.2 + + true + forked-path + @{project.version} + clean test + package + + + + + jdeb + org.vafer + 1.4 + + ${project.build.directory}/${project.artifactId}-${project.version}.deb + + + ${project.build.directory}/${project.build.finalName}.jar + file + + perm + ${graylog.plugin-dir} + 644 + root + root + + + + + + + + org.codehaus.mojo + rpm-maven-plugin + 2.1.4 + + Application/Internet + + /usr + + + _unpackaged_files_terminate_build 0 + _binaries_in_noarch_packages_terminate_build 0 + + 644 + 755 + root + root + + + ${graylog.plugin-dir} + + + ${project.build.directory}/ + + ${project.build.finalName}.jar + + + + + + + + + + + + web-interface-build + + + !skip.web.build + + + + + + com.github.eirslett + frontend-maven-plugin + + + + install node and yarn + + install-node-and-yarn + + + ${nodejs.version} + ${yarn.version} + + + + + yarn install + + yarn + + + + install + + + + + yarn run build + + yarn + + + run build + + + + + + + + + diff --git a/src/deb/control/control b/src/deb/control/control new file mode 100644 index 0000000..dfceadb --- /dev/null +++ b/src/deb/control/control @@ -0,0 +1,8 @@ +Package: [[name]] +Version: [[version]] +Architecture: all +Maintainer: Shohei Hida +Section: web +Priority: optional +Depends: graylog-server | graylog-radio +Description: [[description]] diff --git a/src/main/java/org/graylog/plugins/teams/Teams.java b/src/main/java/org/graylog/plugins/teams/Teams.java new file mode 100644 index 0000000..d36062e --- /dev/null +++ b/src/main/java/org/graylog/plugins/teams/Teams.java @@ -0,0 +1,8 @@ +package org.graylog.plugins.teams; + +/** + * This is the plugin. Your class should implement one of the existing plugin + * interfaces. (i.e. AlarmCallback, MessageInput, MessageOutput) + */ +public class Teams { +} diff --git a/src/main/java/org/graylog/plugins/teams/TeamsMetaData.java b/src/main/java/org/graylog/plugins/teams/TeamsMetaData.java new file mode 100644 index 0000000..ac623ed --- /dev/null +++ b/src/main/java/org/graylog/plugins/teams/TeamsMetaData.java @@ -0,0 +1,57 @@ +package org.graylog.plugins.teams; + +import org.graylog2.plugin.PluginMetaData; +import org.graylog2.plugin.ServerStatus; +import org.graylog2.plugin.Version; + +import java.net.URI; +import java.util.Collections; +import java.util.Set; + +/** + * Implement the PluginMetaData interface here. + */ +public class TeamsMetaData implements PluginMetaData { + private static final String PLUGIN_PROPERTIES = "org.graylog.plugins.graylog-plugin-teams/graylog-plugin.properties"; + + @Override + public String getUniqueId() { + return "org.graylog.plugins.teams.TeamsPlugin"; + } + + @Override + public String getName() { + return "Teams"; + } + + @Override + public String getAuthor() { + return "Shohei Hida"; + } + + @Override + public URI getURL() { + return URI.create("https://github.com/hidapple/graylog-plugin-teams"); + } + + @Override + public Version getVersion() { + return Version.fromPluginProperties(getClass(), PLUGIN_PROPERTIES, "version", Version.from(0, 0, 0, "unknown")); + } + + @Override + public String getDescription() { + // TODO Insert correct plugin description + return "Description of Teams plugin"; + } + + @Override + public Version getRequiredVersion() { + return Version.fromPluginProperties(getClass(), PLUGIN_PROPERTIES, "graylog.version", Version.from(0, 0, 0, "unknown")); + } + + @Override + public Set getRequiredCapabilities() { + return Collections.emptySet(); + } +} diff --git a/src/main/java/org/graylog/plugins/teams/TeamsModule.java b/src/main/java/org/graylog/plugins/teams/TeamsModule.java new file mode 100644 index 0000000..f3c2c4e --- /dev/null +++ b/src/main/java/org/graylog/plugins/teams/TeamsModule.java @@ -0,0 +1,45 @@ +package org.graylog.plugins.teams; + +import org.graylog2.plugin.PluginConfigBean; +import org.graylog2.plugin.PluginModule; + +import java.util.Collections; +import java.util.Set; + +/** + * Extend the PluginModule abstract class here to add you plugin to the system. + */ +public class TeamsModule extends PluginModule { + + /** + * Returns all configuration beans required by this plugin. + * + * Implementing this method is optional. The default method returns an empty {@link Set}. + */ + @Override + public Set getConfigBeans() { + return Collections.emptySet(); + } + + @Override + protected void configure() { + /* + * Register your plugin types here. + * + * Examples: + * + * addMessageInput(Class); + * addMessageFilter(Class); + * addMessageOutput(Class); + * addPeriodical(Class); + * addAlarmCallback(Class); + * addInitializer(Class); + * addRestResource(Class); + * + * + * Add all configuration beans returned by getConfigBeans(): + * + * addConfigBeans(); + */ + } +} diff --git a/src/main/java/org/graylog/plugins/teams/TeamsPlugin.java b/src/main/java/org/graylog/plugins/teams/TeamsPlugin.java new file mode 100644 index 0000000..47a7dfa --- /dev/null +++ b/src/main/java/org/graylog/plugins/teams/TeamsPlugin.java @@ -0,0 +1,23 @@ +package org.graylog.plugins.teams; + +import org.graylog2.plugin.Plugin; +import org.graylog2.plugin.PluginMetaData; +import org.graylog2.plugin.PluginModule; + +import java.util.Collection; +import java.util.Collections; + +/** + * Implement the Plugin interface here. + */ +public class TeamsPlugin implements Plugin { + @Override + public PluginMetaData metadata() { + return new TeamsMetaData(); + } + + @Override + public Collection modules () { + return Collections.singletonList(new TeamsModule()); + } +} diff --git a/src/main/resources/META-INF/services/org.graylog2.plugin.Plugin b/src/main/resources/META-INF/services/org.graylog2.plugin.Plugin new file mode 100644 index 0000000..1058555 --- /dev/null +++ b/src/main/resources/META-INF/services/org.graylog2.plugin.Plugin @@ -0,0 +1 @@ +org.graylog.plugins.teams.TeamsPlugin \ No newline at end of file diff --git a/src/main/resources/org.graylog.plugins.graylog-plugin-teams/graylog-plugin.properties b/src/main/resources/org.graylog.plugins.graylog-plugin-teams/graylog-plugin.properties new file mode 100644 index 0000000..63e3eb5 --- /dev/null +++ b/src/main/resources/org.graylog.plugins.graylog-plugin-teams/graylog-plugin.properties @@ -0,0 +1,12 @@ +# The plugin version +version=${project.version} + +# The required Graylog server version +graylog.version=${graylog.version} + +# 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 +# with other plugins that have isolated=false. +# +# Do not disable this unless this plugin depends on another plugin! +isolated=true diff --git a/src/web/index.jsx b/src/web/index.jsx new file mode 100644 index 0000000..23fc2f6 --- /dev/null +++ b/src/web/index.jsx @@ -0,0 +1,26 @@ +import 'webpack-entry'; + +import { PluginManifest, PluginStore } from 'graylog-web-plugin/plugin'; + +import packageJson from '../../package.json'; + +const manifest = new PluginManifest(packageJson, { + /* This is the place where you define which entities you are providing to the web interface. + Right now you can add routes and navigation elements to it. + + Examples: */ + + // Adding a route to /sample, rendering YourReactComponent when called: + + // routes: [ + // { path: '/sample', component: YourReactComponent, permissions: 'inputs:create' }, + // ], + + // Adding an element to the top navigation pointing to /sample named "Sample": + + // navigation: [ + // { path: '/sample', description: 'Sample' }, + // ] +}); + +PluginStore.register(manifest); diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..f5ecb03 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,8 @@ +const PluginWebpackConfig = require('graylog-web-plugin').PluginWebpackConfig; +const loadBuildConfig = require('graylog-web-plugin').loadBuildConfig; +const path = require('path'); + +// Remember to use the same name here and in `getUniqueId()` in the java MetaData class +module.exports = new PluginWebpackConfig('org.graylog.plugins.teams.TeamsPlugin', loadBuildConfig(path.resolve(__dirname, './build.config')), { + // Here goes your additional webpack configuration. +});