
A recent update introduced an empty file (__init__.py) in the plugins folder which was causing report traceback failures for off system runs. Also the current handling of the --plugin option is broken. The fix to that issue lead to a few additional more general plugin handling improvements. Test Plan: PASS: Verify ignore handling of empty plugin files. PASS: Verify all python file permissions set to executable on fresh pull in git and after on-system package install. PASS: Verify all plugin file permissions are not executable on fresh pull in git and after on-system package install. PASS: Verify general handling of the --plugin option with space delimited plugins that follow. PASS: Verify correlator is not run if there is no plugin data to correlate. PASS: Verify missing plugin output log files do not lead to a file not found error on the console. PASS: Verify refactored plugin search handling success and error paths. PASS: Verify refactored plugin search handling finds and adds built-in and localhost plugins with and without the --plugin option specified. PASS: Verify that previous plugin data is removed prior to a rerun of the tool. This is helpful for localhost plugin development. PASS: Verify handling of adding multiple plugins that span both built-in and localhost locations. PASS: Verify handling of missing plugin(s) when specified with the --plugin option. Regression: PASS: Verify collector package build and passes tox. PASS: Verify both on-system and off-system Report handling. PASS: Verify collect all using --report option PASS: Verify logging with and without --debug option. PASS: Verify no pep8 errors or warnings. Story: 2010533 Task: 48433 Task: 48432 Task: 48443 Change-Id: I42616daad2de6b0785f11736ef20b11e19f19869 Signed-off-by: Eric MacDonald <eric.macdonald@windriver.com>
77 lines
2.4 KiB
Python
Executable File
77 lines
2.4 KiB
Python
Executable File
########################################################################
|
|
#
|
|
# Copyright (c) 2022 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
########################################################################
|
|
#
|
|
# This file contains the functions for the audit plugin algorithm.
|
|
#
|
|
# The audit plugin algorithm counts the audit events found in dcmanager
|
|
# within a specific date range.
|
|
#
|
|
########################################################################
|
|
|
|
from datetime import datetime
|
|
import shutil
|
|
import subprocess
|
|
|
|
|
|
def audit(start, end, audit_log_path):
|
|
"""Counts audit events, like "Trigger load audit", in dcmanager within a
|
|
specified date range
|
|
|
|
Parameters:
|
|
start (string) : start date in YYYY-MM-DD HH:MM:SS format
|
|
end (string) : end date in YYYY-MM-DD HH:MM:SS format
|
|
audit_log_path (string) : absolute path of augit log file
|
|
"""
|
|
if not shutil.which("lnav"):
|
|
raise ValueError("Lnav program not found")
|
|
|
|
SECONDS_PER_HOUR = 3600
|
|
fmt = "%Y-%m-%d %H:%M:%S"
|
|
|
|
d1 = datetime.strptime(start, fmt)
|
|
d2 = datetime.strptime(end, fmt)
|
|
seconds = (d2 - d1).total_seconds()
|
|
|
|
log_texts = [
|
|
"Triggered subcloud audit%",
|
|
"Trigger patch audit%",
|
|
"Trigger load audit%",
|
|
"Triggered firmware audit%",
|
|
"Triggered kubernetes audit%",
|
|
# Counts sum of audits from all subclouds
|
|
]
|
|
INDEX_MIDDLE_WORD = 1
|
|
data = [("These rates and totals represent the sum of audits " +
|
|
"from all subclouds")]
|
|
|
|
def command(text):
|
|
|
|
return (
|
|
f'lnav -R -n -c ";SELECT count(log_body) AS '
|
|
f'{text.split(" ")[INDEX_MIDDLE_WORD]}_total from '
|
|
f'openstack_log WHERE '
|
|
f'(log_time > \\"{start}\\" AND not log_time > \\"{end}\\")'
|
|
f' AND log_body like \\"{text}\\"" "{audit_log_path}"'
|
|
)
|
|
|
|
for text in log_texts:
|
|
p = subprocess.Popen(command(text), shell=True,
|
|
stdout=subprocess.PIPE)
|
|
for line in p.stdout:
|
|
line = line.decode("utf-8").strip()
|
|
if line.isnumeric():
|
|
data.append(
|
|
f"rate "
|
|
f"{round((int(line)/seconds * SECONDS_PER_HOUR), 3)} "
|
|
f"per hour. total: {line}"
|
|
)
|
|
else:
|
|
data.append(line)
|
|
|
|
return data
|