Update the Spylnx integration to use the new config format.

This commit is contained in:
Herbert Wolverson
2023-12-14 10:14:06 -06:00
parent 2e9f96552f
commit ba61f30fa4
2 changed files with 26 additions and 4 deletions

View File

@@ -2,23 +2,24 @@ from pythonCheck import checkPythonVersion
checkPythonVersion()
import requests
import warnings
from ispConfig import excludeSites, findIPv6usingMikrotik, bandwidthOverheadFactor, exceptionCPEs, splynx_api_key, splynx_api_secret, splynx_api_url
from liblqos_python import exclude_sites, find_ipv6_using_mikrotik, bandwidth_overhead_factor, splynx_api_key, \
splynx_api_secret, splynx_api_url
from integrationCommon import isIpv4Permitted
import base64
from requests.auth import HTTPBasicAuth
if findIPv6usingMikrotik == True:
if find_ipv6_using_mikrotik() == True:
from mikrotikFindIPv6 import pullMikrotikIPv6
from integrationCommon import NetworkGraph, NetworkNode, NodeType
def buildHeaders():
credentials = splynx_api_key + ':' + splynx_api_secret
credentials = splynx_api_key() + ':' + splynx_api_secret()
credentials = base64.b64encode(credentials.encode()).decode()
return {'Authorization' : "Basic %s" % credentials}
def spylnxRequest(target, headers):
# Sends a REST GET request to Spylnx and returns the
# result in JSON
url = splynx_api_url + "/api/2.0/" + target
url = splynx_api_url() + "/api/2.0/" + target
r = requests.get(url, headers=headers, timeout=10)
return r.json()

View File

@@ -65,6 +65,9 @@ fn liblqos_python(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(use_ptmp_as_parent))?;
m.add_wrapped(wrap_pyfunction!(uisp_base_url))?;
m.add_wrapped(wrap_pyfunction!(uisp_auth_token))?;
m.add_wrapped(wrap_pyfunction!(splynx_api_key))?;
m.add_wrapped(wrap_pyfunction!(splynx_api_secret))?;
m.add_wrapped(wrap_pyfunction!(splynx_api_url))?;
Ok(())
}
@@ -490,4 +493,22 @@ fn uisp_base_url() -> PyResult<String> {
fn uisp_auth_token() -> PyResult<String> {
let config = lqos_config::load_config().unwrap();
Ok(config.uisp_integration.token)
}
#[pyfunction]
fn splynx_api_key() -> PyResult<String> {
let config = lqos_config::load_config().unwrap();
Ok(config.spylnx_integration.api_key)
}
#[pyfunction]
fn splynx_api_secret() -> PyResult<String> {
let config = lqos_config::load_config().unwrap();
Ok(config.spylnx_integration.api_secret)
}
#[pyfunction]
fn splynx_api_url() -> PyResult<String> {
let config = lqos_config::load_config().unwrap();
Ok(config.spylnx_integration.url)
}