Skip to content

Commit

Permalink
refactor: move file-based modular alert default conf settings
Browse files Browse the repository at this point in the history
There is no reason to keep those settings in the file and read file
every time  we need to create modular alerts. This PR refactors it
the way configuration is now stored in the Python code which should
simplify the development and testing.
  • Loading branch information
artemrys committed Aug 18, 2021
1 parent e2590f3 commit 5f4337b
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 31 deletions.
1 change: 0 additions & 1 deletion .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ header:
- "splunk_add_on_ucc_framework/templates/*"
- "splunk_add_on_ucc_framework/arf_dir_templates/modular_alert_package.settings"
- "splunk_add_on_ucc_framework/modular_alert_builder/build_core/arf_template/**"
- "splunk_add_on_ucc_framework/modular_alert_builder/build_core/alert_actions_conf_default_settings.json"
- "tests/**"
- ".*"

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import json
import os
from json import loads as jloads
from os import linesep
from os import path as op

Expand Down Expand Up @@ -98,7 +97,6 @@ def get_icon_path(self, alert, create_dir_path=True):
class AlertActionsConfGeneration(AlertActionsConfBase):
DEFAULT_CONF_TEMPLATE = "alert_actions.conf.template"
DEFAULT_SPEC_TEMPLATE = "alert_actions.conf.spec.template"
DEFAULT_SETTINGS_FILE = "alert_actions_conf_default_settings.json"
DEFAULT_EVENTTYPES_TEMPLATE = "eventtypes.conf.template"
DEFAULT_TAGS_TEMPLATE = "tags.conf.template"

Expand Down Expand Up @@ -126,10 +124,11 @@ def __init__(
ac.PARAMETERS,
]
self._remove_fields = [ac.SHORT_NAME] + self._html_fields
self._default_settings_file = default_settings_file or op.join(
op.dirname(op.abspath(__file__)),
AlertActionsConfGeneration.DEFAULT_SETTINGS_FILE,
)
self._default_conf_settings = {
"python.version": "python3",
"is_custom": 1,
"payload_format": "json",
}
self._output = {}

def generate_conf(self):
Expand Down Expand Up @@ -300,13 +299,10 @@ def handle(self):
self.generate_tags()

def add_default_settings(self):
with open(self._default_settings_file) as df:
default_settings = jloads(df.read())

for alert in self._alert_settings:
if ac.ALERT_PROPS not in list(alert.keys()):
alert[ac.ALERT_PROPS] = {}
for k, v in list(default_settings.items()):
for k, v in list(self._default_conf_settings.items()):
if k in list(alert[ac.ALERT_PROPS].keys()):
continue

Expand Down
5 changes: 0 additions & 5 deletions tests/unit/test_alert_actions_conf_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ def test_generate_alert_action(self):
},
},
],
"alert_props": {
"python.version": "python3",
"is_custom": 1,
"payload_format": "json",
},
}
],
},
Expand Down
5 changes: 0 additions & 5 deletions tests/unit/test_alert_actions_html_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ def test_generate_alert_action(self):
},
},
],
"alert_props": {
"python.version": "python3",
"is_custom": 1,
"payload_format": "json",
},
}
],
},
Expand Down
5 changes: 0 additions & 5 deletions tests/unit/test_alert_actions_py_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ def test_generate_alert_action(self):
},
},
],
"alert_props": {
"python.version": "python3",
"is_custom": 1,
"payload_format": "json",
},
}
],
},
Expand Down

0 comments on commit 5f4337b

Please sign in to comment.