hi everyone i’m trying to get informations about connection speed and see it in a graphs.
i’m using a python code with nagios plugin but in my service i dont have any metrics so i cant build graphs, i’m also trying to use my python code on each devices but when i use the $HOSTADDRESS$ i have an error, even with nagios documentation it’s really hard to see how to solve my problem.
any idea?
It’s really hard to solve your problem without you showing any code or any hits how you run your code.
Yeah sorry,
i’m using this code, i can get connection speed informations and a graphs of it, i just need to have an automatic ip address with the macro :
import requests
import time
login_url = "http://10.204.103.2/api/login"
start_speedtest_url = "http://10.204.103.2/api/speedtest/actions/start"
speedtest_url = "http://10.204.103.2/api/speedtest/status"
headers = {
"Content-Type": "application/json"
}
data = {
"username": "admin",
"password": "g€@$q87_ygqz"
}
response = requests.post(login_url, headers=headers, json=data)
if response.status_code == 200:
response_json = response.json()
data = response_json['data']
token = data.get('token')
if token:
headers_with_token = {
"Content-Type": "application/json",
"Authorization": f"Bearer {token}"
}
### ================================================== Start Speedtest ================================================== ###
start_response = requests.post(start_speedtest_url, headers=headers_with_token)
if start_response.status_code == 200:
start_response_json = start_response.json()
if start_response_json.get('success'):
time.sleep(10)
### ================================================== Speedtest Data =================================================== ###
speedtest_response = requests.get(speedtest_url, headers=headers_with_token)
if speedtest_response.status_code == 200:
speedtest_response_json = speedtest_response.json()
if speedtest_response_json.get('success'):
speed_data = speedtest_response_json.get('data', {})
state = speed_data.get('state')
if state != "NOT_RUNNING":
avg_upload_speed_str = speed_data.get('avgUploadSpeed')
avg_download_speed_str = speed_data.get('avgDownloadSpeed')
if avg_download_speed_str is not None and avg_upload_speed_str is not None:
try:
avg_upload_speed = int(avg_upload_speed_str)
avg_download_speed = int(avg_download_speed_str)
print(f'| Average Download Speed={avg_download_speed};;;;')
except ValueError:
print("Failed to convert speeds to integers. Please check the response format.")
print("avg_upload_speed:", avg_upload_speed_str)
print("avg_download_speed:", avg_download_speed_str)
else:
print("Failed to fetch speeds: 'avgUploadSpeed' or 'avgDownloadSpeed' not found.")
print("Complete Response JSON:", speedtest_response_json)
else:
print("Speed test is not running. State:", state)
print("Complete Response JSON:", speedtest_response_json)
else:
print("Failed to fetch status: ", speedtest_response_json.get('errors', 'Unknown error'))
else:
print("Failed to fetch device status. Status Code:", speedtest_response.status_code)
print("Response JSON:", speedtest_response.json())
else:
print("Failed to start speedtest: ", start_response_json.get('errors', 'Unknown error'))
else:
print("Failed to login. Status Code:", response.status_code)
print("Response JSON:", response.json())
and i use it to execute my code :
@thl-cmk postet two examples of active checks in another post today, they also contain perfdata, you can take these as an example of how to output the data in the correct format.
Hello,
I already suceed to get the perfdata in the correct format, but i cant apply it on every devices because the ip is written directly in the code it’s not a varible who change for every devices who start the script.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.
