From 7298dc2320ff8b18b16acfb66a06c328c786dd87 Mon Sep 17 00:00:00 2001 From: Adriana Kobylak Date: Tue, 24 Jan 2017 12:21:50 -0600 Subject: logging: Commit: Use transaction id and metadata lookup Add the lookup mako target to the makefile to get it built. Use the lookup map to find the metadata that needs to be added to the error log. Use the transaction id to filter for the desired journal entries. Signed-off-by: Adriana Kobylak Change-Id: Ia57dc83aab4f7ee35f8de32a799c862be28113f7 --- Makefile.am | 13 +++++--- configure.ac | 3 ++ log_manager.cpp | 36 ++++++++++++---------- .../templates/elog-lookup-template.mako.cpp | 4 +-- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/Makefile.am b/Makefile.am index 49c54f0..8487a74 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,10 +14,12 @@ phosphor_log_manager_SOURCES = \ log_manager.cpp \ log_manager_main.cpp -# Be sure to build elog-gen.hpp before compiling -BUILT_SOURCES = elog-gen.hpp +# Be sure to build needed files before compiling +BUILT_SOURCES = elog-gen.hpp elog-lookup.cpp -CLEANFILES=elog-gen.hpp +CLEANFILES = \ + elog-gen.hpp \ + elog-lookup.cpp # systemd required for journal interfaces logging_test_LDFLAGS = $(SYSTEMD_LIBS) $(SDBUSPLUS_LIBS) @@ -26,6 +28,7 @@ phosphor_log_manager_LDFLAGS = $(SYSTEMD_LIBS) $(SDBUSPLUS_LIBS) phosphor_log_manager_CXXFLAGS = $(SYSTEMD_CFLAGS) $(SDBUSPLUS_CFLAGS) ELOG_MAKO ?= elog-gen-template.mako.hpp +LOOKUP_MAKO ?= elog-lookup-template.mako.cpp ELOG_YAML_DIR ?= tools/example/xyz/openbmc_project/Example/ ELOG_TEMPLATE_DIR ?= tools/phosphor-logging/templates/ REQ_FILES_TO_GEN ?= ${abs_srcdir}/tools/elog-gen.py\ @@ -37,6 +40,8 @@ REQ_FILES_TO_GEN ?= ${abs_srcdir}/tools/elog-gen.py\ EXTRA_DIST = $(REQ_FILES_TO_GEN) elog-gen.hpp: $(REQ_FILES_TO_GEN) - $(AM_V_at)${abs_srcdir}/tools/elog-gen.py -y ${abs_srcdir}/${ELOG_YAML_DIR} -t ${abs_srcdir}/${ELOG_TEMPLATE_DIR} -m $(ELOG_MAKO) -o ${abs_srcdir}/elog-gen.hpp + $(AM_V_at)$(PYTHON) ${abs_srcdir}/tools/elog-gen.py -y ${abs_srcdir}/${ELOG_YAML_DIR} -t ${abs_srcdir}/${ELOG_TEMPLATE_DIR} -m $(ELOG_MAKO) -o ${abs_srcdir}/elog-gen.hpp +elog-lookup.cpp: $(REQ_FILES_TO_GEN) + $(AM_V_at)$(PYTHON) ${abs_srcdir}/tools/elog-gen.py -y ${abs_srcdir}/${ELOG_YAML_DIR} -t ${abs_srcdir}/${ELOG_TEMPLATE_DIR} -m $(LOOKUP_MAKO) -o ${abs_srcdir}/elog-lookup.cpp SUBDIRS = test diff --git a/configure.ac b/configure.ac index 4d47f3b..7d0ce66 100644 --- a/configure.ac +++ b/configure.ac @@ -12,6 +12,9 @@ AX_CXX_COMPILE_STDCXX_14([noext]) AX_APPEND_COMPILE_FLAGS([-fpic -Wall -Werror], [CXXFLAGS]) AC_PROG_INSTALL #Checks/sets the install variable to be used AC_PROG_MAKE_SET +# Python +AM_PATH_PYTHON([2.7], [AC_SUBST([PYTHON], [echo "$PYTHON"])], [AC_MSG_ERROR( + [Could not find python-2.7 installed...python-2.7 is required])]) # Surpress the --with-libtool-sysroot error LT_INIT diff --git a/log_manager.cpp b/log_manager.cpp index a3e49e9..06beaa6 100644 --- a/log_manager.cpp +++ b/log_manager.cpp @@ -6,6 +6,7 @@ #include #include #include +#include "elog-lookup.cpp" #include "log.hpp" #include "log_manager.hpp" @@ -18,7 +19,7 @@ void Manager::commit(uint64_t transactionId, std::string errMsg) { // TODO Change /tmp path to a permanent location on flash constexpr const auto path = "/tmp/elog"; - constexpr const auto msgIdStr = "_PID"; + constexpr const auto transactionIdVar = "TRANSACTION_ID"; // Create log file std::string filename{}; @@ -29,9 +30,6 @@ void Manager::commit(uint64_t transactionId, std::string errMsg) efile.open(filename); efile << "{" << std::endl; - //const char* metaVar = nullptr; - std::vector metaList; - sd_journal *j = nullptr; int rc = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); if (rc < 0) @@ -41,6 +39,9 @@ void Manager::commit(uint64_t transactionId, std::string errMsg) return; } + std::string transactionIdStr = std::to_string(transactionId); + std::vector metalist = g_errMetaMap[errMsg]; + // Read the journal from the end to get the most recent entry first. // The result from the sd_journal_get_data() is of the form VARIABLE=value. SD_JOURNAL_FOREACH_BACKWARDS(j) @@ -48,24 +49,23 @@ void Manager::commit(uint64_t transactionId, std::string errMsg) const char *data = nullptr; size_t length = 0; - // Search for the msg id - rc = sd_journal_get_data(j, msgIdStr, (const void **)&data, &length); + // Look for the transaction id metadata variable + rc = sd_journal_get_data(j, transactionIdVar, (const void **)&data, + &length); if (rc < 0) { - // Instance not found, continue to next journal entry + // This journal entry does not have the transaction id, + // continue to next entry continue; } + std::string result(data); -// TODO String msgid is now an int transaction id. This piece will be -// uncommented and reworked with the upcoming change to read the metadata -// fields from the header file. -#if 0 - if (result.find(msgid) == std::string::npos) + if (result.find(transactionIdStr) == std::string::npos) { - // Match not found, continue to next journal entry + // Requested transaction id not found, + // continue to next journal entry. continue; } -#endif // Match found, write to file // TODO This is a draft format based on the redfish event logs written // in json, the final openbmc format is to be determined @@ -81,14 +81,15 @@ void Manager::commit(uint64_t transactionId, std::string errMsg) efile << "\t\"@" << data << "\"," << std::endl; // Search for the metadata variables in the current journal entry - for (auto i : metaList) + for (auto metaVarStr : metalist) { - rc = sd_journal_get_data(j, i, (const void **)&data, &length); + rc = sd_journal_get_data(j, metaVarStr.c_str(), + (const void **)&data, &length); if (rc < 0) { // Not found, continue to next metadata variable logging::log("Failed to find metadata", - logging::entry("META_FIELD=%s", i)); + logging::entry("META_FIELD=%s", metaVarStr.c_str())); continue; } @@ -136,3 +137,4 @@ void Manager::run() noexcept } // namespace logging } // namepsace phosphor + diff --git a/tools/phosphor-logging/templates/elog-lookup-template.mako.cpp b/tools/phosphor-logging/templates/elog-lookup-template.mako.cpp index be4ff96..e53067a 100644 --- a/tools/phosphor-logging/templates/elog-lookup-template.mako.cpp +++ b/tools/phosphor-logging/templates/elog-lookup-template.mako.cpp @@ -1,9 +1,7 @@ ## Note that this file is not auto generated, it is what generates the -## elog-lookup.hpp file +## elog-lookup.cpp file // This file was autogenerated. Do not edit! // See elog-gen.py for more details -#pragma once - #include #include -- cgit v1.2.1