Skip to content

Commit

Permalink
Fixed null issue, added migration for blank configurations. Bumped ve…
Browse files Browse the repository at this point in the history
…rsion.
  • Loading branch information
billmurrin committed Sep 3, 2017
1 parent e19f806 commit 6c23bde
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 24 deletions.
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ New Global System Configuration

Supported Graylog Versions
-----------
* Version 3.0.0 was tested and is compatible with Graylog version 2.3.0 and above.
* Version 3.0.1 was tested and is compatible with Graylog version 2.3.0 and above.
* Version 2.1.0 was tested and is compatible with Graylog versions 2.2.1, 2.2.2, and 2.2.3.
* Version 1.0.0 was tested and is compatible with Graylog version 2.1.3.

Expand Down Expand Up @@ -73,37 +73,40 @@ Way Ahead - Version 3.1.0
-----------
* Add additional Default Configuration options (show table, show pie chart, links, exclude query button)
* Add ability to Turn Off links and/or exclude from Query buttons for each individual widget in the Widget Configuration.

* Add debug configuration option to enable console messaging in order to help in troubleshooting issues with the plugin.

Development
-----------
You can improve your development experience for the web interface part of your plugin dramatically by making use of hot reloading.

To hot reload using Graylog 2.3.0, your plugin directory should be located two directories above your graylog2-web-server directory (../../) and the folder name of your plugin should be begin with graylog-plugin (More info[HERE](https://github.com/Graylog2/graylog2-server/blob/2.3/graylog2-web-interface/webpack.combined.config.js#L11))

Steps for hot-loading setup with the plugin.
#####Steps for hot-loading setup with the plugin.
* Clone the Repositories
```
git clone -b "2.3.1" https://github.com/Graylog2/graylog2-server.git
git clone https://github.com/billmurrin/graylog-plugin-quickvaluesplus-widget.git
git clone -b "2.3.0" https://github.com/Graylog2/graylog2-server.git
```
* Install the Node.JS modules
* Install the `graylog2-web-interface` node modules and build the Vendor Manifest
```
cd graylog-plugin-quickvaluesplus-widget
npm install
cd ../graylog2-server/graylog2-web-interface
cd graylog2-server/graylog2-web-interface
npm install
webpack --config webpack.vendor.js
```
* Build the Vendor file (If you skip this, plugin might fail with an 'call an undefined function')
* Install the `graylog-plugin-quickvaluesplus-widget` node modules
```
webpack --config webpack.vendor.js
cd graylog-plugin-quickvaluesplus-widget
npm install
```
* Start the web server

* From within `graylog2-web-interface`, start the web server
```
cd graylog2-server/graylog2-web-interface
npm start
```

Steps to build the plugin.
* Follow the steps above, but **DO NOT** run the `npm start` command. (no need to start the dev web-server)
#####Steps to build the plugin.
* Follow the steps above for hot-loading, but **DO NOT** run the `npm start` command. (no need to start the dev web-server)
* Run `mvn package`
* Copy the generated JAR file located in the target directory to the Graylog plugin directory.
* Copy the generated JAR file located in the `/target` folder to the Graylog plugin directory.
* Restart Graylog
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "QuickValuesPlusWidget",
"version": "3.0.0",
"version": "3.0.1",
"description": "GrayLog2 QuickValuesPlus Widget Plugin",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>org.graylog.plugins</groupId>
<artifactId>graylog-plugin-quickvaluesplus-widget</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
<packaging>jar</packaging>

<name>${project.artifactId}</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.graylog.plugins.quickvaluesplus;

import org.graylog2.migrations.Migration;
import org.graylog2.cluster.ClusterConfigServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.time.ZonedDateTime;


/**
* Migration creating the quick values plus entries if they do not exist.
*/
public class QuickValuesPlusDefaultValuesMigration extends Migration {
private static final Logger LOG = LoggerFactory.getLogger(QuickValuesPlusDefaultValuesMigration.class);

private final ClusterConfigServiceImpl clusterConfigService;

@Inject
public QuickValuesPlusDefaultValuesMigration(final ClusterConfigServiceImpl clusterConfigService) {
this.clusterConfigService = clusterConfigService;
}

@Override
public ZonedDateTime createdAt() {
return ZonedDateTime.parse("2017-09-03T01:57:00Z");
}

@Override
@SuppressWarnings("unchecked")
public void upgrade() {
if (clusterConfigService.get(QuickValuesPlusPluginConfiguration.class) != null) {
LOG.debug("Migration already done.");
return;
}

LOG.info("Writing values for Quick Values Plugin Configuration");
clusterConfigService.write(QuickValuesPlusPluginConfiguration.create(25, 5, "descending"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import org.graylog2.plugin.PluginModule;
import org.graylog2.plugin.PluginConfigBean;
import org.graylog.plugins.quickvaluesplus.widget.strategy.QuickValuesPlusWidgetStrategy;

import com.github.joschi.jadconfig.Parameter;
import com.google.inject.multibindings.Multibinder;
import org.graylog2.migrations.Migration;
import org.graylog.plugins.quickvaluesplus.QuickValuesPlusDefaultValuesMigration;
import java.util.Collections;
import java.util.Set;

Expand All @@ -12,6 +15,10 @@
*/
public class QuickValuesPlusWidgetModule extends PluginModule {

protected Multibinder<Migration> migrationsBinder() {
return Multibinder.newSetBinder(binder(), Migration.class);
}

@Override
public Set<? extends PluginConfigBean> getConfigBeans() {
return Collections.emptySet();
Expand All @@ -20,5 +27,7 @@ public Set<? extends PluginConfigBean> getConfigBeans() {
@Override
protected void configure() {
addWidgetStrategy(QuickValuesPlusWidgetStrategy.class, QuickValuesPlusWidgetStrategy.Factory.class);

migrationsBinder().addBinding().to(QuickValuesPlusDefaultValuesMigration.class);
}
}
60 changes: 53 additions & 7 deletions src/web/components/FieldQuickValuesPlus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ const FieldQuickValuesPlus = React.createClass({
],
getInitialState() {
return {
debug: false,
field: undefined,
dropdownIsOpen: false,
loaded: false,
data: [],
defaults: {top_values: 5, sort_order: "descending", table_size: 25, show_pie_chart: true, show_data_table: true},
quickValuesOptions: {top_values: 5, sort_order: "descending", table_size: 25, show_pie_chart: true, show_data_table: true}
};
},
Expand All @@ -41,10 +44,13 @@ const FieldQuickValuesPlus = React.createClass({
this.setState({dropdownIsOpen: !this.state.dropdownIsOpen});
},
componentWillMount() {
if (this.state.debug) console.log("In componentWillMount");
this.setState({ dropdownIsOpen: false });
this.setState({quickValuesOptions: {top_values: 5, sort_order: "descending", table_size: 25, show_pie_chart: true, show_data_table: true}});
},

componentDidMount() {
if (this.state.debug) console.log("In componentDidMount");
ConfigurationActions.list("org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration");
this.style.use();
this._loadQuickValuesData();
Expand All @@ -68,6 +74,7 @@ const FieldQuickValuesPlus = React.createClass({
},

componentWillUnmount() {
if (this.state.debug) console.log("In componentWillUnmount");
this.style.unuse();
this._stopTimer();
},
Expand All @@ -89,18 +96,54 @@ const FieldQuickValuesPlus = React.createClass({
this.setState({field: field}, () => this._loadQuickValuesData(false));
},
_loadQuickValuesData() {
if (this.state.configuration !== undefined) {
this.setState({quickValuesOptions: {top_values: this.state.configuration['org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration'].top_values, sort_order: this.state.configuration['org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration'].sort_order, table_size: this.state.configuration['org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration'].table_size, show_pie_chart: true, show_data_table: true}});

if (this.state.field !== undefined) {
this.setState({loadPending: true});
const promise = QuickValuesPlusActions.getQuickValues(this.state.field, this.state.configuration['org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration'].table_size, this.state.configuration['org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration'].sort_order);
promise.then((data) => this.setState({data: data, loadPending: false}));
if (this.state.debug) console.log("Global Configuration value is");
if (this.state.debug) console.log(this.state.configuration);

if (this.state.debug) console.log("Is loaded: " + this.state.loaded);
if (!this.state.loaded) {
if (this.state.configuration !== undefined) {
if (this.state.debug) console.log("Global config loaded. QVP Options using global configuration settings.");
this.setState({
quickValuesOptions: {
top_values: this.state.configuration['org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration'].top_values,
sort_order: this.state.configuration['org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration'].sort_order,
table_size: this.state.configuration['org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration'].table_size,
show_pie_chart: true,
show_data_table: true
},
loaded: true,
});
} else {
if (this.state.debug) console.log("Global config not loaded. QVP Options using internal default values.");
this.setState({
quickValuesOptions: {
top_values: this.state.defaults.top_values,
sort_order: this.state.defaults.sort_order,
table_size: this.state.defaults.table_size,
show_pie_chart: true,
show_data_table: true
},
});
}
}

if (this.state.debug) console.log("QVP Options - _loadQuickValuesData");
if (this.state.debug) console.log(this.state.quickValuesOptions);

if (this.state.field !== undefined) {
this.setState({loadPending: true});
const promise = QuickValuesPlusActions.getQuickValues(
this.state.field,
this.state.quickValuesOptions.table_size,
this.state.quickValuesOptions.sort_order);
promise.then((data) => this.setState({data: data, loadPending: false}));
}
},
_resetStatus() {
if (this.state.debug) console.log("In resetStatus method. Get Initial State");
this.setState(this.getInitialState());
if (this.state.debug) console.log("QVP Options - _resetStatus");
if (this.state.debug) console.log(this.state.quickValuesOptions);
},
sortordermenu: ['ascending', 'descending'],
topvaluesmenu: [5,10,15,20,25],
Expand All @@ -110,9 +153,12 @@ const FieldQuickValuesPlus = React.createClass({
return this.state.quickValuesOptions[configKey] === value ? 'selected' : '';
},
_updateOptionState(configKey, value) {
if (this.state.debug) console.log("In _updateOptionState method. Updating Options");
let newOptions = Object.assign({}, this.state.quickValuesOptions, {[configKey]: value});
this.refs.thedash.refs.widgetModal.setState({config: newOptions});
this.setState({quickValuesOptions: newOptions});
if (this.state.debug) console.log("QVP Options - _updateOptionState");
if (this.state.debug) console.log(this.state.quickValuesOptions);
const promise = QuickValuesPlusActions.getQuickValues(this.state.field, newOptions['table_size'], newOptions['sort_order']);
promise.then((data) => this.setState({data: data, loadPending: false}));
},
Expand Down

0 comments on commit 6c23bde

Please sign in to comment.