Skip to content

Commit

Permalink
Add IRIS Alerter testcode
Browse files Browse the repository at this point in the history
  • Loading branch information
nsano-rururu committed Dec 26, 2023
1 parent 213944b commit 19c0760
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 1 deletion.
2 changes: 2 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
./node_modules/.bin/vue-cli-service test:unit tests/unit/specs/alert/ConfigYamlGitterOpt.spec.js &&
./node_modules/.bin/vue-cli-service test:unit tests/unit/specs/alert/ConfigYamlGoogleChat.spec.js &&
./node_modules/.bin/vue-cli-service test:unit tests/unit/specs/alert/ConfigYamlGoogleChat002.spec.js &&
./node_modules/.bin/vue-cli-service test:unit tests/unit/specs/alert/ConfigYamlIris.spec.js &&
./node_modules/.bin/vue-cli-service test:unit tests/unit/specs/alert/ConfigYamlIris002.spec.js &&
./node_modules/.bin/vue-cli-service test:unit tests/unit/specs/alert/ConfigYamlJira.spec.js &&
./node_modules/.bin/vue-cli-service test:unit tests/unit/specs/alert/ConfigYamlLark.spec.js &&
./node_modules/.bin/vue-cli-service test:unit tests/unit/specs/alert/ConfigYamlLineNotify.spec.js &&
Expand Down
2 changes: 1 addition & 1 deletion src/store/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export default {

commit('alert/UPDATE_IRIS_ALERT_TAGS', config.iris_alert_tags);

if (config.iris_type) {
if (config.iris_alert_status_id) {
commit('alert/UPDATE_IRIS_ALERT_STATUS_ID', config.iris_alert_status_id);
} else {
commit('alert/UPDATE_IRIS_ALERT_STATUS_ID', 2);
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/mockData/alert/ruleDataIris.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export const ruleYaml = `__praeco_query_builder: '{"query":{"logicalOperator":"all","children":[]}}'
alert:
- iris
alert_subject: this is a test subject
alert_subject_args: []
alert_text: this is a test body
alert_text_args: []
alert_text_type: alert_text_only
doc_type: syslog
filter:
- query:
query_string:
query: '@timestamp:*'
import: BaseRule.config
index: hannibal-*
iris_host: testserver
iris_api_token: abcdefghijklmnopqrstuvwxyz
is_enabled: false
name: test123
num_events: 10000
query_key: beat.hostname
realert:
minutes: 5
timeframe:
minutes: 5
timestamp_field: '@timestamp'
timestamp_type: iso
type: frequency
use_count_query: true
use_strftime_index: false
`;
43 changes: 43 additions & 0 deletions tests/unit/mockData/alert/ruleDataIris002.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export const ruleYaml = `__praeco_query_builder: '{"query":{"logicalOperator":"all","children":[]}}'
alert:
- iris
alert_subject: this is a test subject
alert_subject_args: []
alert_text: this is a test body
alert_text_args: []
alert_text_type: alert_text_only
doc_type: syslog
filter:
- query:
query_string:
query: '@timestamp:*'
import: BaseRule.config
index: hannibal-*
iris_alert_note: a
iris_alert_severity_id: 2
iris_alert_source_link: b
iris_alert_status_id: 3
iris_alert_tags: c
iris_api_token: abcdefghijklmnopqrstuvwxyz
iris_ca_cert: true
iris_case_template_id: 5
iris_customer_id: 4
iris_description: d
iris_host: testserver
iris_ignore_ssl_errors: true
iris_overwrite_timestamp: true
iris_type: case
is_enabled: false
name: test123
num_events: 10000
query_key: beat.hostname
realert:
minutes: 5
timeframe:
minutes: 5
timestamp_field: '@timestamp'
timestamp_type: iso
type: frequency
use_count_query: true
use_strftime_index: false
`;
54 changes: 54 additions & 0 deletions tests/unit/specs/alert/ConfigYamlIris.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { expect } from 'chai';
import store from '@/store';
import { mockAxios } from '../../setup';
import { ruleYaml } from '../../mockData/alert/ruleDataIris.js';

mockAxios.onGet('/api/rules/test123').reply(200, { yaml: ruleYaml });

describe('Iris YAML parsing', () => {
it('renders the correct yaml', async () => {
await store.dispatch('config/load', { type: 'rules', path: 'test123' });

let yaml = store.getters['config/yaml']();

let expected = `__praeco_full_path: "test123"
__praeco_query_builder: "{\\"query\\":{\\"logicalOperator\\":\\"all\\",\\"children\\":[]}}"
alert:
- "iris"
alert_subject: "this is a test subject"
alert_text: "this is a test body"
alert_text_type: "alert_text_only"
doc_type: "syslog"
filter:
- query:
query_string:
query: "@timestamp:*"
generate_kibana_discover_url: false
import: "BaseRule.config"
index: "hannibal-*"
iris_alert_severity_id: 1
iris_alert_status_id: 2
iris_api_token: "abcdefghijklmnopqrstuvwxyz"
iris_host: "testserver"
iris_type: "alert"
is_enabled: false
match_enhancements: []
name: "test123"
num_events: 10000
query_key:
- "beat.hostname"
realert:
minutes: 5
terms_size: 50
timeframe:
minutes: 5
timestamp_field: "@timestamp"
timestamp_type: "iso"
type: "frequency"
use_count_query: true
use_strftime_index: false
`;

return expect(yaml).to.equal(expected);
});
});
63 changes: 63 additions & 0 deletions tests/unit/specs/alert/ConfigYamlIris002.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { expect } from 'chai';
import store from '@/store';
import { mockAxios } from '../../setup.js';
import { ruleYaml } from '../../mockData/alert/ruleDataIris002.js';

mockAxios.onGet('/api/rules/test123').reply(200, { yaml: ruleYaml });

describe('Iris 002 YAML parsing', () => {
it('renders the correct yaml', async () => {
await store.dispatch('config/load', { type: 'rules', path: 'test123' });

let yaml = store.getters['config/yaml']();

let expected = `__praeco_full_path: "test123"
__praeco_query_builder: "{\\"query\\":{\\"logicalOperator\\":\\"all\\",\\"children\\":[]}}"
alert:
- "iris"
alert_subject: "this is a test subject"
alert_text: "this is a test body"
alert_text_type: "alert_text_only"
doc_type: "syslog"
filter:
- query:
query_string:
query: "@timestamp:*"
generate_kibana_discover_url: false
import: "BaseRule.config"
index: "hannibal-*"
iris_alert_note: "a"
iris_alert_severity_id: 2
iris_alert_source_link: "b"
iris_alert_status_id: 3
iris_alert_tags: "c"
iris_api_token: "abcdefghijklmnopqrstuvwxyz"
iris_ca_cert: true
iris_case_template_id: 5
iris_customer_id: 4
iris_description: "d"
iris_host: "testserver"
iris_ignore_ssl_errors: true
iris_overwrite_timestamp: true
iris_type: "case"
is_enabled: false
match_enhancements: []
name: "test123"
num_events: 10000
query_key:
- "beat.hostname"
realert:
minutes: 5
terms_size: 50
timeframe:
minutes: 5
timestamp_field: "@timestamp"
timestamp_type: "iso"
type: "frequency"
use_count_query: true
use_strftime_index: false
`;

return expect(yaml).to.equal(expected);
});
});

0 comments on commit 19c0760

Please sign in to comment.