mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Finish porting the Sonar integration over
This commit is contained in:
@@ -2,9 +2,10 @@ from pythonCheck import checkPythonVersion
|
||||
checkPythonVersion()
|
||||
import requests
|
||||
import subprocess
|
||||
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 liblqos_python import sonar_api_key, sonar_api_url, snmp_community, sonar_airmax_ap_model_ids, \
|
||||
sonar_ltu_ap_model_ids, sonar_active_status_ids
|
||||
#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
|
||||
|
||||
@@ -37,7 +38,7 @@ def sonarRequest(query,variables={}):
|
||||
return sonar_list
|
||||
|
||||
def getActiveStatuses():
|
||||
if not sonar_active_status_ids:
|
||||
if not sonar_active_status_ids():
|
||||
query = """query getActiveStatuses {
|
||||
account_statuses (activates_account: true) {
|
||||
entities {
|
||||
@@ -53,7 +54,7 @@ def getActiveStatuses():
|
||||
status_ids.append(status['id'])
|
||||
return status_ids
|
||||
else:
|
||||
return sonar_active_status_ids
|
||||
return sonar_active_status_ids()
|
||||
|
||||
# Sometimes the IP will be under the field data for an item and sometimes it will be assigned to the inventory item itself.
|
||||
def findIPs(inventory_item):
|
||||
@@ -185,7 +186,7 @@ def getAccounts(sonar_active_status_ids):
|
||||
}"""
|
||||
|
||||
active_status_ids = []
|
||||
for status_id in sonar_active_status_ids:
|
||||
for status_id in sonar_active_status_ids():
|
||||
active_status_ids.append({
|
||||
"attribute": "account_status_id",
|
||||
"operator": "EQ",
|
||||
@@ -247,9 +248,9 @@ def getAccounts(sonar_active_status_ids):
|
||||
def mapApCpeMacs(ap):
|
||||
macs = []
|
||||
macs_output = None
|
||||
if ap['model'] in sonar_airmax_ap_model_ids: #Tested with Prism Gen2AC and Rocket M5.
|
||||
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')
|
||||
if ap['model'] in sonar_ltu_ap_model_ids: #Tested with LTU Rocket
|
||||
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')
|
||||
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')
|
||||
|
||||
@@ -100,8 +100,9 @@ pub struct PythonMigration {
|
||||
pub sonar_api_url: String,
|
||||
pub sonar_api_key: String,
|
||||
pub snmp_community: String,
|
||||
// TODO: It isn't clear what types `sonar_api_key,sonar_airmax_ap_model_ids,sonar_active_status_ids,sonar_ltu_ap_model_ids`
|
||||
// are supposed to be.
|
||||
pub sonar_airmax_ap_model_ids: Vec<String>,
|
||||
pub sonar_ltu_ap_model_ids: Vec<String>,
|
||||
pub sonar_active_status_ids: Vec<String>,
|
||||
|
||||
// TODO: httpRestIntegrationConfig
|
||||
}
|
||||
@@ -177,6 +178,9 @@ impl PythonMigration {
|
||||
cfg.sonar_api_key = from_python(&py, "sonar_api_key").unwrap_or("".to_string());
|
||||
cfg.sonar_api_url = from_python(&py, "sonar_api_url").unwrap_or("".to_string());
|
||||
cfg.snmp_community = from_python(&py, "snmp_community").unwrap_or("public".to_string());
|
||||
cfg.sonar_active_status_ids = from_python(&py, "sonar_active_status_ids").unwrap_or(vec![]);
|
||||
cfg.sonar_airmax_ap_model_ids = from_python(&py, "sonar_airmax_ap_model_ids").unwrap_or(vec![]);
|
||||
cfg.sonar_ltu_ap_model_ids = from_python(&py, "sonar_ltu_ap_model_ids").unwrap_or(vec![]);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -90,3 +90,6 @@ enable_sonar = false
|
||||
sonar_api_key = ""
|
||||
sonar_api_url = ""
|
||||
snmp_community = "public"
|
||||
airmax_model_ids = [ "" ]
|
||||
ltu_model_ids = [ "" ]
|
||||
active_status_ids = [ "" ]
|
||||
|
||||
@@ -6,8 +6,9 @@ pub struct SonarIntegration {
|
||||
pub sonar_api_url: String,
|
||||
pub sonar_api_key: String,
|
||||
pub snmp_community: String,
|
||||
// TODO: It isn't clear what types `sonar_api_key,sonar_airmax_ap_model_ids,sonar_active_status_ids,sonar_ltu_ap_model_ids`
|
||||
// are supposed to be.
|
||||
pub airmax_model_ids: Vec<String>,
|
||||
pub ltu_model_ids: Vec<String>,
|
||||
pub active_status_ids: Vec<String>,
|
||||
}
|
||||
|
||||
impl Default for SonarIntegration {
|
||||
@@ -17,6 +18,9 @@ impl Default for SonarIntegration {
|
||||
sonar_api_url: "".to_string(),
|
||||
sonar_api_key: "".to_string(),
|
||||
snmp_community: "public".to_string(),
|
||||
airmax_model_ids: vec![],
|
||||
ltu_model_ids: vec![],
|
||||
active_status_ids: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,9 @@ fn liblqos_python(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
m.add_wrapped(wrap_pyfunction!(sonar_api_url))?;
|
||||
m.add_wrapped(wrap_pyfunction!(sonar_api_key))?;
|
||||
m.add_wrapped(wrap_pyfunction!(snmp_community))?;
|
||||
m.add_wrapped(wrap_pyfunction!(sonar_airmax_ap_model_ids))?;
|
||||
m.add_wrapped(wrap_pyfunction!(sonar_ltu_ap_model_ids))?;
|
||||
m.add_wrapped(wrap_pyfunction!(sonar_active_status_ids))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -582,3 +585,21 @@ fn snmp_community() -> PyResult<String> {
|
||||
let config = lqos_config::load_config().unwrap();
|
||||
Ok(config.sonar_integration.snmp_community)
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn sonar_airmax_ap_model_ids() -> PyResult<Vec<String>> {
|
||||
let config = lqos_config::load_config().unwrap();
|
||||
Ok(config.sonar_integration.airmax_model_ids)
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn sonar_ltu_ap_model_ids() -> PyResult<Vec<String>> {
|
||||
let config = lqos_config::load_config().unwrap();
|
||||
Ok(config.sonar_integration.ltu_model_ids)
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn sonar_active_status_ids() -> PyResult<Vec<String>> {
|
||||
let config = lqos_config::load_config().unwrap();
|
||||
Ok(config.sonar_integration.active_status_ids)
|
||||
}
|
||||
Reference in New Issue
Block a user