Rename troubleshootCollectCommand to troubleshootCommand

This commit is contained in:
Jean-Marcel Flach 2015-02-25 09:51:31 +01:00
parent a6f29e0f64
commit a28685d139
3 changed files with 36 additions and 33 deletions

View File

@ -27,7 +27,7 @@ set(cli_SOURCES
pkiutility.cpp pkiutility.cpp
repositoryclearchangescommand.cpp repositorycommitcommand.cpp repositoryobjectcommand.cpp repositoryutility.cpp repositoryclearchangescommand.cpp repositorycommitcommand.cpp repositoryobjectcommand.cpp repositoryutility.cpp
variablegetcommand.cpp variablelistcommand.cpp variableutility.cpp variablegetcommand.cpp variablelistcommand.cpp variableutility.cpp
troubleshootcollectcommand.cpp troubleshootcommand.cpp
) )
if(ICINGA2_UNITY_BUILD) if(ICINGA2_UNITY_BUILD)

View File

@ -17,7 +17,7 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * * 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/objectlistutility.hpp"
#include "cli/featureutility.hpp" #include "cli/featureutility.hpp"
#include "cli/daemonutility.hpp" #include "cli/daemonutility.hpp"
@ -37,19 +37,19 @@
using namespace icinga; using namespace icinga;
namespace po = boost::program_options; 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."; 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"; return "Collect information for troubleshooting";
} }
class TroubleshootCollectCommand::InfoLog class TroubleshootCommand::InfoLog
{ {
public: public:
InfoLog(const String& path, const bool cons) InfoLog(const String& path, const bool cons)
@ -89,7 +89,7 @@ private:
std::ostream *m_Stream; std::ostream *m_Stream;
}; };
class TroubleshootCollectCommand::InfoLogLine class TroubleshootCommand::InfoLogLine
{ {
public: public:
InfoLogLine(InfoLog& log, LogSeverity sev = LogInformation) 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) InfoLogLine(log)
<< '\n' << std::string(14, '=') << " GENERAL INFORMATION " << std::string(14, '=') << '\n'; << '\n' << std::string(14, '=') << " GENERAL INFORMATION " << std::string(14, '=') << '\n';
@ -136,14 +136,14 @@ bool TroubleshootCollectCommand::GeneralInfo(InfoLog& log, const boost::program_
return true; 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. //TODO Check whether active faetures are operational.
return true; 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) InfoLogLine(log)
<< '\n' << std::string(14, '=') << " OBJECT INFORMATION " << std::string(14, '=') << '\n'; << '\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; 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) InfoLogLine(log)
<< '\n' << std::string(14, '=') << " LOGS AND CRASH REPORTS " << std::string(14, '=') << '\n'; << '\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; 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) InfoLogLine(log)
<< '\n' << std::string(14, '=') << " CONFIGURATION FILES " << std::string(14, '=') << '\n'; << '\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* */ /*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<std::string> ringBuf(numLines); boost::circular_buffer<std::string> ringBuf(numLines);
std::ifstream text; std::ifstream text;
@ -215,6 +215,9 @@ int TroubleshootCollectCommand::Tail(const String& file, int numLines, InfoLog&
if (lines < numLines) if (lines < numLines)
numLines = lines; numLines = lines;
InfoLogLine(log)
<< "[begin: '" << file << "' line: " << numLines-lines << ']';
for (int k = 0; k < numLines; k++) { for (int k = 0; k < numLines; k++) {
InfoLogLine(log) InfoLogLine(log)
@ -229,7 +232,7 @@ int TroubleshootCollectCommand::Tail(const String& file, int numLines, InfoLog&
return numLines; return numLines;
} }
bool TroubleshootCollectCommand::CheckFeatures(InfoLog& log) bool TroubleshootCommand::CheckFeatures(InfoLog& log)
{ {
Dictionary::Ptr features = new Dictionary; Dictionary::Ptr features = new Dictionary;
std::vector<String> disabled_features; std::vector<String> disabled_features;
@ -266,7 +269,7 @@ bool TroubleshootCollectCommand::CheckFeatures(InfoLog& log)
return true; 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 #ifdef _WIN32
struct _stat buf; 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.*"; String spath = Application::GetLocalStateDir() + "/log/icinga2/crash/report.*";
time_t bestTimestamp = 0; time_t bestTimestamp = 0;
@ -330,7 +333,7 @@ bool TroubleshootCollectCommand::PrintCrashReports(InfoLog& log)
return true; return true;
} }
bool TroubleshootCollectCommand::PrintConf(InfoLog& log, const String& path) bool TroubleshootCommand::PrintConf(InfoLog& log, const String& path)
{ {
std::ifstream text; std::ifstream text;
text.open(path.CStr(), std::ifstream::in); text.open(path.CStr(), std::ifstream::in);
@ -340,7 +343,7 @@ bool TroubleshootCollectCommand::PrintConf(InfoLog& log, const String& path)
std::string line; std::string line;
InfoLogLine(log) InfoLogLine(log)
<< "\n[begin: '" << path << "']"; << "[begin: '" << path << "']";
while (std::getline(text, line)) { while (std::getline(text, line)) {
InfoLogLine(log) InfoLogLine(log)
@ -348,12 +351,12 @@ bool TroubleshootCollectCommand::PrintConf(InfoLog& log, const String& path)
} }
InfoLogLine(log) InfoLogLine(log)
<< "\n[end: '" << path << "']"; << "[end: '" << path << "']";
return true; return true;
} }
bool TroubleshootCollectCommand::CheckConfig(void) bool TroubleshootCommand::CheckConfig(void)
{ {
/* Not loading the icinga library would make config validation fail. /* Not loading the icinga library would make config validation fail.
* (Depending on the configuration and the speed of your machine.) * (Depending on the configuration and the speed of your machine.)
@ -365,7 +368,7 @@ bool TroubleshootCollectCommand::CheckConfig(void)
return DaemonUtility::ValidateConfigFiles(configs, Application::GetObjectsPath()); 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<String>& configs) Dictionary::Ptr& logs, std::set<String>& configs)
{ {
InfoLogLine(log) 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()) { if (!logs->GetLength()) {
InfoLogLine(log, LogWarning) InfoLogLine(log, LogWarning)
@ -455,7 +458,7 @@ void TroubleshootCollectCommand::PrintLoggers(InfoLog& log, Dictionary::Ptr& log
ObjectLock ulock(logs); ObjectLock ulock(logs);
BOOST_FOREACH(const Dictionary::Pair& kv, logs) { BOOST_FOREACH(const Dictionary::Pair& kv, logs) {
InfoLogLine(log) InfoLogLine(log)
<< "\nLogger " << kv.first << " at path: " << kv.second; << "Logger " << kv.first << " at path: " << kv.second;
if (!Tail(kv.second, 20, log)) { if (!Tail(kv.second, 20, log)) {
InfoLogLine(log, LogWarning) InfoLogLine(log, LogWarning)
@ -465,7 +468,7 @@ void TroubleshootCollectCommand::PrintLoggers(InfoLog& log, Dictionary::Ptr& log
} }
} }
void TroubleshootCollectCommand::PrintConfig(InfoLog& log, const std::set<String>& configSet, const String::SizeType& countTotal) void TroubleshootCommand::PrintConfig(InfoLog& log, const std::set<String>& configSet, const String::SizeType& countTotal)
{ {
InfoLogLine(log) InfoLogLine(log)
<< countTotal << " objects in total, originating from these files:"; << countTotal << " objects in total, originating from these files:";
@ -476,7 +479,7 @@ void TroubleshootCollectCommand::PrintConfig(InfoLog& log, const std::set<String
} }
} }
void TroubleshootCollectCommand::InitParameters(boost::program_options::options_description& visibleDesc, void TroubleshootCommand::InitParameters(boost::program_options::options_description& visibleDesc,
boost::program_options::options_description& hiddenDesc) const boost::program_options::options_description& hiddenDesc) const
{ {
visibleDesc.add_options() visibleDesc.add_options()
@ -486,7 +489,7 @@ void TroubleshootCollectCommand::InitParameters(boost::program_options::options_
; ;
} }
int TroubleshootCollectCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const int TroubleshootCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
{ {
String path; String path;
InfoLog *log; InfoLog *log;

View File

@ -17,8 +17,8 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/ ******************************************************************************/
#ifndef TROUBLESHOOTCOLLECTCOMMAND_H #ifndef TROUBLESHOOTCOMMAND_H
#define TROUBLESHOOTCOLLECTCOMMAND_H #define TROUBLESHOOTCOMMAND_H
#include "cli/clicommand.hpp" #include "cli/clicommand.hpp"
#include "base/i2-base.hpp" #include "base/i2-base.hpp"
@ -28,14 +28,14 @@ namespace icinga
{ {
/** /**
* The "troubleshoot collect" command. * The "troubleshoot" command.
* *
* @ingroup cli * @ingroup cli
*/ */
class TroubleshootCollectCommand : public CLICommand class TroubleshootCommand : public CLICommand
{ {
public: public:
DECLARE_PTR_TYPEDEFS(TroubleshootCollectCommand); DECLARE_PTR_TYPEDEFS(TroubleshootCommand);
virtual String GetDescription(void) const; virtual String GetDescription(void) const;
virtual String GetShortDescription(void) const; virtual String GetShortDescription(void) const;
@ -67,4 +67,4 @@ private:
}; };
} }
#endif /* TROUBLESHOOTCOLLECTCOMMAND_H */ #endif /* TROUBLESHOOTCOMMAND_H */