Skip to content

Commit

Permalink
Add some helper tools for viewing saved summaries
Browse files Browse the repository at this point in the history
  • Loading branch information
dosaboy committed Mar 28, 2024
1 parent 241c70c commit 875ab93
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 2 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ dependencies = {file = ["requirements.txt"]}

[project.scripts]
hotsos = "hotsos.cli:main"
hotsos-view = "hotsos.tools.summary.view:main"
Empty file added tools/__init__.py
Empty file.
Empty file added tools/summary/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions tools/summary/diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
#
# Description: diff two hotsos summary outputs.
#
src=${1:-""}
dst=${2:-""}
format={3:-yaml}
if [[ -z $src ]] || [[ -z $dst ]]; then
echo "USAGE: `basename $0` <src dir> <dst dir>"
exit
fi

for f in `find $src -maxdepth 1 -name *summary.${format}`; do
diff -y $dst/$f $f| less
done
12 changes: 12 additions & 0 deletions tools/summary/issues-and-bugs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
#
# Description: display only bugs and issues from summary outputs.
#
path=${1:-hotsos-output}
for f in `find $path -maxdepth 1 -name *summary.json`; do
clear
jq -r '"\nHostname: " + .system.hostname,
"Issues:", (.[]|to_entries[]|select(.key=="potential-issues")|.value|to_entries[]|.key, .value),
"Bugs:", (.[]|to_entries[]|select(.key=="known-bugs")|.value|to_entries[]|.key, .value)' $f
read -p "Next? [ENTER]"
done
8 changes: 8 additions & 0 deletions tools/summary/less
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
#
# Description: less each hotsos summary in path
#
path=${1:-hotsos-output}
for f in `find $path -maxdepth 1 -name *summary.yaml`; do
less $f
done
64 changes: 64 additions & 0 deletions tools/summary/view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python3
"""
Create a structured summary of key information from hotsos summary outputs.
"""
import glob
import os
import json
import sys
import subprocess

from hotsos.core import plugintools


if __name__ == "__main__":
if len(sys.argv) > 1:
path = os.path.join(sys.argv[1], '*.json')
else:
path = '*.json'

for f in glob.glob(path):
with open(f) as fd:
subprocess.call(['clear'])
s = json.loads(fd.read())
print("host: {} ".format(s['system']['hostname']))
print("date: {}".format(s['system']['date']))
_enabled = []
_services = {}
_has_bugs = {}
_has_potential_issues = {}
for plugin in plugintools.PLUGINS:
if plugin in s:
_enabled.append(plugin)
if 'services' in s[plugin]:
enabled = s[plugin]['services']
enabled = enabled.get('systemd', {})
_services[plugin] = enabled.get('enabled')

if 'known-bugs' in s[plugin]:
_has_bugs.update(s[plugin]['known-bugs'])

if 'potential-issues' in s[plugin]:
_has_potential_issues.update(
s[plugin]['potential-issues'])

# print("enabled: {}".format(', '.join(sorted(_enabled))))
print("services:")
for plugin, svcs in _services.items():
print(" {}: {}".format(plugin, ', '.join(svcs)))

if _has_bugs:
print("bugs:")
for btype, content in _has_bugs.items():
print(" {}: {}\n".format(btype, '\n'.join(content)))

if _has_potential_issues:
print("issues:")
for btype, content in _has_potential_issues.items():
print(" {}:".format(btype))
for msg in content:
print(" {}".format(msg))

input("\nNext? [ENTER]")

print("")
10 changes: 8 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ setenv = VIRTUAL_ENV={envdir}
TERM=linux
HOTSOS_ROOT={toxinidir}/hotsos
TESTS_DIR={[testenv]unit_tests}
PYFILES={toxinidir}/setup.py {toxinidir}/hotsos/ {[testenv]unit_tests}
PYFILES={toxinidir}/setup.py {toxinidir}/hotsos/ \
{[testenv]unit_tests} \
{toxinidir}/tools
non-utc-tz: TZ=EST+5
deps =
-r{toxinidir}/requirements.txt
Expand Down Expand Up @@ -50,7 +52,11 @@ commands = pylint -v --rcfile={toxinidir}/pylintrc {posargs:{env:PYFILES}}

[testenv:bashate]
allowlist_externals = bashate
commands = bashate --verbose {toxinidir}/build.sh {toxinidir}/tools/test/functest.sh
commands = bashate --verbose {toxinidir}/build.sh \
{toxinidir}/tools/test/functest.sh \
{toxinidir}/tools/summary/diff \
{toxinidir}/tools/summary/less \
{toxinidir}/tools/summary/issues-and-bugs

[testenv:functional]
allowlist_externals = bash
Expand Down

0 comments on commit 875ab93

Please sign in to comment.