diff --git a/run_tests.sh b/run_tests.sh index 61765b3..e8da042 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -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 && diff --git a/src/store/config/index.js b/src/store/config/index.js index 53b9a91..e793e63 100644 --- a/src/store/config/index.js +++ b/src/store/config/index.js @@ -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); diff --git a/tests/unit/mockData/alert/ruleDataIris.js b/tests/unit/mockData/alert/ruleDataIris.js new file mode 100644 index 0000000..639dd14 --- /dev/null +++ b/tests/unit/mockData/alert/ruleDataIris.js @@ -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 +`; diff --git a/tests/unit/mockData/alert/ruleDataIris002.js b/tests/unit/mockData/alert/ruleDataIris002.js new file mode 100644 index 0000000..b83df7c --- /dev/null +++ b/tests/unit/mockData/alert/ruleDataIris002.js @@ -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 +`; diff --git a/tests/unit/specs/alert/ConfigYamlIris.spec.js b/tests/unit/specs/alert/ConfigYamlIris.spec.js new file mode 100644 index 0000000..e71d703 --- /dev/null +++ b/tests/unit/specs/alert/ConfigYamlIris.spec.js @@ -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); + }); +}); diff --git a/tests/unit/specs/alert/ConfigYamlIris002.spec.js b/tests/unit/specs/alert/ConfigYamlIris002.spec.js new file mode 100644 index 0000000..784fd52 --- /dev/null +++ b/tests/unit/specs/alert/ConfigYamlIris002.spec.js @@ -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); + }); +});