MCPcopy Create free account
hub / github.com/Icinga/icinga2 / Connect

Function Connect

plugins/check_nscp_api.cpp:178–211  ·  view source on GitHub ↗

* Connects to host:port and performs a TLS shandshake * * @param host To connect to. * @param port To connect to. * * @returns AsioTlsStream pointer for future HTTP connections. */

Source from the content-addressed store, hash-verified

176 * @returns AsioTlsStream pointer for future HTTP connections.
177 */
178static Shared<AsioTlsStream>::Ptr Connect(const String& host, const String& port)
179{
180 Shared<boost::asio::ssl::context>::Ptr sslContext;
181
182 try {
183 sslContext = MakeAsioSslContext(Empty, Empty, Empty); //TODO: Add support for cert, key, ca parameters
184 } catch(const std::exception& ex) {
185 Log(LogCritical, "DebugConsole")
186 << "Cannot make SSL context: " << ex.what();
187 throw;
188 }
189
190 Shared<AsioTlsStream>::Ptr stream = Shared<AsioTlsStream>::Make(IoEngine::Get().GetIoContext(), *sslContext, host);
191
192 try {
193 icinga::Connect(stream->lowest_layer(), host, port);
194 } catch (const std::exception& ex) {
195 Log(LogWarning, "DebugConsole")
196 << "Cannot connect to REST API on host '" << host << "' port '" << port << "': " << ex.what();
197 throw;
198 }
199
200 auto& tlsStream (stream->next_layer());
201
202 try {
203 tlsStream.handshake(tlsStream.client);
204 } catch (const std::exception& ex) {
205 Log(LogWarning, "DebugConsole")
206 << "TLS handshake with host '" << host << "' failed: " << ex.what();
207 throw;
208 }
209
210 return stream;
211}
212
213static const char l_ReasonToInject[2] = {' ', 'X'};
214

Callers 1

FetchDataFunction · 0.70

Calls 4

MakeAsioSslContextFunction · 0.85
LogClass · 0.85
handshakeMethod · 0.80
whatMethod · 0.45

Tested by

no test coverage detected