Skip to content

Commit 9de5a62

Browse files
authored
Merge pull request #27 from billmurrin/issue25-26-null-error
Fixed null issue, added migration for blank configurations. Bumped ve…
2 parents e19f806 + 6c23bde commit 9de5a62

File tree

6 files changed

+124
-24
lines changed

6 files changed

+124
-24
lines changed

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ New Global System Configuration
4343

4444
Supported Graylog Versions
4545
-----------
46-
* Version 3.0.0 was tested and is compatible with Graylog version 2.3.0 and above.
46+
* Version 3.0.1 was tested and is compatible with Graylog version 2.3.0 and above.
4747
* Version 2.1.0 was tested and is compatible with Graylog versions 2.2.1, 2.2.2, and 2.2.3.
4848
* Version 1.0.0 was tested and is compatible with Graylog version 2.1.3.
4949

@@ -73,37 +73,40 @@ Way Ahead - Version 3.1.0
7373
-----------
7474
* Add additional Default Configuration options (show table, show pie chart, links, exclude query button)
7575
* Add ability to Turn Off links and/or exclude from Query buttons for each individual widget in the Widget Configuration.
76-
76+
* Add debug configuration option to enable console messaging in order to help in troubleshooting issues with the plugin.
77+
7778
Development
7879
-----------
7980
You can improve your development experience for the web interface part of your plugin dramatically by making use of hot reloading.
8081

8182
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))
8283

83-
Steps for hot-loading setup with the plugin.
84+
#####Steps for hot-loading setup with the plugin.
8485
* Clone the Repositories
8586
```
87+
git clone -b "2.3.1" https://github.com/Graylog2/graylog2-server.git
8688
git clone https://github.com/billmurrin/graylog-plugin-quickvaluesplus-widget.git
87-
git clone -b "2.3.0" https://github.com/Graylog2/graylog2-server.git
8889
```
89-
* Install the Node.JS modules
90+
* Install the `graylog2-web-interface` node modules and build the Vendor Manifest
9091
```
91-
cd graylog-plugin-quickvaluesplus-widget
92-
npm install
93-
cd ../graylog2-server/graylog2-web-interface
92+
cd graylog2-server/graylog2-web-interface
9493
npm install
94+
webpack --config webpack.vendor.js
9595
```
96-
* Build the Vendor file (If you skip this, plugin might fail with an 'call an undefined function')
96+
* Install the `graylog-plugin-quickvaluesplus-widget` node modules
9797
```
98-
webpack --config webpack.vendor.js
98+
cd graylog-plugin-quickvaluesplus-widget
99+
npm install
99100
```
100-
* Start the web server
101+
102+
* From within `graylog2-web-interface`, start the web server
101103
```
104+
cd graylog2-server/graylog2-web-interface
102105
npm start
103106
```
104107

