Changeset 72eea1f in nscp
- Timestamp:
- 02/20/12 23:51:38 (15 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- c74d7b6
- Parents:
- 523576e
- Files:
-
- 20 edited
-
changelog (modified) (1 diff)
-
include/nrpe/client/socket.hpp (modified) (1 diff)
-
include/nrpe/server/connection.cpp (modified) (2 diffs)
-
include/nrpe/server/connection.hpp (modified) (1 diff)
-
include/nrpe/server/ssl_connection.cpp (modified) (1 diff)
-
include/nrpe/server/ssl_connection.hpp (modified) (1 diff)
-
include/nrpe/server/tcp_connection.cpp (modified) (1 diff)
-
include/nrpe/server/tcp_connection.hpp (modified) (1 diff)
-
include/parsers/operators.cpp (modified) (3 diffs)
-
include/parsers/where/expression_ast.hpp (modified) (1 diff)
-
include/parsers/where/grammar/grammar.cpp (modified) (1 diff)
-
include/socket/socket_helpers.hpp (modified) (5 diffs)
-
modules/CheckEventLog/CheckEventLog.cpp (modified) (2 diffs)
-
modules/CheckEventLog/eventlog_record.hpp (modified) (6 diffs)
-
modules/CheckEventLog/filter.cpp (modified) (2 diffs)
-
modules/CheckEventLog/filter.hpp (modified) (1 diff)
-
scripts/python/test_eventlog.py (modified) (2 diffs)
-
scripts/python/test_nrpe.py (modified) (2 diffs)
-
version.hpp (modified) (1 diff)
-
version.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
changelog
r523576e r72eea1f 4 4 * Fixa dependonservice LanManWorkStation (old win) 5 5 * Fix RtlStringFromGUID problem on NT4 6 7 2012-02-19 MickeM 8 * Fixed NRPE buffer issue 9 * Added test case for 65K NRPE buffer length as well as 1Mb 10 * Added support for not regexp as operator to filters (Eventlog) (#463) 11 * Added support for computer as filter keyword and format keyword in EventLog (#442) 12 "filter=computer = 'foo'" syntax=%computer% 13 * Improved messages rendering of eventlog messages a bit 6 14 7 15 2012-02-19 MickeM -
include/nrpe/client/socket.hpp
r2ec2eb6 r72eea1f 5 5 #include <socket/socket_helpers.hpp> 6 6 //#include <nsca/nsca_packet.hpp> 7 #include <iostream> 7 8 8 9 using boost::asio::ip::tcp; -
include/nrpe/server/connection.cpp
re396b2f r72eea1f 84 84 response = handler_->create_error(_T("Unknown error handling NRPE packet")); 85 85 } 86 87 86 std::vector<boost::asio::const_buffer> buffers; 88 87 buffers.push_back(buf(response.get_buffer())); 89 88 start_write_request(buffers); 90 cancel_timer(); 89 } else { 90 continue_read_request(buffer_); 91 91 } 92 92 } … … 101 101 } 102 102 103 void connection::handle_write_response(const boost::system::error_code& e ) {103 void connection::handle_write_response(const boost::system::error_code& e, std::size_t bytes_transferred) { 104 104 if (!e) { 105 cancel_timer(); 106 handler_->log_debug(__FILE__, __LINE__, _T("Wrote data: ") + strEx::itos(bytes_transferred)); 105 107 // Initiate graceful connection closure. 106 108 boost::system::error_code ignored_ec; -
include/nrpe/server/connection.hpp
r294b37b r72eea1f 35 35 36 36 virtual void start_read_request(buffer_type &buffer, int timeout) = 0; 37 virtual void continue_read_request(buffer_type &buffer) = 0; 37 38 virtual void start_write_request(const std::vector<boost::asio::const_buffer>& response) = 0; 38 39 //virtual void start_handle_handsc_request(nrpe::packet response) = 0; 39 40 40 41 void handle_read_request(const boost::system::error_code& e, std::size_t bytes_transferred); 41 void handle_write_response(const boost::system::error_code& e );42 void handle_write_response(const boost::system::error_code& e, std::size_t bytes_transferred); 42 43 virtual void handle_handshake(const boost::system::error_code& e) {} 43 44 -
include/nrpe/server/ssl_connection.cpp
re396b2f r72eea1f 50 50 ); 51 51 } 52 void ssl_connection::continue_read_request(buffer_type &buffer) { 53 socket_.async_read_some( 54 boost::asio::buffer(buffer), 55 strand_.wrap( 56 boost::bind(&connection::handle_read_request, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred) 57 ) 58 ); 59 } 52 60 53 61 void ssl_connection::start_write_request(const std::vector<boost::asio::const_buffer>& response) { 54 62 boost::asio::async_write(socket_, response, 55 63 strand_.wrap( 56 boost::bind(&connection::handle_write_response, shared_from_this(), boost::asio::placeholders::error)64 boost::bind(&connection::handle_write_response, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred) 57 65 ) 58 66 ); -
include/nrpe/server/ssl_connection.hpp
r294b37b r72eea1f 33 33 34 34 virtual void start_read_request(connection::buffer_type &buffer, int timeout); 35 void continue_read_request(buffer_type &buffer); 35 36 virtual void start_write_request(const std::vector<boost::asio::const_buffer>& response); 36 37 void handle_handshake(const boost::system::error_code& error); -
include/nrpe/server/tcp_connection.cpp
r1ecd26f r72eea1f 33 33 ); 34 34 } 35 void tcp_connection::continue_read_request(buffer_type &buffer) { 36 socket_.async_read_some( 37 boost::asio::buffer(buffer), 38 strand_.wrap( 39 boost::bind(&connection::handle_read_request, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred) 40 ) 41 ); 42 } 35 43 void tcp_connection::start_write_request(const std::vector<boost::asio::const_buffer>& response) { 36 44 boost::asio::async_write(socket_, response, 37 45 strand_.wrap( 38 boost::bind(&connection::handle_write_response, shared_from_this(),boost::asio::placeholders::error )46 boost::bind(&connection::handle_write_response, shared_from_this(),boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred) 39 47 ) 40 48 ); -
include/nrpe/server/tcp_connection.hpp
r438998b r72eea1f 29 29 30 30 virtual void start_read_request(connection::buffer_type &buffer, int timeout); 31 void continue_read_request(buffer_type &buffer); 31 32 virtual void start_write_request(const std::vector<boost::asio::const_buffer>& response); 32 33 -
include/parsers/operators.cpp
re11d494 r72eea1f 96 96 struct operator_gt : public simple_bool_binary_operator_impl { 97 97 bool eval_int(value_type type, filter_handler handler, const expression_ast &left, const expression_ast & right) const { 98 if (debug_enabled && debug_level > 10) 99 std::cout << "(op_gt) " << left.get_int(handler) << " > " << right.get_int(handler) << std::endl; 98 if (debug_enabled && debug_level > 10) { 99 long long lhs = left.get_int(handler); 100 long long rhs = right.get_int(handler); 101 std::cout << "(op_gt) " << lhs << " > " << rhs << std::endl; 102 } 100 103 return left.get_int(handler) > right.get_int(handler); 101 104 } … … 179 182 boost::wregex re(regexp); 180 183 return boost::regex_match(str, re); 184 } catch (const boost::bad_expression e) { 185 handler->error(_T("Invalid syntax in regular expression:") + regexp); 186 return false; 187 } catch (...) { 188 handler->error(_T("Invalid syntax in regular expression:") + regexp); 189 return false; 190 } 191 }; 192 }; 193 struct operator_not_regexp : public simple_bool_binary_operator_impl { 194 bool eval_int(value_type type, filter_handler handler, const expression_ast &left, const expression_ast & right) const { 195 handler->error(_T("Regular expression not supported on numbers...")); 196 return false; 197 } 198 bool eval_string(value_type type, filter_handler handler, const expression_ast &left, const expression_ast & right) const { 199 std::wstring str = left.get_string(handler); 200 std::wstring regexp = right.get_string(handler); 201 if (debug_enabled) 202 std::wcout << _T("(op_regexp) ") << str << _T(" regexp ") << regexp << std::endl; 203 try { 204 boost::wregex re(regexp); 205 return !boost::regex_match(str, re); 181 206 } catch (const boost::bad_expression e) { 182 207 handler->error(_T("Invalid syntax in regular expression:") + regexp); … … 398 423 if (op == op_regexp) 399 424 return bin_op_type(new operator_impl::operator_regexp()); 425 if (op == op_regexp) 426 return bin_op_type(new operator_impl::operator_not_regexp()); 400 427 401 428 -
include/parsers/where/expression_ast.hpp
r98113da r72eea1f 34 34 35 35 enum operators { 36 op_eq, op_le, op_lt, op_gt, op_ge, op_ne, op_in, op_nin, op_or, op_and, op_inv, op_not, op_like, op_not_like, op_binand, op_binor, op_regexp 36 op_eq, op_le, op_lt, op_gt, op_ge, op_ne, op_in, op_nin, op_or, op_and, op_inv, op_not, op_like, op_not_like, op_binand, op_binor, op_regexp, op_not_regexp 37 37 }; 38 38 -
include/parsers/where/grammar/grammar.cpp
r98113da r72eea1f 180 180 | ascii::no_case[qi::lit("regexp")] [_val = op_regexp] 181 181 | ascii::no_case[qi::lit("not like")] [_val = op_not_like] 182 | ascii::no_case[qi::lit("not regexp")] [_val = op_not_regexp] 182 183 ; 183 184 -
include/socket/socket_helpers.hpp
r96c1461 r72eea1f 172 172 } 173 173 } 174 return false; 174 175 } 175 176 … … 194 195 sock.get_io_service().reset(); 195 196 while (sock.get_io_service().run_one()) { 196 if (read_result) 197 if (read_result) { 197 198 timer.cancel(); 198 else if (timer_result) 199 return true; 200 } 201 else if (timer_result) { 199 202 rawSocket.close(); 200 } 201 202 if (*read_result) 203 return false; 204 } 205 } 206 207 if (read_result && *read_result) 203 208 throw boost::system::system_error(*read_result); 204 return true;209 return false; 205 210 } 206 211 … … 250 255 } 251 256 } 257 return false; 252 258 } 253 259 void set_result(boost::optional<boost::system::error_code>* a, boost::system::error_code ec) { … … 271 277 sock.get_io_service().reset(); 272 278 while (sock.get_io_service().run_one()) { 273 if (read_result) 279 if (read_result) { 274 280 timer.cancel(); 275 else if (timer_result) { 281 return true; 282 } else if (timer_result) { 276 283 rawSocket.close(); 277 284 return false; … … 287 294 if (*read_result) 288 295 throw boost::system::system_error(*read_result); 289 return true;296 return false; 290 297 } 291 298 } -
modules/CheckEventLog/CheckEventLog.cpp
r96c1461 r72eea1f 546 546 uniq_record.message = record.render(fargs->bShowDescriptions, fargs->syntax); 547 547 } else if (!fargs->bShowDescriptions) { 548 uniq_record.message = record. eventSource();548 uniq_record.message = record.get_source(); 549 549 } else { 550 uniq_record.message = record. eventSource();550 uniq_record.message = record.get_source(); 551 551 uniq_record.message += _T("(") + EventLogRecord::translateType(record.eventType()) + _T(", ") + 552 552 strEx::itos(record.eventID()) + _T(", ") + EventLogRecord::translateSeverity(record.severity()) + _T(")"); … … 561 561 strEx::append_list(message, record.render(fargs->bShowDescriptions, fargs->syntax)); 562 562 } else if (!fargs->bShowDescriptions) { 563 strEx::append_list(message, record. eventSource());563 strEx::append_list(message, record.get_source()); 564 564 } else { 565 strEx::append_list(message, record. eventSource());565 strEx::append_list(message, record.get_source()); 566 566 message += _T("(") + EventLogRecord::translateType(record.eventType()) + _T(", ") + 567 567 strEx::itos(record.eventID()) + _T(", ") + EventLogRecord::translateSeverity(record.severity()) + _T(")"); -
modules/CheckEventLog/eventlog_record.hpp
r96c1461 r72eea1f 3 3 #include "simple_registry.hpp" 4 4 #include <config.h> 5 #include <boost/tuple/tuple.hpp> 5 6 6 7 class EventLogRecord { … … 23 24 return pevlr_->TimeWritten; 24 25 } 25 inline std::wstring eventSource() const {26 inline std::wstring get_source() const { 26 27 return reinterpret_cast<const WCHAR*>(reinterpret_cast<const BYTE*>(pevlr_) + sizeof(EVENTLOGRECORD)); 28 } 29 inline std::wstring get_computer() const { 30 size_t len = wcslen(reinterpret_cast<const WCHAR*>(reinterpret_cast<const BYTE*>(pevlr_) + sizeof(EVENTLOGRECORD))); 31 return reinterpret_cast<const WCHAR*>(reinterpret_cast<const BYTE*>(pevlr_) + sizeof(EVENTLOGRECORD) + (len+1)*sizeof(wchar_t)); 27 32 } 28 33 inline DWORD eventID() const { … … 141 146 std::wstring get_dll() const { 142 147 try { 143 return simple_registry::registry_key::get_string(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\EventLog\\") + file_ + (std::wstring)_T("\\") + eventSource(), _T("EventMessageFile"));148 return simple_registry::registry_key::get_string(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\EventLog\\") + file_ + (std::wstring)_T("\\") + get_source(), _T("EventMessageFile")); 144 149 } catch (simple_registry::registry_exception &e) { 145 NSC_LOG_ERROR_STD(_T("Could not extract DLL for eventsource: ") + eventSource() + _T(": ") + e.what());150 NSC_LOG_ERROR_STD(_T("Could not extract DLL for eventsource: ") + get_source() + _T(": ") + e.what()); 146 151 return _T(""); 147 152 } … … 170 175 171 176 }; 177 178 boost::tuple<DWORD,std::wstring> wrapped_format(HMODULE hDLL, DWORD dwLang, DWORD id, tchar_array &buffer) const { 179 LPVOID lpMsgBuf; 180 unsigned long dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_HMODULE|FORMAT_MESSAGE_ARGUMENT_ARRAY|FORMAT_MESSAGE_IGNORE_INSERTS,hDLL, 181 id,dwLang,(LPTSTR)&lpMsgBuf,0,reinterpret_cast<va_list*>(buffer.get_buffer_unsafe())); 182 if (dwRet == 0) { 183 return boost::tuple<DWORD,std::wstring>(GetLastError(), _T("")); 184 } 185 LocalFree(lpMsgBuf); 186 dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_HMODULE|FORMAT_MESSAGE_ARGUMENT_ARRAY,hDLL, 187 id,dwLang,(LPTSTR)&lpMsgBuf,0,reinterpret_cast<va_list*>(buffer.get_buffer_unsafe())); 188 if (dwRet == 0) 189 return boost::make_tuple(GetLastError(), _T("")); 190 std::wstring msg = reinterpret_cast<wchar_t*>(lpMsgBuf); 191 LocalFree(lpMsgBuf); 192 return boost::make_tuple(0, msg); 193 } 172 194 std::wstring render_message(DWORD dwLang = 0) const { 173 195 std::vector<std::wstring> args; 174 196 const TCHAR* p = reinterpret_cast<const TCHAR*>(reinterpret_cast<const BYTE*>(pevlr_) + pevlr_->StringOffset); 175 197 176 tchar_array buffer(pevlr_->NumStrings );177 for (unsigned int i = 0;i<pevlr_->NumStrings;i++) {198 tchar_array buffer(pevlr_->NumStrings+10); 199 for (unsigned int i = 0;i<pevlr_->NumStrings;i++) { 178 200 unsigned int len = buffer.set(i, p); 179 201 p = &(p[len+1]); 202 } 203 for (unsigned int i = pevlr_->NumStrings;i<pevlr_->NumStrings+10;i++) { 204 unsigned int len = buffer.set(i, _T("")); 180 205 } 181 206 std::wstring ret; … … 190 215 continue; 191 216 } 192 LPVOID lpMsgBuf;193 217 if (dwLang == 0) 194 218 dwLang = MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT); 195 unsigned long dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_HMODULE|FORMAT_MESSAGE_ARGUMENT_ARRAY,hDLL, 196 pevlr_->EventID,dwLang,(LPTSTR)&lpMsgBuf,0,reinterpret_cast<va_list*>(buffer.get_buffer_unsafe())); 197 if (dwRet == 0) { 198 DWORD err = GetLastError(); 219 boost::tuple<DWORD,std::wstring> formated_data = wrapped_format(hDLL, dwLang, pevlr_->EventID, buffer); 220 if (formated_data.get<0>() != 0) { 199 221 FreeLibrary(hDLL); 200 if (err == 317) { 222 if (formated_data.get<0>() == 15100) { 223 // Invalid MUI file (wrong language) 201 224 msg = _T(""); 202 225 continue; 203 226 } 204 msg = _T("failed to lookup error code: ") + strEx::itos(eventID()) + _T(" from DLL: ") + (*cit) + _T("( reson: ") + strEx::itos(err) + _T(")"); 227 if (formated_data.get<0>() == 317) { 228 // Missing message 229 msg = _T(""); 230 continue; 231 } 232 msg = _T("failed to lookup error code: ") + strEx::itos(eventID()) + _T(" from DLL: ") + (*cit) + _T("( reason: ") + strEx::itos(formated_data.get<0>()) + _T(")"); 205 233 continue; 206 234 } 207 msg = reinterpret_cast<wchar_t*>(lpMsgBuf);208 LocalFree(lpMsgBuf);209 235 FreeLibrary(hDLL); 236 msg = formated_data.get<1>(); 210 237 } catch (...) { 211 238 msg = _T("Unknown exception getting message"); … … 256 283 } 257 284 258 strEx::replace(syntax, _T("%source%"), eventSource()); 285 strEx::replace(syntax, _T("%source%"), get_source()); 286 strEx::replace(syntax, _T("%computer%"), get_computer()); 259 287 strEx::replace(syntax, _T("%generated%"), strEx::format_date(get_time_generated(), date_format)); 260 288 strEx::replace(syntax, _T("%written%"), strEx::format_date(get_time_written(), date_format)); -
modules/CheckEventLog/filter.cpp
r98113da r72eea1f 52 52 (_T("message"), (type_string)) 53 53 (_T("strings"), (type_string)) 54 (_T("computer"), (type_string)) 54 55 (_T("written"), (type_date)) 55 56 (_T("generated"), (type_date)); … … 80 81 else if (key == _T("strings")) 81 82 ret = &filter_obj::get_strings; 83 else if (key == _T("computer")) 84 ret = &filter_obj::get_computer; 82 85 else 83 86 NSC_DEBUG_MSG_STD(_T("Failed to bind (string): ") + key); -
modules/CheckEventLog/filter.hpp
r98113da r72eea1f 33 33 } 34 34 std::wstring get_source() { 35 return record.eventSource(); 35 return record.get_source(); 36 } 37 std::wstring get_computer() { 38 return record.get_computer(); 36 39 } 37 40 long long get_el_type() { -
scripts/python/test_eventlog.py
r0f7b655 r72eea1f 77 77 log('%s'%self.last_message) 78 78 result.assert_equals(self.last_message, 'error Application Error: ', 'Verify that message is sent through') 79 80 (res, msg, perf) = Core.get().simple_query('CheckEventLog', ['file=Application', 'debug=true', 'warn=gt:1', 'filter=generated gt -2h', 'syntax=:%computer%:, %source%', 'descriptions']) 81 log('===>> %s <==='%msg) 82 result.add_message(self.test_create('Application Error', 1000, '0', 'error', ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']), 'Testing to create a log message') 83 79 84 return result 80 85 … … 87 92 88 93 conf.set_string('/settings/pytest_eventlog/real-time', 'enabled', 'true') 94 #conf.set_string('/settings/pytest_eventlog/real-time', 'filter', 'generated gt -2h') 89 95 conf.set_string('/settings/pytest_eventlog/real-time', 'maximum age', '5s') 90 96 conf.set_string('/settings/pytest_eventlog/real-time', 'destination', 'pytest_evlog') -
scripts/python/test_nrpe.py
r0f7b655 r72eea1f 188 188 log('Waiting for %s (%s/%s)'%(uid,alias,target)) 189 189 sleep(500) 190 if found:191 re turn result192 return None190 if not found: 191 result.add_message(False, 'Testing to recieve message using %s'%alias) 192 return result 193 193 194 194 def test_one(self, ssl=True, length=1024, state = status.UNKNOWN, tag = 'TODO'): … … 232 232 result.add(self.do_one_test(ssl=False)) 233 233 result.add(self.do_one_test(ssl=True, length=4096)) 234 result.add(self.do_one_test(ssl=True, length=65536)) 235 result.add(self.do_one_test(ssl=True, length=1048576)) 234 236 return result 235 237 -
version.hpp
r523576e r72eea1f 1 1 #ifndef VERSION_HPP 2 2 #define VERSION_HPP 3 #define PRODUCTVER 0,4,0,13 54 #define STRPRODUCTVER "0,4,0,13 5"5 #define STRPRODUCTDATE "2012-02- 19"3 #define PRODUCTVER 0,4,0,136 4 #define STRPRODUCTVER "0,4,0,136" 5 #define STRPRODUCTDATE "2012-02-20" 6 6 #endif // VERSION_HPP -
version.txt
r523576e r72eea1f 1 1 version=0.4.0 2 build=13 53 date=2012-02- 192 build=136 3 date=2012-02-20
Note: See TracChangeset
for help on using the changeset viewer.








