Changeset 7354aa1 in nscp
- Timestamp:
- 01/09/12 22:34:25 (17 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- ba63b95
- Parents:
- a87ce04
- Files:
-
- 7 edited
-
changelog (modified) (1 diff)
-
include/client/command_line_parser.cpp (modified) (3 diffs)
-
include/client/command_line_parser.hpp (modified) (1 diff)
-
include/nscapi/functions.hpp (modified) (4 diffs)
-
modules/NSCAClient/NSCAClient.cpp (modified) (4 diffs)
-
modules/NSCAClient/NSCAClient.h (modified) (1 diff)
-
scripts/python/test_nsca.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
changelog
ra87ce04 r7354aa1 6 6 * Fix RtlStringFromGUID problem on NT4 7 7 8 2012-01-09 MickeM 9 * Fixed hostname issue in NSCAClient (hostname = auto now auto detects hostname 10 * Fixed some minor issues in NSCA and CLI api 11 * Added CLI based (exec) APIs to NSCA unit tests (now 697 test for NSCA) 8 12 9 13 2012-01-08 MickeM -
include/client/command_line_parser.cpp
ra87ce04 r7354aa1 25 25 desc.add_options() 26 26 ("command,c", po::wvalue<std::wstring>(&command_data->command), "The name of the command that the remote daemon should run") 27 ("alias,a", po::wvalue<std::wstring>(&command_data->command), "Same as command") 27 28 ("message,m", po::wvalue<std::wstring>(&command_data->message), "Message") 28 ("result,r", po:: value<unsigned int>(&command_data->result), "Result code")29 ("result,r", po::wvalue<std::wstring>(&command_data->result), "Result code either a number or OK, WARN, CRIT, UNKNOWN") 29 30 ; 30 31 } … … 52 53 } 53 54 55 int parse_result(std::wstring key) { 56 if (key == _T("UNKNOWN") || key == _T("unknown")) 57 return NSCAPI::returnUNKNOWN; 58 if (key == _T("warn") || key == _T("WARN") || key == _T("WARNING") || key == _T("warning")) 59 return NSCAPI::returnWARN; 60 if (key == _T("crit") || key == _T("CRIT") || key == _T("CRITICAL") || key == _T("critical")) 61 return NSCAPI::returnWARN; 62 if (key == _T("OK") || key == _T("ok")) 63 return NSCAPI::returnUNKNOWN; 64 try { 65 return strEx::stoi(key); 66 } catch (...) { 67 return NSCAPI::returnUNKNOWN; 68 } 69 } 54 70 55 71 int client::command_line_parser::do_execute_command_as_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result) { … … 226 242 modify_header(config, message.mutable_header(), config.data->recipient); 227 243 message.set_channel("CLI"); 228 nscapi::functions::append_simple_submit_request_payload(message.add_payload(), config.data->command, config.data->result, config.data->message);244 nscapi::functions::append_simple_submit_request_payload(message.add_payload(), config.data->command, parse_result(config.data->result), config.data->message); 229 245 230 246 return config.handler->submit(config.data, message.mutable_header(), message.SerializeAsString(), result); -
include/client/command_line_parser.hpp
ra87ce04 r7354aa1 32 32 std::wstring command_line; 33 33 std::wstring message; 34 unsigned intresult;34 std::wstring result; 35 35 std::vector<std::wstring> arguments; 36 36 -
include/nscapi/functions.hpp
ra87ce04 r7354aa1 347 347 exec_response_message.ParseFromString(data); 348 348 Plugin::QueryResponseMessage query_response_message; 349 query_response_message.mutable_header()->CopyFrom(exec_response_message );349 query_response_message.mutable_header()->CopyFrom(exec_response_message.header()); 350 350 for (int i=0;i<exec_response_message.payload_size();++i) { 351 351 Plugin::ExecuteResponseMessage::Response p = exec_response_message.payload(i); … … 358 358 submit_response_message.ParseFromString(data); 359 359 Plugin::QueryResponseMessage query_response_message; 360 query_response_message.mutable_header()->CopyFrom(submit_response_message );360 query_response_message.mutable_header()->CopyFrom(submit_response_message.header()); 361 361 for (int i=0;i<submit_response_message.payload_size();++i) { 362 362 Plugin::SubmitResponseMessage::Response p = submit_response_message.payload(i); … … 370 370 submit_response_message.ParseFromString(data); 371 371 Plugin::ExecuteResponseMessage exec_response_message; 372 exec_response_message.mutable_header()->CopyFrom(submit_response_message );372 exec_response_message.mutable_header()->CopyFrom(submit_response_message.header()); 373 373 for (int i=0;i<submit_response_message.payload_size();++i) { 374 374 Plugin::SubmitResponseMessage::Response p = submit_response_message.payload(i); … … 381 381 query_response_message.ParseFromString(data); 382 382 Plugin::ExecuteResponseMessage exec_response_message; 383 exec_response_message.mutable_header()->CopyFrom(query_response_message );383 exec_response_message.mutable_header()->CopyFrom(query_response_message.header()); 384 384 for (int i=0;i<query_response_message.payload_size();++i) { 385 385 Plugin::QueryResponseMessage::Response p = query_response_message.payload(i); -
modules/NSCAClient/NSCAClient.cpp
ra87ce04 r7354aa1 80 80 81 81 settings.alias().add_key_to_settings() 82 (_T("hostname"), sh::string_key(&hostname_ ),82 (_T("hostname"), sh::string_key(&hostname_, "auto"), 83 83 _T("HOSTNAME"), _T("The host name of this host if set to blank (default) the windows name of the computer will be used.")) 84 84 … … 122 122 123 123 get_core()->registerSubmissionListener(get_id(), channel_); 124 125 if (hostname_ == "auto") { 126 hostname_ = boost::asio::ip::host_name(); 127 128 } 124 129 125 130 if (!targets.has_target(_T("default"))) { … … 224 229 NSCAPI::nagiosReturn NSCAAgent::handleRAWCommand(const wchar_t* char_command, const std::string &request, std::string &result) { 225 230 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_query_request(char_command, request); 226 std::wstring cmd = client::command_line_parser::parse_command(data.command, _T(" syslog"));231 std::wstring cmd = client::command_line_parser::parse_command(data.command, _T("nsca")); 227 232 client::configuration config; 228 233 setup(config); … … 234 239 NSCAPI::nagiosReturn NSCAAgent::commandRAWLineExec(const wchar_t* char_command, const std::string &request, std::string &result) { 235 240 nscapi::functions::decoded_simple_command_data data = nscapi::functions::parse_simple_exec_request(char_command, request); 236 std::wstring cmd = client::command_line_parser::parse_command(char_command, _T(" syslog"));241 std::wstring cmd = client::command_line_parser::parse_command(char_command, _T("nsca")); 237 242 if (!client::command_line_parser::is_command(cmd)) 238 243 return NSCAPI::returnIgnored; -
modules/NSCAClient/NSCAClient.h
ra87ce04 r7354aa1 68 68 host = url.host; 69 69 port = url.get_port(); 70 sender_hostname = sender.get_string_data("host"); 70 sender_hostname = sender.host; 71 if (sender.has_data("host")) 72 sender_hostname = sender.get_string_data("host"); 71 73 } 72 74 unsigned int get_encryption() { -
scripts/python/test_nsca.py
ra87ce04 r7354aa1 121 121 None 122 122 123 def submit_payload(self, encryption, source, status, msg, perf): 123 def wait_and_validate(self, uuid, result, msg, perf, tag): 124 found = False 125 for i in range(0,10): 126 if self.has_response(uuid): 127 rmsg = self.get_response(uuid) 128 result.add_message(rmsg.got_response, 'Testing to recieve message using %s'%tag) 129 result.add_message(rmsg.got_simple_response, 'Testing to recieve simple message using %s'%tag) 130 #result.assert_equals(rmsg.last_source, source, 'Verify that source is sent through') 131 result.assert_equals(rmsg.command, uuid, 'Verify that command is sent through using %s'%tag) 132 result.assert_contains(rmsg.message, msg, 'Verify that message is sent through using %s'%tag) 133 result.assert_equals(rmsg.perfdata, perf, 'Verify that performance data is sent through using %s'%tag) 134 self.del_response(uuid) 135 return True 136 else: 137 log('Waiting for %s (%d/10)'%(uuid, i+1)) 138 sleep(1) 139 result.add_message(False, 'Failed to recieve message %s using %s'%(uuid, tag)) 140 return False 141 142 143 def submit_payload(self, encryption, source, status, msg, perf, tag, retry=True): 124 144 message = plugin_pb2.SubmitRequestMessage() 125 145 … … 144 164 payload.source = source 145 165 (result_code, err) = core.submit('nsca_test_outbox', message.SerializeToString()) 146 result = TestResult() 147 148 found = False 149 for i in range(0,10): 150 if self.has_response(uid): 151 rmsg = self.get_response(uid) 152 result.add_message(rmsg.got_response, 'Testing to recieve message using %s'%encryption) 153 result.add_message(rmsg.got_simple_response, 'Testing to recieve simple message using %s'%encryption) 154 result.add_message(len(err) == 0, 'Testing to send message using %s'%encryption, err) 155 #result.assert_equals(rmsg.last_source, source, 'Verify that source is sent through') 156 result.assert_equals(rmsg.command, uid, 'Verify that command is sent through') 157 result.assert_contains(rmsg.message, msg, 'Verify that message is sent through') 158 result.assert_equals(rmsg.perfdata, perf, 'Verify that performance data is sent through') 159 self.del_response(uid) 160 found = True 161 break 162 else: 163 log('Waiting for %s'%uid) 164 sleep(1) 165 if not found: 166 return None 166 167 result = TestResult() 168 result.add_message(len(err) == 0, 'Testing to send message using %s/sbp'%tag, err) 169 found = self.wait_and_validate(uid, result, msg, perf, '%s/spb'%tag) 170 if retry and not found: 171 return self.submit_payload(encryption, source, status, msg, perf, tag, False) 172 return result 173 174 def submit_via_exec(self, encryption, source, status, msg, perf, tag, retry=True): 175 uid = str(uuid.uuid4()) 176 177 args = [ 178 #'--exec', 'submit', 179 '--alias', uid, 180 '--result', '%d'%status, 181 '--message', '%s - %s'%(uid, msg), 182 '--encryption', encryption, 183 '--password', 'pwd-%s'%encryption, 184 '--host', '127.0.0.1:15667' 185 ] 186 (result_code, result_message) = core.simple_exec('any', 'nsca_submit', args) 187 result = TestResult() 188 189 result.add_message(result_code == 0, 'Testing to send message using %s/exec:1'%tag) 190 result.add_message(len(result_message) == 1, 'Testing to send message using %s/exec:2'%tag, len(result_message)) 191 result.add_message(len(result_message[0]) == 0, 'Testing to send message using %s/exec:3'%tag, result_message[0]) 192 found = self.wait_and_validate(uid, result, msg, perf, '%s/exec'%tag) 193 if retry and not found: 194 return self.submit_via_exec(encryption, source, status, msg, perf, tag, False) 167 195 return result 168 196 169 197 def test_one_crypto_full(self, encryption, state, key): 170 r1 = self.submit_payload(encryption, '%ssrc%s'%(key, key), state, '%smsg%s'%(key, key), '') 171 if r1: 172 return r1 173 result = TestResult() 174 result.add_message(True, '*FAILED* to send message with %s (retrying)'%encryption) 175 r2 = self.submit_payload(encryption, '%ssrc%s'%(key, key), state, '%smsg%s'%(key, key), '') 176 if r2: 177 result.add(r2) 178 return result 179 result.add_message(False, 'Failed to send message with uuid: %s'%encryption) 198 result = TestResult() 199 result.add(self.submit_payload(encryption, '%ssrc%s'%(key, key), state, '%smsg%s'%(key, key), '', '%s/%s'%(state, encryption))) 200 result.add(self.submit_via_exec(encryption, '%ssrc%s'%(key, key), state, '%smsg%s'%(key, key), '', '%s/%s'%(state, encryption))) 180 201 return result 181 202 … … 186 207 core.reload('test_nsca_server') 187 208 result = TestResult() 209 result.add_message(isOpen('localhost', 15667), 'Checking that port is open') 188 210 result.add(self.test_one_crypto_full(crypto, status.UNKNOWN, 'unknown')) 189 211 result.add(self.test_one_crypto_full(crypto, status.OK, 'ok')) … … 194 216 def run_test(self): 195 217 result = TestResult() 196 result.add_message(isOpen('localhost', 15667), 'Checking that port is open')197 218 # Currently broken: "xor" 198 219 cryptos = ["des", "3des", "cast128", "xtea", "blowfish", "twofish", "rc2", "aes", "serpent", "gost", "none", "3way"]
Note: See TracChangeset
for help on using the changeset viewer.








