diff --git a/src/service/core/smithproxy_objapi.cpp b/src/service/core/smithproxy_objapi.cpp index 9fab157..0c07a00 100644 --- a/src/service/core/smithproxy_objapi.cpp +++ b/src/service/core/smithproxy_objapi.cpp @@ -55,12 +55,26 @@ nlohmann::json ObjAPI::proxy_session_connid_list() { json ret; for_each_proxy([&ret](MitmProxy const* px){ - if(px) ret.push_back(px->to_connection_ID()); + if(px and px->first_left() and px->first_right()) ret.push_back(px->to_connection_ID()); }); return ret; } +nlohmann::json ObjAPI::proxy_session_connid_list_plus() { + + using nlohmann::json; + json ret; + + for_each_proxy([&ret](MitmProxy const* px){ + if(px and px->first_left() and px->first_right()) + ret.push_back(string_format("%s=%s", px->to_connection_ID().c_str(), px->to_connection_label().c_str())); + }); + + return ret; +} + + nlohmann::json ObjAPI::proxy_session_list_json(uint64_t oid, bool active_only, bool tls_info, bool verbose) { using nlohmann::json; auto const& instance = SmithProxy::instance(); diff --git a/src/service/core/smithproxy_objapi.hpp b/src/service/core/smithproxy_objapi.hpp index 139726c..b53848f 100644 --- a/src/service/core/smithproxy_objapi.hpp +++ b/src/service/core/smithproxy_objapi.hpp @@ -9,6 +9,7 @@ struct ObjAPI { std::string instance_OID(); nlohmann::json proxy_session_connid_list(); + nlohmann::json proxy_session_connid_list_plus(); // list, but append also session label nlohmann::json proxy_session_list_json(uint64_t oid, bool active_only, bool tls_info, bool verbose); }; diff --git a/src/service/http/webhooks.cpp b/src/service/http/webhooks.cpp index bf39cb5..92a4a82 100644 --- a/src/service/http/webhooks.cpp +++ b/src/service/http/webhooks.cpp @@ -36,12 +36,31 @@ namespace sx::http::webhooks { }; sx::http::AsyncRequest::emit( to_string(ping), - [](auto reply){ + [](auto ){ // we don't need any response }); } } + void ping_plus() { + if(enabled) { + nlohmann::json const ping = { + { "action", "ping" }, + {"source", get_hostid() }, + {"type", "proxy"}, + {"instance", SmithProxy::instance().API.instance_OID() }, + {"proxies", SmithProxy::instance().API.proxy_session_connid_list() }, + {"proxies-plus", SmithProxy::instance().API.proxy_session_connid_list_plus() } + }; + sx::http::AsyncRequest::emit( + to_string(ping), + [](auto ){ + // we don't need any response + }); + } + } + + void neighbor_new(std::string const& address_str) { if(enabled) { nlohmann::json const nbr_update = { @@ -68,10 +87,14 @@ namespace sx::http::webhooks { {"type", "proxy"}}; msg.push_back({"details", details}); + sx::http::AsyncRequest::emit( to_string(msg), - [](auto reply) { - // we don't need response + [](sx::http::expected_reply repl) { + // if not OK but ACCEPTED, they don't have enough of information - send it + if(repl.has_value() and repl.value().first == 202) { + ping_plus(); + } }); } }