I hope this helps explain what I’d like to achieve.
Keen to get some feedback etc, thanks in advance.
I’ve setup a local docker subpub+ using the starter guide and running the code below to test out some queries.
Note the following code is very rough and just for initial learning:
## Check the message VPN and Auth in the process
def check_message_vpn():
apiUrl = f"http://{primaryBroker}:8080/SEMP/v2/__private_monitor__/msgVpns/{messageVpnName}?select=state"
response = requests.get(apiUrl, auth=(apiUsername, apiPassword), verify=False)
print(response.json())
try:
response = requests.get(apiUrl, auth=(apiUsername, apiPassword), verify=False)
if response.status_code == 200:
vpn_state = response.json().get("data", {}).get("state", "unknown")
if vpn_state == "up":
print(f"Message VPN '{messageVpnName}' is up and responding correctly.")
else:
print(
f"Message VPN '{messageVpnName}' is not up. Current state: {vpn_state}"
)
elif response.status_code == 401:
print("Authentication failed. Please check your username and password.")
else:
print(
f"Failed to fetch the state of the message VPN. Status code: {response.status_code}"
)
print("Response content:", response.text)
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
## Check the queue
def check_queue_health():
apiUrl = f"http://{primaryBroker}:8080/SEMP/v2/config/msgVpns/{messageVpnName}/queues/{queueName}"
try:
response = requests.get(apiUrl, auth=(apiUsername, apiPassword), verify=False)
if response.status_code == 200:
queue_info = response.json().get("data", {})
ingress_enabled = queue_info.get("ingressEnabled", "unknown")
egress_enabled = queue_info.get("egressEnabled", "unknown")
if ingress_enabled and egress_enabled:
print(f"Queue '{queueName}' is up and processing messages.")
else:
print(
f"Queue '{queueName}' is not processing messages correctly. Ingress: {ingress_enabled}, Egress: {egress_enabled}"
)
elif response.status_code == 401:
print("Authentication failed. Please check your username and password.")
else:
print(
f"Failed to fetch the state of the queue. Status code: {response.status_code}"
)
print("Response content:", response.text)
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")