-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(generate):generation of html files for alerts
- Loading branch information
1 parent
f0c4044
commit 4db6be8
Showing
22 changed files
with
117 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 0 additions & 95 deletions
95
splunk_add_on_ucc_framework/commands/modular_alert_builder/alert_actions_html_gen.py
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
...cc_framework/commands/modular_alert_builder/arf_template/default_html_theme/default2.html
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...cc_framework/commands/modular_alert_builder/arf_template/default_html_theme/default3.html
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
splunk_add_on_ucc_framework/generators/html_files/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .html_generator import HTMLGenerator | ||
from .create_alert_html import AlertHtml | ||
|
||
__all__ = ["HTMLGenerator", "AlertHtml"] |
66 changes: 66 additions & 0 deletions
66
splunk_add_on_ucc_framework/generators/html_files/create_alert_html.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from splunk_add_on_ucc_framework.generators.html_files import HTMLGenerator | ||
from splunk_add_on_ucc_framework.global_config import GlobalConfig | ||
from splunk_add_on_ucc_framework.commands.modular_alert_builder import ( | ||
arf_consts as ac, | ||
normalize, | ||
) | ||
from typing import Dict, Any | ||
from os import linesep | ||
from re import search | ||
|
||
|
||
class AlertHtml(HTMLGenerator): | ||
__description__ = ( | ||
" Generates `alert_name.html` file based on alerts configuration present in globalConfig" | ||
" in `default/data/ui/alerts` folder." | ||
) | ||
|
||
def __init__( | ||
self, | ||
global_config: GlobalConfig, | ||
input_dir: str, | ||
output_dir: str, | ||
**kwargs: Dict[str, Any], | ||
) -> None: | ||
super().__init__(global_config, input_dir, output_dir, **kwargs) | ||
|
||
def _set_attributes(self, **kwargs: Dict[str, Any]) -> None: | ||
if self._global_config and self._global_config.has_alerts(): | ||
self._html_home = "alert_html_skeleton.template" | ||
envs = normalize.normalize( | ||
self._global_config.alerts, | ||
self._global_config.namespace, | ||
) | ||
schema_content = envs["schema.content"] | ||
self._alert_settings = schema_content["modular_alerts"] | ||
for self.alert in self._alert_settings: | ||
self.generate_html() | ||
|
||
def generate_html(self) -> Dict[str, str]: | ||
if self._global_config and not self._global_config.has_alerts(): | ||
return super().generate_html() | ||
self.set_template_and_render( | ||
template_file_path=["html_templates"], file_name="mod_alert.html.template" | ||
) | ||
rendered_content = self._template.render( | ||
mod_alert=self.alert, home_page=self._html_home | ||
) | ||
text = linesep.join( | ||
[s for s in rendered_content.splitlines() if not search(r"^\s*$", s)] | ||
) | ||
file_name = f"{self.alert[ac.SHORT_NAME] + '.html'}" | ||
file_path = self.get_file_output_path( | ||
[ | ||
"default", | ||
"data", | ||
"ui", | ||
"alerts", | ||
file_name, | ||
] | ||
) | ||
self.writer( | ||
file_name=file_name, | ||
file_path=file_path, | ||
content=text, | ||
) | ||
return {file_name: file_path} |
31 changes: 31 additions & 0 deletions
31
splunk_add_on_ucc_framework/generators/html_files/html_generator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from ..file_generator import FileGenerator | ||
from typing import Dict, Any, Union, NoReturn | ||
from splunk_add_on_ucc_framework.global_config import GlobalConfig | ||
|
||
|
||
class HTMLGenerator(FileGenerator): | ||
__description__ = "DESCRIBE THE HTML FILE THAT IS GENERATED" | ||
|
||
def __init__( | ||
self, | ||
global_config: GlobalConfig, | ||
input_dir: str, | ||
output_dir: str, | ||
**kwargs: Dict[str, Any] | ||
) -> None: | ||
super().__init__(global_config, input_dir, output_dir, **kwargs) | ||
|
||
def generate(self) -> Dict[str, str]: | ||
html_files: Dict[str, str] = {} | ||
html_files.update(self.generate_html()) | ||
return html_files | ||
|
||
def _set_attributes(self, **kwargs: Any) -> Union[NoReturn, None]: | ||
# parse self._global_config and set the require attributes for self | ||
raise NotImplementedError() | ||
|
||
def generate_html(self) -> Dict[str, str]: | ||
# uses the attributes set in _set_attributes method to set the required attributes | ||
# uses set_template_and_render to load and render the HTML template. | ||
# use self.writer function to create the html file. | ||
return {"": ""} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
tests/unit/commands/modular_alert_builder/test_alert_actions_html_gen.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters