diff --git a/README.md b/README.md index 81876cb4b..8cbe27aaa 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,13 @@ Check the [releases](https://github.com/nsano-rururu/elastalert-kibana-plugin/re [docker-compose sample](https://github.com/nsano-rururu/elastalert-kibana-plugin/wiki/docker-compose-sample) ## Configuration -By default the plugin will connect to `localhost:3030`. If your ElastAlert server is running on a different host or port add/change the following options in your `config/kibana.yml` file: +By default the plugin will connect to `localhost:3030`. If your ElastAlert server is running on a different host or port add/change the global environment variables in your configuration file: ``` -elastalert-kibana-plugin.serverHost: 123.0.0.1 -elastalert-kibana-plugin.serverPort: 9000 +PROTOCOL: http +HOSTNAME: localhost +PORT: 3030 + ``` ## Contribution diff --git a/public/components/rules/editor/editor.tsx b/public/components/rules/editor/editor.tsx index 25f75d1f9..3ccf68024 100644 --- a/public/components/rules/editor/editor.tsx +++ b/public/components/rules/editor/editor.tsx @@ -37,7 +37,7 @@ export default class Editor extends Component { loadRule() { const { httpClient } = this.props; - httpClient.get(`../api/elastalert/rules/${this.props.rule}`).then(resp => { + httpClient.get(`../rules/${this.props.rule}`).then(resp => { this.setState({ value: resp.data, ruleName: this.props.rule }); }); } @@ -48,11 +48,10 @@ export default class Editor extends Component { const ruleID = this.props.editorMode === 'edit' ? this.props.rule : this.state.ruleName; httpClient - .post(`../api/elastalert/rules/${ruleID}`, { + .post(`../rules/${ruleID}`, { yaml: this.state.value }) - .then(resp => { - if (resp.status === 200) { + .then(() => { this.setState({ saving: false }); addToast( 'Saved successfully', @@ -61,7 +60,6 @@ export default class Editor extends Component { ); this.closeModal(); loadRules(); - } }) .catch(e => { this.setState({ saving: false }); @@ -78,7 +76,7 @@ export default class Editor extends Component { this.setState({ testing: true, testFailed: null, testResponse: null }); httpClient - .post(`../api/elastalert/test`, { + .post(`../test`, { rule: this.state.value, testType: 'schemaOnly' }) diff --git a/public/components/rules/list/list.tsx b/public/components/rules/list/list.tsx index 726febc69..3097d5c40 100644 --- a/public/components/rules/list/list.tsx +++ b/public/components/rules/list/list.tsx @@ -60,7 +60,7 @@ export default class List extends Component { this.setState({ rules: [], selectedRules: [], loading: true }); const { httpClient } = this.props; httpClient - .get('../api/elastalert/rules') + .get('../rules') .then(resp => { this.setState({ rules: resp.data.rules.sort(), error: null, loading: false }); }) diff --git a/public/lib/elastalert.ts b/public/lib/elastalert.ts index 2eeb58b0f..8f53b5517 100644 --- a/public/lib/elastalert.ts +++ b/public/lib/elastalert.ts @@ -2,7 +2,7 @@ export const deleteRule = (http, rules, onSuccess, onFail) => { const rulesCopy = rules.slice(); rules.forEach(rule => { - http.delete(`../api/elastalert/rules/${rule}`) + http.delete(`../rules/${rule}`) .then(() => { // Loop through all rules marked for deletion const index = rulesCopy.indexOf(rule); diff --git a/server/routes/index.ts b/server/routes/index.ts index b7ed99495..2f37d0be8 100644 --- a/server/routes/index.ts +++ b/server/routes/index.ts @@ -4,7 +4,7 @@ export function defineRoutes(router: IRouter) { const uri = process.env.PROTOCOL + '://' + process.env.HOSTNAME + process.env.PORT; router.get( { - path: '/api/elastalert/{path}', + path: '/{path}', validate: false, }, async (context, req, response) => { @@ -25,7 +25,7 @@ export function defineRoutes(router: IRouter) { ); router.post( { - path: '/api/elastalert/{path}', + path: '/{path*}', validate: false, }, async (context, req, response) => { @@ -33,7 +33,7 @@ export function defineRoutes(router: IRouter) { method: 'POST', body: JSON.stringify({ params: { - index: 'elastalert', + yaml: req.body, }, }), }; @@ -54,10 +54,17 @@ export function defineRoutes(router: IRouter) { ); router.delete( { - path: '/api/elastalert/{path}', + path: '/{path*}', validate: false, }, async (context, req, response) => { + const deleteRequest = async () => { + return fetch(uri + req.route.path, { + method: 'DELETE', + }) + .then((r: any) => console.log(r)) + }; + await deleteRequest(); return response.ok({ body: { success: true,