From a28685d139881d9a89afa52766b3d87d7c53b4f6 Mon Sep 17 00:00:00 2001 From: Jean-Marcel Flach Date: Wed, 25 Feb 2015 09:51:31 +0100 Subject: [PATCH] Rename troubleshootCollectCommand to troubleshootCommand --- lib/cli/CMakeLists.txt | 2 +- ...ectcommand.cpp => troubleshootcommand.cpp} | 55 ++++++++++--------- ...ectcommand.hpp => troubleshootcommand.hpp} | 12 ++-- 3 files changed, 36 insertions(+), 33 deletions(-) rename lib/cli/{troubleshootcollectcommand.cpp => troubleshootcommand.cpp} (87%) rename lib/cli/{troubleshootcollectcommand.hpp => troubleshootcommand.hpp} (92%) diff --git a/lib/cli/CMakeLists.txt b/lib/cli/CMakeLists.txt index abf51041a..052822c09 100644 --- a/lib/cli/CMakeLists.txt +++ b/lib/cli/CMakeLists.txt @@ -27,7 +27,7 @@ set(cli_SOURCES pkiutility.cpp repositoryclearchangescommand.cpp repositorycommitcommand.cpp repositoryobjectcommand.cpp repositoryutility.cpp variablegetcommand.cpp variablelistcommand.cpp variableutility.cpp - troubleshootcollectcommand.cpp + troubleshootcommand.cpp ) if(ICINGA2_UNITY_BUILD) diff --git a/lib/cli/troubleshootcollectcommand.cpp b/lib/cli/troubleshootcommand.cpp similarity index 87% rename from lib/cli/troubleshootcollectcommand.cpp rename to lib/cli/troubleshootcommand.cpp index fe396480c..c69669812 100644 --- a/lib/cli/troubleshootcollectcommand.cpp +++ b/lib/cli/troubleshootcommand.cpp @@ -17,7 +17,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "cli/troubleshootcollectcommand.hpp" +#include "cli/troubleshootcommand.hpp" #include "cli/objectlistutility.hpp" #include "cli/featureutility.hpp" #include "cli/daemonutility.hpp" @@ -37,19 +37,19 @@ using namespace icinga; namespace po = boost::program_options; -REGISTER_CLICOMMAND("troubleshoot/collect", TroubleshootCollectCommand); +REGISTER_CLICOMMAND("troubleshoot", TroubleshootCommand); -String TroubleshootCollectCommand::GetDescription(void) const +String TroubleshootCommand::GetDescription(void) const { return "Collect logs and other relevant information for troubleshooting purposes."; } -String TroubleshootCollectCommand::GetShortDescription(void) const +String TroubleshootCommand::GetShortDescription(void) const { return "Collect information for troubleshooting"; } -class TroubleshootCollectCommand::InfoLog +class TroubleshootCommand::InfoLog { public: InfoLog(const String& path, const bool cons) @@ -89,7 +89,7 @@ private: std::ostream *m_Stream; }; -class TroubleshootCollectCommand::InfoLogLine +class TroubleshootCommand::InfoLogLine { public: InfoLogLine(InfoLog& log, LogSeverity sev = LogInformation) @@ -114,7 +114,7 @@ private: }; -bool TroubleshootCollectCommand::GeneralInfo(InfoLog& log, const boost::program_options::variables_map& vm) +bool TroubleshootCommand::GeneralInfo(InfoLog& log, const boost::program_options::variables_map& vm) { InfoLogLine(log) << '\n' << std::string(14, '=') << " GENERAL INFORMATION " << std::string(14, '=') << '\n'; @@ -136,14 +136,14 @@ bool TroubleshootCollectCommand::GeneralInfo(InfoLog& log, const boost::program_ return true; } -bool TroubleshootCollectCommand::FeatureInfo(InfoLog& log, const boost::program_options::variables_map& vm) +bool TroubleshootCommand::FeatureInfo(InfoLog& log, const boost::program_options::variables_map& vm) { - TroubleshootCollectCommand::CheckFeatures(log); + TroubleshootCommand::CheckFeatures(log); //TODO Check whether active faetures are operational. return true; } -bool TroubleshootCollectCommand::ObjectInfo(InfoLog& log, const boost::program_options::variables_map& vm, Dictionary::Ptr& logs) +bool TroubleshootCommand::ObjectInfo(InfoLog& log, const boost::program_options::variables_map& vm, Dictionary::Ptr& logs) { InfoLogLine(log) << '\n' << std::string(14, '=') << " OBJECT INFORMATION " << std::string(14, '=') << '\n'; @@ -162,7 +162,7 @@ bool TroubleshootCollectCommand::ObjectInfo(InfoLog& log, const boost::program_o return true; } -bool TroubleshootCollectCommand::ReportInfo(InfoLog& log, const boost::program_options::variables_map& vm, Dictionary::Ptr& logs) +bool TroubleshootCommand::ReportInfo(InfoLog& log, const boost::program_options::variables_map& vm, Dictionary::Ptr& logs) { InfoLogLine(log) << '\n' << std::string(14, '=') << " LOGS AND CRASH REPORTS " << std::string(14, '=') << '\n'; @@ -172,7 +172,7 @@ bool TroubleshootCollectCommand::ReportInfo(InfoLog& log, const boost::program_o return true; } -bool TroubleshootCollectCommand::ConfigInfo(InfoLog& log, const boost::program_options::variables_map& vm) +bool TroubleshootCommand::ConfigInfo(InfoLog& log, const boost::program_options::variables_map& vm) { InfoLogLine(log) << '\n' << std::string(14, '=') << " CONFIGURATION FILES " << std::string(14, '=') << '\n'; @@ -197,7 +197,7 @@ bool TroubleshootCollectCommand::ConfigInfo(InfoLog& log, const boost::program_o } /*Print the last *numLines* of *file* to *os* */ -int TroubleshootCollectCommand::Tail(const String& file, int numLines, InfoLog& log) +int TroubleshootCommand::Tail(const String& file, int numLines, InfoLog& log) { boost::circular_buffer ringBuf(numLines); std::ifstream text; @@ -215,6 +215,9 @@ int TroubleshootCollectCommand::Tail(const String& file, int numLines, InfoLog& if (lines < numLines) numLines = lines; + + InfoLogLine(log) + << "[begin: '" << file << "' line: " << numLines-lines << ']'; for (int k = 0; k < numLines; k++) { InfoLogLine(log) @@ -229,7 +232,7 @@ int TroubleshootCollectCommand::Tail(const String& file, int numLines, InfoLog& return numLines; } -bool TroubleshootCollectCommand::CheckFeatures(InfoLog& log) +bool TroubleshootCommand::CheckFeatures(InfoLog& log) { Dictionary::Ptr features = new Dictionary; std::vector disabled_features; @@ -266,7 +269,7 @@ bool TroubleshootCollectCommand::CheckFeatures(InfoLog& log) return true; } -void TroubleshootCollectCommand::GetLatestReport(const String& filename, time_t& bestTimestamp, String& bestFilename) +void TroubleshootCommand::GetLatestReport(const String& filename, time_t& bestTimestamp, String& bestFilename) { #ifdef _WIN32 struct _stat buf; @@ -283,7 +286,7 @@ void TroubleshootCollectCommand::GetLatestReport(const String& filename, time_t& } } -bool TroubleshootCollectCommand::PrintCrashReports(InfoLog& log) +bool TroubleshootCommand::PrintCrashReports(InfoLog& log) { String spath = Application::GetLocalStateDir() + "/log/icinga2/crash/report.*"; time_t bestTimestamp = 0; @@ -330,7 +333,7 @@ bool TroubleshootCollectCommand::PrintCrashReports(InfoLog& log) return true; } -bool TroubleshootCollectCommand::PrintConf(InfoLog& log, const String& path) +bool TroubleshootCommand::PrintConf(InfoLog& log, const String& path) { std::ifstream text; text.open(path.CStr(), std::ifstream::in); @@ -340,7 +343,7 @@ bool TroubleshootCollectCommand::PrintConf(InfoLog& log, const String& path) std::string line; InfoLogLine(log) - << "\n[begin: '" << path << "']"; + << "[begin: '" << path << "']"; while (std::getline(text, line)) { InfoLogLine(log) @@ -348,12 +351,12 @@ bool TroubleshootCollectCommand::PrintConf(InfoLog& log, const String& path) } InfoLogLine(log) - << "\n[end: '" << path << "']"; + << "[end: '" << path << "']"; return true; } -bool TroubleshootCollectCommand::CheckConfig(void) +bool TroubleshootCommand::CheckConfig(void) { /* Not loading the icinga library would make config validation fail. * (Depending on the configuration and the speed of your machine.) @@ -365,7 +368,7 @@ bool TroubleshootCollectCommand::CheckConfig(void) return DaemonUtility::ValidateConfigFiles(configs, Application::GetObjectsPath()); } -void TroubleshootCollectCommand::CheckObjectFile(const String& objectfile, InfoLog& log, const bool print, +void TroubleshootCommand::CheckObjectFile(const String& objectfile, InfoLog& log, const bool print, Dictionary::Ptr& logs, std::set& configs) { InfoLogLine(log) @@ -443,7 +446,7 @@ void TroubleshootCollectCommand::CheckObjectFile(const String& objectfile, InfoL } } -void TroubleshootCollectCommand::PrintLoggers(InfoLog& log, Dictionary::Ptr& logs) +void TroubleshootCommand::PrintLoggers(InfoLog& log, Dictionary::Ptr& logs) { if (!logs->GetLength()) { InfoLogLine(log, LogWarning) @@ -455,7 +458,7 @@ void TroubleshootCollectCommand::PrintLoggers(InfoLog& log, Dictionary::Ptr& log ObjectLock ulock(logs); BOOST_FOREACH(const Dictionary::Pair& kv, logs) { InfoLogLine(log) - << "\nLogger " << kv.first << " at path: " << kv.second; + << "Logger " << kv.first << " at path: " << kv.second; if (!Tail(kv.second, 20, log)) { InfoLogLine(log, LogWarning) @@ -465,7 +468,7 @@ void TroubleshootCollectCommand::PrintLoggers(InfoLog& log, Dictionary::Ptr& log } } -void TroubleshootCollectCommand::PrintConfig(InfoLog& log, const std::set& configSet, const String::SizeType& countTotal) +void TroubleshootCommand::PrintConfig(InfoLog& log, const std::set& configSet, const String::SizeType& countTotal) { InfoLogLine(log) << countTotal << " objects in total, originating from these files:"; @@ -476,7 +479,7 @@ void TroubleshootCollectCommand::PrintConfig(InfoLog& log, const std::set& ap) const +int TroubleshootCommand::Run(const boost::program_options::variables_map& vm, const std::vector& ap) const { String path; InfoLog *log; diff --git a/lib/cli/troubleshootcollectcommand.hpp b/lib/cli/troubleshootcommand.hpp similarity index 92% rename from lib/cli/troubleshootcollectcommand.hpp rename to lib/cli/troubleshootcommand.hpp index e108fcfef..9934795d8 100644 --- a/lib/cli/troubleshootcollectcommand.hpp +++ b/lib/cli/troubleshootcommand.hpp @@ -17,8 +17,8 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#ifndef TROUBLESHOOTCOLLECTCOMMAND_H -#define TROUBLESHOOTCOLLECTCOMMAND_H +#ifndef TROUBLESHOOTCOMMAND_H +#define TROUBLESHOOTCOMMAND_H #include "cli/clicommand.hpp" #include "base/i2-base.hpp" @@ -28,14 +28,14 @@ namespace icinga { /** - * The "troubleshoot collect" command. + * The "troubleshoot" command. * * @ingroup cli */ -class TroubleshootCollectCommand : public CLICommand +class TroubleshootCommand : public CLICommand { public: - DECLARE_PTR_TYPEDEFS(TroubleshootCollectCommand); + DECLARE_PTR_TYPEDEFS(TroubleshootCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; @@ -67,4 +67,4 @@ private: }; } -#endif /* TROUBLESHOOTCOLLECTCOMMAND_H */ +#endif /* TROUBLESHOOTCOMMAND_H */