Changeset 79e734f in nscp
- Timestamp:
- 12/12/09 13:15:44 (3 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 031acbf
- Parents:
- 9b3f53c
- Files:
-
- 2 added
- 19 edited
-
build.cmake (modified) (1 diff)
-
include/NSCHelper.cpp (modified) (1 diff)
-
include/execute_process.hpp (modified) (1 diff)
-
include/execute_process_unix.hpp (added)
-
include/execute_process_w32.hpp (added)
-
include/file_helpers.hpp (modified) (3 diffs)
-
include/nrpe/nrpepacket.hpp (modified) (2 diffs)
-
include/socket_helpers.hpp (modified) (1 diff)
-
modules/CheckExternalScripts/CheckExternalScripts.cpp (modified) (4 diffs)
-
modules/CheckExternalScripts/CheckExternalScripts.h (modified) (2 diffs)
-
modules/CheckExternalScripts/stdafx.h (modified) (1 diff)
-
modules/CheckHelpers/CheckHelpers.cpp (modified) (1 diff)
-
modules/NRPEClient/NRPEClient.cpp (modified) (1 diff)
-
modules/NRPEClient/stdafx.h (modified) (2 diffs)
-
modules/NRPEListener/NRPEListener.cpp (modified) (2 diffs)
-
modules/NRPEListener/nrpe_connection.cpp (modified) (3 diffs)
-
modules/NRPEListener/nrpe_handler.cpp (modified) (1 diff)
-
modules/NRPEListener/nrpe_handler.hpp (modified) (2 diffs)
-
modules/NRPEListener/stdafx.h (modified) (1 diff)
-
modules/NSClientListener/NSClientListener.h (modified) (1 diff)
-
service/StdAfx.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
build.cmake
rdcd90b2 r79e734f 1 1 SET(Boost_DEBUG 1) 2 2 3 set(Boost_USE_STATIC_LIBS ON)3 #set(Boost_USE_STATIC_LIBS ON) 4 4 set(BOOST_USE_MULTITHREADED ON) 5 5 -
include/NSCHelper.cpp
r9b3f53c r79e734f 350 350 */ 351 351 namespace NSCModuleHelper { 352 NSCAPI::nagiosReturn InjectSplitAndCommand(const std::wstring command, const std::wstring buffer, wchar_t spliwchar_t, std::wstring & message, std::wstring & perf, intescape)352 NSCAPI::nagiosReturn InjectSplitAndCommand(const std::wstring command, const std::wstring buffer, wchar_t spliwchar_t, std::wstring & message, std::wstring & perf, bool escape) 353 353 { 354 354 if (!fNSAPIInject) -
include/execute_process.hpp
r3692371 r79e734f 31 31 }; 32 32 33 #define BUFF_SIZE 4096 33 class exec_arguments { 34 public: 35 exec_arguments(std::wstring root_path_, std::wstring command_, unsigned int timeout_) 36 : root_path(root_path_) 37 , command(command_) 38 , timeout(timeout_) 39 {} 34 40 35 char* createBuffer() { 36 return new char[BUFF_SIZE+1]; 37 } 38 void destroyBuffer(char* buffer) { 39 delete [] buffer; 40 } 41 42 std::string readFromFile(char* buffer, HANDLE hFile) { 43 DWORD dwRead = 0; 44 DWORD retval = 0; 45 std::string str; 46 do { 47 DWORD retval = ReadFile(hFile, buffer, BUFF_SIZE, &dwRead, NULL); 48 if (retval == 0 || dwRead <= 0 || dwRead > BUFF_SIZE) 49 return str; 50 buffer[dwRead] = 0; 51 str += buffer; 52 } while (dwRead == BUFF_SIZE); 53 return str; 54 } 55 56 int executeProcess(std::wstring root_path, std::wstring command, std::wstring &msg, std::wstring &perf, unsigned int timeout) { 57 NSCAPI::nagiosReturn result; 58 PROCESS_INFORMATION pi; 59 STARTUPINFO si; 60 HANDLE hChildOutR, hChildOutW, hChildInR, hChildInW; 61 SECURITY_ATTRIBUTES sec; 62 DWORD dwstate, dwexitcode; 63 // Set up members of SECURITY_ATTRIBUTES structure. 64 sec.nLength = sizeof(SECURITY_ATTRIBUTES); 65 sec.bInheritHandle = TRUE; 66 sec.lpSecurityDescriptor = NULL; 67 68 // Create Pipes 69 CreatePipe(&hChildInR, &hChildInW, &sec, 0); 70 CreatePipe(&hChildOutR, &hChildOutW, &sec, 0); 71 72 // Set up members of STARTUPINFO structure. 73 74 ZeroMemory(&si, sizeof(STARTUPINFO)); 75 si.cb = sizeof(STARTUPINFO); 76 si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; 77 si.hStdInput = hChildInR; 78 si.hStdOutput = hChildOutW; 79 si.hStdError = hChildOutW; 80 si.wShowWindow = SW_HIDE; 81 82 83 // CreateProcess doesn't work with a const command 84 TCHAR *cmd = new TCHAR[command.length()+1]; 85 wcsncpy_s(cmd, command.length()+1, command.c_str(), command.length()); 86 cmd[command.length()] = 0; 87 88 // Create the child process. 89 //HANDLE hWaitEvt = ::CreateEvent(NULL, TRUE, FALSE, NULL); 90 BOOL processOK = CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, root_path.c_str(), &si, &pi); 91 delete [] cmd; 92 if (processOK) { 93 DWORD dwAvail = 0; 94 std::string str; 95 //HANDLE handles[2]; 96 //handles[0] = pi.hProcess; 97 //handles[1] = hWaitEvt; 98 char *buffer = createBuffer(); 99 for (unsigned int i=0;i<timeout;i++) { 100 if (!::PeekNamedPipe(hChildOutR, NULL, 0, NULL, &dwAvail, NULL)) 101 break; 102 if (dwAvail > 0) 103 str += readFromFile(buffer, hChildOutR); 104 dwstate = WaitForSingleObject(pi.hProcess, 1000); 105 if (dwstate != WAIT_TIMEOUT) 106 break; 107 } 108 CloseHandle(hChildInR); 109 CloseHandle(hChildInW); 110 CloseHandle(hChildOutW); 111 112 dwAvail = 0; 113 if (!::PeekNamedPipe(hChildOutR, NULL, 0, NULL, &dwAvail, NULL)) 114 NSC_LOG_ERROR_STD(_T("Failed to peek buffer: ") + error::lookup::last_error()); 115 if (dwAvail > 0) 116 str += readFromFile(buffer, hChildOutR); 117 msg = strEx::string_to_wstring(str); 118 destroyBuffer(buffer); 119 120 if (dwstate == WAIT_TIMEOUT) { 121 TerminateProcess(pi.hProcess, 5); 122 msg = _T("Command (") + command + _T(") didn't terminate within the timeout period (") + strEx::itos(timeout) + _T("s)!"); 123 result = NSCAPI::returnUNKNOWN; 124 } else { 125 if (msg.empty()) { 126 msg = _T("No output available from command (") + command + _T(")."); 127 } else { 128 strEx::token t = strEx::getToken(msg, '|'); 129 msg = t.first; 130 std::wstring::size_type pos = msg.find_last_not_of(_T("\n\r ")); 131 if (pos != std::wstring::npos) { 132 if (pos == msg.size()) 133 msg = msg.substr(0,pos); 134 else 135 msg = msg.substr(0,pos+1); 136 } 137 perf = t.second; 138 } 139 if (GetExitCodeProcess(pi.hProcess, &dwexitcode) == 0) { 140 msg = _T("Failed to get commands (") + command + _T(") return code: ") + error::lookup::last_error(); 141 result = NSCAPI::returnUNKNOWN; 142 } else { 143 result = dwexitcode; 144 } 145 } 146 CloseHandle(pi.hThread); 147 CloseHandle(pi.hProcess); 148 CloseHandle(hChildOutR); 149 } else { 150 DWORD error = GetLastError(); 151 if (error == ERROR_BAD_EXE_FORMAT) { 152 NSC_LOG_ERROR_STD(command + _T(" is not an .exe file or a valid image (if you run a script you usually need to prefix the command with the interpreter like so: \"command=c:\\perl.exe <script>\"")); 153 msg = _T("ExternalCommands: failed to create process (") + command + _T("): it is not an exe file (check NSC.log for more info) - ") + error::lookup::last_error(error); 154 } else { 155 msg = _T("ExternalCommands: failed to create process (") + command + _T("): ") + error::lookup::last_error(error); 156 } 157 result = NSCAPI::returnUNKNOWN; 158 CloseHandle(hChildInR); 159 CloseHandle(hChildInW); 160 CloseHandle(hChildOutW); 161 CloseHandle(pi.hThread); 162 CloseHandle(pi.hProcess); 163 CloseHandle(hChildOutR); 164 } 165 return result; 166 } 41 std::wstring root_path; 42 std::wstring command; 43 unsigned int timeout; 44 }; 167 45 } 168 46 47 #ifdef _WIN32 48 #include "execute_process_w32.hpp" 49 #else 50 #include "execute_process_unix.hpp" 51 #endif 52 -
include/file_helpers.hpp
rf0eb62d r79e734f 1 1 #pragma once 2 3 #include <boost/filesystem.hpp> 2 4 3 5 namespace file_helpers { … … 5 7 public: 6 8 static bool is_directory(std::wstring path) { 7 return is_directory(::GetFileAttributes(path.c_str()));9 boost::filesystem::is_directory(path); 8 10 } 9 static bool is_directory(DWORD dwAtt) {10 if (dwAtt == INVALID_FILE_ATTRIBUTES) {11 return false;12 } else if ((dwAtt&FILE_ATTRIBUTE_DIRECTORY)==FILE_ATTRIBUTE_DIRECTORY) {13 return true;14 }15 return false;16 }11 // static bool is_directory(DWORD dwAtt) { 12 // if (dwAtt == INVALID_FILE_ATTRIBUTES) { 13 // return false; 14 // } else if ((dwAtt&FILE_ATTRIBUTE_DIRECTORY)==FILE_ATTRIBUTE_DIRECTORY) { 15 // return true; 16 // } 17 // return false; 18 // } 17 19 static bool is_file(std::wstring path) { 18 DWORD dwAtt = ::GetFileAttributes(path.c_str()); 19 if (dwAtt == INVALID_FILE_ATTRIBUTES) { 20 return false; 21 } else if ((dwAtt&FILE_ATTRIBUTE_NORMAL)==FILE_ATTRIBUTE_NORMAL) { 22 return true; 23 } 24 return false; 20 return boost::filesystem::is_regular(path); 21 // DWORD dwAtt = ::GetFileAttributes(path.c_str()); 22 // if (dwAtt == INVALID_FILE_ATTRIBUTES) { 23 // return false; 24 // } else if ((dwAtt&FILE_ATTRIBUTE_NORMAL)==FILE_ATTRIBUTE_NORMAL) { 25 // return true; 26 // } 27 // return false; 25 28 } 26 29 static bool exists(std::wstring path) { 27 DWORD dwAtt = ::GetFileAttributes(path.c_str()); 28 if (dwAtt == INVALID_FILE_ATTRIBUTES) { 29 return false; 30 } 31 return true; 30 return boost::filesystem::exists(path); 31 // DWORD dwAtt = ::GetFileAttributes(path.c_str()); 32 // if (dwAtt == INVALID_FILE_ATTRIBUTES) { 33 // return false; 34 // } 35 // return true; 32 36 } 33 37 }; … … 35 39 class patterns { 36 40 public: 37 typedef std::pair< std::wstring,std::wstring> pattern_type;41 typedef std::pair<boost::filesystem::wpath,std::wstring> pattern_type; 38 42 39 static pattern_type split_pattern(std::wstring path) { 40 std::wstring baseDir; 41 if (file_helpers::checks::exists(path)) { 43 static pattern_type split_pattern(boost::filesystem::wpath path) { 44 if (boost::filesystem::is_directory(path)) 42 45 return pattern_type(path, _T("")); 43 } 44 std::wstring::size_type pos = path.find_last_of('\\'); 45 if (pos == std::wstring::npos) { 46 pattern_type(path, _T("*.*")); 47 } 48 return pattern_type(path.substr(0, pos), path.substr(pos+1)); 46 return pattern_type(path.branch_path(), path.leaf() /*filename()*/); 49 47 } 50 static std::wstringcombine_pattern(pattern_type pattern) {51 return pattern.first + _T("\\") +pattern.second;48 static boost::filesystem::wpath combine_pattern(pattern_type pattern) { 49 return pattern.first / pattern.second; 52 50 } 53 51 -
include/nrpe/nrpepacket.hpp
r9b3f53c r79e734f 55 55 return SwapBytes<T, sizeof(T)>(value); 56 56 } 57 57 58 template<class T> 58 59 inline T ntoh(T value) { 59 std::cout << "Swaping (in): " << value << " => " << EndianSwapBytes<EEndian::BIG_ENDIAN_ORDER, EEndian::HOST_ENDIAN_ORDER, T>(value) << std::endl; 60 return EndianSwapBytes<EEndian::BIG_ENDIAN_ORDER, EEndian::HOST_ENDIAN_ORDER, T>(value); 61 } 62 template<class T> 60 return EndianSwapBytes<BIG_ENDIAN_ORDER, HOST_ENDIAN_ORDER, T >(value); 61 } 62 template<typename T> 63 63 inline T hton(T value) { 64 std::cout << "Swaping (out): " << value << " => " << EndianSwapBytes<EEndian::HOST_ENDIAN_ORDER, EEndian::BIG_ENDIAN_ORDER, T>(value) << std::endl; 65 return EndianSwapBytes<EEndian::HOST_ENDIAN_ORDER, EEndian::BIG_ENDIAN_ORDER, T>(value); 64 return EndianSwapBytes<HOST_ENDIAN_ORDER, BIG_ENDIAN_ORDER, T >(value); 66 65 } 67 66 … … 108 107 }; 109 108 110 class nrpe_ packet_exception {109 class nrpe_exception { 111 110 std::wstring error_; 112 111 public: 113 nrpe_ packet_exception(std::wstring error) : error_(error) {}112 nrpe_exception(std::wstring error) : error_(error) {} 114 113 std::wstring getMessage() { 115 114 return error_; 116 115 } 116 }; 117 class nrpe_packet_exception : public nrpe_exception { 118 public: 119 nrpe_packet_exception(std::wstring error) : nrpe_exception(error) {} 117 120 }; 118 121 -
include/socket_helpers.hpp
r9b3f53c r79e734f 92 92 } 93 93 */ 94 return ((allowed.in_addr&allowed.mask)==(remote.S_un.S_addr&allowed.mask));94 return true; //((allowed.in_addr&allowed.mask)==(remote.S_un.S_addr&allowed.mask)); 95 95 } 96 96 bool inAllowedHosts(boost::asio::io_service& io_service, struct in_addr remote) { -
modules/CheckExternalScripts/CheckExternalScripts.cpp
r6672c56 r79e734f 21 21 #include "stdafx.h" 22 22 #include "CheckExternalScripts.h" 23 #include <strEx.h>24 23 #include <time.h> 24 25 25 #include <settings/macros.h> 26 26 #include <msvc_wrappers.h> 27 #include <config.h> 28 #include <strEx.h> 27 29 #include <file_helpers.hpp> 28 #include <config.h> 30 31 #include <boost/regex.hpp> 32 #include <boost/filesystem.hpp> 33 29 34 30 35 CheckExternalScripts gCheckExternalScripts; 31 36 #ifdef _WIN32 32 37 BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 33 38 { … … 35 40 return TRUE; 36 41 } 42 #endif 37 43 38 44 CheckExternalScripts::CheckExternalScripts() {} 39 45 CheckExternalScripts::~CheckExternalScripts() {} 40 46 41 void CheckExternalScripts::addAllScriptsFrom(std::wstring path) { 42 file_helpers::patterns::pattern_type pattern = file_helpers::patterns::split_pattern(path); 43 if (!file_helpers::checks::exists(pattern.first)) 44 pattern.first = NSCModuleHelper::getBasePath() + _T("\\") + pattern.first; 45 if (!file_helpers::checks::exists(pattern.first)) 46 NSC_LOG_ERROR_STD(_T("Path was not found: ") + pattern.first); 47 /* TODO: do we need this? 48 std::wstring::size_type pos = path.find_last_of('*'); 49 if (pos == std::wstring::npos) { 50 path += _T("*.*"); 51 } 52 */ 53 WIN32_FIND_DATA wfd; 54 std::wstring real_path = file_helpers::patterns::combine_pattern(pattern); 55 HANDLE hFind = FindFirstFile(real_path.c_str(), &wfd); 56 if (hFind != INVALID_HANDLE_VALUE) { 57 do { 58 if ((wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY) { 59 addCommand(wfd.cFileName, pattern.first + _T("\\") + wfd.cFileName, _T("")); 60 } 61 } while (FindNextFile(hFind, &wfd)); 62 } else { 63 NSC_LOG_ERROR_STD(_T("No scripts found in path: ") + real_path); 64 return; 65 } 66 FindClose(hFind); 47 void CheckExternalScripts::addAllScriptsFrom(std::wstring str_path) { 48 boost::filesystem::wpath path = str_path; 49 if (path.has_relative_path()) 50 path = NSCModuleHelper::getBasePath() / path; 51 file_helpers::patterns::pattern_type split_path = file_helpers::patterns::split_pattern(path); 52 if (!boost::filesystem::is_directory(split_path.first)) 53 NSC_LOG_ERROR_STD(_T("Path was not found: ") + split_path.first.string()); 54 55 boost::wregex pattern(split_path.second); 56 boost::filesystem::wdirectory_iterator end_itr; // default construction yields past-the-end 57 for ( boost::filesystem::wdirectory_iterator itr( split_path.first ); itr != end_itr; ++itr ) { 58 if ( !is_directory(itr->status()) ) { 59 std::wstring name = itr->path().leaf(); 60 if (regex_match(name, pattern)) 61 addCommand(name, (split_path.first / name).string(), _T("")); 62 } 63 } 67 64 } 68 65 … … 128 125 129 126 NSCAPI::nagiosReturn CheckExternalScripts::handleCommand(const strEx::blindstr command, const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf) { 130 command_list::const_iterator cit = commands.find(command); 127 std::wstring cmd = command.c_str(); 128 boost::to_lower(cmd); 129 command_list::const_iterator cit = commands.find(cmd); 131 130 bool isAlias = false; 132 131 if (cit == commands.end()) { 133 cit = alias.find(c ommand);132 cit = alias.find(cmd); 134 133 if (cit == alias.end()) 135 134 return NSCAPI::returnIgnored; … … 157 156 return NSCModuleHelper::InjectSplitAndCommand(cd.command, args, ' ', message, perf, true); 158 157 } else { 159 int result = process::executeProcess( root_, cd.command + _T(" ") + args, message, perf, timeout);158 int result = process::executeProcess(process::exec_arguments(root_, cd.command + _T(" ") + args, timeout), message, perf); 160 159 if (!NSCHelper::isNagiosReturnCode(result)) { 161 160 NSC_LOG_ERROR_STD(_T("The command (") + cd.command + _T(") returned an invalid return code: ") + strEx::itos(result)); -
modules/CheckExternalScripts/CheckExternalScripts.h
r5da0459 r79e734f 33 33 std::wstring arguments; 34 34 }; 35 typedef std::map<st rEx::blindstr, command_data> command_list;35 typedef std::map<std::wstring, command_data> command_list; 36 36 command_list commands; 37 37 command_list alias; … … 81 81 private: 82 82 void addAllScriptsFrom(std::wstring path); 83 void addCommand(strEx::blindstr key, std::wstring cmd, std::wstring args) { 83 void addCommand(std::wstring key, std::wstring cmd, std::wstring args) { 84 boost::to_lower(key); 84 85 commands[key] = command_data(cmd, args); 85 86 } 86 void addAlias(strEx::blindstr key, std::wstring cmd, std::wstring args) { 87 void addAlias(std::wstring key, std::wstring cmd, std::wstring args) { 88 boost::to_lower(key); 87 89 alias[key] = command_data(cmd, args); 88 90 } -
modules/CheckExternalScripts/stdafx.h
r7f9c823 r79e734f 21 21 #pragma once 22 22 23 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers24 // Windows Header Files:25 #include <windows.h>26 27 23 #include <string> 28 24 #include <functional> 29 30 25 #include <utils.h> 31 26 32 27 #include <boost/lexical_cast.hpp> 33 28 29 #include <types.hpp> 34 30 #include <NSCAPI.h> 35 31 #include <nsc_module_wrapper.hpp> -
modules/CheckHelpers/CheckHelpers.cpp
rd05c3f0 r79e734f 26 26 27 27 CheckHelpers gCheckHelpers; 28 #ifdef WIN3228 #ifdef _WIN32 29 29 BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 30 30 { -
modules/NRPEClient/NRPEClient.cpp
r9b3f53c r79e734f 32 32 NRPEClient gNRPEClient; 33 33 34 #ifdef WIN3234 #ifdef _WIN32 35 35 BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 36 36 { -
modules/NRPEClient/stdafx.h
rdcd90b2 r79e734f 21 21 #pragma once 22 22 23 #ifdef _WIN3224 #define _WIN32_WINNT 0x040025 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers26 // Windows Header Files:27 #include <windows.h>28 #include <winsock2.h>29 #endif30 31 23 #include <string> 32 24 #include <functional> … … 35 27 #include <utils.h> 36 28 29 #include <types.hpp> 37 30 #include <NSCAPI.h> 38 31 #include <NSCHelper.h> -
modules/NRPEListener/NRPEListener.cpp
r9b3f53c r79e734f 28 28 NRPEListener gNRPEListener; 29 29 30 #ifdef _WIN32 30 31 BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 31 32 { … … 33 34 return TRUE; 34 35 } 36 #endif 35 37 36 38 NRPEListener::NRPEListener() : noPerfData_(false), buffer_length_(0) { -
modules/NRPEListener/nrpe_connection.cpp
r9b3f53c r79e734f 24 24 void connection::start() { 25 25 parser_.set_payload_length(handler_.get_payload_length()); 26 std::cout << "Starting..." << std::endl;27 26 socket_.async_read_some(boost::asio::buffer(buffer_), 28 27 strand_.wrap( … … 31 30 boost::asio::placeholders::bytes_transferred) 32 31 )); 33 std::cout << "Starting...done" << std::endl;34 32 } 35 33 36 34 void connection::handle_read(const boost::system::error_code& e, std::size_t bytes_transferred) { 37 std::cout << "read: " << buffer_.c_array() << ": " << bytes_transferred << "(" << e << ")" << std::endl;38 35 if (!e) { 39 36 bool result; … … 103 100 socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec); 104 101 } 105 106 // No new asynchronous operations are started. This means that all shared_ptr107 // references to the connection object will disappear and the object will be108 // destroyed automatically after this handler returns. The connection class's109 // destructor closes the socket.110 102 } 111 103 -
modules/NRPEListener/nrpe_handler.cpp
r9b3f53c r79e734f 2 2 #include <boost/asio.hpp> 3 3 #include "nrpe_handler.hpp" 4 #include <NSCHelper.h> 4 5 5 6 namespace nrpe { 6 7 namespace server { 8 nrpe::packet handler::handle(nrpe::packet p) { 9 strEx::token cmd = strEx::getToken(p.getPayload(), '!'); 10 if (cmd.first == _T("_NRPE_CHECK")) { 11 return nrpe::packet::create_response(NSCAPI::returnOK, _T("I (") + NSCModuleHelper::getApplicationVersionString() + _T(") seem to be doing fine..."), p.get_payload_length()); 12 } 13 std::wstring msg, perf; 14 15 if (allowArgs_) { 16 if (!cmd.second.empty()) { 17 NSC_LOG_ERROR(_T("Request contained arguments (not currently allowed, check the allow_arguments option).")); 18 throw nrpe::nrpe_exception(_T("Request contained arguments (not currently allowed, check the allow_arguments option).")); 19 } 20 } 21 if (allowNasty_) { 22 if (cmd.first.find_first_of(NASTY_METACHARS) != std::wstring::npos) { 23 NSC_LOG_ERROR(_T("Request command contained illegal metachars!")); 24 throw nrpe::nrpe_exception(_T("Request command contained illegal metachars!")); 25 } 26 if (cmd.second.find_first_of(NASTY_METACHARS) != std::wstring::npos) { 27 NSC_LOG_ERROR(_T("Request arguments contained illegal metachars!")); 28 throw nrpe::nrpe_exception(_T("Request command contained illegal metachars!")); 29 } 30 } 31 //TODO REMOVE THIS 32 //return NRPEPacket(NRPEPacket::responsePacket, NRPEPacket::version2, NSCAPI::returnUNKNOWN, _T("TEST TEST TEST"), buffer_length_); 33 34 NSCAPI::nagiosReturn ret = -3; 35 try { 36 ret = NSCModuleHelper::InjectSplitAndCommand(cmd.first, cmd.second, '!', msg, perf); 37 } catch (...) { 38 return nrpe::packet::create_response(NSCAPI::returnUNKNOWN, _T("UNKNOWN: Internal exception"), p.get_payload_length()); 39 } 40 switch (ret) { 41 case NSCAPI::returnInvalidBufferLen: 42 return nrpe::packet::create_response(NSCAPI::returnUNKNOWN, _T("UNKNOWN: Return buffer to small to handle this command."), p.get_payload_length()); 43 case NSCAPI::returnIgnored: 44 return nrpe::packet::create_response(NSCAPI::returnUNKNOWN, _T("UNKNOWN: No handler for that command."), p.get_payload_length()); 45 case NSCAPI::returnOK: 46 case NSCAPI::returnWARN: 47 case NSCAPI::returnCRIT: 48 case NSCAPI::returnUNKNOWN: 49 break; 50 default: 51 return nrpe::packet::create_response(NSCAPI::returnUNKNOWN, _T("UNKNOWN: Internal error."), p.get_payload_length()); 52 } 53 if (msg.length() >= p.get_payload_length()-1) { 54 NSC_LOG_ERROR(_T("Truncating returndata as it is bigger then NRPE allowes :(")); 55 msg = msg.substr(0,p.get_payload_length()-2); 56 } 57 if (perf.empty()||noPerfData_) { 58 return nrpe::packet::create_response(ret, msg, p.get_payload_length()); 59 } else { 60 return nrpe::packet::create_response(ret, msg + _T("|") + perf, p.get_payload_length()); 61 } 62 } 7 63 } 8 64 } -
modules/NRPEListener/nrpe_handler.hpp
r9b3f53c r79e734f 6 6 class handler { 7 7 unsigned int payload_length_; 8 bool allowArgs_; 9 bool allowNasty_; 10 bool noPerfData_; 8 11 public: 9 12 handler(unsigned int payload_length) … … 20 23 return payload_length_; 21 24 } 25 nrpe::packet handle(nrpe::packet packet); 26 /* 22 27 nrpe::packet handle(nrpe::packet packet) { 23 28 return nrpe::packet::create_response(1, _T("HELLO!"), payload_length_); 24 29 } 30 */ 25 31 nrpe::packet create_error(std::wstring msg) { 26 32 return nrpe::packet::create_response(4, msg, payload_length_); -
modules/NRPEListener/stdafx.h
r9b3f53c r79e734f 21 21 #pragma once 22 22 23 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers24 // Windows Header Files:25 #include <windows.h>26 27 23 #include <string> 28 24 #include <functional> 29 25 #include <map> 30 26 #include <vector> 31 32 27 #include <config.h> 33 28 #include <utils.h> 34 29 30 #include <types.hpp> 35 31 #include <NSCAPI.h> 36 32 #include <NSCHelper.h> -
modules/NSClientListener/NSClientListener.h
r9567d4b r79e734f 19 19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 20 20 ***************************************************************************/ 21 #include <Socket.h>21 //#include <Socket.h> 22 22 #include <string> 23 23 #include <utils.h> -
service/StdAfx.h
rb3078b4 r79e734f 21 21 #pragma once 22 22 #include <types.hpp> 23 /*24 #ifdef WIN3225 #define _WINSOCKAPI_26 #include <tchar.h>27 #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers28 #include <windows.h>29 #endif30 23 31 #define COMPILE_NEWAPIS_STUBS32 #define WANT_GETLONGPATHNAME_WRAPPER33 //#include <NewAPIs.h>34 */35 24 #include <iostream> 36 25 #include <string>
Note: See TracChangeset
for help on using the changeset viewer.








