
The current system_info plugin logs the system info for the last host in host_dirs rather than that of the active controller. It also does not capture the system info for all the nodes into its plugin output file. This update improves the system_info plugin as well implements the following improvements to rendering and substring handling improvements. 1. Improve system_info plugin capture and render. 2. Adds which controller was active at the time of the collect to the system info rendering output. 3. Improve report analysis rendering by displaying the full path to plugin and correlation files. 4. Adds string exclude support to the substring algorithm. This allows the generic string rearches like ERROR to be searched for and gathered while also allowing specific noise logs what are considered noise logs to be filtered out. 5. Create a separate SM errors substring plugin using the new exclude option. 6. Adds support for commented and empty lines in the plugins This allows for properly commented and formatted plugins. 7. Adds plugin label name error checking This allows esier debug of improperly coded plugins. 8. Fixed additional pep8 warnings. Test Plan: PASS: Verify on-system collect with --report option PASS: Verify on-system report generation PASS: Verify off-system report generation from git PASS: Verify system_info plugin collects info from all hosts PASS: Verify report displays system_info from active controller PASS: Verify handling when no active controller is detected PASS: Verify new sm_errors substring plugin with excludes PASS: Verify plugins can have empty or # commented lines PASS: Verify report tool plugins output include path to each plugin file PASS: Verify report tool correlations include path to each correlation file PASS: Verify report tool plugin label parsing error handling PASS: Verify all files pass pep8 without warning or error Story: 2010533 Task: 48072 Change-Id: I6d0253a4c3d8804a5e45b970d766e578ea69368f Signed-off-by: Eric MacDonald <eric.macdonald@windriver.com>
77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
########################################################################
|
|
#
|
|
# 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
|