multiple evolutions

This commit is contained in:
Quentin WEPHRE
2025-12-04 08:11:00 +01:00
parent e9715dc239
commit abd00f9e04
9 changed files with 403 additions and 264 deletions

View File

@@ -175,6 +175,14 @@ def find_config_value(config_content, option):
# If the loop finishes without finding the option, return None
return None
def cloud_configuration_csv(result):
lightTelemetry = find_config_value(result, "light-telemetry")
telemetryOn = find_config_value(result, "telemetry-on")
compressionEnabled = find_config_value(result, "compression-enabled")
remoteUpdateOn = find_config_value(result, "remote-update-on")
connectionString = find_config_value(result, "connection-string")
return f"{lightTelemetry};{telemetryOn};{compressionEnabled};{remoteUpdateOn};{connectionString};"
def cloud_configuration_check(hostname, result, iot_hub, proxy_host, proxy_port):
print(f"\tLight telemetry:", end=" ", flush=True)
status = find_config_value(result, "light-telemetry")
@@ -185,7 +193,7 @@ def cloud_configuration_check(hostname, result, iot_hub, proxy_host, proxy_port)
print(f"\tTelemetry:", end=" ", flush=True)
status = find_config_value(result, "telemetry-on")
if status == "true":
if status == "False":
print(f"", end="\n", flush=True)
else:
print(f"")
@@ -437,12 +445,55 @@ def write_remote_config_base64_sudo(c, remote_path, content, sudo_pass, user_own
# Re-raise the exception for the main loop.
raise
def check_for_specific_curl_error(c):
def execute_command(c, command):
"""Executes a simple command on the remote device."""
try:
result = c.run(command, hide=True)
return result.stdout
except Exception as e:
raise
"""
Checks for the specific cURL exit code 35.
Args:
c: The connection object.
Returns:
True if the expected error is caught, False otherwise.
"""
try:
# We call execute_command, but expect it to fail and raise an exception
result = execute_command(c, "curl -m 15 -x https://10.81.35.126:8080 https://iot-ingest-ess-prod.azure-devices.net")
# If the command somehow succeeds, the expected error did not occur.
print(f"Success (unexpected): {result.strip()}", end="\n", flush=True)
return False
except Exception as e:
# The command failed as expected. Now, check if it's the RIGHT failure.
error_message = str(e)
# Check for the unique identifiers of your expected error.
is_exit_code_35 = "Exit code: 35" in error_message
is_ssl_version_error = "wrong version number" in error_message
if is_exit_code_35 and is_ssl_version_error:
# This is the exact error you were expecting.
# print("Caught expected cURL error (Exit code 35, SSL wrong version number).")
return True
else:
# This is a different, unexpected error.
print(f"\n[cURL] An unexpected exception occurred: {e}")
return False
def main():
"""Main function to parse arguments and orchestrate tasks."""
ip_address_prefix = "10.81.56." # DK2 subnet
ip_address_range = list(range(129, 145)) # From 129 to 144 (16 CUBEs)
# ip_address_range.append(72) # Add 85 after 74.
ip_address_prefix = "10.84.165." # DK2 subnet
ip_address_range = list(range(131, 188)) # From 129 to 144 (16 CUBEs)
# ip_address_range.append(85) # Add 85 after 74.
hosts = [f"{ip_address_prefix}{suffix}" for suffix in ip_address_range]
ssh_port = 11022
@@ -459,34 +510,47 @@ def main():
for host in hosts:
print(f"{host}", end=" - ", flush=True)
#print(f"{host}", end=" - ", flush=True)
hostname = ""
result = ""
try:
activate_ssh(host)
activate_ssh(host, True)
except Exception as e:
print(f"Exception: {e}")
continue
with Connection(host=host, user=ssh_user, port=ssh_port, connect_timeout=60, connect_kwargs=connect_args) as c:
# try:
# print(f"Hostname:", end=" ", flush=True)
# result = execute_command(c, "hostname")
# print(f"{result.strip()}", end="\n", flush=True)
# hostname = str.lower(result)
# except Exception as e:
# print(f"[Hostname] Exception: {e}")
# continue
# print(f"cURL:", end=" ", flush=True)
# result = check_for_specific_curl_error(c)
# if result:
# print(f"✅", end="\n", flush=True)
# else:
# print(f"❌", end="\n", flush=True)
try:
print(f"Hostname:", end=" ", flush=True)
result = execute_command(c, "hostname")
print(f"{result.strip()}", end="\n", flush=True)
print(f"{host};{result.strip()}", end=";", flush=True)
hostname = str.lower(result)
except Exception as e:
print(f"[Hostname] Exception: {e}")
print(f"{host};ERROR")
continue
try:
print(f"cURL:", end=" ", flush=True)
result = execute_command(c, "curl -m 15 -x https://10.81.35.126:8080 https://iot-ingest-ess-prod.azure-devices.net")
print(f"{result.strip()}", end="\n", flush=True)
result = read_remote_config_sudo(c, "/etc/cube/config-azure.properties", ssh_password)
print(cloud_configuration_csv(result))
except Exception as e:
print(f"[cURL] Exception: {e}")
continue
# try:
@@ -508,6 +572,35 @@ def main():
# continue
# cloud_configuration_check(hostname, result, "iot-ingest-ess-prod.azure-devices.net", "10.81.35.126", "8080")
# result_telemetry_off = set_config_field(result, "telemetry-on", False)
# result = result_telemetry_off
# cloud_configuration_check(hostname, result, "iot-ingest-ess-prod.azure-devices.net", "10.81.35.126", "8080")
# try:
# write_remote_config_sudo(c, "/etc/cube/config-azure.properties", result, ssh_password, "cube", "root", "644")
# print(f"✅", end="\n", flush=True)
# except Exception as e:
# print(f"❌", end="\n", flush=True)
# print(f"[Proxy configuration] Exception: {e}")
# continue
# print(f"Checking Cloud configuration:", end=" ", flush=True)
# try:
# result = read_remote_config_sudo(c, "/etc/cube/config-azure.properties", ssh_password)
# print(f"✅", end="\n", flush=True)
# except Exception as e:
# print(f"❌", end="\n", flush=True)
# print(f"[Proxy verification] Exception: {e}")
# continue
# try:
# print(f"Restarting cube-web-cloudagent: ", end=" ", flush=True)
# execute_sudo_command(c, "systemctl restart cube-web-cloudagent", ssh_password)
# print(f"✅", end="\n", flush=True)
# except Exception as e:
# print(f"❌", end="\n", flush=True)
# print(f"[Restarting cube-web-cloudagent] Exception: {e}")
# continue
# print(f"Setting proxy configuration:", end="\n", flush=True)
# result_proxy_host = set_config_field(result, "proxy-host", "10.81.35.126", True)