Changeset 440c0cb in nscp


Ignore:
Timestamp:
04/05/12 07:16:26 (14 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
682ccd2
Parents:
acc2c60
Message:
  • Fixed issue with empty filters in active eventlog
  • Resolved some issues with loggingin default set to debug.
  • Fixed so --debug actually works
  • Added --log-to-file and set "nscp test" to not log to file.
  • Fixed typo related to allow arguments option
  • Added levels to comment for log level in config.
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • changelog

    r8d89d7a r440c0cb  
    55 * Fix RtlStringFromGUID problem on NT4 
    66 
     72012-04-04 MickeM 
     8 * Fixed issue with empty filters in active eventlog 
     9 
     102012-04-04 MickeM 
     11 * Resolved some issues with loggingin default set to debug. 
     12 * Fixed so --debug actually works 
     13 * Added --log-to-file and set "nscp test" to not log to file. 
     14 * Fixed typo related to allow arguments option 
     15 * Added levels to comment for log level in config. 
    716 
    8172012-04-01 MickeM 
  • helpers/installer-dlls/main_dll/main_dll.cpp

    r8d89d7a r440c0cb  
    3333 
    3434std::string nsclient::logging::logger_helper::create(NSCAPI::log_level::level level, const char* file, const int line, std::wstring message) { 
    35   if (level < NSCAPI::log_level::log) 
     35  if (level < NSCAPI::log_level::info) 
    3636    return "E" + utf8::cvt<std::string>(message); 
    3737  return "I" + utf8::cvt<std::string>(message); 
  • helpers/installers/installer/Product.wxs

    r8d89d7a r440c0cb  
    121121              <File Id="NSCAServerDLL" Name="NSCAServer.dll" DiskId="1" Source="$(var.Source)/modules/NSCAServer.dll" Vital="no" /> 
    122122              <File Id="SchedulerDLL" Name="Scheduler.dll" DiskId="1" Source="$(var.Source)/modules/Scheduler.dll" Vital="no" /> 
    123             </Component> 
    124             <Component Id="NSCP" Guid="B185B8F1-3718-4e8e-ADA4-38049A0721EA" Win64="$(var.Win64)"> 
    125               <File Id="NSCPClientDLL" Name="NSCPClient.dll" DiskId="1" Source="$(var.Source)/modules/NSCPClient.dll" Vital="no" /> 
    126               <File Id="NSCPServerDLL" Name="NSCPServer.dll" DiskId="1" Source="$(var.Source)/modules/NSCPServer.dll" Vital="no" /> 
    127123            </Component> 
    128124            <Component Id="PythonScript" Guid="49C2120D-634D-48ef-B82E-F2E9B219A768" Win64="$(var.Win64)"> 
     
    268264          <ComponentRef Id="ExtraClients" /> 
    269265        </Feature> 
    270         <Feature Id="NSCPPlugin" Title="NSCP plugin (experimental)" Description="Plugin to submit passive results to an NSCP server" Level="1" Absent="disallow"> 
    271           <ComponentRef Id="NSCP" /> 
    272         </Feature> 
    273266        <Feature Id="PythonScript" Title="Python Scripting" Description="Python scripting requires python to be installed)" Level="1" Absent="disallow"> 
    274267          <ComponentRef Id="PythonScript" /> 
  • include/NSCAPI.h

    r8d89d7a r440c0cb  
    101101    const int error = 10; // Error 
    102102    const int warning = 50; // Warning      <<< Default for command line interface 
    103     const int log = 100;  // Log message    <<< Default for service 
     103    //const int log = 100;  // Log message    <<< Default for service 
    104104    const int info = 150; // information 
    105105    const int debug = 500;  // Debug messages <<< Default for test 
  • include/nscapi/nscapi_core_wrapper.cpp

    ree52cdd r440c0cb  
    4141bool nscapi::core_wrapper::should_log(NSCAPI::nagiosReturn msgType) { 
    4242  enum log_status {unknown, set }; 
    43   static NSCAPI::log_level::level level = NSCAPI::log_level::log; 
     43  static NSCAPI::log_level::level level = NSCAPI::log_level::info; 
    4444  static log_status status = unknown; 
    4545  if (status == unknown) { 
  • include/nscapi/nscapi_helper.cpp

    r8d89d7a r440c0cb  
    9090    PARSE_LOGLEVEL_BEGIN() 
    9191      PARSE_LOGLEVEL("all",   NSCAPI::log_level::trace) 
    92       PARSE_LOGLEVEL("normal",  NSCAPI::log_level::info) 
    93       PARSE_LOGLEVEL("service", NSCAPI::log_level::log) 
    94       PARSE_LOGLEVEL("log",   NSCAPI::log_level::log) 
    95       PARSE_LOGLEVEL("message", NSCAPI::log_level::info) 
    9692      PARSE_LOGLEVEL("error",   NSCAPI::log_level::error) 
    9793      PARSE_LOGLEVEL("critical",  NSCAPI::log_level::critical) 
     
    115111  RENDER_LOGLEVEL_BEGIN() 
    116112    RENDER_LOGLEVEL("all",    NSCAPI::log_level::trace) 
    117     RENDER_LOGLEVEL("normal", NSCAPI::log_level::info) 
    118     RENDER_LOGLEVEL("log",    NSCAPI::log_level::log) 
    119     RENDER_LOGLEVEL("message",  NSCAPI::log_level::info) 
    120113    RENDER_LOGLEVEL("error",    NSCAPI::log_level::error) 
    121114    RENDER_LOGLEVEL("critical", NSCAPI::log_level::critical) 
     
    182175    case NSCAPI::log_level::warning: 
    183176      return _T("warning"); 
    184     case NSCAPI::log_level::log: 
    185       return _T("message"); 
     177    case NSCAPI::log_level::info: 
     178      return _T("info"); 
     179    case NSCAPI::log_level::trace: 
     180      return _T("trace"); 
    186181    case NSCAPI::log_level::debug: 
    187182      return _T("debug"); 
  • include/nscapi/nscapi_protobuf_functions.hpp

    r83c2453 r440c0cb  
    8585        if (ret == NSCAPI::log_level::error) 
    8686          return Plugin::LogEntry_Entry_Level_LOG_ERROR; 
    87         if (ret == NSCAPI::log_level::log) 
    88           return Plugin::LogEntry_Entry_Level_LOG_INFO; 
    8987        if (ret == NSCAPI::log_level::info) 
    9088          return Plugin::LogEntry_Entry_Level_LOG_INFO; 
  • include/nscapi/settings_proxy.hpp

    r8d89d7a r440c0cb  
    5858    } 
    5959    virtual void info(const char* file, int line, std::wstring message)  { 
    60       core_->log(NSCAPI::log_level::log, file, line, message); 
     60      core_->log(NSCAPI::log_level::info, file, line, message); 
    6161    } 
    6262    virtual void debug(const char* file, int line, std::wstring message)  { 
  • include/nsclient/base_logger_impl.cpp

    r8d89d7a r440c0cb  
    1111    case NSCAPI::log_level::error: 
    1212      return _T("e"); 
    13     case NSCAPI::log_level::log: 
    14       return _T("l"); 
    1513    case NSCAPI::log_level::info: 
    1614      return _T("l"); 
     
    3028    case NSCAPI::log_level::warning: 
    3129      return _T("warning"); 
    32     case NSCAPI::log_level::log: 
    33       return _T("message"); 
    3430    case NSCAPI::log_level::info: 
    3531      return _T("message"); 
  • include/nsclient/base_logger_impl.hpp

    r8d89d7a r440c0cb  
    1717      bool console_log_; 
    1818    public: 
    19       logging_interface_impl() : level_(NSCAPI::log_level::trace), console_log_(false) {} 
     19      logging_interface_impl() : level_(NSCAPI::log_level::info), console_log_(false) {} 
    2020 
    2121 
  • include/nsclient/logger.hpp

    r8d89d7a r440c0cb  
    4141      static void set_log_level(std::wstring level); 
    4242 
     43      static void set_backend(std::string backend); 
     44      static void destroy(); 
     45 
    4346    }; 
    4447  } 
  • modules/CheckEventLog/CheckEventLog.cpp

    r83c2453 r440c0cb  
    332332    c.filter = key; 
    333333    filters_.push_back(c); 
     334  } else if (key.empty() && query.empty()) { 
     335    return; 
    334336  } else { 
    335337    c.alias = key; 
  • modules/CheckEventLog/CheckEventLog.h

    r822454f r440c0cb  
    8787  void set_language(std::string lang); 
    8888  void set_filter(std::wstring flt) { 
    89     add_realtime_filter(_T("filter"), flt); 
     89    if (!flt.empty()) 
     90      add_realtime_filter(_T("filter"), flt); 
    9091  } 
    9192  bool has_filters() { 
  • modules/NRPEServer/handler_impl.cpp

    ree52cdd r440c0cb  
    1515  if (!allowArgs_) { 
    1616    if (!cmd.second.empty()) { 
    17       NSC_LOG_ERROR(_T("Request contained arguments (not currently allowed, check the allow_arguments option).")); 
    18       throw nrpe::nrpe_exception(_T("Request contained arguments (not currently allowed, check the allow_arguments option).")); 
     17      NSC_LOG_ERROR(_T("Request contained arguments (not currently allowed, check the allow arguments option).")); 
     18      throw nrpe::nrpe_exception(_T("Request contained arguments (not currently allowed, check the allow arguments option).")); 
    1919    } 
    2020  } 
  • modules/NSCPServer/CMakeLists.txt

    r8d89d7a r440c0cb  
    2424 
    2525ADD_DEFINITIONS(${NSCP_GLOBAL_DEFINES}) 
     26IF(OPENSSL_FOUND) 
     27  ADD_DEFINITIONS(-DUSE_SSL) 
     28ENDIF(OPENSSL_FOUND) 
    2629 
    2730IF(WIN32) 
  • modules/NSClientServer/CMakeLists.txt

    r8d89d7a r440c0cb  
    2323 
    2424ADD_DEFINITIONS(${NSCP_GLOBAL_DEFINES}) 
     25IF(OPENSSL_FOUND) 
     26  ADD_DEFINITIONS(-DUSE_SSL) 
     27ENDIF(OPENSSL_FOUND) 
    2528 
    2629IF(WIN32) 
  • modules/NSClientServer/NSClientServer.cpp

    r84cdb9b r440c0cb  
    7878      _T("TIMEOUT"), _T("Timeout when reading packets on incoming sockets. If the data has not arrived within this time we will bail out.")) 
    7979 
    80       (_T("use ssl"), sh::bool_key(&info_.use_ssl, true), 
     80      (_T("use ssl"), sh::bool_key(&info_.use_ssl, false), 
    8181      _T("ENABLE SSL ENCRYPTION"), _T("This option controls if SSL should be enabled.")) 
    8282 
  • service/NSClient++.cpp

    r8d89d7a r440c0cb  
    334334        addPlugin(pluginPath / v.second, v.first); 
    335335      } catch (const NSPluginException &e) { 
    336         LOG_CRITICAL_CORE_STD(_T("Failed to register plugin: ") + e.wwhat()); 
     336        if (e.file_.find(_T("FileLogger")) != std::wstring::npos) { 
     337          LOG_DEBUG_CORE_STD(_T("Failed to register plugin: ") + e.wwhat()); 
     338        } else { 
     339          LOG_ERROR_CORE(_T("Failed to register plugin: ") + e.wwhat()); 
     340        } 
    337341      } catch (...) { 
    338342        LOG_CRITICAL_CORE_STD(_T("Failed to register plugin key: ") + v.second); 
     
    402406    settings.add_key_to_settings(_T("log")) 
    403407      (_T("level"), sh::wstring_key(&log_level, _T("info")), 
    404       _T("LOG LEVEL"), _T("Log level to use")) 
     408      _T("LOG LEVEL"), _T("Log level to use. Avalible levels are error,warning,info,debug,trace")) 
    405409      ; 
    406410 
     
    542546        addPlugin(pluginPath / boost::filesystem::wpath(file), alias); 
    543547      } catch(const NSPluginException& e) { 
    544         LOG_ERROR_CORE_STD(_T("Exception raised: '") + e.error_ + _T("' in module: ") + e.file_); 
     548        if (e.file_.find(_T("FileLogger")) != std::wstring::npos) { 
     549          LOG_DEBUG_CORE_STD(_T("Exception raised: '") + e.error_ + _T("' in module: ") + e.file_); 
     550        } else { 
     551          LOG_ERROR_CORE_STD(_T("Exception raised: '") + e.error_ + _T("' in module: ") + e.file_); 
     552        } 
    545553      } catch (std::exception e) { 
    546554        LOG_ERROR_CORE_STD(_T("exception loading plugin: ") + file + strEx::string_to_wstring(e.what())); 
  • service/NSClient++.h

    r8d89d7a r440c0cb  
    177177  std::wstring getFolder(std::wstring key); 
    178178  std::wstring expand_path(std::wstring file); 
    179   void set_console_log() { 
    180     nsclient::logging::logger::get_logger()->set_console_log(true); 
    181   } 
    182179 
    183180  typedef boost::function<int(plugin_type)> run_function; 
  • service/cli_parser.hpp

    r8d89d7a r440c0cb  
    1616  po::options_description common; 
    1717  po::options_description unittest; 
     18  po::options_description test; 
    1819 
    1920  bool help; 
     
    2122  std::wstring log_level; 
    2223  std::wstring settings_store; 
     24  bool log_debug; 
    2325 
    2426  static nsclient::logging::logger_interface* get_logger() { 
     
    3436    , service("Service Options") 
    3537    , client("Client Options") 
    36     , unittest("Unittest Options") 
     38    , unittest("Unit-test Options") 
     39    , test("Test Options") 
    3740    , help(false) 
    3841    , version(false) 
     42    , log_debug(false) 
    3943  { 
    4044    root.add_options() 
     
    4246      ("version", po::bool_switch(&version), "Show version information") 
    4347      ; 
     48 
    4449    common.add_options() 
    4550      ("settings", po::value<std::wstring>(&settings_store), "Override (temporarily) settings subsystem to use") 
    4651      ("help", po::bool_switch(&help), "produce help message") 
    47       ("debug", "Set log level to debug (and show debug information)") 
     52      ("debug", po::bool_switch(&log_debug), "Set log level to debug (and show debug information)") 
    4853      ("log", po::value<std::wstring>(&log_level), "The log level to use") 
    4954      ("version", po::bool_switch(&version), "Show version information") 
     
    8489      ("raw-argument", po::wvalue<std::vector<std::wstring> >(), "List of arguments (does not get -- prefixed)") 
    8590      ; 
     91 
    8692    unittest.add_options() 
    8793      ("language,l", po::value<std::wstring>()->implicit_value(_T("")), "Language tests are written in") 
     
    9096      ; 
    9197 
     98    test.add_options() 
     99      ("log-to-file", "Enable file logger (defaults is console only)") 
     100      ; 
     101 
    92102  } 
    93103 
    94104  bool process_common_options(std::string context, po::options_description &desc) { 
    95     core_->set_console_log(); 
     105    nsclient::logging::logger::get_logger()->set_console_log(true); 
     106    if (log_debug) { 
     107      log_level = _T("debug"); 
     108    } 
    96109    if (!log_level.empty()) 
    97110      nsclient::logging::logger::set_log_level(log_level); 
     
    191204 
    192205  int parse_test(int argc, wchar_t* argv[]) { 
    193     bool server = false; 
     206 
     207    po::options_description all("Allowed options (test)"); 
     208    all.add(common).add(test); 
     209 
     210    po::variables_map vm; 
     211    po::store(po::parse_command_line(argc, argv, all), vm); 
     212    po::notify(vm); 
     213 
    194214    if (log_level.empty()) 
    195215      log_level  = _T("debug"); 
    196216 
    197     core_->set_console_log(); 
     217    if (process_common_options("test", all)) 
     218      return 1; 
     219 
     220    if (vm.count("log-to-file") == 0) { 
     221      nsclient::logging::logger::set_backend("console"); 
     222    } 
     223 
    198224    try { 
    199225      po::options_description all("Allowed options (settings)"); 
     
    300326      } 
    301327      if (nsclient::logging::logger::get_logger()->should_log(NSCAPI::log_level::debug)) { 
    302         get_logger()->info(__FILE__, __LINE__, _T("Service name: ") + name); 
    303         get_logger()->info(__FILE__, __LINE__, _T("Service description: ") + desc); 
     328        get_logger()->debug(__FILE__, __LINE__, _T("Service name: ") + name); 
     329        get_logger()->debug(__FILE__, __LINE__, _T("Service description: ") + desc); 
    304330      } 
    305331 
  • service/logger_impl.cpp

    racc2c60 r440c0cb  
    212212 
    213213 
     214class simple_console_logger : public nsclient::logging::logging_interface_impl { 
     215  std::string format_; 
     216public: 
     217  simple_console_logger() : format_("%Y-%m-%d %H:%M:%S") { 
     218  } 
     219 
     220  void do_log(const std::string &data) { 
     221    if (get_console_log()) { 
     222      std::wcout << render_console_message(data) << std::endl; 
     223    } 
     224  } 
     225  void configure() { 
     226    try { 
     227      std::wstring file; 
     228 
     229      sh::settings_registry settings(settings_manager::get_proxy()); 
     230      settings.set_alias(_T("log/file")); 
     231 
     232      settings.add_path_to_settings() 
     233        (_T("log"),_T("LOG SECTION"), _T("Configure log properties.")) 
     234        ; 
     235 
     236      settings.add_key_to_settings(_T("log")) 
     237        (_T("date format"), sh::string_key(&format_, "%Y-%m-%d %H:%M:%S"), 
     238        _T("DATEMASK"), _T("The size of the buffer to use when getting messages this affects the speed and maximum size of messages you can recieve.")) 
     239 
     240        ; 
     241 
     242      settings.register_all(); 
     243      settings.notify(); 
     244 
     245    } catch (nscapi::nscapi_exception &e) { 
     246      log_fatal(std::string("Failed to register command: ") + e.what()); 
     247    } catch (std::exception &e) { 
     248      log_fatal(std::string("Exception caught: ") + e.what()); 
     249    } catch (...) { 
     250      log_fatal("Failed to register command."); 
     251    } 
     252  } 
     253  bool startup() { return true; } 
     254  bool shutdown() { return true; } 
     255}; 
     256 
     257 
    214258 
    215259 
     
    283327}; 
    284328 
    285 static nsclient::logging::logging_interface_impl *impl = NULL; 
    286  
     329static nsclient::logging::logging_interface_impl *logger_impl_ = NULL; 
     330 
     331#define CONSOLE_BACKEND "console" 
     332#define THREADED_FILE_BACKEND "threaded-file" 
     333#define FILE_BACKEND "file" 
     334 
     335 
     336void nsclient::logging::logger::set_backend(std::string backend) { 
     337  nsclient::logging::logging_interface_impl *tmp = NULL; 
     338  if (backend == CONSOLE_BACKEND) { 
     339    tmp = new simple_console_logger(); 
     340  } else if (backend == THREADED_FILE_BACKEND) { 
     341    tmp = new threaded_logger(log_impl_type(new simple_file_logger("nsclient.log"))); 
     342  } else if (backend == FILE_BACKEND) { 
     343    tmp = new simple_file_logger("nsclient.log"); 
     344  } else { 
     345    tmp = new simple_console_logger(); 
     346  } 
     347  nsclient::logging::logging_interface_impl *old = logger_impl_ ; 
     348  logger_impl_  = tmp; 
     349  delete old; 
     350  old = NULL; 
     351} 
     352 
     353 
     354#define DEFAULT_BACKEND THREADED_FILE_BACKEND 
    287355nsclient::logging::logging_interface_impl* get_impl() { 
    288   if (impl == NULL) 
    289     impl = new threaded_logger(log_impl_type(new simple_file_logger("nsclient.log"))); 
    290   return impl; 
     356  if (logger_impl_  == NULL) 
     357    nsclient::logging::logger::set_backend(DEFAULT_BACKEND); 
     358  return logger_impl_ ; 
     359} 
     360void nsclient::logging::logger::destroy() { 
     361  nsclient::logging::logging_interface_impl* old = logger_impl_; 
     362  logger_impl_ = NULL; 
     363  delete old; 
    291364} 
    292365 
  • service/settings_client.hpp

    r8d89d7a r440c0cb  
    2020 
    2121    void boot(std::wstring log) { 
    22       core_->set_console_log(); 
    2322      if (!current_.empty()) 
    2423        core_->set_settings_context(current_); 
  • version.hpp

    racc2c60 r440c0cb  
    11#ifndef VERSION_HPP 
    22#define VERSION_HPP 
    3 #define PRODUCTVER     0,4,0,153 
    4 #define STRPRODUCTVER  "0,4,0,153" 
    5 #define STRPRODUCTDATE "2012-04-02" 
     3#define PRODUCTVER     0,4,0,156 
     4#define STRPRODUCTVER  "0,4,0,156" 
     5#define STRPRODUCTDATE "2012-04-05" 
    66#endif // VERSION_HPP 
  • version.txt

    r8d89d7a r440c0cb  
    11version=0.4.0 
    2 build=153 
    3 date=2012-04-02 
     2build=156 
     3date=2012-04-05 
Note: See TracChangeset for help on using the changeset viewer.