105-
Steps to build the plugin.
106-
* Follow the steps above, but **DO NOT** run the `npm start` command. (no need to start the dev web-server)
108+
#####Steps to build the plugin.
109+
* Follow the steps above for hot-loading, but **DO NOT** run the `npm start` command. (no need to start the dev web-server)
107110
* Run `mvn package`
108-
* Copy the generated JAR file located in the target directory to the Graylog plugin directory.
111+
* Copy the generated JAR file located in the `/target` folder to the Graylog plugin directory.
109112
* Restart Graylog

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "QuickValuesPlusWidget",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "GrayLog2 QuickValuesPlus Widget Plugin",
55
"repository": {
66
"type": "git",

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<groupId>org.graylog.plugins</groupId>
1010
<artifactId>graylog-plugin-quickvaluesplus-widget</artifactId>
11-
<version>3.0.0</version>
11+
<version>3.0.1</version>
1212
<packaging>jar</packaging>
1313

1414
<name>${project.artifactId}</name>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.graylog.plugins.quickvaluesplus;
2+
3+
import org.graylog2.migrations.Migration;
4+
import org.graylog2.cluster.ClusterConfigServiceImpl;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
import javax.inject.Inject;
9+
import java.time.ZonedDateTime;
10+
11+
12+
/**
13+
* Migration creating the quick values plus entries if they do not exist.
14+
*/
15+
public class QuickValuesPlusDefaultValuesMigration extends Migration {
16+
private static final Logger LOG = LoggerFactory.getLogger(QuickValuesPlusDefaultValuesMigration.class);
17+
18+
private final ClusterConfigServiceImpl clusterConfigService;
19+
20+
@Inject
21+
public QuickValuesPlusDefaultValuesMigration(final ClusterConfigServiceImpl clusterConfigService) {
22+
this.clusterConfigService = clusterConfigService;
23+
}
24+
25+
@Override
26+
public ZonedDateTime createdAt() {
27+
return ZonedDateTime.parse("2017-09-03T01:57:00Z");
28+
}
29+
30+
@Override
31+
@SuppressWarnings("unchecked")
32+
public void upgrade() {
33+
if (clusterConfigService.get(QuickValuesPlusPluginConfiguration.class) != null) {
34+
LOG.debug("Migration already done.");
35+
return;
36+
}
37+
38+
LOG.info("Writing values for Quick Values Plugin Configuration");
39+
clusterConfigService.write(QuickValuesPlusPluginConfiguration.create(25, 5, "descending"));
40+
}
41+
42+
}

src/main/java/org/graylog/plugins/quickvaluesplus/QuickValuesPlusWidgetModule.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import org.graylog2.plugin.PluginModule;
44
import org.graylog2.plugin.PluginConfigBean;
55
import org.graylog.plugins.quickvaluesplus.widget.strategy.QuickValuesPlusWidgetStrategy;
6-
6+
import com.github.joschi.jadconfig.Parameter;
7+
import com.google.inject.multibindings.Multibinder;
8+
import org.graylog2.migrations.Migration;
9+
import org.graylog.plugins.quickvaluesplus.QuickValuesPlusDefaultValuesMigration;
710
import java.util.Collections;
811
import java.util.Set;
912

@@ -12,6 +15,10 @@
1215
*/
1316
public class QuickValuesPlusWidgetModule extends PluginModule {
1417

18+
protected Multibinder<Migration> migrationsBinder() {
19+
return Multibinder.newSetBinder(binder(), Migration.class);
20+
}
21+
1522
@Override
1623
public Set<? extends PluginConfigBean> getConfigBeans() {
1724
return Collections.emptySet();
@@ -20,5 +27,7 @@ public Set<? extends PluginConfigBean> getConfigBeans() {
2027
@Override
2128
protected void configure() {
2229
addWidgetStrategy(QuickValuesPlusWidgetStrategy.class, QuickValuesPlusWidgetStrategy.Factory.class);
30+
31+
migrationsBinder().addBinding().to(QuickValuesPlusDefaultValuesMigration.class);
2332
}
2433
}

src/web/components/FieldQuickValuesPlus.jsx

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ const FieldQuickValuesPlus = React.createClass({
3030
],
3131
getInitialState() {
3232
return {
33+
debug: false,
3334
field: undefined,
3435
dropdownIsOpen: false,
36+
loaded: false,
3537
data: [],
38+
defaults: {top_values: 5, sort_order: "descending", table_size: 25, show_pie_chart: true, show_data_table: true},
3639
quickValuesOptions: {top_values: 5, sort_order: "descending", table_size: 25, show_pie_chart: true, show_data_table: true}
3740
};
3841
},
@@ -41,10 +44,13 @@ const FieldQuickValuesPlus = React.createClass({
4144
this.setState({dropdownIsOpen: !this.state.dropdownIsOpen});
4245
},
4346
componentWillMount() {
47+
if (this.state.debug) console.log("In componentWillMount");
4448
this.setState({ dropdownIsOpen: false });
4549
this.setState({quickValuesOptions: {top_values: 5, sort_order: "descending", table_size: 25, show_pie_chart: true, show_data_table: true}});
4650
},
51+
4752
componentDidMount() {
53+
if (this.state.debug) console.log("In componentDidMount");
4854
ConfigurationActions.list("org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration");
4955
this.style.use();
5056
this._loadQuickValuesData();
@@ -68,6 +74,7 @@ const FieldQuickValuesPlus = React.createClass({
6874
},
6975

7076
componentWillUnmount() {
77+
if (this.state.debug) console.log("In componentWillUnmount");
7178
this.style.unuse();
7279
this._stopTimer();
7380
},
@@ -89,18 +96,54 @@ const FieldQuickValuesPlus = React.createClass({
8996
this.setState({field: field}, () => this._loadQuickValuesData(false));
9097
},
9198
_loadQuickValuesData() {
92-
if (this.state.configuration !== undefined) {
93-
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}});
94-
95-
if (this.state.field !== undefined) {
96-
this.setState({loadPending: true});
97-
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);
98-
promise.then((data) => this.setState({data: data, loadPending: false}));
99+
if (this.state.debug) console.log("Global Configuration value is");
100+
if (this.state.debug) console.log(this.state.configuration);
101+
102+
if (this.state.debug) console.log("Is loaded: " + this.state.loaded);
103+
if (!this.state.loaded) {
104+
if (this.state.configuration !== undefined) {
105+
if (this.state.debug) console.log("Global config loaded. QVP Options using global configuration settings.");
106+
this.setState({
107+
quickValuesOptions: {
108+
top_values: this.state.configuration['org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration'].top_values,
109+
sort_order: this.state.configuration['org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration'].sort_order,
110+
table_size: this.state.configuration['org.graylog.plugins.quickvaluesplus.QuickValuesPlusPluginConfiguration'].table_size,
111+
show_pie_chart: true,
112+
show_data_table: true
113+
},
114+
loaded: true,
115+
});
116+
} else {
117+
if (this.state.debug) console.log("Global config not loaded. QVP Options using internal default values.");
118+
this.setState({
119+
quickValuesOptions: {
120+
top_values: this.state.defaults.top_values,
121+
sort_order: this.state.defaults.sort_order,
122+
table_size: this.state.defaults.table_size,
123+
show_pie_chart: true,
124+
show_data_table: true
125+
},
126+
});
99127
}
100128
}
129+
130+
if (this.state.debug) console.log("QVP Options - _loadQuickValuesData");
131+
if (this.state.debug) console.log(this.state.quickValuesOptions);
132+
133+
if (this.state.field !== undefined) {
134+
this.setState({loadPending: true});
135+
const promise = QuickValuesPlusActions.getQuickValues(
136+
this.state.field,
137+
this.state.quickValuesOptions.table_size,
138+
this.state.quickValuesOptions.sort_order);
139+
promise.then((data) => this.setState({data: data, loadPending: false}));
140+
}
101141
},
102142
_resetStatus() {
143+
if (this.state.debug) console.log("In resetStatus method. Get Initial State");
103144
this.setState(this.getInitialState());
145+
if (this.state.debug) console.log("QVP Options - _resetStatus");
146+
if (this.state.debug) console.log(this.state.quickValuesOptions);
104147
},
105148
sortordermenu: ['ascending', 'descending'],
106149
topvaluesmenu: [5,10,15,20,25],
@@ -110,9 +153,12 @@ const FieldQuickValuesPlus = React.createClass({
110153
return this.state.quickValuesOptions[configKey] === value ? 'selected' : '';
111154
},
112155
_updateOptionState(configKey, value) {
156+
if (this.state.debug) console.log("In _updateOptionState method. Updating Options");
113157
let newOptions = Object.assign({}, this.state.quickValuesOptions, {[configKey]: value});
114158
this.refs.thedash.refs.widgetModal.setState({config: newOptions});
115159
this.setState({quickValuesOptions: newOptions});
160+
if (this.state.debug) console.log("QVP Options - _updateOptionState");
161+
if (this.state.debug) console.log(this.state.quickValuesOptions);
116162
const promise = QuickValuesPlusActions.getQuickValues(this.state.field, newOptions['table_size'], newOptions['sort_order']);
117163
promise.then((data) => this.setState({data: data, loadPending: false}));
118164
},

0 commit comments

Comments
 (0)