syncthing-monitor/syncthing_monitor/syncthing_rest.py

50 lines
1.6 KiB
Python
Raw Normal View History

2021-01-28 13:31:25 +00:00
import json
import requests
from retrying import retry
@retry
def get_device_id(host, gui_port, api_key):
syncthing_headers = {'X-API-Key': api_key}
response = requests.get("http://" + host + ":" + gui_port + "/rest/system/status", headers=syncthing_headers)
return json.loads(response.content)["myID"]
2021-01-29 09:59:59 +00:00
@retry
def print_debug_info(host, gui_port, api_key):
syncthing_headers = {'X-API-Key': api_key}
response = requests.get("http://" + host + ":" + gui_port + "/rest/config/devices", headers=syncthing_headers)
print("/rest/config/devices: {0}".format(response.content))
def post_devices(device_ids, host, gui_port, api_key):
syncthing_headers = {'X-API-Key': api_key}
for device_id in device_ids:
post_data = {
"deviceID": device_id,
"name": "Laptop",
"addresses": [
"dynamic",
"tcp://192.168.1.2:22000"
],
"compression": "metadata",
"certName": "",
"introducer": False,
"skipIntroductionRemovals": False,
"introducedBy": "",
"paused": False,
"allowedNetworks": [],
"autoAcceptFolders": False,
"maxSendKbps": 0,
"maxRecvKbps": 0,
"ignoredFolders": [],
"pendingFolders": [],
"maxRequestKiB": 0
}
response = requests.post("http://" + host + ":" + gui_port + "/rest/config/devices",
headers=syncthing_headers, data=json.dumps(post_data))
print("Attempt to add device {0} to syncthing: {1}".format(device_id, response.content))