Confdump Agent
1.4.0
|
00001 /* 00002 * Confdump-Agent - Dump static and runtime system configuration 00003 * Copyright (C) 2009-2012 Straton IT, SAS 00004 * 00005 * This program is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 3 as 00007 * published by the Free Software Foundation. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #include "boost/config.hpp" 00019 #include "boost/program_options.hpp" 00020 #include "boost/shared_ptr.hpp" 00021 #include "boost/foreach.hpp" 00022 00023 #include "QTextStream" 00024 00025 #include "Confdump/Options.hpp" 00026 #include "Confdump/Result.hpp" 00027 #include "Confdump/NoSuchTable.hpp" 00028 #include "Confdump/DataOutput.hpp" 00029 #include "Confdump/Formatter.hpp" 00030 #include "Confdump/DumperFactory.hpp" 00031 #include "Confdump/Dumper.hpp" 00032 00033 using namespace std; 00034 using namespace Confdump; 00035 using boost::shared_ptr; 00036 namespace po = boost::program_options; 00037 00038 int main( int argc, char* argv[] ) 00039 { 00040 QTextStream error( stderr ); // bypass cerr, buggy on RHEL4 00041 try { 00042 DumperFactory factory; 00043 Options options( argc, argv, cout ); 00044 factory.registerSpecifications( options.dumperSpecifications() ); 00045 DataOutput output; 00046 if ( !options.outputFile().isEmpty() ) 00047 output.setSink( options.outputFile() ); 00048 else 00049 output.setSink( stdout ); 00050 00051 switch ( options.operatingMode() ) 00052 { 00053 case Options::HelpTablesMode: 00054 BOOST_FOREACH( QString alias, factory.aliasList() ) 00055 { 00056 shared_ptr<Dumper> dumper = factory.dumper( alias ); 00057 BOOST_FOREACH( QString table, dumper->listTables() ) 00058 output.stream() << alias << "." << table << "\n"; 00059 } 00060 break; 00061 00062 case Options::NormalMode: 00063 if ( options.tables().empty() ) 00064 { 00065 error << "No tables specified, try --help for usage information." << endl; 00066 #if CD_WIN32 00067 error << "\nPress a key to continue..." << endl; 00068 getchar(); 00069 #endif 00070 } 00071 else 00072 { 00073 shared_ptr<Dumper> driver = factory.dumper( "main" ); 00074 shared_ptr<Formatter> fmt = output.createFormatter( options.outputFormat() ); 00075 00076 QString identifier; 00077 try { 00078 identifier = driver->computerIdentifier(); 00079 } 00080 catch ( std::exception ) 00081 { 00082 // Let the identifier default to the empty string if it 00083 // can't be queried. Until we can log, at least. 00084 } 00085 fmt->printHeader( identifier ); 00086 00087 BOOST_FOREACH( Options::TableList::value_type table, options.tables() ) 00088 { 00089 try { 00090 shared_ptr<Dumper> driver = factory.dumper( table.first ); 00091 fmt->printTable( table.second, driver->queryTable( table.second ) ); 00092 } 00093 catch ( NoSuchThing &e ) 00094 { 00095 cerr << e.what() << endl; 00096 } 00097 } 00098 00099 #if CD_UNIX 00100 fmt->printTable( "CD_ConfigurationFile", driver->queryTable( "CD_ConfigurationFile" ) ); 00101 #endif 00102 00103 fmt->printFooter(); 00104 } 00105 00106 break; 00107 00108 case Options::HelpMode: 00109 break; 00110 } 00111 00112 return 0; 00113 } 00114 catch ( exception& e ) 00115 { 00116 error << "error: " << e.what() << endl; 00117 return 1; 00118 } 00119 catch (...) 00120 { 00121 error << "Exception of unknown type!" << endl; 00122 return 1; 00123 } 00124 } 00125 00128 namespace Confdump 00129 { 00130 } 00131