Changeset 6b690bf in nscp


Ignore:
Timestamp:
02/03/08 17:15:14 (5 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
b5ef837
Parents:
8b206ee
Message:

+ Added API for scripts to register commands

+ Added command descriptions (for some modules)

  • Fixed issue in NRPE that displayed a console window when running commands
  • New improved "inject" dialog from the system tray Lists avalible commands, and shows command descriptions and a lot of other improvments.
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • AutoBuild.h

    r8b206ee r6b690bf  
    33// change the FALSE to TRUE for autoincrement of build number 
    44#define INCREMENT_VERSION TRUE 
    5 #define FILEVER        0,3,0,33 
    6 #define PRODUCTVER     0,3,0,33 
    7 #define STRFILEVER     _T("0.3.0.33") 
    8 #define STRPRODUCTVER  _T("0.3.0.33") 
     5#define FILEVER        0,3,0,35 
     6#define PRODUCTVER     0,3,0,35 
     7#define STRFILEVER     _T("0.3.0.35") 
     8#define STRPRODUCTVER  _T("0.3.0.35") 
    99#define STRPRODUCTDATE  _T("2008-02-03") 
    1010#endif // AUTOBUILD_H 
  • NSClient++.cpp

    r5ca3931 r6b690bf  
    412412} 
    413413 
     414 
     415std::wstring NSClientT::describeCommand(std::wstring command) { 
     416  ReadLock readLock(&m_mutexRWcmdDescriptions, true, 5000); 
     417  if (!readLock.IsLocked()) { 
     418    LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex when trying to get command list.")); 
     419    return _T("Failed to get mutex when describing command: ") + command; 
     420  } 
     421  cmdMap::const_iterator cit = cmdDescriptions_.find(command); 
     422  if (cit == cmdDescriptions_.end()) 
     423    return _T("Command not found: ") + command + _T(", maybe it has not been register?"); 
     424  return (*cit).second; 
     425} 
     426std::list<std::wstring> NSClientT::getAllCommandNames() { 
     427  std::list<std::wstring> lst; 
     428  ReadLock readLock(&m_mutexRWcmdDescriptions, true, 5000); 
     429  if (!readLock.IsLocked()) { 
     430    LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex when trying to get command list.")); 
     431    return lst; 
     432  } 
     433  for (cmdMap::const_iterator cit = cmdDescriptions_.begin(); cit != cmdDescriptions_.end(); ++cit) { 
     434    lst.push_back((*cit).first); 
     435  } 
     436  return lst; 
     437} 
     438void NSClientT::registerCommand(std::wstring cmd, std::wstring desc) { 
     439  WriteLock writeLock(&m_mutexRWcmdDescriptions, true, 10000); 
     440  if (!writeLock.IsLocked()) { 
     441    LOG_ERROR_STD(_T("FATAL ERROR: Failed to describe command:") + cmd); 
     442    return; 
     443  } 
     444  cmdDescriptions_[cmd] = desc; 
     445} 
     446 
    414447NSCAPI::nagiosReturn NSClientT::inject(std::wstring command, std::wstring arguments, TCHAR splitter, bool escape, std::wstring &msg, std::wstring & perf) { 
    415448  unsigned int aLen = 0; 
     
    773806NSCAPI::errorReturn NSAPIRehash(int flag) { 
    774807  return NSCAPI::hasFailed; 
     808} 
     809NSCAPI::errorReturn NSAPIDescribeCommand(const TCHAR* command, TCHAR* buffer, unsigned int bufLen) { 
     810  return NSCHelper::wrapReturnString(buffer, bufLen, mainClient.describeCommand(command), NSCAPI::isSuccess); 
     811} 
     812NSCAPI::errorReturn NSAPIGetAllCommandNames(arrayBuffer::arrayBuffer* aBuffer, unsigned int *bufLen) { 
     813  unsigned int len = 0; 
     814  *aBuffer = arrayBuffer::list2arrayBuffer(mainClient.getAllCommandNames(), len); 
     815  *bufLen = len; 
     816  return NSCAPI::isSuccess; 
     817} 
     818NSCAPI::errorReturn NSAPIReleaseAllCommandNamessBuffer(TCHAR*** aBuffer, unsigned int * bufLen) { 
     819  arrayBuffer::destroyArrayBuffer(*aBuffer, *bufLen); 
     820  *bufLen = 0; 
     821  *aBuffer = NULL; 
     822  return NSCAPI::isSuccess; 
     823} 
     824NSCAPI::errorReturn NSAPIRegisterCommand(const TCHAR* cmd,const TCHAR* desc) { 
     825  mainClient.registerCommand(cmd, desc); 
     826  return NSCAPI::isSuccess; 
    775827} 
    776828 
     
    813865  if (_wcsicmp(buffer, _T("NSAPIRehash")) == 0) 
    814866    return &NSAPIRehash; 
     867  if (_wcsicmp(buffer, _T("NSAPIDescribeCommand")) == 0) 
     868    return &NSAPIDescribeCommand; 
     869  if (_wcsicmp(buffer, _T("NSAPIGetAllCommandNames")) == 0) 
     870    return &NSAPIGetAllCommandNames; 
     871  if (_wcsicmp(buffer, _T("NSAPIReleaseAllCommandNamessBuffer")) == 0) 
     872    return &NSAPIReleaseAllCommandNamessBuffer; 
     873  if (_wcsicmp(buffer, _T("NSAPIRegisterCommand")) == 0) 
     874    return &NSAPIRegisterCommand; 
     875 
    815876  return NULL; 
    816877} 
  • NSClient++.h

    r99e4d8f r6b690bf  
    2828#include <NSCAPI.h> 
    2929#include <MutexRW.h> 
     30#include <map> 
    3031 
    3132 
     
    5960  typedef NSCPlugin* plugin_type; 
    6061  typedef std::vector<plugin_type> pluginList; 
     62  typedef std::map<std::wstring,std::wstring> cmdMap; 
    6163  pluginList plugins_; 
    6264  pluginList commandHandlers_; 
     
    6668  MutexHandler messageMutex; 
    6769  MutexRW  m_mutexRW; 
     70  MutexRW  m_mutexRWcmdDescriptions; 
     71  cmdMap cmdDescriptions_; 
    6872  bool debug_; 
    6973 
     
    9599  void loadPlugins(void); 
    96100  void unloadPlugins(void); 
     101  std::wstring describeCommand(std::wstring command); 
     102  std::list<std::wstring> getAllCommandNames(); 
     103  void registerCommand(std::wstring cmd, std::wstring desc); 
    97104 
    98105  bool logDebug(); 
     
    134141NSCAPI::errorReturn NSAPIReadSettings(int type); 
    135142NSCAPI::errorReturn NSAPIRehash(int flag); 
     143NSCAPI::errorReturn NSAPIDescribeCommand(const TCHAR*,TCHAR*,unsigned int); 
     144NSCAPI::errorReturn NSAPIGetAllCommandNames(TCHAR***, unsigned int *); 
     145NSCAPI::errorReturn NSAPIReleaseAllCommandNamessBuffer(TCHAR***, unsigned int *); 
     146NSCAPI::errorReturn NSAPIRegisterCommand(const TCHAR*,const TCHAR*); 
    136147 
    137148////////////////////////////////////////////////////////////////////////// 
  • changelog

    r777180d r6b690bf  
    882008-02-03 MickeM 
    99 + Added encryption subsystem to NSCA module (still no mcrypt support, but atleast you have "xor" and passwords) 
     10 + Added API for scripts to register commands 
     11 + Added command descriptions (for some modules) 
     12 * Fixed issue in NRPE that displayed a console window when running commands 
     13 * New improved "inject" dialog from the system tray 
     14   Lists avalible commands, and shows command descriptions and a lot of other improvments. 
    1015 
    11162008-02-02 MickeM 
  • include/NSCHelper.cpp

    r99e4d8f r6b690bf  
    137137  lpNSAPIReadSettings fNSAPIReadSettings = NULL; 
    138138  lpNSAPIRehash fNSAPIRehash = NULL; 
     139  lpNSAPIDescribeCommand fNSAPIDescribeCommand= NULL; 
     140  lpNSAPIGetAllCommandNames fNSAPIGetAllCommandNames= NULL; 
     141  lpNSAPIReleaseAllCommandNamessBuffer fNSAPIReleaseAllCommandNamessBuffer= NULL; 
     142  lpNSAPIRegisterCommand fNSAPIRegisterCommand= NULL; 
    139143 
    140144} 
     
    468472} 
    469473 
     474std::list<std::wstring> NSCModuleHelper::getAllCommandNames() { 
     475  if (!fNSAPIGetAllCommandNames || !fNSAPIReleaseAllCommandNamessBuffer ) 
     476    throw NSCMHExcpetion(_T("NSCore has not been initiated...")); 
     477  arrayBuffer::arrayBuffer aBuffer = NULL; 
     478  unsigned int argLen = 0; 
     479  if (fNSAPIGetAllCommandNames(&aBuffer, &argLen) != NSCAPI::isSuccess) { 
     480    throw NSCMHExcpetion(_T("Commands could not be retrieved.")); 
     481  } 
     482  std::list<std::wstring> ret = arrayBuffer::arrayBuffer2list(argLen, aBuffer); 
     483  if (fNSAPIReleaseAllCommandNamessBuffer(&aBuffer, &argLen) != NSCAPI::isSuccess) { 
     484    throw NSCMHExcpetion(_T("Commands could not be destroyed.")); 
     485  } 
     486  assert(aBuffer == NULL); 
     487  return ret; 
     488} 
     489std::wstring NSCModuleHelper::describeCommand(std::wstring command) { 
     490  if (!fNSAPIDescribeCommand) 
     491    throw NSCMHExcpetion(_T("NSCore has not been initiated...")); 
     492  TCHAR *buffer = new TCHAR[BUFF_LEN+1]; 
     493  if (fNSAPIDescribeCommand(command.c_str(), buffer, BUFF_LEN) != NSCAPI::isSuccess) { 
     494    delete [] buffer; 
     495    throw NSCMHExcpetion(_T("Base path could not be retrieved")); 
     496  } 
     497  std::wstring ret = buffer; 
     498  delete [] buffer; 
     499  return ret; 
     500} 
     501void NSCModuleHelper::registerCommand(std::wstring command, std::wstring description) { 
     502  if (!fNSAPIRegisterCommand) 
     503    throw NSCMHExcpetion(_T("NSCore has not been initiated...")); 
     504  fNSAPIRegisterCommand(command.c_str(), description.c_str()); 
     505} 
     506 
    470507 
    471508bool NSCModuleHelper::checkLogMessages(int type) { 
     
    545582  NSCModuleHelper::fNSAPIReadSettings = (NSCModuleHelper::lpNSAPIReadSettings)f(_T("NSAPIReadSettings")); 
    546583  NSCModuleHelper::fNSAPIRehash = (NSCModuleHelper::lpNSAPIRehash)f(_T("NSAPIRehash")); 
     584 
     585  NSCModuleHelper::fNSAPIDescribeCommand = (NSCModuleHelper::lpNSAPIDescribeCommand)f(_T("NSAPIDescribeCommand")); 
     586  NSCModuleHelper::fNSAPIGetAllCommandNames = (NSCModuleHelper::lpNSAPIGetAllCommandNames)f(_T("NSAPIGetAllCommandNames")); 
     587  NSCModuleHelper::fNSAPIReleaseAllCommandNamessBuffer = (NSCModuleHelper::lpNSAPIReleaseAllCommandNamessBuffer)f(_T("NSAPIReleaseAllCommandNamessBuffer")); 
     588  NSCModuleHelper::fNSAPIRegisterCommand = (NSCModuleHelper::lpNSAPIRegisterCommand)f(_T("NSAPIRegisterCommand")); 
     589 
    547590  return NSCAPI::isSuccess; 
    548591} 
  • include/NSCHelper.h

    r99e4d8f r6b690bf  
    119119  typedef NSCAPI::errorReturn (*lpNSAPIReadSettings)(int); 
    120120  typedef NSCAPI::errorReturn (*lpNSAPIRehash)(int); 
     121  typedef NSCAPI::errorReturn (*lpNSAPIDescribeCommand)(const TCHAR*,TCHAR*,unsigned int); 
     122  typedef NSCAPI::errorReturn (*lpNSAPIGetAllCommandNames)(arrayBuffer::arrayBuffer*, unsigned int *); 
     123  typedef NSCAPI::errorReturn (*lpNSAPIReleaseAllCommandNamessBuffer)(arrayBuffer::arrayBuffer*, unsigned int *); 
     124  typedef NSCAPI::errorReturn (*lpNSAPIRegisterCommand)(const TCHAR*,const TCHAR*); 
    121125 
    122126  // Helper functions for calling into the core 
     
    142146  NSCAPI::errorReturn ReadSettings(int type); 
    143147  NSCAPI::errorReturn Rehash(int flag); 
     148  std::list<std::wstring> getAllCommandNames(); 
     149  std::wstring describeCommand(std::wstring command); 
     150  void registerCommand(std::wstring command, std::wstring description); 
    144151}; 
    145152 
  • modules/CheckDisk/CheckDisk.cpp

    r978bd31 r6b690bf  
    4040} 
    4141 
    42  
    4342bool CheckDisk::loadModule() { 
     43  try { 
     44    NSCModuleHelper::registerCommand(_T("CheckFileSize"), _T("Check or directory a file and verify its size.")); 
     45    NSCModuleHelper::registerCommand(_T("CheckDriveSize"), _T("Check the size (free-space) of a drive or volume.")); 
     46    NSCModuleHelper::registerCommand(_T("CheckFile"), _T("Check various aspects of a file and/or folder.")); 
     47  } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     48    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
     49  } catch (...) { 
     50    NSC_LOG_ERROR_STD(_T("Failed to register command.")); 
     51  } 
    4452  return true; 
    4553} 
  • modules/CheckEventLog/CheckEventLog.cpp

    r52215d7 r6b690bf  
    4545 
    4646bool CheckEventLog::loadModule() { 
     47  try { 
     48    NSCModuleHelper::registerCommand(_T("CheckEventLog"), _T("Check for errors in the event logger!")); 
     49  } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     50    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
     51  } catch (...) { 
     52    NSC_LOG_ERROR_STD(_T("Failed to register command.")); 
     53  } 
    4754  return true; 
    4855} 
  • modules/CheckHelpers/CheckHelpers.cpp

    r99e4d8f r6b690bf  
    4040 
    4141bool CheckHelpers::loadModule() { 
     42  try { 
     43    NSCModuleHelper::registerCommand(_T("CheckAlwaysOK"), _T("Run another check and regardless of its return code return OK.")); 
     44    NSCModuleHelper::registerCommand(_T("CheckAlwaysCRITICAL"), _T("Run another check and regardless of its return code return CRIT.")); 
     45    NSCModuleHelper::registerCommand(_T("CheckAlwaysWARNING"), _T("Run another check and regardless of its return code return WARN.")); 
     46    NSCModuleHelper::registerCommand(_T("CheckMultiple"), _T("Run more then one check and return the worst state.")); 
     47  } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     48    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
     49  } catch (...) { 
     50    NSC_LOG_ERROR_STD(_T("Failed to register command.")); 
     51  } 
    4252  return true; 
    4353} 
  • modules/CheckSystem/CheckSystem.cpp

    r978bd31 r6b690bf  
    108108    } 
    109109  } 
    110    
     110  try { 
     111    NSCModuleHelper::registerCommand(_T("checkCPU"), _T("Check the CPU load of the computer.")); 
     112    NSCModuleHelper::registerCommand(_T("checkUpTime"), _T("Check the up-time of the computer.")); 
     113    NSCModuleHelper::registerCommand(_T("checkServiceState"), _T("Check the state of one or more of the computer services.")); 
     114    NSCModuleHelper::registerCommand(_T("checkProcState"), _T("Check the state of one or more of the processes running on the computer.")); 
     115    NSCModuleHelper::registerCommand(_T("checkMem"), _T("Check free/used memory on the system.")); 
     116    NSCModuleHelper::registerCommand(_T("checkCounter"), _T("Check a PDH counter.")); 
     117  } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     118    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
     119  } catch (...) { 
     120    NSC_LOG_ERROR_STD(_T("Failed to register command.")); 
     121  } 
    111122  return true; 
    112123} 
  • modules/CheckWMI/CheckWMI.cpp

    r99e4d8f r6b690bf  
    4343 
    4444bool CheckWMI::loadModule() { 
     45  try { 
     46    NSCModuleHelper::registerCommand(_T("CheckWMIValue"), _T("Run a WMI query and check the resulting value (the values of each row determin the state).")); 
     47    NSCModuleHelper::registerCommand(_T("CheckWMI"), _T("Run a WMI query and check the resulting rows (the number of hits determine state).")); 
     48  } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     49    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
     50  } catch (...) { 
     51    NSC_LOG_ERROR_STD(_T("Failed to register command.")); 
     52  } 
    4553  return wmiQuery.initialize(); 
    4654} 
  • modules/NRPEListener/NRPEListener.cpp

    r45241f5 r6b690bf  
    265265  ZeroMemory(&si, sizeof(STARTUPINFO)); 
    266266  si.cb = sizeof(STARTUPINFO); 
    267   si.dwFlags = STARTF_USESTDHANDLES; 
     267  si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; 
    268268  si.hStdInput = hChildInR; 
    269269  si.hStdOutput = hChildOutW; 
    270270  si.hStdError = hChildOutW; 
     271  si.wShowWindow = SW_HIDE; 
    271272 
    272273 
  • modules/SysTray/SysTray-2005.vcproj

    r3f569d3 r6b690bf  
    17741774  </Files> 
    17751775  <Globals> 
     1776    <Global 
     1777      Name="RESOURCE_FILE" 
     1778      Value="SysTray.rc" 
     1779    /> 
    17761780  </Globals> 
    17771781</VisualStudioProject> 
  • modules/SysTray/SysTray.cpp

    r978bd31 r6b690bf  
    7575    } 
    7676  } else { 
    77     NSC_LOG_ERROR_STD(_T("Undefined command, usgae: install or uninstall")); 
     77    NSC_LOG_ERROR_STD(_T("Undefined command, usage: install or uninstall")); 
    7878    return -1; 
    7979  } 
  • modules/SysTray/SysTray.rc

    ra0528c4 r6b690bf  
    4242    BEGIN 
    4343        LEFTMARGIN, 7 
    44         RIGHTMARGIN, 317 
    45         VERTGUIDE, 207 
    46         VERTGUIDE, 267 
     44        RIGHTMARGIN, 351 
     45        VERTGUIDE, 114 
     46        VERTGUIDE, 291 
    4747        TOPMARGIN, 7 
    48         BOTTOMMARGIN, 43 
     48        BOTTOMMARGIN, 144 
     49        HORZGUIDE, 15 
     50        HORZGUIDE, 27 
     51        HORZGUIDE, 47 
     52        HORZGUIDE, 59 
     53        HORZGUIDE, 63 
     54        HORZGUIDE, 77 
     55        HORZGUIDE, 81 
     56        HORZGUIDE, 85 
    4957    END 
    5058END 
     
    5765// 
    5866 
    59 IDD_INJECTDIALOG DIALOGEX 0, 0, 324, 50 
    60 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP |  
    61     WS_CAPTION | WS_SYSMENU 
     67IDD_INJECTDIALOG DIALOGEX 0, 0, 358, 151 
     68STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU 
    6269CAPTION "Inject command into NSClient++" 
    6370FONT 8, "MS Shell Dlg", 400, 0, 0x1 
    6471BEGIN 
    65     DEFPUSHBUTTON   "Inject",IDOK,267,29,50,14 
    66     PUSHBUTTON      "Cancel",IDCANCEL,207,29,50,14 
    67     EDITTEXT        IDC_COMMAND,7,7,310,12,ES_AUTOHSCROLL 
     72    COMBOBOX        IDC_CMD_BOX,7,15,107,279,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP 
     73    EDITTEXT        IDC_ARG_BOX,7,35,344,24,ES_MULTILINE | ES_AUTOHSCROLL 
     74    EDITTEXT        IDC_MSG,7,93,344,12,ES_AUTOHSCROLL | ES_READONLY 
     75    EDITTEXT        IDC_PERF,7,113,344,12,ES_AUTOHSCROLL | ES_READONLY 
     76    DEFPUSHBUTTON   "Inject",IDC_INJECT,291,63,60,14 
     77    PUSHBUTTON      "Done",IDCANCEL,291,130,60,14 
     78    LTEXT           "Command:",IDC_STATIC,7,7,35,8 
     79    LTEXT           "Arguments:",IDC_STATIC,7,27,38,8 
     80    CONTROL         "",IDC_STATIC,"Static",SS_ETCHEDHORZ,7,80,344,1 
     81    LTEXT           "Result message:",IDC_STATIC,7,85,54,8 
     82    LTEXT           "Performance data:",IDC_STATIC,7,105,61,8 
     83    LTEXT           "",IDC_DESCRIPTION,114,15,237,12 
    6884END 
    6985 
     
    132148#endif //_WIN32 
    133149 
    134 #ifdef APSTUDIO_INVOKED 
    135 ///////////////////////////////////////////////////////////////////////////// 
    136 // 
    137 // TEXTINCLUDE 
    138 // 
    139  
    140 3 TEXTINCLUDE  
    141 BEGIN 
    142     "\r\n" 
    143     "\0" 
    144 END 
    145  
    146 #endif    // APSTUDIO_INVOKED 
    147  
    148  
    149150///////////////////////////////////////////////////////////////////////////// 
    150151// 
     
    179180END 
    180181 
     182 
     183#ifdef APSTUDIO_INVOKED 
     184///////////////////////////////////////////////////////////////////////////// 
     185// 
     186// TEXTINCLUDE 
     187// 
     188 
     1893 TEXTINCLUDE  
     190BEGIN 
     191    "\r\n" 
     192    "\0" 
     193END 
     194 
     195#endif    // APSTUDIO_INVOKED 
     196 
    181197#endif    // Swedish resources 
    182198///////////////////////////////////////////////////////////////////////////// 
  • modules/SysTray/TrayIcon.cpp

    r978bd31 r6b690bf  
    2222#include ".\trayicon.h" 
    2323#include "resource.h" 
     24#include <commctrl.h> 
    2425#include <strEx.h> 
    2526#include <ShellAPI.h> 
     
    5960} 
    6061 
     62std::wstring getDlgItemText(HWND hDlg, int nIDDlgItem) { 
     63#define BUFF_LEN 4096 
     64  std::wstring ret; 
     65  TCHAR *buffer = new TCHAR[BUFF_LEN+1]; 
     66  if (!GetDlgItemText(hDlg, nIDDlgItem, buffer, BUFF_LEN)) 
     67    buffer[0]=0; 
     68  ret = buffer; 
     69  delete [] buffer; 
     70  return ret; 
     71} 
     72void updateDescFromCmd(HWND hDlg, std::wstring cmd) { 
     73  std::wstring result = _T(""); 
     74  try { 
     75    result = NSCModuleHelper::describeCommand(cmd); 
     76  } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     77    result = _T("Error: ") + e.msg_; 
     78  } catch (...) { 
     79    result = _T("Unknown error!"); 
     80  } 
     81  SetDlgItemText(hDlg, IDC_DESCRIPTION, result.c_str()); 
     82} 
    6183/* 
    6284INT_PTR CALLBACK DialogProc(          HWND hwndDlg, 
     
    7092  { 
    7193  case WM_INITDIALOG: 
    72     SetDlgItemText(hwndDlg, IDC_COMMAND, TrayIcon::defaultCommand.c_str()); 
     94    { 
     95      SetDlgItemText(hwndDlg, IDC_CMD_BOX, TrayIcon::defaultCommand.c_str()); 
     96      SetDlgItemText(hwndDlg, IDC_DESCRIPTION, _T("Loading commands, please wait...")); 
     97 
     98      SendDlgItemMessage(hwndDlg, IDC_CMD_BOX, CB_RESETCONTENT, 0, 0);  
     99      std::wstring result = _T(""); 
     100      try { 
     101        std::list<std::wstring> lst = NSCModuleHelper::getAllCommandNames(); 
     102        for (std::list<std::wstring>::const_iterator cit = lst.begin(); cit != lst.end(); ++cit) { 
     103          SendDlgItemMessage(hwndDlg, IDC_CMD_BOX, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>( (*cit).c_str() )); 
     104        } 
     105      } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     106        result = _T("Error: ") + e.msg_; 
     107      } catch (...) { 
     108        result = _T("Unknown error!"); 
     109      } 
     110      SetDlgItemText(hwndDlg, IDC_DESCRIPTION, result.c_str()); 
     111    } 
     112    break; 
    73113  case WM_COMMAND:  
    74114    switch (LOWORD(wParam)) 
    75115    { 
     116    case IDC_CMD_BOX:  
     117      switch(HIWORD(wParam))  
     118      { 
     119      case CBN_SELCHANGE: 
     120        { 
     121          std::wstring cmd; 
     122          unsigned int id = SendDlgItemMessage(hwndDlg, IDC_CMD_BOX, CB_GETCURSEL, 0, 0);  
     123          unsigned int len = SendDlgItemMessage(hwndDlg, IDC_CMD_BOX, CB_GETLBTEXTLEN, id, 0); 
     124          TCHAR *buf = new TCHAR[len+2]; 
     125          LRESULT ret; 
     126          ret = SendDlgItemMessage(hwndDlg, IDC_CMD_BOX, CB_GETLBTEXT, id, reinterpret_cast<LPARAM>(buf)); 
     127          if (ret > 0 && ret <= len) { 
     128            cmd = buf; 
     129            updateDescFromCmd(hwndDlg, cmd); 
     130          } 
     131          delete [] buf; 
     132        } 
     133        break; 
     134      case CBN_KILLFOCUS: 
     135        updateDescFromCmd(hwndDlg, getDlgItemText(hwndDlg, IDC_CMD_BOX)); 
     136        break; 
     137      } 
     138      break; 
     139    case IDC_INJECT: 
     140      { 
     141#define BUFF_LEN 4096 
     142        std::wstring result = _T(""); 
     143        std::wstring cmd = getDlgItemText(hwndDlg, IDC_CMD_BOX); 
     144        std::wstring args = getDlgItemText(hwndDlg, IDC_ARG_BOX); 
     145        std::wstring msg; 
     146        std::wstring perf; 
     147        try { 
     148          NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectSplitAndCommand(cmd, args, ' ', msg, perf); 
     149          if (ret == NSCAPI::returnIgnored) { 
     150            result = _T("Command not found!"); 
     151          } else { 
     152            result = NSCHelper::translateReturn(ret); 
     153          } 
     154        } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     155          result = _T("Error: ") + e.msg_; 
     156        } catch (...) { 
     157          result = _T("Unknown error!"); 
     158        } 
     159        SetDlgItemText(hwndDlg, IDC_DESCRIPTION, result.c_str()); 
     160        SetDlgItemText(hwndDlg, IDC_MSG, msg.c_str()); 
     161        SetDlgItemText(hwndDlg, IDC_PERF, perf.c_str()); 
     162      } 
     163      break; 
    76164    case IDOK:  
    77165      { 
     
    116204          TrayIcon::defaultCommand = NSCModuleHelper::getSettingsString(_T("systray"), _T("defaultCommand"), _T("")); 
    117205        if (DialogBox(NSCModuleWrapper::getModule(),MAKEINTRESOURCE(IDD_INJECTDIALOG),NULL,InjectDialogProc) == IDOK) { 
    118           // @todo NSCModuleHelper::InjectCommand(TrayIcon::defaultCommand); 
     206          //NSCModuleHelper::InjectSplitAndCommand(TrayIcon::defaultCommand, buffer); 
    119207        } 
    120208        break; 
     
    122210        { 
    123211          long long err = reinterpret_cast<long long>(ShellExecute(hwndDlg, _T("open"),  
    124             (NSCModuleHelper::getBasePath() + NSCModuleHelper::getSettingsString(_T("log"), _T("file"), _T(""))).c_str(),  
     212            (NSCModuleHelper::getBasePath() + _T("\\") + NSCModuleHelper::getSettingsString(_T("log"), _T("file"), _T(""))).c_str(),  
    125213            NULL, NULL, SW_SHOWNORMAL)); 
    126214          if (err <=32) { 
  • modules/SysTray/resource.h

    ra0528c4 r6b690bf  
    99#define IDD_INJECTDIALOG                105 
    1010#define IDC_COMMAND                     1000 
     11#define IDC_ARG_BOX                     1000 
     12#define IDC_CMD_BOX                     1001 
     13#define IDC_MSG                         1003 
     14#define IDC_PERF                        1004 
     15#define IDC_DESCRIPTION                 1005 
     16#define IDC_INJECT                      1006 
    1117#define ID_POPUP_NSCLIENT               40006 
    1218#define ID_POPUP_INJECTCOMMAND          40007 
     
    2127#define _APS_NEXT_RESOURCE_VALUE        106 
    2228#define _APS_NEXT_COMMAND_VALUE         40011 
    23 #define _APS_NEXT_CONTROL_VALUE         1001 
     29#define _APS_NEXT_CONTROL_VALUE         1007 
    2430#define _APS_NEXT_SYMED_VALUE           101 
    2531#endif 
Note: See TracChangeset for help on using the changeset viewer.