Changeset 1eef1ee in nscp for NSClient++.cpp


Ignore:
Timestamp:
03/20/05 20:54:25 (8 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
c6e008c
Parents:
2a94f3f
Message:

*OBS* This might no longer work! (expect updated code in the next few days if things are broken)

  • Fundamental API changes (due to NRPE compatibility)
    • HandleCommand? has changed
    • Inject has changed
    • Most API calls have new "return codes" (typedef:ed INT to allow for return code compiler checks)
    • A lot of the old return codes have changed
  • Preliminary NRPE support (can parse and execute incoming requests, cant return data yet, and no encryption)
  • New SimpleSocket? in include/ will be used as base class for Listeners
  • A lot of rewrite to the NSC API
File:
1 edited

Legend:

Unmodified
Added
Removed
  • NSClient++.cpp

    r2a94f3f r1eef1ee  
    220220 * @return The result, empty string if no result 
    221221 */ 
    222 int NSClientT::injectRAW(const char* command, const unsigned int argLen, char **argument, char *returnBuffer, unsigned int returnBufferLen) { 
     222NSCAPI::nagiosReturn NSClientT::injectRAW(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen) { 
    223223  MutexLock lock(pluginMutex); 
    224224 
     
    228228  for (plit = commandHandlers_.begin(); plit != commandHandlers_.end(); ++plit) { 
    229229    try { 
    230       int c = (*plit)->handleCommand(command, argLen, argument, returnBuffer, returnBufferLen); 
    231       if (c == NSCAPI::handled) {         // module handled the message "we are done..." 
    232         LOG_DEBUG_STD("Injected Result: " +(std::string) returnBuffer); 
    233         return c; 
    234       } else if (c == NSCAPI::isfalse) {      // Module ignored the message 
    235         LOG_DEBUG("A module ignored this message"); 
    236       } else if (c == NSCAPI::invalidBufferLen) { // Buffer is to small 
    237         LOG_ERROR("Return buffer to small to handle this command."); 
    238         return c; 
    239       } else if (c == NSCAPI::isError) {      // Error 
    240         LOG_ERROR("An error occured while handling this command."); 
    241         return c; 
    242       } else {                  // Something else went wrong... 
    243         LOG_ERROR_STD("Unknown error from handleCommand: " + strEx::itos(c)); 
    244         return c; 
     230      NSCAPI::nagiosReturn c = (*plit)->handleCommand(command, argLen, argument, returnMessageBuffer, returnMessageBufferLen, returnPerfBuffer, returnPerfBufferLen); 
     231      switch (c) { 
     232        case NSCAPI::returnInvalidBufferLen: 
     233          LOG_ERROR("Return buffer to small to handle this command."); 
     234          return c; 
     235        case NSCAPI::returnIgnored: 
     236          LOG_DEBUG("A module ignored this message"); 
     237          break; 
     238        case NSCAPI::returnOK: 
     239        case NSCAPI::returnWARN: 
     240        case NSCAPI::returnCRIT: 
     241        case NSCAPI::returnUNKNOWN: 
     242          LOG_DEBUG_STD("Injected Result: " +(std::string) returnMessageBuffer); 
     243          LOG_DEBUG_STD("Injected Performance Result: " +(std::string) returnPerfBuffer); 
     244          return c; 
     245        default: 
     246          LOG_ERROR_STD("Unknown error from handleCommand: " + strEx::itos(c)); 
     247          return c; 
    245248      } 
    246249    } catch(const NSPluginException& e) { 
    247250      LOG_ERROR_STD("Exception raised: " + e.error_ + " in module: " + e.file_); 
    248       return NSCAPI::isError; 
     251      return NSCAPI::returnCRIT; 
    249252    } 
    250253  } 
    251254  LOG_MESSAGE_STD("No handler for command: " + command); 
    252   return NSCAPI::isfalse; 
     255  return NSCAPI::returnIgnored; 
    253256} 
    254257/** 
     
    271274 * ie. pair<int,string> 
    272275 */ 
     276/* 
    273277std::string NSClientT::execute(std::string password, std::string cmd, std::list<std::string> args) { 
    274278  MutexLock lock(pluginMutex); 
     
    312316  return ret; 
    313317} 
     318*/ 
    314319/** 
    315320 * Report a message to all logging enabled modules. 
     
    372377 
    373378 
    374 int NSAPIGetSettingsString(const char* section, const char* key, const char* defaultValue, char* buffer, unsigned int bufLen) { 
    375   return NSCHelper::wrapReturnString(buffer, bufLen, Settings::getInstance()->getString(section, key, defaultValue)); 
     379NSCAPI::errorReturn NSAPIGetSettingsString(const char* section, const char* key, const char* defaultValue, char* buffer, unsigned int bufLen) { 
     380  return NSCHelper::wrapReturnString(buffer, bufLen, Settings::getInstance()->getString(section, key, defaultValue), NSCAPI::isSuccess); 
    376381} 
    377382int NSAPIGetSettingsInt(const char* section, const char* key, int defaultValue) { 
    378383  return Settings::getInstance()->getInt(section, key, defaultValue); 
    379384} 
    380 int NSAPIGetBasePath(char*buffer, unsigned int bufLen) { 
    381   return NSCHelper::wrapReturnString(buffer, bufLen, mainClient.getBasePath()); 
    382 } 
    383 int NSAPIGetApplicationName(char*buffer, unsigned int bufLen) { 
    384   return NSCHelper::wrapReturnString(buffer, bufLen, SZAPPNAME); 
    385 } 
    386 int NSAPIGetApplicationVersionStr(char*buffer, unsigned int bufLen) { 
    387   return NSCHelper::wrapReturnString(buffer, bufLen, SZVERSION); 
     385NSCAPI::errorReturn NSAPIGetBasePath(char*buffer, unsigned int bufLen) { 
     386  return NSCHelper::wrapReturnString(buffer, bufLen, mainClient.getBasePath(), NSCAPI::isSuccess); 
     387} 
     388NSCAPI::errorReturn NSAPIGetApplicationName(char*buffer, unsigned int bufLen) { 
     389  return NSCHelper::wrapReturnString(buffer, bufLen, SZAPPNAME, NSCAPI::isSuccess); 
     390} 
     391NSCAPI::errorReturn NSAPIGetApplicationVersionStr(char*buffer, unsigned int bufLen) { 
     392  return NSCHelper::wrapReturnString(buffer, bufLen, SZVERSION, NSCAPI::isSuccess); 
    388393} 
    389394void NSAPIMessage(int msgType, const char* file, const int line, const char* message) { 
     
    393398  serviceControll::Stop(SZSERVICENAME); 
    394399} 
    395 int NSAPIInject(const char* command, const unsigned int argLen, char **argument, char *returnBuffer, unsigned int returnBufferLen) { 
    396   return mainClient.injectRAW(command, argLen, argument, returnBuffer, returnBufferLen); 
     400NSCAPI::nagiosReturn NSAPIInject(const char* command, const unsigned int argLen, char **argument, char *returnMessageBuffer, unsigned int returnMessageBufferLen, char *returnPerfBuffer, unsigned int returnPerfBufferLen) { 
     401  return mainClient.injectRAW(command, argLen, argument, returnMessageBuffer, returnMessageBufferLen, returnPerfBuffer, returnPerfBufferLen); 
    397402} 
    398403 
Note: See TracChangeset for help on using the changeset viewer.