Update the parts of the Sonar configuration that are ported. Still have to figure out some types.

This commit is contained in:
Herbert Wolverson
2024-01-27 09:46:46 -06:00
parent 9c2747de37
commit 8a812fe190
2 changed files with 27 additions and 5 deletions

View File

@@ -2,7 +2,8 @@ from pythonCheck import checkPythonVersion
checkPythonVersion()
import requests
import subprocess
from ispConfig import sonar_api_url,sonar_api_key,sonar_airmax_ap_model_ids,sonar_active_status_ids,sonar_ltu_ap_model_ids,snmp_community
from liblqos_python import sonar_api_key, sonar_api_url, snmp_community
from ispConfig import sonar_airmax_ap_model_ids,sonar_active_status_ids,sonar_ltu_ap_model_ids
all_models = sonar_airmax_ap_model_ids + sonar_ltu_ap_model_ids
from integrationCommon import NetworkGraph, NetworkNode, NodeType
from multiprocessing.pool import ThreadPool
@@ -26,7 +27,7 @@ from multiprocessing.pool import ThreadPool
def sonarRequest(query,variables={}):
r = requests.post(sonar_api_url, json={'query': query, 'variables': variables}, headers={'Authorization': 'Bearer ' + sonar_api_key}, timeout=10)
r = requests.post(sonar_api_url(), json={'query': query, 'variables': variables}, headers={'Authorization': 'Bearer ' + sonar_api_key()}, timeout=10)
r_json = r.json()
# Sonar responses look like this: {"data": {"accounts": {"entities": [{"id": '1'},{"id": 2}]}}}
@@ -247,11 +248,11 @@ def mapApCpeMacs(ap):
macs = []
macs_output = None
if ap['model'] in sonar_airmax_ap_model_ids: #Tested with Prism Gen2AC and Rocket M5.
macs_output = subprocess.run(['snmpwalk', '-Os', '-v', '1', '-c', snmp_community, ap['ip'], '.1.3.6.1.4.1.41112.1.4.7.1.1.1'], capture_output=True).stdout.decode('utf8')
macs_output = subprocess.run(['snmpwalk', '-Os', '-v', '1', '-c', snmp_community(), ap['ip'], '.1.3.6.1.4.1.41112.1.4.7.1.1.1'], capture_output=True).stdout.decode('utf8')
if ap['model'] in sonar_ltu_ap_model_ids: #Tested with LTU Rocket
macs_output = subprocess.run(['snmpwalk', '-Os', '-v', '1', '-c', snmp_community, ap['ip'], '.1.3.6.1.4.1.41112.1.10.1.4.1.11'], capture_output=True).stdout.decode('utf8')
macs_output = subprocess.run(['snmpwalk', '-Os', '-v', '1', '-c', snmp_community(), ap['ip'], '.1.3.6.1.4.1.41112.1.10.1.4.1.11'], capture_output=True).stdout.decode('utf8')
if macs_output:
name_output = subprocess.run(['snmpwalk', '-Os', '-v', '1', '-c', snmp_community, ap['ip'], '.1.3.6.1.2.1.1.5.0'], capture_output=True).stdout.decode('utf8')
name_output = subprocess.run(['snmpwalk', '-Os', '-v', '1', '-c', snmp_community(), ap['ip'], '.1.3.6.1.2.1.1.5.0'], capture_output=True).stdout.decode('utf8')
ap['name'] = name_output[name_output.find('"')+1:name_output.rfind('"')]
for mac_line in macs_output.splitlines():
mac = mac_line[mac_line.find(':')+1:]

View File

@@ -75,6 +75,9 @@ fn liblqos_python(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(powercode_api_key))?;
m.add_wrapped(wrap_pyfunction!(powercode_api_url))?;
m.add_wrapped(wrap_pyfunction!(automatic_import_sonar))?;
m.add_wrapped(wrap_pyfunction!(sonar_api_url))?;
m.add_wrapped(wrap_pyfunction!(sonar_api_key))?;
m.add_wrapped(wrap_pyfunction!(snmp_community))?;
Ok(())
}
@@ -560,4 +563,22 @@ fn powercode_api_url() -> PyResult<String> {
fn automatic_import_sonar() -> PyResult<bool> {
let config = lqos_config::load_config().unwrap();
Ok(config.sonar_integration.enable_sonar)
}
#[pyfunction]
fn sonar_api_url() -> PyResult<String> {
let config = lqos_config::load_config().unwrap();
Ok(config.sonar_integration.sonar_api_url)
}
#[pyfunction]
fn sonar_api_key() -> PyResult<String> {
let config = lqos_config::load_config().unwrap();
Ok(config.sonar_integration.sonar_api_key)
}
#[pyfunction]
fn snmp_community() -> PyResult<String> {
let config = lqos_config::load_config().unwrap();
Ok(config.sonar_integration.snmp_community)
}