Skip to content

Commit

Permalink
Fix #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Karql committed Jan 20, 2022
1 parent ba97fc0 commit 877bdc1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.4.1 (2022-01-20)

### Bug fixes
- Testing rules #9 (required [ElastAlert2 Server](https://github.com/Karql/elastalert2-server) in version >=5.0.0-next.4)

## 1.4.0 (2021-03-16)

### Features
Expand Down
4 changes: 2 additions & 2 deletions dev/dev-env/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:

# https://github.com/Karql/elastalert fork of bitsensor/elastalert
elastalert:
image: karql/elastalert2-server:5.0.0-next.2
image: karql/elastalert2-server:5.0.0-next.4
restart: always
expose:
- 3030
Expand All @@ -38,4 +38,4 @@ services:
- ./conf/elastalert/rule_templates:/opt/elastalert/rule_templates
- ./rules:/opt/elastalert/rules
links:
- "elasticsearch"
- "elasticsearch"
2 changes: 1 addition & 1 deletion dev/test-env/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:

# https://github.com/Karql/elastalert fork of bitsensor/elastalert
elastalert:
image: karql/elastalert2-server:5.0.0-next.2
image: karql/elastalert2-server:5.0.0-next.4
restart: always
expose:
- 3030
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elastalert-kibana-plugin",
"version": "1.4.0",
"version": "1.4.1",
"author": {
"name": "Mateusz Karkula",
"email": "[email protected]",
Expand Down
7 changes: 4 additions & 3 deletions public/components/console/console.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from 'react';
import { EuiCallOut } from '@elastic/eui';

export const Console = (hasError: boolean, consoleOutput: any) => (
export const Console = (props: { hasError: boolean, consoleOutput: string }) => (
<EuiCallOut
size="s"
title="Console output"
iconType="console"
color={hasError ? 'danger' : 'success'}
color={props.hasError ? 'danger' : 'success'}
style={{ whiteSpace: 'pre-wrap' }}

>
{consoleOutput}
{props.consoleOutput}
</EuiCallOut>
);
11 changes: 6 additions & 5 deletions public/components/rules/editor/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export default class Editor extends Component {
body: JSON.stringify({
rule: this.state.value,
options: {
testType: 'schemaOnly'
}
testType: 'all'
}
})
})
.then(resp => {
Expand All @@ -95,15 +95,16 @@ export default class Editor extends Component {
});
})
.catch(e => {
let body = e.body;
this.setState({
testing: false,
testFailed: true,
testResponse: e.message ? e.message : e,
testResponse: body.message ? body.message : body,
});
});
};

onChange = value => {
onChange = value => {
this.setState({ value: value });
};

Expand Down Expand Up @@ -158,7 +159,7 @@ export default class Editor extends Component {
}}
/>
<EuiSpacer size="m" />
{this.state.testResponse && (
{this.state.testResponse !== null && (
<Console
hasError={this.state.testFailed}
consoleOutput={this.state.testResponse}
Expand Down
21 changes: 11 additions & 10 deletions server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ConfigType } from '../config';
import fetch from 'node-fetch';

interface RegisterRoutesParams {
config$: Observable<ConfigType>;
config$: Observable<ConfigType>;
logger: Logger;
router: IRouter;
}
Expand Down Expand Up @@ -41,7 +41,7 @@ export const registerRoutes = (options: RegisterRoutesParams) => {
},
body: JSON.stringify(req.body),
};

const postRequest = async () => {
let url = (await getElastAlertServerUrl()) + `/rules/${req.params.ruleID}`;
logger.debug(`POST ${url}`);
Expand All @@ -54,6 +54,7 @@ export const registerRoutes = (options: RegisterRoutesParams) => {
};

const result = await postRequest();

return response.ok({
body: {
data: result,
Expand Down Expand Up @@ -83,21 +84,21 @@ export const registerRoutes = (options: RegisterRoutesParams) => {
},
body: JSON.stringify(req.body),
};

const postRequest = async () => {
let url = (await getElastAlertServerUrl()) + `/test`;
logger.debug(`POST ${url}`);
return fetch(url, postParams);
return fetch(url, postParams);
};

const result = await postRequest();
return response.ok({
body: {
data: result,
},

return response.custom({
statusCode: result.status,
body: result.body
});
}
);
);

router.get(
{
Expand All @@ -122,7 +123,7 @@ export const registerRoutes = (options: RegisterRoutesParams) => {
}
);

router.delete(
router.delete(
{
path: '/api/elastalert/rules/{ruleID}',
validate: {
Expand Down

0 comments on commit 877bdc1

Please sign in to comment.