Changeset 035c51f in nscp
- Timestamp:
- 02/03/08 11:10:38 (5 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 777180d
- Parents:
- 52215d7
- Files:
-
- 1 added
- 8 edited
-
NSC.dist (modified) (3 diffs)
-
changelog (modified) (1 diff)
-
include/Socket.cpp (modified) (1 diff)
-
include/Socket.h (modified) (1 diff)
-
include/config.h (modified) (1 diff)
-
modules/NSCAAgent/NSCAAgent-2005.vcproj (modified) (2 diffs)
-
modules/NSCAAgent/NSCAThread.cpp (modified) (3 diffs)
-
modules/NSCAAgent/NSCAThread.h (modified) (5 diffs)
-
modules/NSCAAgent/nsca_enrypt.hpp (added)
Legend:
- Unmodified
- Added
- Removed
-
NSC.dist
r3f69109 r035c51f 181 181 ; real.ini 182 182 183 183 184 [NSCA Agent] 184 185 ;# CHECK INTERVALL (in seconds) 185 186 ; How often we should run the checks and submit the results. 186 interval=5187 ;interval=5 187 188 ; 188 189 ;# ENCRYPTION METHOD … … 196 197 ; Values: 197 198 ; 0 = None (Do NOT use this option) 198 ; -- only 0 is supported as of now, but will change in the future -- 199 ;encryption_method=0 199 ; 1 = Simple XOR (No security, just obfuscation, but very fast) 200 ; (no MCRYPT yet, but soon...) 201 ;encryption_method=1 202 ; 203 ;# ENCRYPTION PASSWORD 204 ; This is the password/passphrase that should be used to encrypt the sent packets. 205 ;password= 200 206 ; 201 207 ;# BIND TO ADDRESS 202 208 ; Allows you to bind server to a specific local address. This has to be a dotted ip adress not a hostname. 203 209 ; Leaving this blank will bind to "one" local interface. 204 ; -- not supported as of now --205 210 ;bind_to_address= 206 211 ; … … 212 217 ; The port to the nagios server to submit results to. 213 218 ;nsca_port=5667 214 215 ; The checks to run everytime we submit results back to nagios 219 ; 220 221 ;# CHECK COMMAND LIST 222 ; The checks to run everytime we submit results back to nagios 216 223 ; 217 224 [NSCA Commands] 218 225 my_cpu_check=checkCPU warn=80 crit=90 time=20m time=10s time=4 219 226 my_mem_check=checkMem MaxWarn=80% MaxCrit=90% ShowAll type=page 220 my_svc_check=checkServiceState CheckAll 227 my_svc_check=checkServiceState CheckAll exclude=wampmysqld exclude=MpfService -
changelog
r52215d7 r035c51f 5 5 * Add module for relaying events 6 6 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 7 8 2008-02-03 MickeM 9 + Added encryption subsystem to NSCA module (still no mcrypt support, but atleast you have "xor") 7 10 8 11 2008-02-02 MickeM -
include/Socket.cpp
r47b843a r035c51f 42 42 char *tmpBuffer = new char[tmpBufferLength+1]; 43 43 int n=recv(socket_,tmpBuffer,tmpBufferLength,0); 44 std::wcout << _T("read: ") << n << std::endl;44 //std::wcout << _T("read: ") << n << std::endl; 45 45 while ((n!=SOCKET_ERROR )&&(n!=0)) { 46 46 if (n == tmpBufferLength) { -
include/Socket.h
r47b843a r035c51f 137 137 length_ = length; 138 138 buffer_[length_] = 0; 139 } 140 std::wstring toString() { 141 std::wstringstream ss; 142 for (unsigned int i =0;i<length_;i++) { 143 if (i%64==0) { 144 ss << std::endl; 145 } 146 if (buffer_[i] < 30 || buffer_[i] > 'z') 147 ss << _T(" "); 148 else 149 ss << buffer_[i]; 150 } 151 return ss.str(); 139 152 } 140 153 }; -
include/config.h
r47b843a r035c51f 142 142 #define NSCA_PORT _T("nsca_port") 143 143 #define NSCA_PORT_DEFAULT 5667 144 #define NSCA_ENCRYPTION _T("encryption_method") 145 #define NSCA_ENCRYPTION_DEFAULT 1 146 #define NSCA_PASSWORD _T("password") 147 #define NSCA_PASSWORD_DEFAULT _T("") 144 148 145 149 #define C_SYSTEM_SVC_ALL_0 _T("check_all_services[SERVICE_BOOT_START]") -
modules/NSCAAgent/NSCAAgent-2005.vcproj
r3f69109 r035c51f 70 70 Name="VCLinkerTool" 71 71 AdditionalDependencies="ws2_32.lib" 72 OutputFile=" $(OutDir)\$(ProjectName).dll"72 OutputFile="../../Debug/modules/$(ProjectName).dll" 73 73 LinkIncremental="2" 74 74 ModuleDefinitionFile="NSCAAgent.def" … … 1901 1901 <File 1902 1902 RelativePath="..\..\include\error.hpp" 1903 > 1904 </File> 1905 <File 1906 RelativePath=".\nsca_enrypt.hpp" 1903 1907 > 1904 1908 </File> -
modules/NSCAAgent/NSCAThread.cpp
r5ca3931 r035c51f 27 27 host_ = NSCModuleHelper::getSettingsString(NSCA_AGENT_SECTION_TITLE, NSCA_HOSTNAME, NSCA_HOSTNAME_DEFAULT); 28 28 port_ = NSCModuleHelper::getSettingsInt(NSCA_AGENT_SECTION_TITLE, NSCA_PORT, NSCA_PORT_DEFAULT); 29 encryption_method_ = NSCModuleHelper::getSettingsInt(NSCA_AGENT_SECTION_TITLE, NSCA_ENCRYPTION, NSCA_ENCRYPTION_DEFAULT); 30 password_ = strEx::wstring_to_string(NSCModuleHelper::getSettingsString(NSCA_AGENT_SECTION_TITLE, NSCA_PASSWORD, NSCA_PASSWORD_DEFAULT)); 29 31 std::list<std::wstring> items = NSCModuleHelper::getSettingsSection(NSCA_CMD_SECTION_TITLE); 30 32 for (std::list<std::wstring>::const_iterator cit = items.begin(); cit != items.end(); ++cit) { … … 100 102 results.push_back((*cit).execute(host_)); 101 103 } 102 103 104 send(results); 104 105 105 _time64( &stop ); 106 106 __int64 elapsed = stop-start; … … 129 129 } 130 130 void NSCAThread::send(const std::list<Command::Result> &results) { 131 NSC_LOG_MESSAGE_STD(_T(">>> Attempting to send results...")); 132 simpleSocket::Socket socket(true); 133 simpleSocket::DataBuffer inc; 134 if (socket.connect(host_, port_) == SOCKET_ERROR) { 135 NSC_LOG_MESSAGE_STD(_T("<<< Could not connect to: ") + host_ + strEx::itos(port_)); 131 try { 132 nsca_encrypt crypt_inst; 133 simpleSocket::Socket socket(true); 134 simpleSocket::DataBuffer inc; 135 if (socket.connect(host_, port_) == SOCKET_ERROR) { 136 NSC_LOG_ERROR_STD(_T("<<< Could not connect to: ") + host_ + strEx::itos(port_)); 137 return; 138 } 139 if (!socket.readAll(inc, sizeof(NSCAPacket::init_packet_struct), sizeof(NSCAPacket::init_packet_struct))) { 140 NSC_LOG_ERROR_STD(_T("<<< Failed to read header: ") + host_ + strEx::itos(port_)); 141 return; 142 } 143 NSCAPacket::init_packet_struct *packet_in = (NSCAPacket::init_packet_struct*) inc.getBuffer(); 144 try { 145 crypt_inst.encrypt_init(password_.c_str(),encryption_method_,packet_in->iv); 146 } catch (nsca_encrypt::exception &e) { 147 NSC_LOG_ERROR_STD(_T("<<< Failed to initalize encryption header: ") + e.getMessage()); 148 return; 149 } catch (...) { 150 NSC_LOG_ERROR_STD(_T("<<< Failed to initalize encryption header!")); 151 return; 152 } 153 154 try { 155 for (std::list<Command::Result>::const_iterator cit = results.begin(); cit != results.end(); ++cit) { 156 //NSC_DEBUG_MSG_STD(_T("Sending : ") + (*cit).toString()); 157 socket.send((*cit).getBuffer(crypt_inst)); 158 } 159 } catch (nsca_encrypt::exception &e) { 160 NSC_LOG_ERROR_STD(_T("<<< Failed to encrypt packet: ") + e.getMessage()); 161 return; 162 } catch (...) { 163 NSC_LOG_ERROR_STD(_T("<<< Failed to encrypt packet!")); 164 return; 165 } 166 socket.close(); 167 } catch (...) { 168 NSC_LOG_ERROR_STD(_T("<<< Failed to initalize encryption header!")); 136 169 return; 137 170 } 138 NSC_DEBUG_MSG_STD(_T("... Connected, attempting to read: ") + strEx::itos(sizeof(NSCAPacket::init_packet_struct)));139 if (!socket.readAll(inc, sizeof(NSCAPacket::init_packet_struct), sizeof(NSCAPacket::init_packet_struct))) {140 NSC_LOG_MESSAGE_STD(_T("<<< Failed to read header: ") + host_ + strEx::itos(port_));141 return;142 }143 NSC_DEBUG_MSG_STD(_T("... Read..."));144 NSCAPacket::init_packet_struct *packet_in = (NSCAPacket::init_packet_struct*) inc.getBuffer();145 NSC_LOG_MESSAGE_STD(_T("Read: ") + strEx::format_date(packet_in->timestamp));146 for (std::list<Command::Result>::const_iterator cit = results.begin(); cit != results.end(); ++cit) {147 NSC_LOG_MESSAGE_STD(_T("Sending : ") + (*cit).toString());148 socket.send((*cit).getBuffer());149 }150 NSC_DEBUG_MSG_STD(_T("... Done..."));151 socket.close();152 NSC_LOG_MESSAGE_STD(_T("<<< Attempting to send results..."));153 171 } 154 172 -
modules/NSCAAgent/NSCAThread.h
r5ca3931 r035c51f 25 25 #include <arrayBuffer.h> 26 26 #include <Socket.h> 27 #include "nsca_enrypt.hpp" 27 28 28 29 /** … … 139 140 Result(std::wstring _host) : host(_host){ 140 141 _time32(&time); 141 time+=60*60 + 2*60;142 //time+=60*60 + 2*60; 142 143 } 143 144 std::wstring service; … … 153 154 } 154 155 155 simpleSocket::DataBuffer getBuffer( ) const {156 simpleSocket::DataBuffer getBuffer(nsca_encrypt &crypt_inst) const { 156 157 std::string s = strEx::wstring_to_string(service); 157 158 std::string r = strEx::wstring_to_string(result); … … 170 171 unsigned int calculated_crc32=calculate_crc32(reinterpret_cast<char*>(&data),sizeof(data)); 171 172 data.crc32_value=static_cast<NSCAPacket::u_int32_t>(htonl(calculated_crc32)); 172 173 return simpleSocket::DataBuffer(reinterpret_cast<char*>(&data),sizeof(data)); 173 char * buffer = reinterpret_cast<char*>(&data); 174 crypt_inst.encrypt_buffer(buffer, sizeof(data)); 175 return simpleSocket::DataBuffer(buffer,sizeof(data)); 174 176 } 175 177 … … 207 209 std::wstring host_; 208 210 unsigned int port_; 211 std::string password_; 212 int encryption_method_; 209 213 210 214 public:
Note: See TracChangeset
for help on using the changeset viewer.








