Changeset 1bfe6f0 in nscp for include


Ignore:
Timestamp:
01/17/10 12:29:46 (3 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
6822839
Parents:
cc2efd6
Message:

Finnished Scheduler and added basic "Notify" support (no sinks yet)

Location:
include
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • include/NSCHelper.cpp

    r79e734f r1bfe6f0  
    8383 
    8484 
     85#define REPORT_ERROR  0x01 
     86#define REPORT_WARNING  0x02 
     87#define REPORT_UNKNOWN  0x04 
     88#define REPORT_OK   0x08 
     89 
     90unsigned int NSCHelper::report::parse(std::wstring str) { 
     91  unsigned int report = 0; 
     92  strEx::splitList lst = strEx::splitEx(str, _T(",")); 
     93  for (strEx::splitList::const_iterator key = lst.begin(); key != lst.end(); ++key) { 
     94    if (*key == _T("all")) { 
     95      report |= REPORT_ERROR|REPORT_OK|REPORT_UNKNOWN|REPORT_WARNING; 
     96    } else if (*key == _T("error") || *key == _T("err") || *key == _T("critical") || *key == _T("crit")) { 
     97      report |= REPORT_ERROR; 
     98    } else if (*key == _T("warning") || *key == _T("warn")) { 
     99      report |= REPORT_WARNING; 
     100    } else if (*key == _T("unknown")) { 
     101      report |= REPORT_UNKNOWN; 
     102    } else if (*key == _T("ok")) { 
     103      report |= REPORT_OK; 
     104    } 
     105  } 
     106  return report; 
     107} 
     108bool NSCHelper::report::matches(unsigned int report, NSCAPI::nagiosReturn code) { 
     109  return ( 
     110    (code == NSCAPI::returnOK && (report&REPORT_OK)==REPORT_OK) || 
     111    (code == NSCAPI::returnCRIT && ((report&REPORT_ERROR)==REPORT_ERROR) ) || 
     112    (code == NSCAPI::returnWARN && ((report&REPORT_WARNING)==REPORT_WARNING) ) || 
     113    (code == NSCAPI::returnUNKNOWN && ((report&REPORT_UNKNOWN)==REPORT_UNKNOWN) ) || 
     114    ( (code != NSCAPI::returnOK) && (code != NSCAPI::returnCRIT) && (code != NSCAPI::returnWARN) && (code != NSCAPI::returnUNKNOWN) ) 
     115    ); 
     116} 
     117std::wstring NSCHelper::report::to_string(unsigned int report) { 
     118  std::wstring ret; 
     119  if ((report&REPORT_OK)!=0) { 
     120    if (!ret.empty()) ret += _T(","); 
     121    ret += _T("ok"); 
     122  } 
     123  if ((report&REPORT_WARNING)!=0) { 
     124    if (!ret.empty()) ret += _T(","); 
     125    ret += _T("warning"); 
     126  } 
     127  if ((report&REPORT_ERROR)!=0) { 
     128    if (!ret.empty()) ret += _T(","); 
     129    ret += _T("critical"); 
     130  } 
     131  if ((report&REPORT_UNKNOWN)!=0) { 
     132    if (!ret.empty()) ret += _T(","); 
     133    ret += _T("unknown"); 
     134  } 
     135  return ret; 
     136} 
     137 
     138 
    85139/** 
    86140 * Translate a message type into a human readable string. 
     
    151205  lpNSAPIExit fNSAPIExit = NULL; 
    152206  lpNSAPIInject fNSAPIInject = NULL; 
     207  lpNSAPINotify fNSAPINotify = NULL; 
    153208  lpNSAPICheckLogMessages fNSAPICheckLogMessages = NULL; 
    154209  lpNSAPIEncrypt fNSAPIEncrypt = NULL; 
     
    225280  return fNSAPIInject(command, argLen, argument, returnMessageBuffer, returnMessageBufferLen, returnPerfBuffer, returnPerfBufferLen); 
    226281} 
     282 
     283NSCAPI::errorReturn NSCModuleHelper::NotifyChannel(std::wstring channel, std::wstring command, NSCAPI::nagiosReturn code, std::wstring message, std::wstring perf) { 
     284  if (!fNSAPINotify) 
     285    throw NSCMHExcpetion(_T("NSCore has not been initiated...")); 
     286  return fNSAPINotify(channel.c_str(), command.c_str(), code, message.c_str(), perf.c_str()); 
     287} 
     288 
    227289/** 
    228290 * Inject a request command in the core (this will then be sent to the plug-in stack for processing) 
     
    734796  //NSCModuleHelper::fNSAPIExit = (NSCModuleHelper::lpNSAPIExit)f(_T("NSAPIExit")); 
    735797  NSCModuleHelper::fNSAPIInject = (NSCModuleHelper::lpNSAPIInject)f(_T("NSAPIInject")); 
     798  NSCModuleHelper::fNSAPINotify = (NSCModuleHelper::lpNSAPINotify)f(_T("NSAPINotify")); 
    736799  NSCModuleHelper::fNSAPIGetBasePath = (NSCModuleHelper::lpNSAPIGetBasePath)f(_T("NSAPIGetBasePath")); 
    737800  NSCModuleHelper::fNSAPICheckLogMessages = (NSCModuleHelper::lpNSAPICheckLogMessages)f(_T("NSAPICheckLogMessages")); 
  • include/NSCHelper.h

    r01a278b r1bfe6f0  
    9494    if (currentReturnCode != NSCAPI::returnCRIT) 
    9595      currentReturnCode = NSCAPI::returnWARN; 
     96  } 
     97 
     98  namespace report { 
     99    unsigned int parse(std::wstring str); 
     100    bool matches(unsigned int report, NSCAPI::nagiosReturn code); 
     101    std::wstring to_string(unsigned int report); 
    96102  } 
    97103}; 
     
    124130  typedef NSCAPI::errorReturn (*lpNSAPIExit)(void); 
    125131  typedef NSCAPI::nagiosReturn (*lpNSAPIInject)(const wchar_t*, const unsigned int, wchar_t **, wchar_t *, unsigned int, wchar_t *, unsigned int); 
    126    
     132 
     133  typedef NSCAPI::errorReturn (*lpNSAPINotify)(const wchar_t*, const wchar_t*, NSCAPI::nagiosReturn, const wchar_t*, const wchar_t*); 
     134 
    127135  typedef NSCAPI::boolReturn (*lpNSAPICheckLogMessages)(int); 
    128136  typedef NSCAPI::errorReturn (*lpNSAPIEncrypt)(unsigned int, const wchar_t*, unsigned int, wchar_t*, unsigned int *); 
     
    158166  NSCAPI::nagiosReturn InjectCommand(const wchar_t* command, const unsigned int argLen, wchar_t **argument, std::wstring & message, std::wstring & perf); 
    159167  NSCAPI::nagiosReturn InjectCommand(const wchar_t* command, std::list<std::wstring> argument, std::wstring & message, std::wstring & perf); 
     168  NSCAPI::errorReturn NotifyChannel(std::wstring channel, std::wstring command, NSCAPI::nagiosReturn code, std::wstring message, std::wstring perf); 
    160169  NSCAPI::nagiosReturn InjectSplitAndCommand(const wchar_t* command, wchar_t* buffer, wchar_t splitChar, std::wstring & message, std::wstring & perf); 
    161170  NSCAPI::nagiosReturn InjectSplitAndCommand(const std::wstring command, const std::wstring buffer, wchar_t splitChar, std::wstring & message, std::wstring & perf, bool escape = false); 
  • include/strEx.h

    r753ea6d r1bfe6f0  
    382382    return value * smallest_unit; 
    383383  } 
     384  inline unsigned stoui_as_time_sec(std::wstring time, unsigned int smallest_unit = 1) { 
     385    std::wstring::size_type p = time.find_first_of(_T("sSmMhHdDwW")); 
     386    std::wstring::size_type pend = time.find_first_not_of(_T("0123456789")); 
     387    unsigned int value = boost::lexical_cast<unsigned int>(pend==std::wstring::npos?time:time.substr(0,pend).c_str()); 
     388    if (p == std::wstring::npos) 
     389      return value * smallest_unit; 
     390    else if ( (time[p] == 's') || (time[p] == 'S') ) 
     391      return value; 
     392    else if ( (time[p] == 'm') || (time[p] == 'M') ) 
     393      return value * 60; 
     394    else if ( (time[p] == 'h') || (time[p] == 'H') ) 
     395      return value * 60 * 60; 
     396    else if ( (time[p] == 'd') || (time[p] == 'D') ) 
     397      return value * 24 * 60 * 60; 
     398    else if ( (time[p] == 'w') || (time[p] == 'W') ) 
     399      return value * 7 * 24 * 60 * 60; 
     400    return value * smallest_unit; 
     401  } 
    384402 
    385403  inline unsigned long long stoi64_as_time(std::wstring time, unsigned int smallest_unit = 1000) { 
Note: See TracChangeset for help on using the changeset viewer.