check agent on ds list
Some checks failed
Build-Test-Publish / build (linux/amd64) (push) Successful in 34s
Build-Test-Publish / build (linux/arm64) (push) Has been cancelled

This commit is contained in:
j
2026-01-02 22:36:02 +13:00
parent ae5a6fabe9
commit 226707539b
3 changed files with 30 additions and 17 deletions

View File

@@ -154,20 +154,30 @@ namespace dropshell
// get_all_services_status : SHARED COMMAND
// Uses all_status.sh on the remote server to get status for all services in one SSH call
// ------------------------------------------------------------------------------------------------
std::map<std::string, ServiceStatus> get_all_services_status(const ServerConfig & server_env)
std::map<std::string, ServiceStatus> get_all_services_status(const ServerConfig & server_env, bool* agent_match)
{
std::map<std::string, ServiceStatus> status;
bool all_match = true;
bool any_checked = false;
for (const auto& user : server_env.get_users()) {
status.merge(get_all_services_status(server_env, user.user));
bool user_match = false;
status.merge(get_all_services_status(server_env, user.user, &user_match));
if (!user_match) all_match = false;
any_checked = true;
}
// Only report match if we actually checked something and all matched
if (agent_match) *agent_match = (any_checked && all_match);
return status;
}
std::map<std::string, ServiceStatus> get_all_services_status(const ServerConfig & server_env, std::string user)
std::map<std::string, ServiceStatus> get_all_services_status(const ServerConfig & server_env, std::string user, bool* agent_match)
{
std::map<std::string, ServiceStatus> status;
std::string server_name = server_env.get_server_name();
// Default to false (mismatch/unknown) - only set to true if we get explicit confirmation
if (agent_match) *agent_match = false;
// Run all_status.sh on the remote server to get all service statuses in one call
std::string agent_path = remotepath(server_name, user).agent();
std::string script_path = agent_path + "/all_status.sh";
@@ -192,16 +202,12 @@ namespace dropshell
try {
nlohmann::json json_response = nlohmann::json::parse(output);
// Check agent hash match
// Check agent hash match - if field is missing, agent is too old (mismatch)
if (json_response.contains("agent_match") && json_response["agent_match"].is_boolean()) {
if (!json_response["agent_match"].get<bool>()) {
std::string remote_hash = json_response.contains("agent_hash") ?
json_response["agent_hash"].get<std::string>() : "unknown";
warning << "Agent mismatch on " << server_name << " (remote: " << remote_hash.substr(0, 8)
<< "..., expected: " << expected_hash.substr(0, 8) << "...)" << std::endl;
warning << "Run 'ds install " << server_name << "' to update the agent" << std::endl;
}
bool match = json_response["agent_match"].get<bool>();
if (agent_match) *agent_match = match;
}
// If agent_match field is missing, leave as false (old agent = needs update)
if (!json_response.contains("services") || !json_response["services"].is_array()) {
debug << "Invalid JSON response from all_status.sh" << std::endl;