This commit is contained in:
@@ -83,44 +83,61 @@ void list_servers() {
|
||||
tableprint tp("All DropShell Servers");
|
||||
tp.add_row({"Name", "Address", "User", "Health", "Ports"});
|
||||
|
||||
info << "Checking "<<servers.size() << " servers: " << std::flush;
|
||||
|
||||
typedef std::map<std::string, shared_commands::ServiceStatus> tServiceStatusMap;
|
||||
std::vector<tServiceStatusMap> service_status_maps;
|
||||
|
||||
typedef struct {dropshell::ServerConfig server; dropshell::UserConfig user;} server_user_pair;
|
||||
std::vector<server_user_pair> server_user_pairs;
|
||||
for (const auto& server : servers)
|
||||
for (const auto& user : server.get_users())
|
||||
server_user_pairs.push_back({server, user});
|
||||
|
||||
// mutex for the tableprint
|
||||
std::mutex tp_mutex;
|
||||
|
||||
info << "Checking "<<server_user_pairs.size() << " agents: " << std::flush;
|
||||
int checked = 0;
|
||||
|
||||
transwarp::parallel exec{servers.size()};
|
||||
auto task = transwarp::for_each(exec, servers.begin(), servers.end(), [&](const server_config& server) {
|
||||
|
||||
server_config server_env(server.get_server_name());
|
||||
transwarp::parallel exec{server_user_pairs.size()};
|
||||
auto task = transwarp::for_each(exec, server_user_pairs.begin(), server_user_pairs.end(), [&](const server_user_pair& sup) {
|
||||
|
||||
ServerConfig server_env(sup.server.get_server_name());
|
||||
if (!server_env.is_valid())
|
||||
{
|
||||
error << "Invalid server environment for " << server.get_server_name() << std::endl;
|
||||
error << "Invalid server environment for " << sup.server.get_server_name() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
int first=true;
|
||||
for (const auto &user : server_env.get_users())
|
||||
{
|
||||
std::map<std::string, shared_commands::ServiceStatus> status = shared_commands::get_all_services_status(server.get_server_name(),user.user);
|
||||
std::string serviceticks = "";
|
||||
std::string ports_used_str = "";
|
||||
std::set<int> ports_used;
|
||||
|
||||
std::set<int> ports_used;
|
||||
std::string serviceticks = "";
|
||||
for (const auto& [service_name, service_status] : status) {
|
||||
ports_used.insert(service_status.ports.begin(), service_status.ports.end());
|
||||
serviceticks += shared_commands::HealthStatus2String(service_status.health) + " ";
|
||||
}
|
||||
std::string ports_used_str = "";
|
||||
for (const auto& port : ports_used)
|
||||
ports_used_str += std::to_string(port) + " ";
|
||||
std::map<std::string, shared_commands::ServiceStatus> status = shared_commands::get_all_services_status(sup.server.get_server_name(),sup.user.user);
|
||||
|
||||
tp.add_row({(first ? server.get_server_name() : ""), (first ? server.get_SSH_HOST() : ""), user.user, serviceticks, ports_used_str});
|
||||
first = false;
|
||||
}
|
||||
for (const auto& [service_name, service_status] : status) {
|
||||
ports_used.insert(service_status.ports.begin(), service_status.ports.end());
|
||||
serviceticks += shared_commands::HealthStatus2String(service_status.health) + " ";
|
||||
}
|
||||
|
||||
++checked;
|
||||
// print out a tick character for each server checked.
|
||||
info << checked << " ✓ " << std::flush;
|
||||
for (const auto& port : ports_used)
|
||||
ports_used_str += std::to_string(port) + " ";
|
||||
// critical section
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(tp_mutex);
|
||||
tp.add_row({sup.server.get_server_name(), sup.server.get_SSH_HOST(), sup.user.user, serviceticks, ports_used_str});
|
||||
|
||||
++checked;
|
||||
// print out a tick character for each server checked.
|
||||
info << checked << " ✓ " << std::flush;
|
||||
}
|
||||
});
|
||||
task->wait();
|
||||
info << std::endl << std::endl;
|
||||
|
||||
tp.sort({0,2});
|
||||
|
||||
tp.print();
|
||||
}
|
||||
|
||||
@@ -128,7 +145,7 @@ void list_servers() {
|
||||
|
||||
|
||||
void show_server_details(const std::string& server_name) {
|
||||
server_config env(server_name);
|
||||
ServerConfig env(server_name);
|
||||
if (!env.is_valid()) {
|
||||
error << "Error: Invalid server environment file: " << server_name << std::endl;
|
||||
return;
|
||||
|
Reference in New Issue
Block a user