Changeset b67d231 in nscp


Ignore:
Timestamp:
06/12/12 23:49:05 (12 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
482e07e
Parents:
81dbd0c
Message:
  • Added log level = off to disable logging.
  • Added option in NSCAClient to hostname (auto-lc) to use lower case version of hostname. #533
  • Reworked how commands are read. If a command is defined without a section (default) no section will be added and instead a comment will be addded on how to add the section. This should (I hope) resolve the "missing command" for good.
  • Improved error messages for missing commands
  • Fixed scientific notation on performance data (#)
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • changelog

    r1cc8566 rb67d231  
    44 * Fixa dependonservice LanManWorkStation (old win) 
    55 * Fix RtlStringFromGUID problem on NT4 
     6 
     72012-06-12 MickeM 
     8 * Added log level = off to disable logging. 
     9 * Added option in NSCAClient to hostname (auto-lc) to use lower case version of hostname. #533 
     10 * Reworked how commands are read. 
     11   If a command is defined without a section (default) no section will be added and instead a comment will be addded on how to add the section. 
     12   This should (I hope) resolve the "missing command" for good. 
     13 * Improved error messages for missing commands 
     14 * Fixed scientific notation on performance data (#) 
    615 
    7162012-05-19 MickeM 
  • include/NSCAPI.h

    r440c0cb rb67d231  
    9898  namespace log_level { 
    9999    typedef int level; 
     100    const int off = 0;    // Used to disable logging 
    100101    const int critical = 1; // Critical error 
    101102    const int error = 10; // Error 
  • include/nscapi/nscapi_helper.cpp

    r440c0cb rb67d231  
    7979} 
    8080 
    81 #define PARSE_LOGLEVEL_BEGIN() if (false) {} 
    82 #define PARSE_LOGLEVEL(key_str, value)  else if (*key == _T(key_str) && level < value) { level = value; } 
    83 #define PARSE_LOGLEVEL_END()  
    84  
    8581NSCAPI::log_level::level nscapi::logging::parse(std::wstring str) { 
    86   unsigned int level = 0; 
    8782  std::transform(str.begin(), str.end(), str.begin(), ::tolower); 
    88   strEx::splitList lst = strEx::splitEx(str, _T(",")); 
    89   for (strEx::splitList::const_iterator key = lst.begin(); key != lst.end(); ++key) { 
    90     PARSE_LOGLEVEL_BEGIN() 
    91       PARSE_LOGLEVEL("all",   NSCAPI::log_level::trace) 
    92       PARSE_LOGLEVEL("error",   NSCAPI::log_level::error) 
    93       PARSE_LOGLEVEL("critical",  NSCAPI::log_level::critical) 
    94       PARSE_LOGLEVEL("debug",   NSCAPI::log_level::debug) 
    95       PARSE_LOGLEVEL("trace",   NSCAPI::log_level::trace) 
    96       PARSE_LOGLEVEL("info",    NSCAPI::log_level::info) 
    97       PARSE_LOGLEVEL("warning", NSCAPI::log_level::warning) 
    98     PARSE_LOGLEVEL_END() 
    99   } 
    100   return level; 
     83  if (_T("all") == str) { 
     84    return NSCAPI::log_level::trace; 
     85  } else if (_T("error") == str) { 
     86    return NSCAPI::log_level::error; 
     87  } else if (_T("critical") == str) { 
     88    return NSCAPI::log_level::critical; 
     89  } else if (_T("debug") == str) { 
     90    return NSCAPI::log_level::debug; 
     91  } else if (_T("trace") == str) { 
     92    return NSCAPI::log_level::trace; 
     93  } else if (_T("info") == str) { 
     94    return NSCAPI::log_level::info; 
     95  } else if (_T("warning") == str) { 
     96    return NSCAPI::log_level::warning; 
     97  } else if (_T("off") == str) { 
     98    return NSCAPI::log_level::off; 
     99  } 
     100  return NSCAPI::log_level::error; 
    101101} 
    102102bool nscapi::logging::matches(NSCAPI::log_level::level level, NSCAPI::nagiosReturn code) { 
     
    104104} 
    105105 
    106 #define RENDER_LOGLEVEL_BEGIN()  
    107 #define RENDER_LOGLEVEL(key_str, value)  if (level == value) { return _T(key_str); } 
    108 #define RENDER_LOGLEVEL_END()  
    109  
    110106std::wstring nscapi::logging::to_string(NSCAPI::log_level::level level) { 
    111   RENDER_LOGLEVEL_BEGIN() 
    112     RENDER_LOGLEVEL("all",    NSCAPI::log_level::trace) 
    113     RENDER_LOGLEVEL("error",    NSCAPI::log_level::error) 
    114     RENDER_LOGLEVEL("critical", NSCAPI::log_level::critical) 
    115     RENDER_LOGLEVEL("debug",    NSCAPI::log_level::debug) 
    116     RENDER_LOGLEVEL("trace",    NSCAPI::log_level::trace) 
    117     RENDER_LOGLEVEL("info",   NSCAPI::log_level::info) 
    118     RENDER_LOGLEVEL("warning",  NSCAPI::log_level::warning) 
    119   RENDER_LOGLEVEL_END() 
     107  switch (level) { 
     108    case NSCAPI::log_level::trace: 
     109      return _T("trace"); 
     110    case NSCAPI::log_level::error: 
     111      return _T("error"); 
     112    case NSCAPI::log_level::critical: 
     113      return _T("critical"); 
     114    case NSCAPI::log_level::debug: 
     115      return _T("debug"); 
     116    case NSCAPI::log_level::info: 
     117      return _T("info"); 
     118    case NSCAPI::log_level::warning: 
     119      return _T("warning"); 
     120    case NSCAPI::log_level::off: 
     121      return _T("off"); 
     122  } 
    120123  return strEx::itos(level); 
    121124} 
  • include/nscapi/nscapi_protobuf_functions.cpp

    r308ae18 rb67d231  
    617617          if (!fval.has_warning()) 
    618618            continue; 
    619           ss << ";" << fval.warning(); 
     619          ss << ";" << strEx::s::itos_non_sci(fval.warning()); 
    620620          if (!fval.has_critical())  
    621621            continue; 
    622           ss << ";" << fval.critical(); 
     622          ss << ";" << strEx::s::itos_non_sci(fval.critical()); 
    623623          if (!fval.has_minimum()) 
    624624            continue; 
    625           ss << ";" << fval.minimum(); 
     625          ss << ";" << strEx::s::itos_non_sci(fval.minimum()); 
    626626          if (!fval.has_maximum()) 
    627627            continue; 
    628           ss << ";" << fval.maximum(); 
     628          ss << ";" << strEx::s::itos_non_sci(fval.maximum()); 
    629629        } 
    630630      } 
  • include/nscapi/nscapi_targets.hpp

    r83c2453 rb67d231  
    9292    struct target_object_reader { 
    9393      typedef target_object object_type; 
    94       static void read_object(boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object); 
     94      static void read_object(boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object, bool oneliner); 
    9595      static void apply_parent(object_type &object, object_type &parent); 
    9696    }; 
     
    110110      } 
    111111 
    112       static void read_object(boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object) { 
     112      static void read_object(boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object, bool oneliner) { 
    113113        object.address = net::parse(object.value, 0); 
    114114        if (object.alias == _T("default")) 
  • include/nscapi/settings_object.hpp

    r67c6d04 rb67d231  
    2929    template<class object_type> 
    3030    class default_object_reader { 
    31       static void read_object(boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object) {} 
     31      static void read_object(boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object, bool oneliner) {} 
    3232      static void apply_parent(object_type &object, object_type &parent) {} 
    3333      static void post_process_object(object_type &object) {} 
     
    6464        object.is_template = false; 
    6565 
    66         object_reader::read_object(proxy, object); 
     66        std::list<std::wstring> keys = proxy->get_keys(object.path); 
     67        object_reader::read_object(proxy, object, keys.empty()); 
     68 
    6769 
    6870        if (!object.parent.empty() && object.parent != alias & object.parent != object.alias) { 
     
    108110      } 
    109111 
    110       bool has_object(std::wstring alias) { 
     112      bool has_object(std::wstring alias) const { 
    111113        typename object_list_type::const_iterator cit = object_list.find(alias); 
    112114        if (cit != object_list.end()) 
     
    116118          return true; 
    117119        return false; 
     120      } 
     121 
     122      bool empty() const { 
     123        return object_list.empty(); 
    118124      } 
    119125 
  • include/strEx.h

    rfa11893 rb67d231  
    282282      ss << std::noshowpoint << std::fixed << i; 
    283283      std::string s = ss.str(); 
    284       std::string::size_type pos = s.find_last_not_of('0'); 
     284      std::string::size_type pos = s.find('.'); 
     285      if (pos != std::string::npos && (s.length()-pos) > 6) { 
     286        s = s.substr(0, pos+6); 
     287      } 
     288       
     289      pos = s.find_last_not_of('0'); 
    285290      if (pos == std::wstring::npos) 
    286291        return s; 
  • modules/CheckExternalScripts/CheckExternalScripts.cpp

    r67c6d04 rb67d231  
    8787      , _T("EXTERNAL SCRIPT WRAPPINGS SECTION"), _T("A list of templates for wrapped scripts")) 
    8888 
     89      (_T("alias"), sh::fun_values_path(boost::bind(&CheckExternalScripts::add_alias, this, _1, _2)),  
     90      _T("EXTERNAL SCRIPT ALIAS SECTION"), _T("A list of aliases available. An alias is an internal command that has been \"wrapped\" (to add arguments). Be careful so you don't create loops (ie check_loop=check_a, check_a=check_loop)")) 
     91 
    8992      ; 
    9093 
     
    103106    } 
    104107 
     108    if (aliases_.empty()) { 
     109      NSC_DEBUG_MSG(_T("No aliases found (adding default)")); 
     110 
     111      add_alias(_T("alias_cpu"), _T("checkCPU warn=80 crit=90 time=5m time=1m time=30s")); 
     112      add_alias(_T("alias_cpu_ex"), _T("checkCPU warn=$ARG1$ crit=$ARG2$ time=5m time=1m time=30s")); 
     113      add_alias(_T("alias_mem"), _T("checkMem MaxWarn=80% MaxCrit=90% ShowAll=long type=physical type=virtual type=paged type=page")); 
     114      add_alias(_T("alias_up"), _T("checkUpTime MinWarn=1d MinWarn=1h")); 
     115      add_alias(_T("alias_disk"), _T("CheckDriveSize MinWarn=10% MinCrit=5% CheckAll FilterType=FIXED")); 
     116      add_alias(_T("alias_disk_loose"), _T("CheckDriveSize MinWarn=10% MinCrit=5% CheckAll FilterType=FIXED ignore-unreadable")); 
     117      add_alias(_T("alias_volumes"), _T("CheckDriveSize MinWarn=10% MinCrit=5% CheckAll=volumes FilterType=FIXED")); 
     118      add_alias(_T("alias_volumes_loose"), _T("CheckDriveSize MinWarn=10% MinCrit=5% CheckAll=volumes FilterType=FIXED ignore-unreadable ")); 
     119      add_alias(_T("alias_service"), _T("checkServiceState CheckAll")); 
     120      add_alias(_T("alias_service_ex"), _T("checkServiceState CheckAll \"exclude=Net Driver HPZ12\" \"exclude=Pml Driver HPZ12\" exclude=stisvc")); 
     121      add_alias(_T("alias_process"), _T("checkProcState \"$ARG1$=started\"")); 
     122      add_alias(_T("alias_process_stopped"), _T("checkProcState \"$ARG1$=stopped\"")); 
     123      add_alias(_T("alias_process_count"), _T("checkProcState MaxWarnCount=$ARG2$ MaxCritCount=$ARG3$ \"$ARG1$=started\"")); 
     124      add_alias(_T("alias_process_hung"), _T("checkProcState MaxWarnCount=1 MaxCritCount=1 \"$ARG1$=hung\"")); 
     125      add_alias(_T("alias_event_log"), _T("CheckEventLog file=application file=system MaxWarn=1 MaxCrit=1 \"filter=generated gt -2d AND severity NOT IN ('success', 'informational') AND source != 'SideBySide'\" truncate=800 unique descriptions \"syntax=%severity%: %source%: %message% (%count%)\"")); 
     126      add_alias(_T("alias_file_size"), _T("CheckFiles \"filter=size > $ARG2$\" \"path=$ARG1$\" MaxWarn=1 MaxCrit=1 \"syntax=%filename% %size%\" max-dir-depth=10")); 
     127      add_alias(_T("alias_file_age"), _T("checkFile2 filter=out \"file=$ARG1$\" filter-written=>1d MaxWarn=1 MaxCrit=1 \"syntax=%filename% %write%\"")); 
     128      add_alias(_T("alias_sched_all"), _T("CheckTaskSched \"filter=exit_code ne 0\" \"syntax=%title%: %exit_code%\" warn=>0")); 
     129      add_alias(_T("alias_sched_long"), _T("CheckTaskSched \"filter=status = 'running' AND most_recent_run_time < -$ARG1$\" \"syntax=%title% (%most_recent_run_time%)\" warn=>0")); 
     130      add_alias(_T("alias_sched_task"), _T("CheckTaskSched \"filter=title eq '$ARG1$' AND exit_code ne 0\" \"syntax=%title% (%most_recent_run_time%)\" warn=>0")); 
     131      add_alias(_T("alias_updates"), _T("check_updates -warning 0 -critical 0")); 
     132      add_alias(_T("check_ok"), _T("CheckOK Everything is fine!")); 
     133    } 
     134 
    105135    settings.alias().add_path_to_settings() 
    106136      (_T("EXTERNAL SCRIPT SECTION"), _T("Section for external scripts configuration options (CheckExternalScripts).")) 
     
    108138      (_T("scripts"), sh::fun_values_path(boost::bind(&CheckExternalScripts::add_command, this, _1, _2)),  
    109139      _T("EXTERNAL SCRIPT SCRIPT SECTION"), _T("A list of scripts available to run from the CheckExternalScripts module. Syntax is: <command>=<script> <arguments>")) 
    110  
    111       (_T("alias"), sh::fun_values_path(boost::bind(&CheckExternalScripts::add_alias, this, _1, _2)),  
    112       _T("EXTERNAL SCRIPT ALIAS SECTION"), _T("A list of aliases available. An alias is an internal command that has been \"wrapped\" (to add arguments). Be careful so you don't create loops (ie check_loop=check_a, check_a=check_loop)")) 
    113140 
    114141      (_T("wrapped scripts"), sh::fun_values_path(boost::bind(&CheckExternalScripts::add_wrapping, this, _1, _2)),  
     
    227254  } 
    228255 
    229   NSC_LOG_MESSAGE(_T("Arguments: ") + xargs); 
     256  NSC_DEBUG_MSG(_T("Arguments: ") + xargs); 
    230257 
    231258 
     
    233260    std::wstring message; 
    234261    try { 
    235       return nscapi::core_helper::simple_query(cd.command, args, response); 
     262      int result = nscapi::core_helper::simple_query(cd.command, args, response); 
     263      if (result == NSCAPI::returnIgnored) { 
     264        nscapi::functions::create_simple_query_response_unknown(data.command, _T("No handler for command: ") + cd.command, response); 
     265        return NSCAPI::returnUNKNOWN; 
     266      } 
     267      return result; 
    236268    } catch (boost::escaped_list_error &e) { 
    237269      NSC_LOG_MESSAGE(_T("Failed to parse alias expression: ") + strEx::string_to_wstring(e.what())); 
  • modules/CheckExternalScripts/commands.hpp

    r1cc8566 rb67d231  
    118118 
    119119 
    120     static void read_object(boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object) { 
     120    static void read_object(boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object, bool oneliner) { 
    121121      object.set_command(object.value); 
    122122      std::wstring alias; 
     
    126126      nscapi::settings_helper::settings_registry settings(proxy); 
    127127 
    128       /* 
    129       object_type::options_type options; 
    130       */ 
    131       /* 
    132       settings.path(object.path).add_path() 
    133         (object.alias, nscapi::settings_helper::wstring_map_path(&options),  
    134         _T("TARGET DEFENITION"), _T("Target definition for: ") + object.alias) 
    135  
    136         ; 
    137         */ 
    138  
     128      if (oneliner) { 
     129        std::wstring::size_type pos = object.path.find_last_of(_T("/")); 
     130        if (pos != std::wstring::npos) { 
     131          std::wstring path = object.path.substr(0, pos); 
     132          std::wstring key = object.path.substr(pos+1); 
     133          proxy->register_key(path, key, NSCAPI::key_string, object.alias, _T("Alias for ") + object.alias + _T(". To configure this item add a section called: ") + object.path, _T(""), false); 
     134          proxy->set_string(path, key, object.value); 
     135          return; 
     136        } 
     137      } 
    139138      settings.path(object.path).add_path() 
    140139        (_T("COMMAND DEFENITION"), _T("Command definition for: ") + object.alias) 
     
    169168      if (!alias.empty()) 
    170169        object.alias = alias; 
    171  
    172       /* 
    173       BOOST_FOREACH(const object_type::options_type::value_type &kvp, options) { 
    174         if (!object.has_option(kvp.first)) 
    175           object.options[kvp.first] = kvp.second; 
    176       } 
    177       */ 
    178  
    179170    } 
    180171 
     
    184175      import_string(object.password, parent.password); 
    185176      import_string(object.command, parent.command); 
    186       //import_string(object.arguments, parent.arguments); 
    187177      if (object.arguments.empty() && !parent.arguments.empty()) 
    188178        object.arguments = parent.arguments; 
    189       /* 
    190       object.address.import(parent.address); 
    191       BOOST_FOREACH(object_type::options_type::value_type i, parent.options) { 
    192         if (object.options.find(i.first) == object.options.end()) 
    193           object.options[i.first] = i.second; 
    194       } 
    195       */ 
    196179    } 
    197180 
  • modules/NSCAClient/NSCAClient.cpp

    r308ae18 rb67d231  
    101101    if (hostname_ == "auto") { 
    102102      hostname_ = boost::asio::ip::host_name(); 
     103    } else if (hostname_ == "auto-lc") { 
     104      hostname_ = boost::asio::ip::host_name(); 
     105      std::transform(hostname_.begin(), hostname_.end(), hostname_.begin(), ::tolower); 
    103106    } else { 
    104107      std::pair<std::string,std::string> dn = strEx::split<std::string>(boost::asio::ip::host_name(), "."); 
  • modules/Scheduler/schedules.hpp

    rc630d09 rb67d231  
    110110 
    111111 
    112     static void read_object(boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object) { 
     112    static void read_object(boost::shared_ptr<nscapi::settings_proxy> proxy, object_type &object, bool oneliner) { 
    113113      object.set_command(object.value); 
    114114      if (object.alias == _T("default")) { 
  • service/NSClient++.cpp

    r682ccd2 rb67d231  
    942942      if (!plugin) { 
    943943        LOG_ERROR_CORE(_T("No handler for command: ") + cmd + _T(" avalible commands: ") + commands_.to_wstring()); 
     944        nscapi::functions::create_simple_query_response_unknown(cmd, _T("No handler for command: ") + cmd, response); 
    944945        return NSCAPI::returnIgnored; 
    945946      } 
     
    10651066  nsclient::commands::plugin_type plugin = commands_.get(command); 
    10661067  if (!plugin) { 
    1067     LOG_ERROR_CORE(_T("No handler for command: ") + command + _T(" avalible commands: ") + commands_.to_wstring()); 
     1068    LOG_ERROR_CORE(_T("No handler for command: ") + command + _T(" available commands: ") + commands_.to_wstring()); 
     1069    resp.push_back(_T("No handler for command: ") + command); 
    10681070    return NSCAPI::returnUNKNOWN; 
    10691071  } 
  • version.hpp

    r81dbd0c rb67d231  
    11#ifndef VERSION_HPP 
    22#define VERSION_HPP 
    3 #define PRODUCTVER     0,4,0,174 
    4 #define STRPRODUCTVER  "0,4,0,174" 
    5 #define STRPRODUCTDATE "2012-05-19" 
     3#define PRODUCTVER     0,4,0,175 
     4#define STRPRODUCTVER  "0,4,0,175" 
     5#define STRPRODUCTDATE "2012-06-12" 
    66#endif // VERSION_HPP 
  • version.txt

    r81dbd0c rb67d231  
    11version=0.4.0 
    2 build=174 
    3 date=2012-05-19 
     2build=175 
     3date=2012-06-12 
Note: See TracChangeset for help on using the changeset viewer.