This commit is contained in:
@@ -99,7 +99,7 @@ void list_servers() {
|
||||
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());
|
||||
std::map<std::string, shared_commands::ServiceStatus> status = shared_commands::get_all_services_status(server.get_server_name(),user.user);
|
||||
|
||||
std::set<int> ports_used;
|
||||
std::string serviceticks = "";
|
||||
@@ -136,28 +136,20 @@ void show_server_details(const std::string& server_name) {
|
||||
|
||||
//---------------------
|
||||
// Check if server is reachable via SSH
|
||||
std::string ssh_address = env.get_SSH_HOST();
|
||||
std::string ssh_user = env.get_SSH_UNPRIVILEGED_USER();
|
||||
std::string ssh_port = env.get_SSH_PORT();
|
||||
if (!ssh_address.empty()) {
|
||||
info << std::endl << "Server Status:" << std::endl;
|
||||
info << std::string(40, '-') << std::endl;
|
||||
|
||||
// Try to connect to the server
|
||||
std::string cmd = "ssh -o ConnectTimeout=5 " + ssh_user + "@" + ssh_address + " -p " + ssh_port + " 'true' 2>/dev/null";
|
||||
int result = system(cmd.c_str());
|
||||
if (result == 0) {
|
||||
info << "Status: Online" << std::endl;
|
||||
|
||||
// // Get uptime if possible
|
||||
// cmd = "ssh " + ssh_address + " 'uptime' 2>/dev/null";
|
||||
// int rval = system(cmd.c_str());
|
||||
// if (rval != 0) {
|
||||
// std::cout << "Error: Failed to get uptime" << std::endl;
|
||||
// }
|
||||
} else {
|
||||
warning << "Status: Offline" << std::endl;
|
||||
}
|
||||
ASSERT(env.get_users().size() > 0, "No users found for server " + server_name);
|
||||
sSSHInfo sshinfo = env.get_SSH_INFO(env.get_users()[0].user);
|
||||
ASSERT(sshinfo.valid(), "Invalid SSH info for server " + server_name);
|
||||
|
||||
info << std::endl << "Server Status:" << std::endl;
|
||||
info << std::string(40, '-') << std::endl;
|
||||
|
||||
// Try to connect to the server
|
||||
std::string cmd = "ssh -o ConnectTimeout=5 " + sshinfo.get_user() + "@" + sshinfo.get_host() + " -p " + sshinfo.get_port() + " 'true' 2>/dev/null";
|
||||
int result = system(cmd.c_str());
|
||||
if (result == 0) {
|
||||
info << "Status: Online" << std::endl;
|
||||
} else {
|
||||
warning << "Status: Offline" << std::endl;
|
||||
}
|
||||
info << std::endl;
|
||||
|
||||
@@ -165,9 +157,21 @@ void show_server_details(const std::string& server_name) {
|
||||
{
|
||||
std::cout << std::endl;
|
||||
tableprint tp("Server Configuration: " + server_name, true);
|
||||
|
||||
tp.add_row({"Key", "Value"});
|
||||
for (const auto& [key, value] : env.get_variables()) {
|
||||
tp.add_row({key, value});
|
||||
if (key == "SSH_USERS")
|
||||
{
|
||||
int i=1;
|
||||
for (const auto& user : env.get_users())
|
||||
{
|
||||
tp.add_row({"USERS -> USER[" + std::to_string(i) + "]", user.user});
|
||||
tp.add_row({"USERS -> DIR[" + std::to_string(i) + "]", user.dir});
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
tp.add_row({key, value});
|
||||
}
|
||||
tp.print();
|
||||
}
|
||||
@@ -177,7 +181,6 @@ void show_server_details(const std::string& server_name) {
|
||||
{
|
||||
tableprint tp("Services: " + server_name, false);
|
||||
tp.add_row({"Status", "Service", "Template","Ports"});
|
||||
|
||||
|
||||
std::map<std::string, shared_commands::ServiceStatus> status = shared_commands::get_all_services_status(server_name);
|
||||
|
||||
@@ -189,8 +192,12 @@ void show_server_details(const std::string& server_name) {
|
||||
std::string ports_str = "";
|
||||
for (const auto& port : service_status.ports)
|
||||
ports_str += std::to_string(port) + " ";
|
||||
|
||||
std::string template_name = get_service_info(server_name,service_name).template_name;
|
||||
if (template_name.empty())
|
||||
template_name = "Unknown";
|
||||
|
||||
tp.add_row({healthy, service_name, get_service_info(server_name,service_name).template_name, ports_str});
|
||||
tp.add_row({healthy, service_name, template_name, ports_str});
|
||||
} // end of for (const auto& service : services)
|
||||
tp.print();
|
||||
} // end of list services
|
||||
|
Reference in New Issue
Block a user