Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor visualization scripts to include indexer stats plots #5518

Merged
merged 20 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.

### Added

- Added the capability to plot indexed alerts and vulnerabilities. ([#5518](https://github.com/wazuh/wazuh-qa/pull/5518)) \- (Framework)
- Add functionality to unify data of the binary processes with their subprocesses to plot ([#5500](https://github.com/wazuh/wazuh-qa/pull/5500)) \- (Framework)

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
]
},
"alerts_info": {
"title": "Alerts and events info.",
"title": "Alerts and events info",
"columns": [
"Events processed", "Events received", "Written alerts", "Written firewall", "Written fts"
"Events processed", "Events received", "Written alerts", "Written firewall", "Written fts",
"Written archives", "Written stats"
]
}
}
63 changes: 53 additions & 10 deletions deps/wazuh_testing/wazuh_testing/scripts/data_visualizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,46 @@
from os.path import exists
from tempfile import gettempdir

from wazuh_testing.tools.performance.visualization import DataVisualizer
from wazuh_testing.tools.performance.visualization import (
BinaryDatavisualizer,
ClusterStatisticsVisualizer,
DaemonStatisticsVisualizer,
IndexerAlerts,
IndexerVulnerabilities,
LogcollectorStatisticsVisualizer,
)

supported_targets = ['binary', 'analysis', 'remote', 'wazuhdb', 'logcollector',
'cluster', 'indexer-alerts',
'indexer-vulnerabilities']
daemon_supported_statistics = ['analysis', 'remote', 'wazuhdb']
strategy_plot_by_target = {
'binary': BinaryDatavisualizer,
'daemon-statistics': DaemonStatisticsVisualizer,
'cluster': ClusterStatisticsVisualizer,
'logcollector': LogcollectorStatisticsVisualizer,
'indexer-alerts': IndexerAlerts,
'indexer-vulnerabilities': IndexerVulnerabilities
}


def create_destination_directory(destination_directory):
if not exists(destination_directory):
makedirs(destination_directory)


def validate_arguments(options):
if options.visualization_target != 'binary' and options.unify:
raise ValueError('Unify option is not allowed for non binary data plotting')


def get_script_arguments():
parser = argparse.ArgumentParser(usage="%(prog)s [options]", description="Script to generate data visualizations",
parser = argparse.ArgumentParser(usage='%(prog)s [options]', description='Script to generate data visualizations',
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('-s', '--sources', dest='csv_list', required=True, type=str, nargs='+', action='store',
help='Paths to the CSV files separated by whitespace.')
parser.add_argument('-t', '--target', dest='visualization_target', default='binary',
choices=['binary', 'analysis', 'remote', 'agent', 'logcollector', 'cluster', 'api', 'wazuhdb'],
choices=supported_targets,
help='Generate data visualizations for a specific target. Default binary.')
parser.add_argument('-d', '--destination', dest='destination', default=gettempdir(),
help=f'Directory to store the images. Default {gettempdir()}')
Expand All @@ -21,20 +51,33 @@ def get_script_arguments():
parser.add_argument('-c', '--columns', dest='columns', default=None,
help=f'Path to Json with Columns to Plot. Default {None}.')
parser.add_argument('-u', '--unify', dest='unify', action='store_true',
help=f'Unify data of the binary processes with their subprocesses to plot.')
help='Unify data of the binary processes with their subprocesses to plot.')

return parser.parse_args()


def main():
options = get_script_arguments()
destination = options.destination
create_destination_directory(options.destination)

target = options.visualization_target
validate_arguments(options)

visualization_options = {
'dataframes': options.csv_list,
'store_path': options.destination,
'base_name': options.name
}

strategy = target
if target in daemon_supported_statistics:
visualization_options['daemon'] = target
strategy = 'daemon-statistics'
elif target == 'binary':
visualization_options['unify_child_daemon_metrics'] = options.unify

dv = strategy_plot_by_target[strategy](**visualization_options)

if not exists(destination):
makedirs(destination)
dv = DataVisualizer(dataframes=options.csv_list, target=options.visualization_target,
compare=False, store_path=options.destination, base_name=options.name,
columns_path=options.columns, unify_child_daemon_metrics=options.unify)
dv.plot()


Expand Down
Loading
Loading