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

Replace/rename hb_report as crm report #883

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
10 changes: 5 additions & 5 deletions .github/workflows/crmsh-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ jobs:
run: |
tox -v

functional_test_hb_report_bugs:
functional_test_crm_report_bugs:
runs-on: ubuntu-latest
timeout-minutes: 40
steps:
- uses: actions/checkout@v2
- name: functional test for hb_report
- name: functional test for crm_report
run: |
$DOCKER_SCRIPT hb_report before_install
$DOCKER_SCRIPT hb_report run bugs
$DOCKER_SCRIPT crm_report before_install
$DOCKER_SCRIPT crm_report run bugs

functional_test_bootstrap_bugs:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -169,7 +169,7 @@ jobs:

delivery:
needs: [unit_test,
functional_test_hb_report_bugs,
functional_test_crm_report_bugs,
functional_test_bootstrap_bugs,
functional_test_bootstrap_common,
functional_test_bootstrap_options,
Expand Down
7 changes: 1 addition & 6 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ crmconf_DATA = etc/crm.conf etc/profiles.yml
contribdir = $(docdir)/contrib
contrib_DATA = contrib/pcmk.vim contrib/README.vimsyntax
helpdir = $(datadir)/$(PACKAGE)
asciiman = doc/crm.8.adoc doc/crmsh_hb_report.8.adoc doc/profiles.adoc
asciiman = doc/crm.8.adoc doc/crmsh_crm_report.8.adoc doc/profiles.adoc
help_DATA = doc/crm.8.adoc

generated_docs =
Expand All @@ -55,11 +55,6 @@ install-data-hook:
mv $(DESTDIR)$(datadir)/@PACKAGE@/test $(DESTDIR)$(datadir)/@PACKAGE@/tests; \
cp test/testcases/xmlonly.sh $(DESTDIR)$(datadir)/@PACKAGE@/tests/testcases/configbasic-xml.filter

hanoarchdir = $(datadir)/@PACKAGE@/hb_report
hanoarch_DATA = hb_report/constants.py hb_report/utillib.py hb_report/collect.py
hanoarch_SCRIPTS = hb_report/hb_report
EXTRA_DIST = $(hanoarch_DATA)

# Python module installation
all-local:
(cd $(srcdir); $(PYTHON) setup.py build \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ included in the repository.
./test: unit tests and regression tests
./contrib: vim highlighting scripts and other semi-related
contributions
./hb_report: log file collection and analysis tool
./crm report: log file collection and analysis tool
```

## Development
Expand Down
1 change: 0 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ AC_PATH_PROGS(ASCIIDOC, asciidoc)
AM_CONDITIONAL(BUILD_ASCIIDOC, test x"${ASCIIDOC}" != x"")

AC_CONFIG_FILES(Makefile \
hb_report/hb_report \
etc/crm.conf \
version \
crmsh.spec \
Expand Down
2 changes: 1 addition & 1 deletion crmsh.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ result2=$?
%{crmsh_docdir}/COPYING
%{crmsh_docdir}/AUTHORS
%{crmsh_docdir}/crm.8.html
%{crmsh_docdir}/crmsh_hb_report.8.html
%{crmsh_docdir}/crmsh_crm_report.8.html
%{crmsh_docdir}/profiles.html
%{crmsh_docdir}/ChangeLog
%{crmsh_docdir}/README.md
Expand Down
8 changes: 5 additions & 3 deletions crmsh/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,12 @@ def get(self, value):
'from_time': opt_string('-12H'),
'compress': opt_boolean('yes'),
'speed_up': opt_boolean('no'),
'collect_extra_logs': opt_string('/var/log/messages /var/log/pacemaker/pacemaker.log /var/log/pacemaker.log /var/log/crmsh/crmsh.log'),
'collect_extra_logs': opt_string('/var/log/messages /var/log/pacemaker/pacemaker.log \
/var/log/pacemaker.log /var/log/crmsh/crmsh.log /etc/crm/profiles.yml /etc/crm/crm.conf'),
'remove_exist_dest': opt_boolean('no'),
'single_node': opt_boolean('no'),
'sanitize_rule': opt_string('passw.*')
'sanitize_rule': opt_string('passw.*'),
'verbosity': opt_string('0')
}
}

Expand Down Expand Up @@ -370,7 +372,7 @@ def get(self, section, name, raw=False):
return DEFAULTS[section][name].get(self.get_impl(section, name))

def set(self, section, name, value):
if section not in ('core', 'path', 'color'):
if section not in ('core', 'path', 'color', 'report'):
raise ValueError("Setting invalid section " + str(section))
if not self._defaults.has_option(section, name):
raise ValueError("Setting invalid option %s.%s" % (section, name))
Expand Down
19 changes: 7 additions & 12 deletions crmsh/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@


#
# hb_report interface
# crm report interface
#
# read hb_report generated report, show interesting stuff, search
# read crm report generated report, show interesting stuff, search
# through logs, get PE input files, get log slices (perhaps even
# coloured nicely!)
#
Expand Down Expand Up @@ -122,9 +122,9 @@ def mkarchive(idir):

class Report(object):
'''
A hb_report class.
A crm report class.
'''
live_recent = 6*60*60 # recreate live hb_report once every 6 hours
live_recent = 6*60*60 # recreate live crm report once every 6 hours
short_live_recent = 60 # update once a minute
nodecolors = ("NORMAL",
"GREEN",
Expand Down Expand Up @@ -191,7 +191,7 @@ def session_list(self):

def unpack_report(self, tarball):
'''
Unpack hb_report tarball.
Unpack crm report tarball.
Don't unpack if the directory already exists!
'''
bfname = os.path.basename(tarball)
Expand Down Expand Up @@ -458,12 +458,7 @@ def new_live_report(self):
'''
Run the report command to get logs now.
'''
from . import ui_report

extcmd = ui_report.report_tool()
if extcmd is None:
self.error("No reporting tool found")
return None
extcmd = "crm report"

d = self._live_loc()
if not utils.is_path_sane(d):
Expand Down Expand Up @@ -559,7 +554,7 @@ def set_node_colors(self):

def _report_setup_source(self):
constants.pcmk_version = None
# is this an hb_report or a crm_report?
# is this an crm report or a crm_report?
for descname in ("description.txt", "report.summary"):
self.desc = os.path.join(self.loc, descname)
if os.path.isfile(self.desc):
Expand Down
54 changes: 47 additions & 7 deletions crmsh/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ class ConsoleCustomFormatter(logging.Formatter):
FORMAT = "%(levelname)s: %(message)s"
FORMAT_RAW = "%(message)s"

def __init__(self, lineno=-1, raw_msg=False):
def __init__(self, lineno=-1, raw_msg=False, fmt=None):
self.lineno = lineno
if raw_msg:
if fmt:
super().__init__(fmt=fmt)
elif raw_msg:
super().__init__(fmt=self.FORMAT_RAW)
else:
super().__init__(fmt=self.FORMAT)
Expand All @@ -67,6 +69,16 @@ def format(self, record):
return super().format(record)


class ConsoleReportFormatter(ConsoleCustomFormatter):
"""
Custom formatter for crm report
"""
FORMAT_REPORT = "{}: %(levelname)s: %(message)s".format(socket.gethostname())

def __init__(self):
super().__init__(fmt=self.FORMAT_REPORT)


class FileCustomFormatter(logging.Formatter):
"""
A custom formatter for file
Expand All @@ -83,9 +95,11 @@ class DebugCustomFilter(logging.Filter):
A custom filter for debug message
"""
def filter(self, record):
from .config import core, report
if record.levelname == "DEBUG":
from .config import core
return core.debug
return core.debug or int(report.verbosity) >= 1
if record.levelname == "DEBUG2":
return int(report.verbosity) > 1
else:
return True

Expand All @@ -94,6 +108,9 @@ def filter(self, record):
"version": 1,
"disable_existing_loggers": "False",
"formatters": {
"console_report": {
"()": ConsoleReportFormatter
},
"console": {
"()": ConsoleCustomFormatter
},
Expand All @@ -110,6 +127,11 @@ def filter(self, record):
'null': {
'class': 'logging.NullHandler'
},
"console_report": {
"()": ConsoleCustomHandler,
"formatter": "console_report",
"filters": ["filter"]
},
"console": {
"()": ConsoleCustomHandler,
"formatter": "console",
Expand Down Expand Up @@ -139,8 +161,8 @@ def filter(self, record):
"propagate": False,
"level": "DEBUG"
},
"hb_report": {
"handlers": ["null", "file", "console"],
"crmsh.report": {
"handlers": ["null", "file", "console_report"],
"propagate": False,
"level": "DEBUG"
}
Expand All @@ -163,6 +185,14 @@ def __init__(self, logger):
self.lineno = 0
self.__save_lineno = 0

def set_debug2_level(self):
"""
Create DEBUG2 level for verbosity
"""
logging.DEBUG2 = logging.DEBUG + 5
logging.addLevelName(logging.DEBUG2, "DEBUG2")
self.logger.debug2 = lambda msg, *args: self.logger._log(logging.DEBUG2, msg, args)

def get_handler(self, _type):
"""
Get logger specific handler
Expand Down Expand Up @@ -200,7 +230,7 @@ def incr_lineno(self):
"""
self.lineno += 1
self.set_console_formatter(self.lineno)

@contextmanager
def suppress_new_line(self):
"""
Expand Down Expand Up @@ -421,3 +451,13 @@ def setup_logger(name):
logger.handlers = logger.parent.handlers
logger.propagate = False
return logger


def setup_report_logger(name):
"""
Get the logger for crm report
"""
logger = setup_logger(name)
logger_utils = LoggerUtils(logger)
logger_utils.set_debug2_level()
return logger
File renamed without changes.
23 changes: 12 additions & 11 deletions hb_report/collect.py → crmsh/report/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import pwd
import datetime

sys.path.append(os.path.dirname(os.path.realpath(__file__)))

import constants
import utillib
from crmsh import log
from crmsh import utils as crmutils
from crmsh.report import constants, utillib


logger = log.setup_report_logger(__name__)


def collect_ocfs2_info():
Expand Down Expand Up @@ -52,7 +53,7 @@ def collect_ratraces():
trace_dir = os.path.join(constants.HA_VARLIB, "trace_ra")
if not os.path.isdir(trace_dir):
return
utillib.log_debug("looking for RA trace files in %s" % trace_dir)
logger.debug("looking for RA trace files in %s", trace_dir)
flist = []
for f in utillib.find_files(trace_dir, constants.FROM_TIME, constants.TO_TIME):
dest_dir = os.path.join(constants.WORKDIR, '/'.join(f.split('/')[-3:-1]))
Expand Down Expand Up @@ -140,7 +141,7 @@ def collect_backtraces():
flist = [f for f in cores if "core" in os.path.basename(f)]
if flist:
utillib.print_core_backtraces(flist)
utillib.log_debug("found backtraces: %s" % ' '.join(flist))
logger.debug("found backtraces: %s", ' '.join(flist))


def collect_config():
Expand Down Expand Up @@ -178,7 +179,7 @@ def collect_pe_inputs():
to_time = constants.TO_TIME
work_dir = constants.WORKDIR
pe_dir = constants.PE_STATE_DIR
utillib.log_debug("looking for PE files in %s in %s" % (pe_dir, constants.WE))
logger.debug("looking for PE files in %s in %s", pe_dir, constants.WE)

flist = []
for f in utillib.find_files(pe_dir, from_time, to_time):
Expand All @@ -191,16 +192,16 @@ def collect_pe_inputs():
utillib._mkdir(flist_dir)
for f in flist:
os.symlink(f, os.path.join(flist_dir, os.path.basename(f)))
utillib.log_debug("found %d pengine input files in %s" % (len(flist), pe_dir))
logger.debug("found %d pengine input files in %s", len(flist), pe_dir)

if len(flist) <= 20:
if not constants.SKIP_LVL:
for f in flist:
utillib.pe_to_dot(os.path.join(flist_dir, os.path.basename(f)))
else:
utillib.log_debug("too many PE inputs to create dot files")
logger.debug("too many PE inputs to create dot files")
else:
utillib.log_debug("Nothing found for the giving time")
logger.debug("Nothing found for the giving time")


def collect_sbd_info():
Expand Down Expand Up @@ -256,7 +257,7 @@ def collect_sys_info():
out_string += "Kernel release: %s\n" % os.uname()[2]
out_string += "Architecture: %s\n" % os.uname()[-1]
if os.uname()[0] == "Linux":
out_string += "Distribution: %s\n" % utillib.distro()
out_string += "Distribution: %s\n" % utillib.get_distro_info()

sys_info_f = os.path.join(constants.WORKDIR, constants.SYSINFO_F)
crmutils.str2file(out_string, sys_info_f)
2 changes: 1 addition & 1 deletion hb_report/constants.py → crmsh/report/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,5 @@
TIME_F = "time.txt"
OCFS2_F = "ocfs2.txt"
SBD_F = "sbd.txt"

OSRELEASE = "/etc/os-release"
# vim:ts=4:sw=4:et:
Loading