Changeset 81e420c in nscp


Ignore:
Timestamp:
09/01/11 07:05:41 (21 months ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
3b11e65
Parents:
1307e3f5
Message:
  • Added support for loading same plugin twice (in different sessions)
  • Added preliminary support for routing passive checks
Files:
2 added
57 edited

Legend:

Unmodified
Added
Removed
  • changelog

    r4b1e6fe r81e420c  
    55 * Fixa dependonservice LanManWorkStation (old win) 
    66 * Fix RtlStringFromGUID problem on NT4 
     7 
     82011-08-31 MickeM 
     9 * Added support for loading same plugin twice (in different sessions) 
     10 * Added preliminary support for routing passive checks 
    711 
    8122011-08-30 MickeM 
  • include/NSCAPI.h

    r4b1e6fe r81e420c  
    7474  const int key_integer = 200; 
    7575  const int key_bool = 300; 
     76 
     77  const int message_processed = 0x01; 
     78  const int message_routed  = 0x02; 
     79  const int message_ignored = 0x04; 
     80  const int message_digested  = 0x08; 
     81  const int message_modified  = 0x10; 
    7682 
    7783  typedef int nagiosReturn; 
     
    168174 
    169175  namespace plugin_api { 
    170     typedef int (*lpModuleHelperInit)(unsigned int, ::nscapi::core_api::lpNSAPILoader f); 
    171     typedef int (*lpLoadModule)(const wchar_t*,int); 
    172     typedef int (*lpGetName)(wchar_t*,unsigned int); 
    173     typedef int (*lpGetDescription)(wchar_t*,unsigned int); 
    174     typedef int (*lpGetVersion)(int*,int*,int*); 
    175     typedef int (*lpHasCommandHandler)(); 
    176     typedef int (*lpHasMessageHandler)(); 
    177     typedef NSCAPI::nagiosReturn (*lpHandleCommand)(const wchar_t*,const char*,const unsigned int,char**,unsigned int*); 
    178     typedef int (*lpDeleteBuffer)(char**); 
    179     typedef int (*lpCommandLineExec)(const wchar_t*,const char*,const unsigned int,char**,unsigned int*); 
    180     typedef int (*lpHandleMessage)(const char*); 
    181     typedef int (*lpUnLoadModule)(); 
    182     typedef void (*lpShowTray)(); 
    183     typedef void (*lpHideTray)(); 
    184     typedef int (*lpHasNotificationHandler)(); 
    185     typedef int (*lpHandleNotification)(const wchar_t *channel, const wchar_t* command, NSCAPI::nagiosReturn code, char* result, unsigned int result_len); 
     176    typedef NSCAPI::errorReturn (*lpGetName)(wchar_t*,unsigned int); 
     177    typedef NSCAPI::errorReturn (*lpGetDescription)(wchar_t*,unsigned int); 
     178    typedef NSCAPI::errorReturn (*lpModuleHelperInit)(unsigned int, ::nscapi::core_api::lpNSAPILoader f); 
     179    typedef NSCAPI::errorReturn (*lpGetVersion)(int* major, int* minor, int* revision); 
     180    typedef NSCAPI::errorReturn (*lpDeleteBuffer)(char** buffer); 
     181 
     182    typedef NSCAPI::errorReturn (*lpLoadModule)(unsigned int plugin_id, const wchar_t* alias, int mode); 
     183    typedef NSCAPI::errorReturn (*lpUnLoadModule)(unsigned int plugin_id); 
     184 
     185    typedef NSCAPI::errorReturn (*lpHasCommandHandler)(unsigned int plugin_id); 
     186    typedef NSCAPI::errorReturn (*lpHandleCommand)(unsigned int plugin_id, const wchar_t* command, const char* in_buffer, const unsigned int in_buffer_len, char** out_buffer, unsigned int* out_buffer_len); 
     187 
     188    typedef NSCAPI::errorReturn (*lpHasMessageHandler)(unsigned int plugin_id); 
     189    typedef NSCAPI::errorReturn (*lpHandleMessage)(unsigned int plugin_id, const char* buffer, const unsigned int buffer_len); 
     190 
     191    typedef NSCAPI::errorReturn (*lpHasNotificationHandler)(unsigned int plugin_id); 
     192    typedef NSCAPI::errorReturn (*lpHandleNotification)(unsigned int plugin_id, const wchar_t *channel, const wchar_t* command, const char* buffer, unsigned int buffer_len); 
     193 
     194    typedef NSCAPI::errorReturn (*lpHasRoutingHandler)(unsigned int plugin_id); 
     195    typedef NSCAPI::errorReturn (*lpRouteMessage)(unsigned int plugin_id, const wchar_t *channel, const wchar_t* command, const char* buffer, unsigned int buffer_len, wchar_t **new_channel_buffer, char **new_buffer, unsigned int *new_buffer_len); 
     196 
     197    typedef NSCAPI::errorReturn (*lpCommandLineExec)(unsigned int plugin_id, const wchar_t* command, const char* in_buffer ,const unsigned int in_buffer_len, char** out_buffer, unsigned int* out_buffer_len); 
    186198  } 
    187199} 
  • include/nscapi/functions.hpp

    r4b1e6fe r81e420c  
    105105 
    106106 
    107     static void create_simple_header(Plugin::Common::Header* hdr, Plugin::Common_Header_Type type)  { 
    108       hdr->set_type(type); 
     107    static void create_simple_header(Plugin::Common::Header* hdr)  { 
    109108      hdr->set_version(Plugin::Common_Version_VERSION_1); 
    110109      hdr->set_max_supported_version(Plugin::Common_Version_VERSION_1); 
     
    117116    static void create_simple_query_request(std::wstring command, std::vector<std::wstring> arguments, std::string &buffer) { 
    118117      Plugin::QueryRequestMessage message; 
    119       create_simple_header(message.mutable_header(), Plugin::Common_Header_Type_QUERY_REQUEST); 
     118      create_simple_header(message.mutable_header()); 
    120119 
    121120      Plugin::QueryRequestMessage::Request *payload = message.add_payload(); 
     
    129128    static void create_simple_query_request(std::wstring command, std::list<std::wstring> arguments, std::string &buffer) { 
    130129      Plugin::QueryRequestMessage message; 
    131       create_simple_header(message.mutable_header(), Plugin::Common_Header_Type_QUERY_REQUEST); 
     130      create_simple_header(message.mutable_header()); 
    132131 
    133132      Plugin::QueryRequestMessage::Request *payload = message.add_payload(); 
     
    146145    static void create_simple_query_response(std::wstring command, NSCAPI::nagiosReturn ret, std::wstring msg, std::wstring perf, std::string &buffer) { 
    147146      Plugin::QueryResponseMessage message; 
    148       create_simple_header(message.mutable_header(), Plugin::Common_Header_Type_QUERY_RESPONSE); 
     147      create_simple_header(message.mutable_header()); 
    149148 
    150149      Plugin::QueryResponseMessage::Response *payload = message.add_payload(); 
     
    197196       
    198197      Plugin::ExecuteRequestMessage message; 
    199       create_simple_header(message.mutable_header(), Plugin::Common_Header_Type_EXEC_REQUEST); 
     198      create_simple_header(message.mutable_header()); 
    200199 
    201200      Plugin::ExecuteRequestMessage::Request *payload = message.add_payload(); 
     
    210209 
    211210      Plugin::ExecuteRequestMessage message; 
    212       create_simple_header(message.mutable_header(), Plugin::Common_Header_Type_EXEC_REQUEST); 
     211      create_simple_header(message.mutable_header()); 
    213212 
    214213      Plugin::ExecuteRequestMessage::Request *payload = message.add_payload(); 
     
    231230    static void create_simple_exec_response(std::wstring command, NSCAPI::nagiosReturn ret, std::wstring result, std::string &response) { 
    232231      Plugin::ExecuteResponseMessage message; 
    233       create_simple_header(message.mutable_header(), Plugin::Common_Header_Type_EXEC_RESPONSE); 
     232      create_simple_header(message.mutable_header()); 
    234233 
    235234      Plugin::ExecuteResponseMessage::Response *payload = message.add_payload(); 
  • include/nscapi/macros.hpp

    r4b1e6fe r81e420c  
    11#pragma once 
    22#include <unicode_char.hpp> 
     3#include <boost/shared_ptr.hpp> 
     4#include <map> 
    35 
    46////////////////////////////////////////////////////////////////////////// 
     
    79  extern "C" int NSModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f); \ 
    810  extern "C" int NSLoadModule(); \ 
    9   extern "C" int NSLoadModuleEx(wchar_t* alias, int mode); \ 
     11  extern "C" int NSLoadModuleEx(unsigned int plugin_id, wchar_t* alias, int mode); \ 
    1012  extern "C" void NSDeleteBuffer(char**buffer); \ 
    1113  extern "C" int NSGetModuleName(wchar_t* buf, int buflen); \ 
    1214  extern "C" int NSGetModuleDescription(wchar_t* buf, int buflen); \ 
    1315  extern "C" int NSGetModuleVersion(int *major, int *minor, int *revision); \ 
    14   extern "C" NSCAPI::boolReturn NSHasCommandHandler(); \ 
    15   extern "C" NSCAPI::boolReturn NSHasMessageHandler(); \ 
    16   extern "C" void NSHandleMessage(const char* data); \ 
    17   extern "C" NSCAPI::nagiosReturn NSHandleCommand(const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len); \ 
    18   extern "C" int NSUnloadModule(); 
     16  extern "C" NSCAPI::boolReturn NSHasCommandHandler(unsigned int plugin_id); \ 
     17  extern "C" NSCAPI::boolReturn NSHasMessageHandler(unsigned int plugin_id); \ 
     18  extern "C" void NSHandleMessage(unsigned int plugin_id, const char* data, unsigned int len); \ 
     19  extern "C" NSCAPI::nagiosReturn NSHandleCommand(unsigned int plugin_id, const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len); \ 
     20  extern "C" int NSUnloadModule(unsigned int plugin_id); 
    1921 
    2022 
    2123#define NSC_WRAPPERS_CLI() \ 
    22   extern "C" int NSCommandLineExec(wchar_t *command, char *request_buffer, unsigned int request_len, char **response_buffer, unsigned int *response_len); 
     24  extern "C" int NSCommandLineExec(unsigned int plugin_id, wchar_t *command, char *request_buffer, unsigned int request_len, char **response_buffer, unsigned int *response_len); 
    2325 
    2426#define NSC_WRAPPERS_CHANNELS() \ 
    25   extern "C" int NSHasNotificationHandler(); \ 
    26   extern "C" int NSHandleNotification(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const char*, unsigned int); 
     27  extern "C" int NSHasNotificationHandler(unsigned int plugin_id); \ 
     28  extern "C" int NSHandleNotification(unsigned int plugin_id, const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const char*, unsigned int); 
     29 
     30#define NSC_WRAPPERS_ROUTING() \ 
     31  extern "C" int NSHasRoutingHandler(unsigned int plugin_id); \ 
     32  extern "C" int NSRouteMessage(unsigned int plugin_id, const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const char*, unsigned int); 
    2733 
    2834////////////////////////////////////////////////////////////////////////// 
     
    7076#endif 
    7177 
    72 #define NSC_WRAPPERS_MAIN_DEF(toObject) \ 
     78template<class impl_type> 
     79struct plugin_instance_data { 
     80  typedef std::map<unsigned int, boost::shared_ptr<impl_type> > plugin_list_type; 
     81  plugin_list_type plugins; 
     82  boost::shared_ptr<impl_type> get(unsigned int id) { 
     83    plugin_list_type::iterator it = plugins.find(id); 
     84    if (it != plugins.end()) 
     85      return it->second; 
     86    boost::shared_ptr<impl_type> impl = boost::shared_ptr<impl_type>(new impl_type()); 
     87    plugins[id] = impl; 
     88    return impl;  
     89  } 
     90  void erase(unsigned int id) { 
     91    plugins.erase(id); 
     92  } 
     93}; 
     94 
     95 
     96#define NSC_WRAPPERS_MAIN_DEF(impl_class) \ 
     97  static plugin_instance_data<impl_class> plugin_instance; \ 
    7398  extern int NSModuleHelperInit(unsigned int id, nscapi::core_api::lpNSAPILoader f) { \ 
    7499    try { \ 
     
    79104    } \ 
    80105  } \ 
    81   extern int NSLoadModuleEx(wchar_t* alias, int mode) { \ 
    82   try { \ 
    83   return GET_PLUGIN()->wrapLoadModule(toObject.loadModuleEx(alias, mode)); \ 
     106  extern int NSLoadModuleEx(unsigned int id, wchar_t* alias, int mode) { \ 
     107  try { \ 
     108  return GET_PLUGIN()->wrapLoadModule(plugin_instance.get(id)->loadModuleEx(alias, mode)); \ 
    84109    } catch (...) { \ 
    85110    NSC_LOG_CRITICAL(_T("Unknown exception in: wrapLoadModule(...)")); \ 
     
    88113  } \ 
    89114  extern int NSLoadModule() { \ 
    90   try { \ 
    91   return GET_PLUGIN()->wrapLoadModule(toObject.loadModule()); \ 
    92     } catch (...) { \ 
    93     NSC_LOG_CRITICAL(_T("Unknown exception in: wrapLoadModule(...)")); \ 
    94115    return NSCAPI::hasFailed; \ 
    95     } \ 
    96116  } \ 
    97117  extern int NSGetModuleName(wchar_t* buf, int buflen) { \ 
    98118    try { \ 
    99       return GET_PLUGIN()->wrapGetModuleName(buf, buflen, toObject.getModuleName()); \ 
     119      return GET_PLUGIN()->wrapGetModuleName(buf, buflen, impl_class::getModuleName()); \ 
    100120    } catch (...) { \ 
    101121      NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleName(...)")); \ 
     
    105125  extern int NSGetModuleDescription(wchar_t* buf, int buflen) { \ 
    106126    try { \ 
    107       return GET_PLUGIN()->wrapGetModuleName(buf, buflen, toObject.getModuleDescription()); \ 
     127      return GET_PLUGIN()->wrapGetModuleName(buf, buflen, impl_class::getModuleDescription()); \ 
    108128    } catch (...) { \ 
    109129      NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleName(...)")); \ 
     
    113133  extern int NSGetModuleVersion(int *major, int *minor, int *revision) { \ 
    114134    try { \ 
    115       return GET_PLUGIN()->wrapGetModuleVersion(major, minor, revision, toObject.getModuleVersion()); \ 
     135      return GET_PLUGIN()->wrapGetModuleVersion(major, minor, revision, impl_class::getModuleVersion()); \ 
    116136    } catch (...) { \ 
    117137      NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleVersion(...)")); \ 
     
    119139    } \ 
    120140  } \ 
    121   extern int NSUnloadModule() { \ 
    122     try { \ 
    123       return GET_PLUGIN()->wrapUnloadModule(toObject.unloadModule()); \ 
     141  extern int NSUnloadModule(unsigned int id) { \ 
     142    try { \ 
     143      int ret = GET_PLUGIN()->wrapUnloadModule(plugin_instance.get(id)->unloadModule()); \ 
     144      plugin_instance.erase(id); \ 
     145      return ret; \ 
    124146    } catch (...) { \ 
    125147      NSC_LOG_CRITICAL(_T("Unknown exception in: wrapGetModuleVersion(...)")); \ 
     
    135157  } 
    136158#define NSC_WRAPPERS_HANDLE_MSG_DEF(toObject) \ 
    137   extern void NSHandleMessage(const char* data) { \ 
    138     try { \ 
    139       toObject.handleMessageRAW(data); \ 
     159  extern void NSHandleMessage(unsigned int id, const char* request_buffer, unsigned int request_buffer_len) { \ 
     160    try { \ 
     161      std::string request(request_buffer, request_buffer_len); \ 
     162      plugin_instance.get(id)->handleMessageRAW(request); \ 
    140163    } catch (...) { \ 
    141164      NSC_LOG_CRITICAL(_T("Unknown exception in: handleMessage(...)")); \ 
    142165    } \ 
    143166  } \ 
    144   extern NSCAPI::boolReturn NSHasMessageHandler() { \ 
    145     try { \ 
    146       return GET_PLUGIN()->wrapHasMessageHandler(toObject.hasMessageHandler()); \ 
     167  extern NSCAPI::boolReturn NSHasMessageHandler(unsigned int id) { \ 
     168    try { \ 
     169      return GET_PLUGIN()->wrapHasMessageHandler(plugin_instance.get(id)->hasMessageHandler()); \ 
    147170    } catch (...) { \ 
    148171      NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasMessageHandler(...)")); \ 
     
    151174  } 
    152175#define NSC_WRAPPERS_IGNORE_MSG_DEF() \ 
    153   extern void NSHandleMessage(const char* data) {} \ 
    154   extern NSCAPI::boolReturn NSHasMessageHandler() { return NSCAPI::isfalse; } 
    155 #define NSC_WRAPPERS_HANDLE_CMD_DEF(toObject) \ 
    156   extern NSCAPI::nagiosReturn NSHandleCommand(const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len) \ 
     176  extern void NSHandleMessage(unsigned int id, const char* data, unsigned int len) {} \ 
     177  extern NSCAPI::boolReturn NSHasMessageHandler(unsigned int id) { return NSCAPI::isfalse; } 
     178#define NSC_WRAPPERS_HANDLE_CMD_DEF() \ 
     179  extern NSCAPI::nagiosReturn NSHandleCommand(unsigned int id, const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len, char** reply_buffer, unsigned int *reply_buffer_len) \ 
    157180  { \ 
    158181  try { \ 
    159182  std::string request(request_buffer, request_buffer_len), reply; \ 
    160   NSCAPI::nagiosReturn retCode = (&toObject)->handleRAWCommand(command, request, reply); \ 
     183  NSCAPI::nagiosReturn retCode = plugin_instance.get(id)->handleRAWCommand(command, request, reply); \ 
    161184  return GET_PLUGIN()->wrapHandleCommand(retCode, reply, reply_buffer, reply_buffer_len); \ 
    162185    } catch (...) { \ 
     
    165188    } \ 
    166189  } \ 
    167   extern NSCAPI::boolReturn NSHasCommandHandler() { \ 
    168   try { \ 
    169   return GET_PLUGIN()->wrapHasCommandHandler(toObject.hasCommandHandler()); \ 
     190  extern NSCAPI::boolReturn NSHasCommandHandler(unsigned int id) { \ 
     191  try { \ 
     192  return GET_PLUGIN()->wrapHasCommandHandler(plugin_instance.get(id)->hasCommandHandler()); \ 
    170193    } catch (...) { \ 
    171194    NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasCommandHandler(...)")); \ 
     
    173196    } \ 
    174197  } 
     198#define NSC_WRAPPERS_ROUTING_DEF() \ 
     199  extern NSCAPI::nagiosReturn NSRouteMessage(unsigned int id, const wchar_t* channel, const wchar_t* command, const char* request_buffer, const unsigned int request_buffer_len) \ 
     200  { \ 
     201  try { \ 
     202  std::string request(request_buffer, request_buffer_len), reply; \ 
     203  return GET_PLUGIN()->wrapRouteMessage(plugin_instance.get(id)->RAWRouteMessage(channel, command, request)); \ 
     204    } catch (...) { \ 
     205    NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHandleCommand(...)")); \ 
     206    return NSCAPI::returnIgnored; \ 
     207    } \ 
     208  } \ 
     209  extern NSCAPI::boolReturn NSHasRoutingHandler(unsigned int id) { \ 
     210  try { \ 
     211  return GET_PLUGIN()->wrapHasRoutingHandler(plugin_instance.get(id)->hasRoutingHandler()); \ 
     212    } catch (...) { \ 
     213    NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasCommandHandler(...)")); \ 
     214    return NSCAPI::isfalse; \ 
     215    } \ 
     216  } 
    175217#define NSC_WRAPPERS_IGNORE_CMD_DEF() \ 
    176   extern NSCAPI::nagiosReturn NSHandleCommand(const wchar_t* IN_cmd, const unsigned int IN_argsLen, wchar_t **IN_args, \ 
     218  extern NSCAPI::nagiosReturn NSHandleCommand(unsigned int id, const wchar_t* IN_cmd, const unsigned int IN_argsLen, wchar_t **IN_args, \ 
    177219  wchar_t *OUT_retBufMessage, unsigned int IN_retBufMessageLen, wchar_t *OUT_retBufPerf, unsigned int IN_retBufPerfLen) { \ 
    178220  return NSCAPI::returnIgnored; \ 
    179221  } \ 
    180   extern NSCAPI::boolReturn NSHasCommandHandler() { return NSCAPI::isfalse; } 
     222  extern NSCAPI::boolReturn NSHasCommandHandler(unsigned int id) { return NSCAPI::isfalse; } 
    181223#define NSC_WRAPPERS_IGNORE_NOTIFICATION_DEF() \ 
    182224  extern void NSHandleNotification(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const char*, unsigned int) {} \ 
    183   extern NSCAPI::boolReturn NSHasNotificationHandler() { return NSCAPI::isfalse; } 
    184 #define NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF(toObject) \ 
    185   extern NSCAPI::nagiosReturn NSHandleNotification(const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code, const char* result_buffer, unsigned int result_buffer_len) \ 
     225  extern NSCAPI::boolReturn NSHasNotificationHandler(unsigned int id) { return NSCAPI::isfalse; } 
     226#define NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF() \ 
     227  extern NSCAPI::nagiosReturn NSHandleNotification(unsigned int id, const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code, const char* result_buffer, unsigned int result_buffer_len) \ 
    186228  { \ 
    187229    try { \ 
    188230      std::string result(result_buffer, result_buffer_len); \ 
    189       return GET_PLUGIN()->wrapHandleNotification((&toObject)->handleRAWNotification(channel, command, code, result)); \ 
     231      return GET_PLUGIN()->wrapHandleNotification(plugin_instance.get(id)->handleRAWNotification(channel, command, code, result)); \ 
    190232    } catch (...) { \ 
    191233      NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasNotificationHandler(...)")); \ 
     
    193235    } \ 
    194236  } \ 
    195   extern NSCAPI::boolReturn NSHasNotificationHandler() { \ 
    196     try { \ 
    197       return GET_PLUGIN()->wrapHasNotificationHandler(toObject.hasNotificationHandler()); \ 
     237  extern NSCAPI::boolReturn NSHasNotificationHandler(unsigned int id) { \ 
     238    try { \ 
     239      return GET_PLUGIN()->wrapHasNotificationHandler(plugin_instance.get(id)->hasNotificationHandler()); \ 
    198240    } catch (...) { \ 
    199241      NSC_LOG_CRITICAL(_T("Unknown exception in: wrapHasNotificationHandler(...)")); \ 
     
    203245 
    204246 
    205 #define NSC_WRAPPERS_CLI_DEF(toObject) \ 
    206   extern int NSCommandLineExec(wchar_t *command, char *request_buffer, unsigned int request_len, char **response_buffer, unsigned int *response_len) { \ 
     247#define NSC_WRAPPERS_CLI_DEF() \ 
     248  extern int NSCommandLineExec(unsigned int id, wchar_t *command, char *request_buffer, unsigned int request_len, char **response_buffer, unsigned int *response_len) { \ 
    207249    try { \ 
    208250    std::string request = std::string(request_buffer, request_len); \ 
    209251    std::string response; \ 
    210     NSCAPI::nagiosReturn retCode = (&toObject)->commandRAWLineExec(command, request, response); \ 
     252    NSCAPI::nagiosReturn retCode = plugin_instance.get(id)->commandRAWLineExec(command, request, response); \ 
    211253    return GET_PLUGIN()->wrapCommandLineExec(retCode, response, response_buffer, response_len); \ 
    212254    } catch (const std::exception &e) { \ 
     
    220262    } \ 
    221263  } \ 
    222  
    223264 
    224265 
  • include/nscapi/nscapi_plugin_wrapper.cpp

    rd7e265d r81e420c  
    135135  return has?NSCAPI::istrue:NSCAPI::isfalse; 
    136136} 
     137NSCAPI::boolReturn nscapi::plugin_wrapper::wrapHasRoutingHandler(bool has) { 
     138  return has?NSCAPI::istrue:NSCAPI::isfalse; 
     139} 
    137140 
    138141NSCAPI::nagiosReturn nscapi::plugin_wrapper::wrapHandleNotification(NSCAPI::nagiosReturn retResult) { 
     142  return retResult; 
     143} 
     144NSCAPI::nagiosReturn nscapi::plugin_wrapper::wrapRouteMessage(NSCAPI::nagiosReturn retResult) { 
    139145  return retResult; 
    140146} 
  • include/nscapi/nscapi_plugin_wrapper.hpp

    rb38e845 r81e420c  
    6666    NSCAPI::boolReturn wrapHasCommandHandler(bool has); 
    6767    NSCAPI::boolReturn wrapHasMessageHandler(bool has); 
     68    NSCAPI::boolReturn wrapHasRoutingHandler(bool has); 
    6869    NSCAPI::boolReturn wrapHasNotificationHandler(bool has); 
    6970    NSCAPI::nagiosReturn wrapHandleNotification(NSCAPI::nagiosReturn retResult); 
     
    7172    NSCAPI::nagiosReturn wrapHandleCommand(NSCAPI::nagiosReturn retResult, const std::string &reply, char **reply_buffer, unsigned int *size); 
    7273    NSCAPI::nagiosReturn wrapCommandLineExec(NSCAPI::nagiosReturn retResult, const std::string &reply, char **reply_buffer, unsigned int *size); 
     74    NSCAPI::nagiosReturn wrapRouteMessage(NSCAPI::nagiosReturn retResult); 
    7375     
    7476    void wrapDeleteBuffer(char**buffer); 
  • libs/protobuf/plugin.proto

    rb38e845 r81e420c  
    2323    optional bool bool_data = 5; 
    2424  } 
     25 
     26  message KeyValue { 
     27    required string key = 1; 
     28    required string value = 2; 
     29    repeated string data = 3; 
     30  } 
    2531   
    2632 
     
    3036 
    3137  message Header { 
    32     enum Type { 
    33       QUERY_REQUEST = 1; 
    34       QUERY_RESPONSE = 2; 
    35        
    36       EXEC_REQUEST = 3; 
    37       EXEC_RESPONSE = 4; 
    38        
    39       LOG_MESSAGE = 5; 
    40     }; 
    41     required Type type = 1; 
    42     required Common.Version version = 2; 
    43     optional Common.Version max_supported_version = 3; 
    44      
    45     optional string sender = 17; 
    46     optional string recipient = 18; 
    47     optional int64 id = 19; 
    48   }; 
    49  
     38     
     39    required Common.Version version = 1; 
     40    optional Common.Version max_supported_version = 2; 
     41     
     42    optional string sender = 3; 
     43    optional string recipient = 4; 
     44     
     45    optional int64 id = 16; 
     46     
     47    repeated Common.KeyValue metadata = 5; 
     48    repeated string tags = 6; 
     49  }; 
     50 
     51  message Attachment { 
     52     
     53    optional int64 id = 1; 
     54    required string type = 2; 
     55    repeated Common.KeyValue metadata = 3; 
     56    repeated string tags = 4; 
     57    required string data = 5; 
     58  }; 
     59   
    5060  message PerformanceData { 
    5161    message IntValue { 
     
    97107    required string command = 2; 
    98108    repeated string arguments = 3; 
     109    repeated Common.Attachment attachments = 17; 
    99110  }; 
    100111 
    101112  required Common.Header header = 1; 
    102113  repeated Request payload = 2; 
     114  repeated Common.Attachment attachments = 3; 
    103115} 
    104116message QueryResponseMessage { 
     
    112124    required Common.ResultCode result = 3; 
    113125    required string message = 4; 
    114     optional string legacyPerf = 17; 
    115126    repeated Common.PerformanceData perf = 5; 
     127    repeated Common.Attachment attachments = 17; 
    116128     
    117129  } 
     
    119131  required Common.Header header = 1; 
    120132  repeated Response payload = 2; 
     133  repeated Common.Attachment attachments = 3; 
    121134} 
    122135 
     
    160173    required string command = 2; 
    161174    repeated string arguments = 3; 
     175    repeated Common.Attachment attachments = 17; 
    162176  }; 
    163177 
    164178  required Common.Header header = 1; 
    165179  repeated Request payload = 2; 
     180  repeated Common.Attachment attachments = 3; 
    166181} 
    167182message ExecuteResponseMessage { 
     
    190205     
    191206    optional ResponseData data = 11; 
     207    repeated Common.Attachment attachments = 17; 
    192208     
    193209  } 
    194210  required Common.Header header = 1; 
    195211  repeated Response payload = 2; 
     212  repeated Common.Attachment attachments = 3; 
    196213} 
    197214 
     
    206223  required Common.Header header = 1; 
    207224  repeated QueryResponseMessage.Response payload = 2; 
     225  repeated Common.Attachment attachments = 3; 
    208226} 
    209227 
  • modules/CheckDisk/CheckDisk.cpp

    r4b1e6fe r81e420c  
    4141 
    4242namespace sh = nscapi::settings_helper; 
    43  
    44 CheckDisk gCheckDisk; 
    4543 
    4644CheckDisk::CheckDisk() : show_errors_(false) { 
     
    787785 
    788786NSC_WRAP_DLL(); 
    789 NSC_WRAPPERS_MAIN_DEF(gCheckDisk); 
     787NSC_WRAPPERS_MAIN_DEF(CheckDisk); 
    790788NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    791 NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckDisk); 
     789NSC_WRAPPERS_HANDLE_CMD_DEF(); 
  • modules/CheckDisk/CheckDisk.h

    rfe75eff r81e420c  
    3838  bool unloadModule(); 
    3939 
    40   std::wstring getModuleName() { 
     40  static std::wstring getModuleName() { 
    4141    return _T("CheckDisk"); 
    4242  } 
    43   std::wstring getModuleDescription() { 
     43  static std::wstring getModuleDescription() { 
    4444    return _T("CheckDisk can check various file and disk related things.\nThe current version has commands to check Size of hard drives and directories."); 
    4545  } 
    46   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     46  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    4747    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    4848    return version; 
  • modules/CheckEventLog/CheckEventLog.cpp

    r4b1e6fe r81e420c  
    5151#include "simple_registry.hpp" 
    5252#include "eventlog_record.hpp" 
    53  
    54 CheckEventLog gCheckEventLog; 
    5553 
    5654CheckEventLog::CheckEventLog() { 
     
    375373 
    376374NSC_WRAP_DLL(); 
    377 NSC_WRAPPERS_MAIN_DEF(gCheckEventLog); 
     375NSC_WRAPPERS_MAIN_DEF(CheckEventLog); 
    378376NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    379 NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckEventLog); 
     377NSC_WRAPPERS_HANDLE_CMD_DEF(); 
  • modules/CheckEventLog/CheckEventLog.h

    rfe75eff r81e420c  
    2727 
    2828 
    29 class CheckEventLog  : public nscapi::impl::simple_command, nscapi::impl::simple_plugin { 
     29class CheckEventLog : public nscapi::impl::simple_command, nscapi::impl::simple_plugin { 
    3030private: 
    3131  bool debug_; 
     
    4242  bool unloadModule(); 
    4343 
    44   std::wstring getModuleName() { 
     44  static std::wstring getModuleName() { 
    4545    return _T("Event log Checker."); 
    4646  } 
    47   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     47  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    4848    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    4949    return version; 
    5050  } 
    51   std::wstring getModuleDescription() { 
     51  static std::wstring getModuleDescription() { 
    5252    return _T("Check for errors and warnings in the event log.\nThis is only supported through NRPE so if you plan to use only NSClient this wont help you at all."); 
    5353  } 
  • modules/CheckExternalScripts/CheckExternalScripts.cpp

    rd7e265d r81e420c  
    3434 
    3535namespace sh = nscapi::settings_helper; 
    36  
    37  
    38 CheckExternalScripts gCheckExternalScripts; 
    3936 
    4037CheckExternalScripts::CheckExternalScripts() {} 
     
    198195  } 
    199196} 
    200 //  
    201 //  
    202 //  
    203 //  std::wstring msg, perf; 
    204 //  NSCAPI::nagiosReturn ret = handleCommand(data.command, data.args, msg, perf); 
    205 //  return nscapi::functions::process_simple_command_result(data.command, ret, msg, perf); 
    206 // } 
    207 //  
    208 // NSCAPI::nagiosReturn CheckExternalScripts::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 
    209 //  command_list::const_iterator cit = commands.find(command); 
    210 //  bool isAlias = false; 
    211 //  if (cit == commands.end()) { 
    212 //    cit = alias.find(command); 
    213 //    if (cit == alias.end()) 
    214 //      return NSCAPI::returnIgnored; 
    215 //    isAlias = true; 
    216 //  } 
    217 //  
    218 //  const command_data cd = (*cit).second; 
    219 //  std::wstring args = cd.arguments; 
    220 //  if (isAlias || allowArgs_) { 
    221 //    int i=1; 
    222 //    BOOST_FOREACH(std::wstring str, arguments) { 
    223 //      if (!isAlias && !allowNasty_) { 
    224 //        if (str.find_first_of(NASTY_METACHARS) != std::wstring::npos) { 
    225 //          NSC_LOG_ERROR(_T("Request string contained illegal metachars!")); 
    226 //          return NSCAPI::returnIgnored; 
    227 //        } 
    228 //      } 
    229 //      strEx::replace(args, _T("$ARG") + strEx::itos(i++) + _T("$"), str); 
    230 //    } 
    231 //  } 
    232 //  if (isAlias) { 
    233 //    try { 
    234 //      return GET_CORE()->InjectSplitAndCommand(cd.command, args, ' ', message, perf, true); 
    235 //    } catch (boost::escaped_list_error &e) { 
    236 //      NSC_LOG_MESSAGE(_T("Failed to parse alias expression: ") + strEx::string_to_wstring(e.what())); 
    237 //      NSC_LOG_MESSAGE(_T("We will now try parsing the old syntax instead...")); 
    238 //      return GET_CORE()->InjectSplitAndCommand(cd.command, args, ' ', message, perf, false); 
    239 //    } 
    240 //  } else { 
    241 //    int result = process::executeProcess(process::exec_arguments(root_, cd.command + _T(" ") + args, timeout), message, perf); 
    242 //    if (!nscapi::plugin_helper::isNagiosReturnCode(result)) { 
    243 //      NSC_LOG_ERROR_STD(_T("The command (") + cd.command + _T(") returned an invalid return code: ") + strEx::itos(result)); 
    244 //      return NSCAPI::returnUNKNOWN; 
    245 //    } 
    246 //    return nscapi::plugin_helper::int2nagios(result); 
    247 //  } 
    248 //  
    249 // } 
    250  
    251  
    252197NSC_WRAP_DLL(); 
    253 NSC_WRAPPERS_MAIN_DEF(gCheckExternalScripts); 
     198NSC_WRAPPERS_MAIN_DEF(CheckExternalScripts); 
    254199NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    255 NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckExternalScripts); 
    256  
     200NSC_WRAPPERS_HANDLE_CMD_DEF(); 
     201 
  • modules/CheckExternalScripts/CheckExternalScripts.h

    rc391984 r81e420c  
    8080 
    8181 
    82   std::wstring getModuleName() { 
     82  static std::wstring getModuleName() { 
    8383    return _T("Check External Scripts"); 
    8484  } 
    85   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     85  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    8686    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    8787    return version; 
    8888  } 
    89   std::wstring getModuleDescription() { 
     89  static std::wstring getModuleDescription() { 
    9090    return _T("A simple wrapper to run external scripts and batch files."); 
    9191  } 
  • modules/CheckHelpers/CheckHelpers.cpp

    r4b1e6fe r81e420c  
    3131#include <settings/client/settings_client.hpp> 
    3232 
    33  
    34 CheckHelpers gCheckHelpers; 
    35  
    3633CheckHelpers::CheckHelpers() { 
    3734} 
     
    332329 
    333330NSC_WRAP_DLL(); 
    334 NSC_WRAPPERS_MAIN_DEF(gCheckHelpers); 
     331NSC_WRAPPERS_MAIN_DEF(CheckHelpers); 
    335332NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    336 NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckHelpers); 
     333NSC_WRAPPERS_HANDLE_CMD_DEF(); 
  • modules/CheckHelpers/CheckHelpers.h

    rfe75eff r81e420c  
    3535 
    3636 
    37   std::wstring getModuleName() { 
     37  static std::wstring getModuleName() { 
    3838    return _T("Helper function"); 
    3939  } 
    40   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     40  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    4141    nscapi::plugin_wrapper::module_version version = {0, 3, 0 }; 
    4242    return version; 
    4343  } 
    44   std::wstring getModuleDescription() { 
     44  static std::wstring getModuleDescription() { 
    4545    return _T("Various helper function to extend other checks.\nThis is also only supported through NRPE."); 
    4646  } 
  • modules/CheckNSCP/CheckNSCP.cpp

    r4b1e6fe r81e420c  
    2626#include <settings/client/settings_client.hpp> 
    2727namespace sh = nscapi::settings_helper; 
    28  
    29 CheckNSCP gCheckNSCP; 
    30  
    31  
    3228 
    3329bool CheckNSCP::loadModule() { 
     
    163159 
    164160NSC_WRAP_DLL(); 
    165 NSC_WRAPPERS_MAIN_DEF(gCheckNSCP); 
    166 NSC_WRAPPERS_HANDLE_MSG_DEF(gCheckNSCP); 
    167 NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckNSCP); 
     161NSC_WRAPPERS_MAIN_DEF(CheckNSCP); 
     162NSC_WRAPPERS_HANDLE_MSG_DEF(); 
     163NSC_WRAPPERS_HANDLE_CMD_DEF(); 
  • modules/CheckNSCP/CheckNSCP.h

    rfe75eff r81e420c  
    4747 
    4848 
    49   std::wstring getModuleName() { 
     49  static std::wstring getModuleName() { 
    5050    return _T("Check NSCP"); 
    5151  } 
    52   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     52  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    5353    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    5454    return version; 
    5555  } 
    56   std::wstring getModuleDescription() { 
     56  static std::wstring getModuleDescription() { 
    5757    return _T("Checkes the state of the agent"); 
    5858  } 
  • modules/CheckSystem/CheckSystem.cpp

    r4b1e6fe r81e420c  
    3838#include <settings/client/settings_client.hpp> 
    3939#include <arrayBuffer.h> 
    40  
    41 CheckSystem gCheckSystem; 
    4240 
    4341/** 
     
    16251623 
    16261624NSC_WRAP_DLL(); 
    1627 NSC_WRAPPERS_MAIN_DEF(gCheckSystem); 
     1625NSC_WRAPPERS_MAIN_DEF(CheckSystem); 
    16281626NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    1629 NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckSystem); 
     1627NSC_WRAPPERS_HANDLE_CMD_DEF(); 
    16301628//NSC_WRAPPERS_CLI_DEF(gCheckSystem); 
    16311629 
  • modules/CheckSystem/CheckSystem.h

    rfe75eff r81e420c  
    5959  * @return The module name 
    6060  */ 
    61   std::wstring getModuleName() { 
     61  static std::wstring getModuleName() { 
    6262    return _T("CheckSystem"); 
    6363  } 
     
    6666  * @return module version 
    6767  */ 
    68   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     68  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    6969    nscapi::plugin_wrapper::module_version version = {0, 3, 0 }; 
    7070    return version; 
    7171  } 
    72   std::wstring getModuleDescription() { 
     72  static std::wstring getModuleDescription() { 
    7373    return _T("Various system related checks, such as CPU load, process state, service state memory usage and PDH counters."); 
    7474  } 
  • modules/CheckTaskSched/CheckTaskSched.cpp

    r4b1e6fe r81e420c  
    3838#include "settings.hpp" 
    3939 
    40  
    41 CheckTaskSched gCheckTaskSched; 
    4240 
    4341bool CheckTaskSched::loadModule() { 
     
    184182 
    185183NSC_WRAP_DLL(); 
    186 NSC_WRAPPERS_MAIN_DEF(gCheckTaskSched); 
     184NSC_WRAPPERS_MAIN_DEF(CheckTaskSched); 
    187185NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    188 NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckTaskSched); 
     186NSC_WRAPPERS_HANDLE_CMD_DEF(); 
    189187//NSC_WRAPPERS_CLI_DEF(gCheckTaskSched); 
  • modules/CheckTaskSched/CheckTaskSched.h

    rfe75eff r81e420c  
    3838  bool unloadModule(); 
    3939 
    40   std::wstring getModuleName() { 
     40  static std::wstring getModuleName() { 
    4141    return _T("CheckTaskSched"); 
    4242  } 
    43   std::wstring getModuleDescription() { 
     43  static std::wstring getModuleDescription() { 
    4444    return _T("CheckTaskSched can check various file and disk related things.\nThe current version has commands to check Size of hard drives and directories."); 
    4545  } 
    46   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     46  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    4747    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    4848    return version; 
  • modules/CheckTaskSched2/CheckTaskSched2.cpp

    r4b1e6fe r81e420c  
    3737#include <settings/client/settings_client.hpp> 
    3838#include "../CheckTaskSched/settings.hpp" 
    39  
    40 CheckTaskSched2 gCheckTaskSched2; 
    4139 
    4240bool CheckTaskSched2::loadModule() { 
     
    183181 
    184182NSC_WRAP_DLL(); 
    185 NSC_WRAPPERS_MAIN_DEF(gCheckTaskSched2); 
     183NSC_WRAPPERS_MAIN_DEF(CheckTaskSched2); 
    186184NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    187 NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckTaskSched2); 
     185NSC_WRAPPERS_HANDLE_CMD_DEF(CheckTaskSched2); 
    188186//NSC_WRAPPERS_CLI_DEF(gCheckTaskSched); 
  • modules/CheckTaskSched2/CheckTaskSched2.h

    rfe75eff r81e420c  
    3838  bool unloadModule(); 
    3939 
    40   std::wstring getModuleName() { 
     40  static std::wstring getModuleName() { 
    4141    return _T("CheckTaskSched2"); 
    4242  } 
    43   std::wstring getModuleDescription() { 
     43  static std::wstring getModuleDescription() { 
    4444    return _T("CheckTaskSched2 can check various file and disk related things.\nThe current version has commands to check Size of hard drives and directories."); 
    4545  } 
    46   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     46  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    4747    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    4848    return version; 
  • modules/CheckWMI/CheckWMI.cpp

    r4b1e6fe r81e420c  
    3232 
    3333#include <arrayBuffer.h> 
    34  
    35 CheckWMI gCheckWMI; 
    3634 
    3735CheckWMI::CheckWMI() { 
     
    443441 
    444442NSC_WRAP_DLL(); 
    445 NSC_WRAPPERS_MAIN_DEF(gCheckWMI); 
     443NSC_WRAPPERS_MAIN_DEF(CheckWMI); 
    446444NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    447 NSC_WRAPPERS_HANDLE_CMD_DEF(gCheckWMI); 
     445NSC_WRAPPERS_HANDLE_CMD_DEF(); 
    448446//NSC_WRAPPERS_CLI_DEF(gCheckWMI); 
  • modules/CheckWMI/CheckWMI.h

    rfe75eff r81e420c  
    9797  bool unloadModule(); 
    9898 
    99   std::wstring getModuleName() { 
     99  static std::wstring getModuleName() { 
    100100    return _T("CheckWMI"); 
    101101  } 
    102   std::wstring getModuleDescription() { 
     102  static std::wstring getModuleDescription() { 
    103103    return _T("CheckWMI can check various file and disk related things.\nThe current version has commands to check Size of hard drives and directories."); 
    104104  } 
    105   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     105  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    106106    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    107107    return version; 
  • modules/FileLogger/FileLogger.cpp

    r4b1e6fe r81e420c  
    3636 
    3737namespace sh = nscapi::settings_helper; 
    38  
    39 FileLogger gFileLogger; 
    4038 
    4139FileLogger::FileLogger() : init_(false) { 
     
    232230 
    233231NSC_WRAP_DLL(); 
    234 NSC_WRAPPERS_MAIN_DEF(gFileLogger); 
    235 NSC_WRAPPERS_HANDLE_MSG_DEF(gFileLogger); 
     232NSC_WRAPPERS_MAIN_DEF(FileLogger); 
     233NSC_WRAPPERS_HANDLE_MSG_DEF(); 
    236234NSC_WRAPPERS_IGNORE_CMD_DEF(); 
  • modules/FileLogger/FileLogger.h

    r3bdaf18 r81e420c  
    4444 
    4545 
    46   std::wstring getModuleName() { 
     46  static std::wstring getModuleName() { 
    4747    return _T("File logger"); 
    4848  } 
    49   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     49  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    5050    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    5151    return version; 
    5252  } 
    53   std::wstring getModuleDescription() { 
     53  static std::wstring getModuleDescription() { 
    5454    return _T("Writes errors and (if configured) debug info to a text file."); 
    5555  } 
  • modules/LUAScript/LUAScript.cpp

    rfe75eff r81e420c  
    2929#include <settings/client/settings_client.hpp> 
    3030 
    31  
    32 LUAScript gLUAScript; 
    3331 
    3432LUAScript::LUAScript() { 
     
    183181 
    184182NSC_WRAP_DLL(); 
    185 NSC_WRAPPERS_MAIN_DEF(gLUAScript); 
     183NSC_WRAPPERS_MAIN_DEF(LUAScript); 
    186184NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    187 NSC_WRAPPERS_HANDLE_CMD_DEF(gLUAScript); 
     185NSC_WRAPPERS_HANDLE_CMD_DEF(); 
  • modules/LUAScript/LUAScript.h

    rfe75eff r81e420c  
    6565  bool reload(std::wstring &msg); 
    6666 
    67   std::wstring getModuleName() { 
     67  static std::wstring getModuleName() { 
    6868    return _T("LUAScript"); 
    6969  } 
    70   std::wstring getModuleDescription() { 
     70  static std::wstring getModuleDescription() { 
    7171    return _T("LUAScript..."); 
    7272  } 
    73   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     73  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    7474    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    7575    return version; 
  • modules/NRPEClient/NRPEClient.cpp

    rd7e265d r81e420c  
    8888namespace sh = nscapi::settings_helper; 
    8989 
    90 NRPEClient gNRPEClient; 
    91  
    9290NRPEClient::NRPEClient() : buffer_length_(0) { 
    9391} 
     
    320318 
    321319NSC_WRAP_DLL(); 
    322 NSC_WRAPPERS_MAIN_DEF(gNRPEClient); 
     320NSC_WRAPPERS_MAIN_DEF(NRPEClient); 
    323321NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    324 NSC_WRAPPERS_HANDLE_CMD_DEF(gNRPEClient); 
    325 NSC_WRAPPERS_CLI_DEF(gNRPEClient); 
    326  
     322NSC_WRAPPERS_HANDLE_CMD_DEF(); 
     323NSC_WRAPPERS_CLI_DEF(); 
     324 
  • modules/NRPEClient/NRPEClient.h

    rfe75eff r81e420c  
    101101 
    102102 
    103   std::wstring getModuleName() { 
     103  static std::wstring getModuleName() { 
    104104#ifdef USE_SSL 
    105105    return _T("NRPE client (w/ SSL)"); 
     
    108108#endif 
    109109  } 
    110   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     110  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    111111    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    112112    return version; 
    113113  } 
    114   std::wstring getModuleDescription() { 
     114  static std::wstring getModuleDescription() { 
    115115    return _T("A simple client for checking remote NRPE servers (think proxy).\n") 
    116116#ifndef USE_BOOST 
  • modules/NRPEServer/NRPEServer.cpp

    rb9498ef r81e420c  
    3232namespace sh = nscapi::settings_helper; 
    3333 
    34 NRPEListener gNRPEListener; 
    3534 
    3635NRPEListener::NRPEListener() : info_(boost::shared_ptr<nrpe::server::handler>(new handler_impl(1024))) { 
     
    183182} 
    184183 
    185  
    186  
    187  
    188 // void NRPEListener::onAccept(simpleSocket::Socket *client)  
    189 // { 
    190 //  if (!allowedHosts.inAllowedHosts(client->getAddr())) { 
    191 //    NSC_LOG_ERROR(_T("Unauthorize access from: ") + client->getAddrString()); 
    192 //    client->close(); 
    193 //    return; 
    194 //  } 
    195 //  try { 
    196 //    simpleSocket::DataBuffer block; 
    197 //    int i; 
    198 //    int maxWait = socketTimeout_*10; 
    199 //    for (i=0;i<maxWait;i++) { 
    200 //      bool lastReadHasMore = false; 
    201 //      try { 
    202 //        lastReadHasMore = client->readAll(block, 1048); 
    203 //      } catch (simpleSocket::SocketException e) { 
    204 //        NSC_LOG_MESSAGE(_T("Could not read NRPE packet from socket :") + e.getMessage()); 
    205 //        client->close(); 
    206 //        return; 
    207 //      } 
    208 //      if (block.getLength() >= NRPEPacket::getBufferLength(buffer_length_)) 
    209 //        break; 
    210 //      if (!lastReadHasMore) { 
    211 //        NSC_LOG_MESSAGE(_T("Could not read a full NRPE packet from socket, only got: ") + strEx::itos(block.getLength())); 
    212 //        client->close(); 
    213 //        return; 
    214 //      } 
    215 //      Sleep(100); 
    216 //    } 
    217 //    if (i >= maxWait) { 
    218 //      NSC_LOG_ERROR_STD(_T("Timeout reading NRPE-packet (increase socket_timeout), we only got: ") + strEx::itos(block.getLength())); 
    219 //      client->close(); 
    220 //      return; 
    221 //    } 
    222 //    if (block.getLength() == NRPEPacket::getBufferLength(buffer_length_)) { 
    223 //      try { 
    224 //        NRPEPacket out = handlePacket(NRPEPacket(block.getBuffer(), block.getLength(), buffer_length_)); 
    225 //        block.copyFrom(out.getBuffer(), out.getBufferLength()); 
    226 //      } catch (NRPEPacket::NRPEPacketException e) { 
    227 //        NSC_LOG_ERROR_STD(_T("NRPESocketException: ") + e.getMessage()); 
    228 //        try { 
    229 //          NRPEPacket err(NRPEPacket::responsePacket, NRPEPacket::version2, NSCAPI::returnUNKNOWN, _T("Could not construct return paket in NRPE handler check clientside (nsclient.log) logs..."), buffer_length_); 
    230 //          block.copyFrom(err.getBuffer(), err.getBufferLength()); 
    231 //        } catch (NRPEPacket::NRPEPacketException e) { 
    232 //          NSC_LOG_ERROR_STD(_T("NRPESocketException (again): ") + e.getMessage()); 
    233 //          client->close(); 
    234 //          return; 
    235 //        } 
    236 //      } 
    237 //      int maxWait = socketTimeout_*10; 
    238 //      for (i=0;i<maxWait;i++) { 
    239 //        bool lastReadHasMore = false; 
    240 //        try { 
    241 //          if (client->canWrite()) 
    242 //            lastReadHasMore = client->sendAll(block); 
    243 //        } catch (simpleSocket::SocketException e) { 
    244 //          NSC_LOG_MESSAGE(_T("Could not send NRPE packet from socket :") + e.getMessage()); 
    245 //          client->close(); 
    246 //          return; 
    247 //        } 
    248 //        if (!lastReadHasMore) { 
    249 //          client->close(); 
    250 //          return; 
    251 //        } 
    252 //        Sleep(100); 
    253 //      } 
    254 //      if (i >= maxWait) { 
    255 //        NSC_LOG_ERROR_STD(_T("Timeout reading NRPE-packet (increase socket_timeout)")); 
    256 //        client->close(); 
    257 //        return; 
    258 //      } 
    259 //    } else { 
    260 //      NSC_LOG_ERROR_STD(_T("We got more then we wanted ") + strEx::itos(NRPEPacket::getBufferLength(buffer_length_)) + _T(", we only got: ") + strEx::itos(block.getLength())); 
    261 //      client->close(); 
    262 //      return; 
    263 //    } 
    264 //  } catch (simpleSocket::SocketException e) { 
    265 //    NSC_LOG_ERROR_STD(_T("SocketException: ") + e.getMessage()); 
    266 //  } catch (NRPEException e) { 
    267 //    NSC_LOG_ERROR_STD(_T("NRPEException: ") + e.getMessage()); 
    268 //  } catch (...) { 
    269 //    NSC_LOG_ERROR_STD(_T("Unhandled Exception in NRPE listner...")); 
    270 //  } 
    271 //  client->close(); 
    272 // } 
    273 //  
    274 // NRPEPacket NRPEListener::handlePacket(NRPEPacket p) { 
    275 //  if (p.getType() != NRPEPacket::queryPacket) { 
    276 //    NSC_LOG_ERROR(_T("Request is not a query.")); 
    277 //    throw NRPEException(_T("Invalid query type: ") + strEx::itos(p.getType())); 
    278 //  } 
    279 //  if (p.getVersion() != NRPEPacket::version2) { 
    280 //    NSC_LOG_ERROR(_T("Request had unsupported version.")); 
    281 //    throw NRPEException(_T("Invalid version")); 
    282 //  } 
    283 //  if (!p.verifyCRC()) { 
    284 //    NSC_LOG_ERROR(_T("Request had invalid checksum.")); 
    285 //    throw NRPEException(_T("Invalid checksum")); 
    286 //  } 
    287 //  strEx::token cmd = strEx::getToken(p.getPayload(), '!'); 
    288 //  if (cmd.first == _T("_NRPE_CHECK")) { 
    289 //    return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, NSCAPI::returnOK, _T("I (") + NSCModuleHelper::getApplicationVersionString() + _T(") seem to be doing fine..."), buffer_length_); 
    290 //  } 
    291 //  std::wstring msg, perf; 
    292 //  
    293 //  if (allowArgs_) { 
    294 //    if (!cmd.second.empty()) { 
    295 //      NSC_LOG_ERROR(_T("Request contained arguments (not currently allowed, check the allow_arguments option).")); 
    296 //      throw NRPEException(_T("Request contained arguments (not currently allowed, check the allow_arguments option).")); 
    297 //    } 
    298 //  } 
    299 //  if (allowNasty_) { 
    300 //    if (cmd.first.find_first_of(NASTY_METACHARS) != std::wstring::npos) { 
    301 //      NSC_LOG_ERROR(_T("Request command contained illegal metachars!")); 
    302 //      throw NRPEException(_T("Request command contained illegal metachars!")); 
    303 //    } 
    304 //    if (cmd.second.find_first_of(NASTY_METACHARS) != std::wstring::npos) { 
    305 //      NSC_LOG_ERROR(_T("Request arguments contained illegal metachars!")); 
    306 //      throw NRPEException(_T("Request command contained illegal metachars!")); 
    307 //    } 
    308 //  } 
    309 //  //TODO REMOVE THIS 
    310 //  //return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, NSCAPI::returnUNKNOWN, _T("TEST TEST TEST"), buffer_length_); 
    311 //  
    312 //  NSCAPI::nagiosReturn ret = -3; 
    313 //  try { 
    314 //    ret = NSCModuleHelper::InjectSplitAndCommand(cmd.first, cmd.second, '!', msg, perf); 
    315 //  } catch (...) { 
    316 //    return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, NSCAPI::returnUNKNOWN, _T("UNKNOWN: Internal exception"), buffer_length_); 
    317 //  } 
    318 //  switch (ret) { 
    319 //    case NSCAPI::returnInvalidBufferLen: 
    320 //      msg = _T("UNKNOWN: Return buffer to small to handle this command."); 
    321 //      ret = NSCAPI::returnUNKNOWN; 
    322 //      break; 
    323 //    case NSCAPI::returnIgnored: 
    324 //      msg = _T("UNKNOWN: No handler for that command"); 
    325 //      ret = NSCAPI::returnUNKNOWN; 
    326 //      break; 
    327 //    case NSCAPI::returnOK: 
    328 //    case NSCAPI::returnWARN: 
    329 //    case NSCAPI::returnCRIT: 
    330 //    case NSCAPI::returnUNKNOWN: 
    331 //      break; 
    332 //    default: 
    333 //      msg = _T("UNKNOWN: Internal error."); 
    334 //      ret = NSCAPI::returnUNKNOWN; 
    335 //  } 
    336 //  if (msg.length() >= buffer_length_-1) { 
    337 //    NSC_LOG_ERROR(_T("Truncating returndata as it is bigger then NRPE allowes :(")); 
    338 //    msg = msg.substr(0,buffer_length_-2); 
    339 //  } 
    340 //  if (perf.empty()||noPerfData_) { 
    341 //    return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, ret, msg, buffer_length_); 
    342 //  } else { 
    343 //    return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, ret, msg + _T("|") + perf, buffer_length_); 
    344 //  } 
    345 // } 
    346  
    347184NSC_WRAP_DLL(); 
    348 NSC_WRAPPERS_MAIN_DEF(gNRPEListener); 
     185NSC_WRAPPERS_MAIN_DEF(NRPEListener); 
    349186NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    350187NSC_WRAPPERS_IGNORE_CMD_DEF(); 
  • modules/NRPEServer/NRPEServer.h

    rb9498ef r81e420c  
    4848 
    4949 
    50   std::wstring getModuleName() { 
     50  static std::wstring getModuleName() { 
    5151#ifdef USE_SSL 
    5252    return _T("NRPE server"); 
     
    5555#endif 
    5656  } 
    57   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     57  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    5858    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    5959    return version; 
    6060  } 
    61   std::wstring getModuleDescription() { 
     61  static std::wstring getModuleDescription() { 
    6262    return _T("A simple server that listens for incoming NRPE connection and handles them.\nNRPE is preferred over NSClient as it is more flexible. You can of cource use both NSClient and NRPE."); 
    6363  } 
  • modules/NSCAAgent/NSCAAgent.cpp

    r4b1e6fe r81e420c  
    3030 
    3131#include <settings/client/settings_client.hpp> 
    32  
    33 NSCAAgent gNSCAAgent; 
    3432 
    3533namespace sh = nscapi::settings_helper; 
     
    176174 
    177175NSC_WRAP_DLL(); 
    178 NSC_WRAPPERS_MAIN_DEF(gNSCAAgent); 
     176NSC_WRAPPERS_MAIN_DEF(NSCAAgent); 
    179177NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    180178NSC_WRAPPERS_IGNORE_CMD_DEF(); 
    181 NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF(gNSCAAgent); 
     179NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF(); 
  • modules/NSCAAgent/NSCAAgent.h

    rc760fc9 r81e420c  
    5050  * @return The module name 
    5151  */ 
    52   std::wstring getModuleName() { 
     52  static std::wstring getModuleName() { 
    5353#ifdef HAVE_LIBCRYPTOPP 
    5454    return _T("NSCAAgent (w/ encryption)"); 
     
    6161  * @return module version 
    6262  */ 
    63   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     63  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    6464    nscapi::plugin_wrapper::module_version version = {0, 3, 0 }; 
    6565    return version; 
    6666  } 
    67   std::wstring getModuleDescription() { 
     67  static std::wstring getModuleDescription() { 
    6868    return std::wstring(_T("Passive check support (needs NSCA on nagios server).\nAvalible crypto are: ")) + getCryptos(); 
    6969  } 
    7070  bool hasNotificationHandler() { return true; } 
    7171 
    72   std::wstring getCryptos(); 
     72  static std::wstring getCryptos(); 
    7373 
    7474  NSCAPI::nagiosReturn handleSimpleNotification(const std::wstring channel, const std::wstring command, NSCAPI::nagiosReturn code, std::wstring msg, std::wstring perf); 
  • modules/NSCPClient/NSCPClient.cpp

    r60e6c18 r81e420c  
    3636namespace sh = nscapi::settings_helper; 
    3737 
    38 NSCPClient gNSCPClient; 
    39  
    4038NSCPClient::NSCPClient() : buffer_length_(0) { 
    4139} 
     
    533531 
    534532NSC_WRAP_DLL(); 
    535 NSC_WRAPPERS_MAIN_DEF(gNSCPClient); 
     533NSC_WRAPPERS_MAIN_DEF(NSCPClient); 
    536534NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    537 NSC_WRAPPERS_HANDLE_CMD_DEF(gNSCPClient); 
    538 NSC_WRAPPERS_CLI_DEF(gNSCPClient); 
    539  
     535NSC_WRAPPERS_HANDLE_CMD_DEF(); 
     536NSC_WRAPPERS_CLI_DEF(); 
     537 
  • modules/NSCPClient/NSCPClient.h

    r60e6c18 r81e420c  
    8080 
    8181 
    82   std::wstring getModuleName() { 
     82  static std::wstring getModuleName() { 
    8383#ifdef USE_SSL 
    8484    return _T("NSCP client (w/ SSL)"); 
     
    8787#endif 
    8888  } 
    89   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     89  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    9090    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    9191    return version; 
    9292  } 
    93   std::wstring getModuleDescription() { 
     93  static std::wstring getModuleDescription() { 
    9494    return _T("A simple client for checking remote NSCP servers (think proxy).\n") 
    9595#ifndef USE_SSL 
  • modules/NSCPServer/NSCPServer.cpp

    r438998b r81e420c  
    3131 
    3232namespace sh = nscapi::settings_helper; 
    33  
    34 NSCPListener gNSCPListener; 
    3533 
    3634NSCPListener::NSCPListener() : info_(boost::shared_ptr<nscp::server::handler>(new handler_impl(1024))) { 
     
    160158 
    161159NSC_WRAP_DLL(); 
    162 NSC_WRAPPERS_MAIN_DEF(gNSCPListener); 
     160NSC_WRAPPERS_MAIN_DEF(NSCPListener); 
    163161NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    164162NSC_WRAPPERS_IGNORE_CMD_DEF(); 
  • modules/NSCPServer/NSCPServer.h

    r438998b r81e420c  
    4848 
    4949 
    50   std::wstring getModuleName() { 
     50  static std::wstring getModuleName() { 
    5151#ifdef USE_SSL 
    5252    return _T("NSCP server"); 
     
    5555#endif 
    5656  } 
    57   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     57  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    5858    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    5959    return version; 
    6060  } 
    61   std::wstring getModuleDescription() { 
     61  static std::wstring getModuleDescription() { 
    6262    return _T("A simple server that listens for incoming NSCP connection and handles them."); 
    6363  } 
  • modules/NSClientServer/NSClientServer.cpp

    rb9498ef r81e420c  
    2727#include "settings.hpp" 
    2828#include <settings/client/settings_client.hpp> 
    29  
    30 NSClientListener gNSClientListener; 
    31  
    32  
    3329 
    3430namespace sh = nscapi::settings_helper; 
     
    172168} 
    173169 
    174 // void NSClientListener::sendTheResponse(simpleSocket::Socket *client, std::string response) { 
    175 //  client->send(response.c_str(), static_cast<int>(response.length()), 0); 
    176 // } 
    177 //  
    178 // void NSClientListener::retrivePacket(simpleSocket::Socket *client) { 
    179 //  simpleSocket::DataBuffer db; 
    180 //  unsigned int i; 
    181 //  unsigned int maxWait = socketTimeout_*10; 
    182 //  for (i=0;i<maxWait;i++) { 
    183 //    bool lastReadHasMore = false; 
    184 //    try { 
    185 //      lastReadHasMore = client->readAll(db); 
    186 //    } catch (simpleSocket::SocketException e) { 
    187 //      NSC_LOG_ERROR_STD(_T("Read on socket failed: ") + e.getMessage()); 
    188 //      client->close(); 
    189 //      return; 
    190 //    } 
    191 //    if (db.getLength() > 0) { 
    192 //      unsigned long long pos = db.find('\n'); 
    193 //      if (pos==-1) { 
    194 //        std::string incoming(db.getBuffer(), db.getLength()); 
    195 //        sendTheResponse(client, parseRequest(incoming)); 
    196 //        break; 
    197 //      } else if (pos > 0) { 
    198 //        simpleSocket::DataBuffer buffer = db.unshift(static_cast<const unsigned int>(pos)); 
    199 //        std::string bstr(buffer.getBuffer(), buffer.getLength()); 
    200 //        db.nibble(1); 
    201 //        std::string rstr(db.getBuffer(), db.getLength()); 
    202 //        std::string incoming(buffer.getBuffer(), buffer.getLength()); 
    203 //        sendTheResponse(client, parseRequest(incoming) + "\n"); 
    204 //      } else { 
    205 //        db.nibble(1); 
    206 //        NSC_LOG_ERROR_STD(_T("First char should (i think) not be a \\n :(")); 
    207 //      } 
    208 //    } else if (!lastReadHasMore) { 
    209 //      client->close(); 
    210 //      return; 
    211 //    } else { 
    212 //      Sleep(100); 
    213 //    } 
    214 //  } 
    215 //  if (i >= maxWait) { 
    216 //    NSC_LOG_ERROR_STD(_T("Timeout reading NS-client packet (increase socket_timeout).")); 
    217 //    client->close(); 
    218 //    return; 
    219 //  } 
    220 // } 
    221  
    222 //  
    223 // void NSClientListener::onAccept(simpleSocket::Socket *client) { 
    224 //  if (!allowedHosts.inAllowedHosts(client->getAddr())) { 
    225 //    NSC_LOG_ERROR(_T("Unauthorized access from: ") + client->getAddrString()); 
    226 //    client->close(); 
    227 //    return; 
    228 //  } 
    229 //  //client->setNonBlock(); 
    230 //  retrivePacket(client); 
    231 //  
    232 //  
    233 //  
    234 // // client->readAll(db); 
    235 // // if (db.getLength() > 0) { 
    236 // //   std::wstring incoming(db.getBuffer(), db.getLength()); 
    237 // //   NSC_DEBUG_MSG_STD("Incoming data: " + incoming); 
    238 // //   std::wstring response = parseRequest(incoming); 
    239 // //   NSC_DEBUG_MSG("Outgoing data: " + response); 
    240 // //   client->send(response.c_str(), static_cast<int>(response.length()), 0); 
    241 // // } 
    242 //  client->close(); 
    243 // } 
    244  
    245170NSC_WRAP_DLL(); 
    246 NSC_WRAPPERS_MAIN_DEF(gNSClientListener); 
     171NSC_WRAPPERS_MAIN_DEF(NSClientListener); 
    247172NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    248173NSC_WRAPPERS_IGNORE_CMD_DEF(); 
  • modules/NSClientServer/NSClientServer.h

    rb9498ef r81e420c  
    4040 
    4141 
    42   std::wstring getModuleName() { 
     42  static std::wstring getModuleName() { 
    4343    return _T("NSClient server"); 
    4444  } 
    45   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     45  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    4646    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    4747    return version; 
    4848  } 
    49   std::wstring getModuleDescription() { 
     49  static std::wstring getModuleDescription() { 
    5050    return _T("A simple server that listens for incoming NSClient (check_nt) connection and handles them.\nAlthough NRPE is the preferred method NSClient is fully supported and can be used for simplicity or for compatibility."); 
    5151  } 
  • modules/PythonScript/PythonScript.cpp

    r4b1e6fe r81e420c  
    3232 
    3333#include "script_wrapper.hpp" 
    34  
    35 PythonScript gPythonScript; 
    3634 
    3735PythonScript::PythonScript() { 
     
    9997    ; 
    10098  def("log", script_wrapper::log_msg); 
    101   def("get_alias", script_wrapper::get_alias); 
     99//  def("get_module_alias", script_wrapper::get_module_alias); 
     100//  def("get_script_alias", script_wrapper::get_script_alias); 
    102101} 
    103102 
     
    241240  return true; 
    242241} 
    243  
    244  
    245242 
    246243bool PythonScript::reload(std::wstring &message) { 
     
    324321 
    325322NSC_WRAP_DLL(); 
    326 NSC_WRAPPERS_MAIN_DEF(gPythonScript); 
     323NSC_WRAPPERS_MAIN_DEF(PythonScript); 
    327324NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    328 NSC_WRAPPERS_HANDLE_CMD_DEF(gPythonScript); 
    329 NSC_WRAPPERS_CLI_DEF(gPythonScript); 
    330 NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF(gPythonScript); 
     325NSC_WRAPPERS_HANDLE_CMD_DEF(); 
     326NSC_WRAPPERS_CLI_DEF(); 
     327NSC_WRAPPERS_HANDLE_NOTIFICATION_DEF(); 
  • modules/PythonScript/PythonScript.h

    r2c95d22 r81e420c  
    6565  } 
    6666 
    67   std::wstring getModuleName() { 
     67  static std::wstring getModuleName() { 
    6868    return _T("PythonScript"); 
    6969  } 
    70   std::wstring getModuleDescription() { 
     70  static std::wstring getModuleDescription() { 
    7171    return _T("PythonScript..."); 
    7272  } 
    73   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     73  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    7474    nscapi::plugin_wrapper::module_version version = {0, 0, 1 }; 
    7575    return version; 
  • modules/PythonScript/script_wrapper.cpp

    rb9498ef r81e420c  
    99boost::shared_ptr<script_wrapper::functions> script_wrapper::functions::instance; 
    1010 
    11 extern PythonScript gPythonScript; 
     11//extern PythonScript gPythonScript; 
    1212 
    1313 
     
    1515  NSC_LOG_ERROR_STD(utf8::cvt<std::wstring>(x)); 
    1616} 
     17/* 
    1718std::string script_wrapper::get_alias() { 
    1819  return utf8::cvt<std::string>(gPythonScript.get_alias()); 
    1920} 
     21*/ 
    2022 
    2123void script_wrapper::log_exception() { 
  • modules/PythonScript/script_wrapper.hpp

    r2c95d22 r81e420c  
    1616  void log_exception(); 
    1717  void log_msg(std::wstring x); 
    18   std::string get_alias(); 
     18  //std::string get_alias(); 
    1919 
    2020  std::list<std::wstring> convert(boost::python::list lst); 
  • modules/Scheduler/Scheduler.cpp

    r4b1e6fe r81e420c  
    2727 
    2828#include <settings/client/settings_client.hpp> 
    29  
    30 Scheduler gInstance; 
    3129 
    3230namespace sh = nscapi::settings_helper; 
     
    179177 
    180178NSC_WRAP_DLL(); 
    181 NSC_WRAPPERS_MAIN_DEF(gInstance); 
     179NSC_WRAPPERS_MAIN_DEF(Scheduler); 
    182180NSC_WRAPPERS_IGNORE_MSG_DEF(); 
    183181NSC_WRAPPERS_IGNORE_CMD_DEF(); 
  • modules/Scheduler/Scheduler.h

    rc015acc r81e420c  
    4545  void on_error(std::wstring error); 
    4646 
    47   std::wstring getModuleName() { 
     47  static std::wstring getModuleName() { 
    4848    return _T("Scheduler"); 
    4949  } 
    50   nscapi::plugin_wrapper::module_version getModuleVersion() { 
     50  static nscapi::plugin_wrapper::module_version getModuleVersion() { 
    5151    nscapi::plugin_wrapper::module_version version = {0, 3, 0 }; 
    5252    return version; 
    5353  } 
    54   std::wstring getModuleDescription() { 
     54  static std::wstring getModuleDescription() { 
    5555    return _T("A scheduler which schedules checks at regular intervals"); 
    5656  } 
  • scripts/python/test.py

    r4b1e6fe r81e420c  
    1 from NSCP import Settings, Registry, Core, log, status, get_alias 
     1from NSCP import Settings, Registry, Core, log, status 
    22#import sys 
    33#sys.path.append('D:/source/nscp/build/x64/scripts/python/include') 
     
    3939  message = plugin_pb2.QueryRequestMessage() 
    4040   
    41   message.header.type = plugin_pb2.Common.Header.QUERY_REQUEST 
    4241  message.header.version = plugin_pb2.Common.VERSION_1 
    4342 
     
    105104    prefix = '%s_'%alias 
    106105 
    107   log('Script: test.py with alias: %s from %s'%(alias, get_alias())) 
     106  log('Script: test.py with alias: %s'%alias) 
    108107 
    109108  conf = Settings.get() 
  • service/CMakeLists.txt

    r04ef932 r81e420c  
    3838    cli_parser.hpp 
    3939     
     40    plugin_list.hpp 
    4041    commands.hpp 
    4142    channels.hpp 
     43    routers.hpp 
    4244    logger.hpp 
    4345    service_manager.hpp 
  • service/NSCPlugin.cpp

    r39c73cd r81e420c  
    4242  ,fGetVersion(NULL) 
    4343  ,fCommandLineExec(NULL) 
    44   ,fShowTray(NULL) 
    45   ,fHideTray(NULL) 
    4644  ,fHasNotificationHandler(NULL) 
    4745  ,fHandleNotification(NULL) 
     46  ,fHasRoutingHandler(NULL) 
     47  ,fRouteMessage(NULL) 
    4848  ,loaded_(false) 
    4949  ,lastIsMsgPlugin_(false) 
     
    5454 
    5555} 
    56 /* 
    57 NSCPlugin::NSCPlugin(NSCPlugin &other) 
    58   :module_() 
    59   ,fLoadModule(NULL) 
    60   ,fGetName(NULL) 
    61   ,fHasCommandHandler(NULL) 
    62   ,fUnLoadModule(NULL) 
    63   ,fHasMessageHandler(NULL) 
    64   ,fHandleMessage(NULL) 
    65   ,fGetDescription(NULL) 
    66   ,fGetVersion(NULL) 
    67   ,fCommandLineExec(NULL) 
    68   ,fShowTray(NULL) 
    69   ,fHideTray(NULL) 
    70   ,bLoaded_(false) 
    71   ,lastIsMsgPlugin_(false) 
    72   ,broken_(false) 
    73 { 
    74   if (other.bLoaded_) { 
    75     file_ = other.file_; 
    76     hModule_ = LoadLibrary(file_.c_str()); 
    77     if (!hModule_) 
    78       throw NSPluginException(file_, _T("Could not load library: ") + error::lookup::last_error()); 
    79     loadRemoteProcs_(); 
    80     if (!fLoadModule) 
    81       throw NSPluginException(file_, _T("Critical error (fLoadModule)")); 
    82     bLoaded_ = other.bLoaded_; 
    83   } 
    84 } 
    85 */ 
    8656/** 
    8757 * Default d-tor 
     
    144114  if (!fLoadModule) 
    145115    throw NSPluginException(module_, _T("Critical error (fLoadModule)")); 
    146   if (fLoadModule(alias_.c_str(), mode)) { 
     116  if (fLoadModule(plugin_id_, alias_.c_str(), mode)) { 
    147117    loaded_ = true; 
    148118    return true; 
     
    189159    throw NSPluginException(module_, _T("Module not loaded")); 
    190160  try { 
    191     if (fHasCommandHandler()) 
     161    if (fHasCommandHandler(plugin_id_)) 
    192162      return true; 
    193163    return false; 
     
    205175    throw NSPluginException(module_, _T("Module not loaded")); 
    206176  try { 
    207     if (fHasMessageHandler()) { 
     177    if (fHasMessageHandler(plugin_id_)) { 
    208178      lastIsMsgPlugin_ = true; 
    209179      return true; 
     
    220190    return false; 
    221191  try { 
    222     if (fHasNotificationHandler()) { 
     192    if (fHasNotificationHandler(plugin_id_)) { 
     193      return true; 
     194    } 
     195    return false; 
     196  } catch (...) { 
     197    throw NSPluginException(module_, _T("Unhandled exception in hasMessageHandler.")); 
     198  } 
     199} 
     200bool NSCPlugin::has_routing_handler() { 
     201  if (!isLoaded()) 
     202    throw NSPluginException(module_, _T("Module not loaded")); 
     203  if (!fHasRoutingHandler) 
     204    return false; 
     205  try { 
     206    if (fHasRoutingHandler(plugin_id_)) { 
    223207      return true; 
    224208    } 
     
    247231    throw NSPluginException(module_, _T("Library is not loaded")); 
    248232  try { 
    249     return fHandleCommand(command, dataBuffer, dataBuffer_len, returnBuffer, returnBuffer_len); 
     233    return fHandleCommand(plugin_id_, command, dataBuffer, dataBuffer_len, returnBuffer, returnBuffer_len); 
    250234  } catch (...) { 
    251235    throw NSPluginException(module_, _T("Unhandled exception in handleCommand.")); 
     
    253237} 
    254238 
    255 bool NSCPlugin::handleNotification(const wchar_t *channel, const wchar_t* command, NSCAPI::nagiosReturn code, char* result, unsigned int result_len) { 
     239bool NSCPlugin::handleNotification(const wchar_t *channel, const wchar_t* command, const char* result, unsigned int result_len) { 
    256240  if (!isLoaded() || fHandleNotification == NULL) 
    257241    throw NSPluginException(module_, _T("Library is not loaded")); 
    258242  try { 
    259     return fHandleNotification(channel, command, code, result, result_len); 
    260   } catch (...) { 
    261     throw NSPluginException(module_, _T("Unhandled exception in handleCommand.")); 
    262   } 
    263 } 
    264  
     243    return fHandleNotification(plugin_id_, channel, command, result, result_len); 
     244  } catch (...) { 
     245    throw NSPluginException(module_, _T("Unhandled exception in handleNotification.")); 
     246  } 
     247} 
     248 
     249bool NSCPlugin::route_message(const wchar_t *channel, const wchar_t *command, const char* buffer, unsigned int buffer_len, wchar_t **new_channel_buffer, char **new_buffer, unsigned int *new_buffer_len) { 
     250  if (!isLoaded() || fRouteMessage == NULL) 
     251    throw NSPluginException(module_, _T("Library is not loaded")); 
     252  try { 
     253    return fRouteMessage(plugin_id_, channel, command, buffer, buffer_len, new_channel_buffer, new_buffer, new_buffer_len); 
     254  } catch (...) { 
     255    throw NSPluginException(module_, _T("Unhandled exception in route_message.")); 
     256  } 
     257} 
    265258 
    266259 
     
    294287 * @throws NSPluginException if the module is not loaded. 
    295288 */ 
    296 void NSCPlugin::handleMessage(const char* data) { 
     289void NSCPlugin::handleMessage(const char* data, unsigned int len) { 
    297290  if (!fHandleMessage) 
    298291    throw NSPluginException(module_, _T("Library is not loaded")); 
    299292  try { 
    300     fHandleMessage(data); 
     293    fHandleMessage(plugin_id_, data, len); 
    301294  } catch (...) { 
    302295    throw NSPluginException(module_, _T("Unhandled exception in handleMessage.")); 
     
    314307    throw NSPluginException(module_, _T("Critical error (fUnLoadModule)")); 
    315308  try { 
    316     fUnLoadModule(); 
     309    fUnLoadModule(plugin_id_); 
    317310  } catch (...) { 
    318311    throw NSPluginException(module_, _T("Unhandled exception in fUnLoadModule.")); 
     
    336329  } catch (...) { 
    337330    throw NSPluginException(module_, _T("Unhandled exception in getDescription.")); 
    338   } 
    339 } 
    340  
    341 void NSCPlugin::showTray() { 
    342   if (fShowTray == NULL) 
    343     throw NSPluginException(module_, _T("Critical error (ShowTray)")); 
    344   try { 
    345     fShowTray(); 
    346   } catch (...) { 
    347     throw NSPluginException(module_, _T("Unhandled exception in ShowTray.")); 
    348   } 
    349 } 
    350 void NSCPlugin::hideTray() { 
    351   if (fHideTray == NULL) 
    352     throw NSPluginException(module_, _T("Critical error (HideTray)")); 
    353   try { 
    354     fHideTray(); 
    355   } catch (...) { 
    356     throw NSPluginException(module_, _T("Unhandled exception in HideTray.")); 
    357331  } 
    358332} 
     
    420394    fHandleNotification = (nscapi::plugin_api::lpHandleNotification)module_.load_proc("NSHandleNotification"); 
    421395    fHasNotificationHandler = (nscapi::plugin_api::lpHasNotificationHandler)module_.load_proc("NSHasNotificationHandler"); 
    422      
    423     fShowTray = (nscapi::plugin_api::lpShowTray)module_.load_proc("ShowIcon"); 
    424     fHideTray = (nscapi::plugin_api::lpHideTray)module_.load_proc("HideIcon"); 
    425      
     396 
     397    fHasRoutingHandler = (nscapi::plugin_api::lpHasRoutingHandler)module_.load_proc("NSHasRoutingHandler"); 
     398    fRouteMessage = (nscapi::plugin_api::lpRouteMessage)module_.load_proc("NSRouteMessage"); 
     399 
    426400  } catch (NSPluginException &e) { 
    427401    throw e; 
     
    454428    throw NSPluginException(module_, _T("Library is not loaded or modules does not support command line")); 
    455429  try { 
    456     return fCommandLineExec(command, request, request_len, reply, reply_len); 
     430    return fCommandLineExec(plugin_id_, command, request, request_len, reply, reply_len); 
    457431  } catch (...) { 
    458432    throw NSPluginException(module_, _T("Unhandled exception in handleCommand.")); 
  • service/NSCPlugin.h

    r39c73cd r81e420c  
    118118  nscapi::plugin_api::lpUnLoadModule fUnLoadModule; 
    119119  nscapi::plugin_api::lpCommandLineExec fCommandLineExec; 
    120   nscapi::plugin_api::lpShowTray fShowTray; 
    121   nscapi::plugin_api::lpHideTray fHideTray; 
    122120  nscapi::plugin_api::lpHasNotificationHandler fHasNotificationHandler; 
    123121  nscapi::plugin_api::lpHandleNotification fHandleNotification; 
     122  nscapi::plugin_api::lpHasRoutingHandler fHasRoutingHandler; 
     123  nscapi::plugin_api::lpRouteMessage fRouteMessage; 
    124124 
    125125public: 
    126126  NSCPlugin(const unsigned int id, const boost::filesystem::wpath file, std::wstring alias); 
    127   //NSCPlugin(NSCPlugin &other); 
    128127  virtual ~NSCPlugin(void); 
    129128 
     
    140139  NSCAPI::nagiosReturn handleCommand(const wchar_t *command, const char* dataBuffer, const unsigned int dataBuffer_len, char** returnBuffer, unsigned int *returnBuffer_len); 
    141140  NSCAPI::nagiosReturn handleCommand(const wchar_t* command, std::string &request, std::string &reply); 
    142   bool handleNotification(const wchar_t *channel, const wchar_t* command, NSCAPI::nagiosReturn code, char* result, unsigned int result_len); 
     141  bool handleNotification(const wchar_t *channel, const wchar_t* command, const char* result, unsigned int result_len); 
    143142  void deleteBuffer(char**buffer); 
    144   void handleMessage(const char* data); 
     143  void handleMessage(const char* data, unsigned int len); 
    145144  void unload(void); 
    146145  std::wstring getCongifurationMeta(); 
     
    148147  int commandLineExec(const wchar_t* command, const char* request, const unsigned int request_len, char** reply, unsigned int *reply_len); 
    149148  bool has_command_line_exec(); 
    150   void showTray(); 
    151   void hideTray(); 
    152149  bool is_duplicate( boost::filesystem::wpath file, std::wstring alias ); 
     150 
     151 
     152  bool has_routing_handler(); 
     153 
     154   
     155  bool route_message(const wchar_t *channel, const wchar_t *command, const char* buffer, unsigned int buffer_len, wchar_t **new_channel_buffer, char **new_buffer, unsigned int *new_buffer_len); 
    153156 
    154157  std::wstring get_alias() { 
  • service/NSClient++.cpp

    r8840f09 r81e420c  
    955955    if (plugin->hasMessageHandler()) 
    956956      logger_master_.add_plugin(plugin); 
     957    if (plugin->has_routing_handler()) 
     958      routers_.add_plugin(plugin); 
    957959    //settings_manager::get_core()->register_key(_T("/modules"), plugin->getModule(), settings::settings_core::key_string, plugin->getName(), plugin->getDescription(), _T(""), false); 
    958960    // TODO add comments elsewhere to the settings store for all loaded modules... 
     
    11601162 
    11611163  Plugin::ExecuteResponseMessage response_message; 
    1162   nscapi::functions::create_simple_header(response_message.mutable_header(), Plugin::Common_Header_Type_EXEC_RESPONSE); 
     1164  nscapi::functions::create_simple_header(response_message.mutable_header()); 
    11631165 
    11641166  BOOST_FOREACH(std::string r, responses) { 
     
    11771179 
    11781180 
    1179  
    1180 NSCAPI::errorReturn NSClientT::send_notification(const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code,  char* result, unsigned int result_len) { 
     1181NSCAPI::errorReturn NSClientT::reroute(std::wstring &channel, const wchar_t* command, std::string &buffer) { 
     1182  BOOST_FOREACH(nsclient::plugin_type p, routers_.get(channel)) { 
     1183    wchar_t *new_channel_buffer; 
     1184    char *new_buffer; 
     1185    unsigned int new_buffer_len; 
     1186    int status = p->route_message(channel.c_str(), command, buffer.c_str(), buffer.size(), &new_channel_buffer, &new_buffer, &new_buffer_len); 
     1187    if (status&NSCAPI::message_modified == NSCAPI::message_modified) { 
     1188      buffer = std::string(new_buffer, new_buffer_len); 
     1189      p->deleteBuffer(&new_buffer); 
     1190    } 
     1191    if (status&NSCAPI::message_routed == NSCAPI::message_routed) { 
     1192      channel = new_channel_buffer; 
     1193      //p->deleteBuffer(new_channel_buffer); 
     1194      return NSCAPI::message_routed; 
     1195    } 
     1196    if (status&NSCAPI::message_ignored == NSCAPI::message_ignored) 
     1197      return NSCAPI::message_ignored; 
     1198    if (status&NSCAPI::message_digested == NSCAPI::message_digested) 
     1199      return NSCAPI::message_ignored; 
     1200  } 
     1201  return NSCAPI::isfalse; 
     1202} 
     1203 
     1204NSCAPI::errorReturn NSClientT::send_notification(const wchar_t* channel, const wchar_t* command, char* buffer, unsigned int buffer_len) { 
    11811205  boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::milliseconds(5000)); 
    11821206  if (!readLock.owns_lock()) { 
     
    11841208    return NSCAPI::hasFailed; 
    11851209  } 
     1210 
     1211  std::wstring schannel = channel; 
     1212  std::string sbuffer = std::string(buffer, buffer_len); 
     1213  try { 
     1214    int count = 0; 
     1215    while (reroute(schannel, command, sbuffer)==NSCAPI::message_routed && count++ <= 10) { 
     1216      LOG_DEBUG_CORE_STD(_T("Re-routing message to: ") + schannel); 
     1217    } 
     1218    if (count >= 10) { 
     1219      LOG_ERROR_CORE(_T("More then 10 routes, discarding message...")); 
     1220      return NSCAPI::hasFailed; 
     1221    } 
     1222  } catch (nsclient::plugins_list_exception &e) { 
     1223    LOG_ERROR_CORE(_T("Erroro routing channel: ") + std::wstring(channel) + _T(": ") + to_wstring(e.what())); 
     1224    return NSCAPI::hasFailed; 
     1225  } catch (...) { 
     1226    LOG_ERROR_CORE(_T("Error routing channel: ") + std::wstring(channel)); 
     1227    return NSCAPI::hasFailed; 
     1228  } 
     1229 
    11861230  try { 
    11871231    //LOG_ERROR_CORE_STD(_T("Notifying: ") + strEx::strip_hex(to_wstring(std::string(result,result_len)))); 
    11881232    bool found = false; 
    1189     BOOST_FOREACH(nsclient::channels::plugin_type p, channels_.get(channel)) { 
    1190       p->handleNotification(channel, command, code, result, result_len); 
     1233    BOOST_FOREACH(nsclient::plugin_type p, channels_.get(schannel)) { 
     1234      p->handleNotification(schannel.c_str(), command, sbuffer.c_str(), sbuffer.length()); 
    11911235      found = true; 
    11921236    } 
    11931237    if (!found) { 
    1194       LOG_ERROR_CORE_STD(_T("Noone listens for events from: ") + std::wstring(channel)); 
     1238      LOG_ERROR_CORE_STD(_T("No one listens for events from: ") + schannel + _T(" (") + std::wstring(channel) + _T(")")); 
     1239      return NSCAPI::hasFailed; 
    11951240    } 
    11961241    return NSCAPI::isSuccess; 
    1197   } catch (nsclient::channels::channel_exception &e) { 
     1242  } catch (nsclient::plugins_list_exception &e) { 
    11981243    LOG_ERROR_CORE(_T("No handler for channel: ") + std::wstring(channel) + _T(": ") + to_wstring(e.what())); 
    11991244    return NSCAPI::hasFailed; 
  • service/NSClient++.h

    rb38e845 r81e420c  
    3232#include "commands.hpp" 
    3333#include "channels.hpp" 
     34#include "routers.hpp" 
    3435#include "logger.hpp" 
    3536 
     
    110111  nsclient::commands commands_; 
    111112  nsclient::channels channels_; 
     113  nsclient::routers routers_; 
    112114  unsigned int next_plugin_id_; 
    113115  std::wstring service_name_; 
     
    117119  typedef std::multimap<std::wstring,std::wstring> plugin_alias_list_type; 
    118120  // c-tor, d-tor 
    119   NSClientT(void) : debug_(log_state_unknown), enable_shared_session_(false), commands_(this), channels_(this), next_plugin_id_(0), service_name_(DEFAULT_SERVICE_NAME) { 
     121  NSClientT(void) : debug_(log_state_unknown), enable_shared_session_(false), commands_(this), channels_(this), routers_(this), next_plugin_id_(0), service_name_(DEFAULT_SERVICE_NAME) { 
    120122    logger_master_.start_slave(); 
    121123  } 
     
    160162  // Member functions 
    161163  boost::filesystem::wpath getBasePath(void); 
    162   NSCAPI::errorReturn send_notification(const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code, char* result, unsigned int result_len); 
     164 
     165  NSCAPI::errorReturn reroute(std::wstring &channel, const wchar_t* command, std::string &buffer); 
     166  NSCAPI::errorReturn send_notification(const wchar_t* channel, const wchar_t* command, char* buffer, unsigned int buffer_len); 
    163167  NSCAPI::nagiosReturn injectRAW(const wchar_t* command, std::string &request, std::string &response); 
    164168  NSCAPI::nagiosReturn inject(std::wstring command, std::wstring arguments, std::wstring &msg, std::wstring & perf); 
  • service/channels.hpp

    r1ecd26f r81e420c  
    11#pragma once 
    22 
    3 #include <set> 
    4  
    5 #include <boost/shared_ptr.hpp> 
    6 #include <boost/foreach.hpp> 
    7  
    83#include "NSCPlugin.h" 
    9 #include "logger.hpp" 
     4#include "plugin_list.hpp" 
    105 
    116using namespace nscp::helpers; 
    127 
    138namespace nsclient { 
    14   class channels : boost::noncopyable { 
    15   public: 
    16     class channel_exception : public std::exception { 
    17       std::string what_; 
    18     public: 
    19       channel_exception(std::wstring error) throw() : what_(to_string(error).c_str()) {} 
    20       channel_exception(std::string error) throw() : what_(error.c_str()) {} 
    21       virtual ~channel_exception() throw() {}; 
     9  struct channels : public plugins_list_with_listener { 
    2210 
    23       virtual const char* what() const throw() { 
    24         return what_.c_str(); 
    25       } 
    26  
    27     }; 
    28  
    29     typedef boost::shared_ptr<NSCPlugin> plugin_type; 
    30     typedef std::map<unsigned long,plugin_type> plugin_list_type; 
    31     typedef std::set<unsigned long> plugin_id_type; 
    32     typedef std::map<std::wstring,plugin_id_type > channel_list_type; 
    33  
    34  
    35   private: 
    36     nsclient::logger *logger_; 
    37     plugin_list_type plugins_; 
    38     channel_list_type channels_; 
    39     boost::shared_mutex mutex_; 
    40  
    41   public: 
    42  
    43     channels(nsclient::logger *logger) : logger_(logger) {} 
     11    channels(nsclient::logger *logger) : plugins_list_with_listener(logger) {} 
    4412 
    4513    void add_plugin(plugin_type plugin) { 
    4614      if (!plugin || !plugin->hasNotificationHandler()) 
    4715        return; 
    48       plugins_[plugin->get_id()] = plugin; 
    49        
     16      plugins_list_with_listener::add_plugin(plugin); 
    5017    } 
    5118 
    52     void remove_all() { 
    53       boost::unique_lock<boost::shared_mutex> writeLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(30)); 
    54       if (!writeLock.owns_lock()) { 
    55         log_error(__FILE__, __LINE__, _T("Failed to get mutex: channels::remove_all")); 
    56         return; 
    57       } 
    58       channels_.clear(); 
    59       plugins_.clear(); 
    60     } 
    61  
    62     void remove_plugin(unsigned long id) { 
    63       boost::unique_lock<boost::shared_mutex> writeLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(10)); 
    64       if (!writeLock.owns_lock()) { 
    65         log_error(__FILE__, __LINE__, _T("Failed to get mutex in remove_plugin for plugin id: ") + ::to_wstring(id)); 
    66         return; 
    67       } 
    68       channel_list_type::iterator it = channels_.begin(); 
    69       while (it != channels_.end()) { 
    70         if ((*it).second.count(id) > 0) { 
    71           channel_list_type::iterator toerase = it; 
    72           ++it; 
    73           channels_.erase(toerase); 
    74         } else 
    75           ++it; 
    76       } 
    77       plugin_list_type::iterator pit = plugins_.find(id); 
    78       if (pit != plugins_.end()) 
    79         plugins_.erase(pit); 
    80     } 
    81  
    82     void register_listener(unsigned long plugin_id, std::wstring channel) { 
    83       boost::unique_lock<boost::shared_mutex> writeLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(10)); 
    84       if (!writeLock.owns_lock()) { 
    85         log_error(__FILE__, __LINE__, _T("Failed to get mutex: ") + channel); 
    86         return; 
    87       } 
    88       std::wstring lc = make_key(channel); 
    89       if (!have_plugin(plugin_id)) 
    90         throw channel_exception("Failed to find plugin: " + ::to_string(plugin_id)); 
    91       channels_[lc].insert(plugin_id); 
    92     } 
    93  
    94     std::list<std::wstring> list() { 
    95       std::list<std::wstring> lst; 
    96       boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); 
    97       if (!readLock.owns_lock()) { 
    98         log_error(__FILE__, __LINE__, _T("Failed to get mutex")); 
    99         return lst; 
    100       } 
    101        
    102       BOOST_FOREACH(channel_list_type::value_type i, channels_) { 
    103         lst.push_back(i.first); 
    104       } 
    105       return lst; 
    106     } 
    107  
    108     std::list<plugin_type> get(std::wstring channel) { 
    109       boost::shared_lock<boost::shared_mutex> readLock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); 
    110       if (!readLock.owns_lock()) { 
    111         log_error(__FILE__, __LINE__, _T("Failed to get mutex: ") + channel); 
    112         throw channel_exception("Failed to get mutex (channel::get)"); 
    113       } 
    114       std::wstring lc = make_key(channel); 
    115       channel_list_type::iterator cit = channels_.find(lc); 
    116       if (cit == channels_.end()) { 
    117         throw channel_exception("Channel not found: " + to_string(channel)); 
    118       } 
    119       std::list<plugin_type> ret; 
    120       BOOST_FOREACH(unsigned long id, cit->second) { 
    121         ret.push_back(plugins_[id]); 
    122       } 
    123       return ret; 
    124     } 
    125  
    126     std::wstring to_wstring() { 
    127       std::wstring ret; 
    128       BOOST_FOREACH(std::wstring str, list()) { 
    129         if (!ret.empty()) ret += _T(", "); 
    130         ret += str; 
    131       } 
    132       return ret; 
    133     } 
    134  
    135     inline std::wstring make_key(std::wstring key) { 
    136       return boost::algorithm::to_lower_copy(key); 
    137     } 
    138     void log_error(std::string file, int line, std::wstring error) { 
    139       if (logger_ != NULL) 
    140         logger_->nsclient_log_error(file, line, error); 
    141     } 
    142  
    143     inline bool have_plugin(unsigned long plugin_id) { 
    144       return !(plugins_.find(plugin_id) == plugins_.end()); 
    145     } 
    14619  }; 
    14720} 
  • service/core_api.cpp

    r2c95d22 r81e420c  
    483483} 
    484484 
    485 NSCAPI::errorReturn NSAPINotify(const wchar_t* channel, const wchar_t* command, NSCAPI::nagiosReturn code,  char* result, unsigned int result_len) { 
    486   return mainClient.send_notification(channel, command, code, result, result_len); 
     485NSCAPI::errorReturn NSAPINotify(const wchar_t* channel, const wchar_t* command, char* result, unsigned int result_len) { 
     486  return mainClient.send_notification(channel, command, result, result_len); 
    487487} 
    488488 
  • service/core_api.h

    r2c95d22 r81e420c  
    6060NSCAPI::errorReturn NSAPIReleasePluginList(int,NSCAPI::plugin_info*[]); 
    6161NSCAPI::errorReturn NSAPISettingsSave(void); 
    62 NSCAPI::errorReturn NSAPINotify(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, char*, unsigned int); 
     62NSCAPI::errorReturn NSAPINotify(const wchar_t*, const wchar_t*, char*, unsigned int); 
    6363void NSAPIDestroyBuffer(char**); 
    6464NSCAPI::errorReturn NSAPIExpandPath(const wchar_t*,wchar_t*,unsigned int); 
  • service/logger.hpp

    rb38e845 r81e420c  
    214214            const char* cache_buf = s.c_str(); 
    215215            BOOST_FOREACH(plugin_type p, plugins_) { 
    216               p->handleMessage(cache_buf); 
     216              p->handleMessage(cache_buf, s.length()); 
    217217            } 
    218218          } 
     
    220220        } 
    221221        const char* buf = buffer.c_str(); 
     222        unsigned int len = buffer.length(); 
    222223        BOOST_FOREACH(plugin_type p, plugins_) { 
    223           p->handleMessage(buf); 
     224          p->handleMessage(buf, len); 
    224225        } 
    225226      } 
Note: See TracChangeset for help on using the changeset viewer.