Improve coding style conformation

refs #3446
This commit is contained in:
Jean Flach 2015-02-20 16:13:25 +01:00
parent 6455ef6b0a
commit 41f7ec9c8e

View File

@ -70,11 +70,13 @@ public:
Log(sev, "troubleshoot", str); Log(sev, "troubleshoot", str);
if (sev == LogCritical || sev == LogWarning) { if (sev == LogCritical || sev == LogWarning) {
*m_Stream << std::string(24, '#') << '\n' *m_Stream
<< "# " << str << '\n' << std::string(24, '#') << '\n'
<< std::string(24, '#') << '\n'; << "# " << str << '\n'
<< std::string(24, '#') << '\n';
} else } else
*m_Stream << str << '\n'; *m_Stream
<< str << '\n';
} }
bool GetStreamHealth(void) const bool GetStreamHealth(void) const
@ -114,7 +116,8 @@ private:
bool TroubleshootCollectCommand::GeneralInfo(InfoLog& log, const boost::program_options::variables_map& vm) bool TroubleshootCollectCommand::GeneralInfo(InfoLog& log, const boost::program_options::variables_map& vm)
{ {
InfoLogLine(log) << '\n' << std::string(14, '=') << " GENERAL INFORMATION " << std::string(14, '=') << '\n'; InfoLogLine(log)
<< '\n' << std::string(14, '=') << " GENERAL INFORMATION " << std::string(14, '=') << '\n';
//Application::DisplayInfoMessage() but formatted //Application::DisplayInfoMessage() but formatted
InfoLogLine(log) InfoLogLine(log)
@ -142,14 +145,16 @@ bool TroubleshootCollectCommand::FeatureInfo(InfoLog& log, const boost::program_
bool TroubleshootCollectCommand::ObjectInfo(InfoLog& log, const boost::program_options::variables_map& vm, Dictionary::Ptr& logs) bool TroubleshootCollectCommand::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'; InfoLogLine(log)
<< '\n' << std::string(14, '=') << " OBJECT INFORMATION " << std::string(14, '=') << '\n';
String objectfile = Application::GetObjectsPath(); String objectfile = Application::GetObjectsPath();
std::set<String> configs; std::set<String> configs;
if (!Utility::PathExists(objectfile)) { if (!Utility::PathExists(objectfile)) {
InfoLogLine(log, LogCritical) << "Cannot open object file '" << objectfile << "'.\n" InfoLogLine(log, LogCritical)
<< "FAILED: This probably means you have a fault configuration."; << "Cannot open object file '" << objectfile << "'.\n"
<< "FAILED: This probably means you have a fault configuration.";
return false; return false;
} else } else
CheckObjectFile(objectfile, log, vm.count("include-objects"), logs, configs); CheckObjectFile(objectfile, log, vm.count("include-objects"), logs, configs);
@ -159,7 +164,8 @@ bool TroubleshootCollectCommand::ObjectInfo(InfoLog& log, const boost::program_o
bool TroubleshootCollectCommand::ReportInfo(InfoLog& log, const boost::program_options::variables_map& vm, Dictionary::Ptr& logs) bool TroubleshootCollectCommand::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'; InfoLogLine(log)
<< '\n' << std::string(14, '=') << " LOGS AND CRASH REPORTS " << std::string(14, '=') << '\n';
PrintLoggers(log, logs); PrintLoggers(log, logs);
PrintCrashReports(log); PrintCrashReports(log);
@ -168,9 +174,12 @@ bool TroubleshootCollectCommand::ReportInfo(InfoLog& log, const boost::program_o
bool TroubleshootCollectCommand::ConfigInfo(InfoLog& log, const boost::program_options::variables_map& vm) bool TroubleshootCollectCommand::ConfigInfo(InfoLog& log, const boost::program_options::variables_map& vm)
{ {
InfoLogLine(log) << '\n' << std::string(14, '=') << " CONFIGURATION FILES " << std::string(14, '=') << '\n'; InfoLogLine(log)
<< '\n' << std::string(14, '=') << " CONFIGURATION FILES " << std::string(14, '=') << '\n';
InfoLogLine(log)
<< "A collection of important configuration files follows, please make sure to remove any sensitive data such as credentials, internal company names, etc";
InfoLogLine(log) << "A collection of important configuration files follows, please make sure to remove any sensitive data such as credentials, internal company names, etc";
if (!PrintConf(log, Application::GetSysconfDir() + "/icinga2/icinga2.conf")) { if (!PrintConf(log, Application::GetSysconfDir() + "/icinga2/icinga2.conf")) {
InfoLogLine(log, LogWarning) InfoLogLine(log, LogWarning)
<< "icinga2.conf not found, therefore skipping validation.\n" << "icinga2.conf not found, therefore skipping validation.\n"
@ -214,7 +223,7 @@ int TroubleshootCollectCommand::Tail(const String& file, int numLines, InfoLog&
text.close(); text.close();
InfoLogLine(log) InfoLogLine(log)
<< "[end: '" << file << "' line: " << lines << ']'; << "[end: '" << file << "' line: " << lines << ']';
return numLines; return numLines;
@ -245,11 +254,14 @@ bool TroubleshootCollectCommand::CheckFeatures(InfoLog& log)
<< "Disabled features:\n\t" << boost::algorithm::join(disabled_features, " ") << '\n'; << "Disabled features:\n\t" << boost::algorithm::join(disabled_features, " ") << '\n';
if (!features->Get("checker").ToBool()) if (!features->Get("checker").ToBool())
InfoLogLine(log, LogWarning) << "checker is disabled, no checks can be run from this instance"; InfoLogLine(log, LogWarning)
<< "checker is disabled, no checks can be run from this instance";
if (!features->Get("mainlog").ToBool()) if (!features->Get("mainlog").ToBool())
InfoLogLine(log, LogWarning) << "mainlog is disabled, please activate it and rerun icinga2"; InfoLogLine(log, LogWarning)
<< "mainlog is disabled, please activate it and rerun icinga2";
if (!features->Get("debuglog").ToBool()) if (!features->Get("debuglog").ToBool())
InfoLogLine(log, LogWarning) << "debuglog is disabled, please activate it and rerun icinga2"; InfoLogLine(log, LogWarning)
<< "debuglog is disabled, please activate it and rerun icinga2";
return true; return true;
} }
@ -291,16 +303,15 @@ bool TroubleshootCollectCommand::PrintCrashReports(InfoLog& log)
return false; return false;
} }
} }
InfoLogLine(log, LogWarning) InfoLogLine(log, LogWarning)
<< "Error printing crash reports"; << "Error printing crash reports";
return false; return false;
} }
#else #else
catch (...) { catch (...) {
InfoLogLine(log, LogWarning) InfoLogLine(log, LogWarning) << "Error printing crash reports.\n"
<< "Error printing crash reports.\nDoes " << "Does " << Application::GetLocalStateDir() << "/log/icinga2/crash/ exist?";
<< Application::GetLocalStateDir() << "/log/icinga2/crash/ exist?";
return false; return false;
} }
@ -328,11 +339,11 @@ bool TroubleshootCollectCommand::PrintConf(InfoLog& log, const String& path)
std::string line; std::string line;
InfoLogLine(log) InfoLogLine(log)
<< "\n[begin: '" << path << "']"; << "\n[begin: '" << path << "']";
while (std::getline(text, line)) { while (std::getline(text, line)) {
InfoLogLine(log) InfoLogLine(log)
<< '\t' << line; << '\t' << line;
} }
@ -504,9 +515,10 @@ int TroubleshootCollectCommand::Run(const boost::program_options::variables_map&
String appName = Utility::BaseName(Application::GetArgV()[0]); String appName = Utility::BaseName(Application::GetArgV()[0]);
double goTime = Utility::GetTime(); double goTime = Utility::GetTime();
InfoLogLine(*log) << appName << " -- Troubleshooting help:\n" InfoLogLine(*log)
<< "Should you run into problems with Icinga please add this file to your help request\n" << appName << " -- Troubleshooting help:\n"
<< "Began procedure at timestamp " << Convert::ToString(goTime) << '\n'; << "Should you run into problems with Icinga please add this file to your help request\n"
<< "Began procedure at timestamp " << Convert::ToString(goTime) << '\n';
if (appName.GetLength() > 3 && appName.SubStr(0, 3) == "lt-") if (appName.GetLength() > 3 && appName.SubStr(0, 3) == "lt-")
appName = appName.SubStr(3, appName.GetLength() - 3); appName = appName.SubStr(3, appName.GetLength() - 3);
@ -532,7 +544,8 @@ int TroubleshootCollectCommand::Run(const boost::program_options::variables_map&
<< "\nTook " << Convert::ToString(endTime - goTime) << " seconds\n"; << "\nTook " << Convert::ToString(endTime - goTime) << " seconds\n";
if (!vm.count("console")) { if (!vm.count("console")) {
std::cout << "\nFinished collection. See '" << path << "'\n"; std::cout
<< "\nFinished collection. See '" << path << "'\n";
} }
delete log; delete log;