Changeset b24c97f in nscp
- Timestamp:
- 11/10/11 00:04:50 (19 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- d48afa1
- Parents:
- 40fca56
- Files:
-
- 7 added
- 7 edited
-
changelog (modified) (2 diffs)
-
include/client/command_line_parser.hpp (modified) (1 diff)
-
include/net/net.hpp (modified) (1 diff)
-
include/settings/settings_ini.hpp (modified) (2 diffs)
-
modules/SMTPClient/SMTPClient.cpp (modified) (7 diffs)
-
modules/SMTPClient/SMTPClient.def (modified) (1 diff)
-
modules/SMTPClient/SMTPClient.h (modified) (2 diffs)
-
modules/SyslogClient/CMakeLists.txt (added)
-
modules/SyslogClient/SyslogClient.cpp (added)
-
modules/SyslogClient/SyslogClient.def (added)
-
modules/SyslogClient/SyslogClient.h (added)
-
modules/SyslogClient/module.cmake (added)
-
modules/SyslogClient/stdafx.cpp (added)
-
modules/SyslogClient/stdafx.h (added)
Legend:
- Unmodified
- Added
- Removed
-
changelog
r40fca56 rb24c97f 7 7 8 8 2011-11-09 MickeM 9 * Added initial SyslogClient module to allow syuslog forwarding (of passive checks ish) 10 Still requires template support and configuration options (mainly PoC right now). 9 11 * Added initial SMTPClient to allow sending messages via SMTP. 10 12 Still requires template support and configuration options (mainly PoC right now). … … 1287 1289 2005-02-14 MickeM 1288 1290 * Initial SourceForge release 1289 1290 -
include/client/command_line_parser.hpp
r98113da rb24c97f 114 114 static std::list<std::string> simple_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments); 115 115 116 static std::wstring parse_command(std::wstring command, std::wstring prefix) { 117 std::wstring cmd = command; 118 if (command.length() > prefix.length()) { 119 if (command.substr(0,prefix.length()) == prefix) 120 cmd = command.substr(prefix.length()); 121 else if (command.substr(command.length()-prefix.length()) == prefix) 122 cmd = command.substr(0, command.length()-prefix.length()); 123 if (cmd[0] == L'_') 124 cmd = cmd.substr(1); 125 if (cmd[cmd.length()-1] == L'_') 126 cmd = cmd.substr(0, cmd.length()-1); 127 } 128 return cmd; 129 } 130 116 131 static int query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &msg, std::wstring &perf); 117 132 //static std::list<std::string> submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments); -
include/net/net.hpp
ra629015 rb24c97f 10 10 std::string query; 11 11 unsigned int port; 12 std::string get_port() { 13 std::stringstream ss; 14 ss << port; 15 return ss.str(); 16 } 12 17 std::string to_string() { 13 18 std::stringstream ss; -
include/settings/settings_ini.hpp
rfb7e36a rb24c97f 160 160 get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("Get sections for: ")) + path); 161 161 CSimpleIni::TNamesDepend lst; 162 std::wstring::size_type path_len = path.length(); 162 163 ini.GetAllSections(lst); 163 164 if (path.empty()) { … … 172 173 } 173 174 } else { 174 for (CSimpleIni::TNamesDepend::const_iterator cit = lst.begin(); cit != lst.end(); ++cit) {175 std::wstring mapped = (*cit).pItem;176 std::wstring::size_type mapped_len = mapped.length();177 std::wstring::size_type path_len = path.length();178 if (mapped_len > path_len+1 && mapped.substr(0,path_len) == path) {179 std::wstring::size_type pos = mapped.find(L'/', path_len+1);175 BOOST_FOREACH(const CSimpleIni::Entry e, lst) { 176 std::wstring key = e.pItem; 177 get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T(" + ")) + key); 178 if (key.length() > path_len+1 && key.substr(0,path_len) == path) { 179 get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T(" + >> ")) + key); 180 std::wstring::size_type pos = key.find(L'/', path_len+1); 180 181 if (pos == std::wstring::npos) 181 mapped = mapped.substr(path_len+1);182 key = key.substr(path_len+1); 182 183 else 183 mapped = mapped.substr(path_len+1, pos-path_len-1);184 list.push_back( mapped);184 key = key.substr(path_len+1, pos-path_len-1); 185 list.push_back(key); 185 186 } 186 187 } -
modules/SMTPClient/SMTPClient.cpp
r40fca56 rb24c97f 61 61 try { 62 62 sh::settings_registry settings(get_settings_proxy()); 63 settings.set_alias(_T(" NSCA"), alias, _T("client"));63 settings.set_alias(_T("SMTP"), alias, _T("client")); 64 64 target_path = settings.alias().get_settings_path(_T("targets")); 65 65 … … 124 124 125 125 std::wstring SMTPClient::setup(client::configuration &config, const std::wstring &command) { 126 clp_handler_impl *handler = new clp_handler_impl(this , payload_length_, time_delta_);126 clp_handler_impl *handler = new clp_handler_impl(this); 127 127 add_local_options(config.local, handler->local_data); 128 std::wstring cmd = command; 129 if (command.length() > 5 && command.substr(0,5) == _T("nsca_")) 130 cmd = command.substr(5); 131 if (command.length() > 5 && command.substr(command.length()-5) == _T("_nsca")) 132 cmd = command.substr(0, command.length()-5); 128 std::wstring cmd = client::command_line_parser::parse_command(command, _T("smtp")); 133 129 config.handler = client::configuration::handler_type(handler); 134 130 return cmd; 135 131 } 136 137 132 138 133 NSCAPI::nagiosReturn SMTPClient::handleCommand(const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &message, std::wstring &perf) { … … 159 154 NSCAPI::nagiosReturn SMTPClient::handleRAWNotification(const wchar_t* channel, std::string request, std::string &response) { 160 155 try { 161 162 156 client::configuration config; 163 157 net::wurl url; 164 158 url.protocol = _T("smtp"); 165 166 159 nscapi::target_handler::optarget target = targets.find_target(_T("default")); 167 160 if (target) { … … 183 176 } 184 177 return NSCAPI::isSuccess; 185 } catch (nsca::nsca_encrypt::encryption_exception &e) {186 NSC_LOG_ERROR_STD(_T("Failed to encrypt data: ") + str::to_wstring(e.what()));187 return NSCAPI::hasFailed;188 178 } catch (std::exception &e) { 189 179 NSC_LOG_ERROR_STD(_T("Failed to send data: ") + utf8::cvt<std::wstring>(e.what())); … … 194 184 } 195 185 } 196 NSCAPI::nagiosReturn SMTPClient::send(sender_information &data, const std::list<nsca::packet> packets) {197 try {198 // TODO Add email sending here199 return NSCAPI::isSuccess;200 } catch (nsca::nsca_encrypt::encryption_exception &e) {201 NSC_LOG_ERROR_STD(_T("Failed to encrypt data: ") + str::to_wstring(e.what()));202 return NSCAPI::hasFailed;203 } catch (std::exception &e) {204 NSC_LOG_ERROR_STD(_T("Failed to send data: ") + utf8::cvt<std::wstring>(e.what()));205 return NSCAPI::hasFailed;206 } catch (...) {207 NSC_LOG_ERROR_STD(_T("Failed to send data: UNKNOWN"));208 return NSCAPI::hasFailed;209 }210 }211 212 186 213 187 ////////////////////////////////////////////////////////////////////////// 214 188 // Parser implementations 215 189 int SMTPClient::clp_handler_impl::query(client::configuration::data_type data, std::string request, std::string &reply) { 216 NSC_LOG_ERROR_STD(_T(" NSCAdoes not support query patterns"));190 NSC_LOG_ERROR_STD(_T("SMTP does not support query patterns")); 217 191 return NSCAPI::hasFailed; 218 192 } 193 int SMTPClient::clp_handler_impl::exec(client::configuration::data_type data, std::string request, std::string &reply) { 194 NSC_LOG_ERROR_STD(_T("SMTP does not support exec patterns")); 195 return NSCAPI::hasFailed; 196 } 197 219 198 int SMTPClient::clp_handler_impl::submit(client::configuration::data_type data, ::Plugin::Common_Header* header, const std::string &request, std::string &response) { 220 199 try { … … 222 201 Plugin::SubmitRequestMessage message; 223 202 message.ParseFromString(request); 224 std::list<nsca::packet> list;225 int iii = message.payload_size();226 203 227 204 std::wstring alias, command, msg, perf; … … 248 225 } 249 226 } 250 int SMTPClient::clp_handler_impl::exec(client::configuration::data_type data, std::string request, std::string &reply) {251 NSC_LOG_ERROR_STD(_T("NSCA does not support exec patterns"));252 return NSCAPI::hasFailed;253 }254 255 256 227 257 228 NSC_WRAP_DLL(); -
modules/SMTPClient/SMTPClient.def
r40fca56 rb24c97f 1 LIBRARY NSCAAgent1 LIBRARY SMTPClient 2 2 3 3 EXPORTS -
modules/SMTPClient/SMTPClient.h
r40fca56 rb24c97f 34 34 35 35 std::string hostname_; 36 unsigned int payload_length_;37 unsigned int timeout_;38 36 std::wstring channel_; 39 int time_delta_;40 37 nscapi::target_handler targets; 41 38 std::wstring target_path; 42 39 43 44 struct sender_information {45 sender_information(nscapi::functions::destination_container &src) : timeout(10) {46 net::url u = src.get_url(25);47 host = u.host;48 port = u.port;49 //password = src.data["password"];50 //encryption = src.data["encryption"];51 }52 std::string password;53 std::string encryption;54 std::string host;55 unsigned int timeout;56 int port;57 };58 40 struct connection_data : public client::nscp_cli_data {}; 59 41 struct clp_handler_impl : public client::clp_handler { 60 42 61 43 SMTPClient *instance; 62 clp_handler_impl(SMTPClient *instance , unsigned int payload_length, int time_delta) : instance(instance) {}44 clp_handler_impl(SMTPClient *instance) : instance(instance) {} 63 45 connection_data local_data; 64 46 … … 100 82 int commandLineExec(const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result); 101 83 102 NSCAPI::nagiosReturn send(sender_information &data, const std::list<nsca::packet> packets);103 104 105 84 std::wstring setup(client::configuration &config, const std::wstring &command); 106 85 void add_local_options(boost::program_options::options_description &desc, connection_data &command_data);
Note: See TracChangeset
for help on using the changeset viewer.








