mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Powercode
This commit is contained in:
parent
d9f16f2da6
commit
bf61e603f0
127
src/integrationPowercode.py
Normal file
127
src/integrationPowercode.py
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
from pythonCheck import checkPythonVersion
|
||||||
|
checkPythonVersion()
|
||||||
|
import requests
|
||||||
|
import warnings
|
||||||
|
from ispConfig import excludeSites, findIPv6usingMikrotik, bandwidthOverheadFactor, exceptionCPEs, powercode_api_key, powercode_api_url
|
||||||
|
from integrationCommon import isIpv4Permitted
|
||||||
|
import base64
|
||||||
|
from requests.auth import HTTPBasicAuth
|
||||||
|
if findIPv6usingMikrotik == True:
|
||||||
|
from mikrotikFindIPv6 import pullMikrotikIPv6
|
||||||
|
from integrationCommon import NetworkGraph, NetworkNode, NodeType
|
||||||
|
from urllib3.exceptions import InsecureRequestWarning
|
||||||
|
|
||||||
|
def getCustomerInfo():
|
||||||
|
headers= {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||||
|
url = powercode_api_url + ":444/api/preseem/index.php"
|
||||||
|
data = {}
|
||||||
|
data['apiKey'] = powercode_api_key
|
||||||
|
data['action'] = 'list_customers'
|
||||||
|
|
||||||
|
r = requests.post(url, data=data, headers=headers, verify=False, timeout=10)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
def getServiceInfo(customerID):
|
||||||
|
headers= {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||||
|
url = powercode_api_url + ":444/api/1/index.php"
|
||||||
|
data = {}
|
||||||
|
data['apiKey'] = powercode_api_key
|
||||||
|
data['action'] = 'readCustomerService'
|
||||||
|
data['customerID'] = customerID
|
||||||
|
|
||||||
|
r = requests.post(url, data=data, headers=headers, verify=False, timeout=10)
|
||||||
|
servicesDict = {}
|
||||||
|
for service in r.json()['services']:
|
||||||
|
if 'internetInfo' in service:
|
||||||
|
servicesDict[service['serviceID']] = {}
|
||||||
|
servicesDict[service['serviceID']]['downloadMbps'] = int(round(int(service['internetInfo']['maxIn']) / 1000))
|
||||||
|
servicesDict[service['serviceID']]['uploadMbps'] = int(round(int(service['internetInfo']['maxOut']) / 1000))
|
||||||
|
return servicesDict
|
||||||
|
|
||||||
|
def createShaper():
|
||||||
|
net = NetworkGraph()
|
||||||
|
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
||||||
|
print("Fetching data from Powercode")
|
||||||
|
|
||||||
|
customerInfo = getCustomerInfo()
|
||||||
|
|
||||||
|
customerIDs = []
|
||||||
|
for customer in customerInfo:
|
||||||
|
if customer['id'] != '1':
|
||||||
|
if customer['id'] != '':
|
||||||
|
if customer['status'] == 'Active':
|
||||||
|
customerIDint = int(customer['id'])
|
||||||
|
if customerIDint != 0:
|
||||||
|
if customerIDint != None:
|
||||||
|
if customerIDint not in customerIDs:
|
||||||
|
customerIDs.append(customerIDint)
|
||||||
|
|
||||||
|
allServices = {}
|
||||||
|
for customerID in customerIDs:
|
||||||
|
allServices.update(getServiceInfo(customerID))
|
||||||
|
|
||||||
|
acceptableEquipment = ['Customer Owned Equipment', 'Router', 'Customer Owned Equipment', 'Managed Routers'] #'CPE'
|
||||||
|
|
||||||
|
devicesByCustomerID = {}
|
||||||
|
for customer in customerInfo:
|
||||||
|
if customer['status'] == 'Active':
|
||||||
|
chosenName = ''
|
||||||
|
if customer['name'] != '':
|
||||||
|
chosenName = customer['name']
|
||||||
|
elif customer['company_name'] != '':
|
||||||
|
chosenName = customer['company_name']
|
||||||
|
else:
|
||||||
|
chosenName = customer['id']
|
||||||
|
for equipment in customer['equipment']:
|
||||||
|
if equipment['type'] in acceptableEquipment:
|
||||||
|
if equipment['service_id'] in allServices:
|
||||||
|
device = {}
|
||||||
|
device['id'] = "c_" + customer['id'] + "_s_" + "_d_" + equipment['id']
|
||||||
|
device['name'] = equipment['name']
|
||||||
|
device['ipv4'] = equipment['ip_address']
|
||||||
|
device['mac'] = equipment['mac_address']
|
||||||
|
if customer['id'] not in devicesByCustomerID:
|
||||||
|
devicesByCustomerID[customer['id']] = {}
|
||||||
|
devicesByCustomerID[customer['id']]['name'] = chosenName
|
||||||
|
devicesByCustomerID[customer['id']]['downloadMbps'] = allServices[equipment['service_id']]['downloadMbps']
|
||||||
|
devicesByCustomerID[customer['id']]['uploadMbps'] = allServices[equipment['service_id']]['uploadMbps']
|
||||||
|
if 'devices' not in devicesByCustomerID[customer['id']]:
|
||||||
|
devicesByCustomerID[customer['id']]['devices'] = []
|
||||||
|
devicesByCustomerID[customer['id']]['devices'].append(device)
|
||||||
|
|
||||||
|
for customerID in devicesByCustomerID:
|
||||||
|
customer = NetworkNode(
|
||||||
|
type=NodeType.client,
|
||||||
|
id=customerID,
|
||||||
|
displayName=devicesByCustomerID[customerID]['name'],
|
||||||
|
address='',
|
||||||
|
customerName=devicesByCustomerID[customerID]['name'],
|
||||||
|
download=devicesByCustomerID[customerID]['downloadMbps'],
|
||||||
|
upload=devicesByCustomerID[customerID]['uploadMbps'],
|
||||||
|
)
|
||||||
|
net.addRawNode(customer)
|
||||||
|
for device in devicesByCustomerID[customerID]['devices']:
|
||||||
|
newDevice = NetworkNode(
|
||||||
|
id=device['id'],
|
||||||
|
displayName=device["name"],
|
||||||
|
type=NodeType.device,
|
||||||
|
parentId=customerID,
|
||||||
|
mac=device["mac"],
|
||||||
|
ipv4=[device['ipv4']],
|
||||||
|
ipv6=[]
|
||||||
|
)
|
||||||
|
net.addRawNode(newDevice)
|
||||||
|
net.prepareTree()
|
||||||
|
net.plotNetworkGraph(False)
|
||||||
|
if net.doesNetworkJsonExist():
|
||||||
|
print("network.json already exists. Leaving in-place.")
|
||||||
|
else:
|
||||||
|
net.createNetworkJson()
|
||||||
|
net.createShapedDevices()
|
||||||
|
|
||||||
|
def importFromPowercode():
|
||||||
|
#createNetworkJSON()
|
||||||
|
createShaper()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
importFromPowercode()
|
@ -77,6 +77,12 @@ overwriteNetworkJSONalways = False
|
|||||||
ignoreSubnets = ['192.168.0.0/16']
|
ignoreSubnets = ['192.168.0.0/16']
|
||||||
allowedSubnets = ['100.64.0.0/10']
|
allowedSubnets = ['100.64.0.0/10']
|
||||||
|
|
||||||
|
# Powercode Integration
|
||||||
|
automaticImportPowercode = False
|
||||||
|
powercode_api_key = ''
|
||||||
|
# Everything before :444/api/ in your Powercode instance URL
|
||||||
|
powercode_api_url = ''
|
||||||
|
|
||||||
# Splynx Integration
|
# Splynx Integration
|
||||||
automaticImportSplynx = False
|
automaticImportSplynx = False
|
||||||
splynx_api_key = ''
|
splynx_api_key = ''
|
||||||
|
@ -11,6 +11,12 @@ if automaticImportUISP:
|
|||||||
from integrationUISP import importFromUISP
|
from integrationUISP import importFromUISP
|
||||||
if automaticImportSplynx:
|
if automaticImportSplynx:
|
||||||
from integrationSplynx import importFromSplynx
|
from integrationSplynx import importFromSplynx
|
||||||
|
try:
|
||||||
|
from ispConfig import automaticImportPowercode
|
||||||
|
except:
|
||||||
|
automaticImportPowercode = False
|
||||||
|
if automaticImportPowercode:
|
||||||
|
from integrationPowercode import importFromPowercode
|
||||||
from apscheduler.schedulers.background import BlockingScheduler
|
from apscheduler.schedulers.background import BlockingScheduler
|
||||||
from apscheduler.executors.pool import ThreadPoolExecutor
|
from apscheduler.executors.pool import ThreadPoolExecutor
|
||||||
|
|
||||||
@ -27,6 +33,11 @@ def importFromCRM():
|
|||||||
importFromSplynx()
|
importFromSplynx()
|
||||||
except:
|
except:
|
||||||
print("Failed to import from Splynx")
|
print("Failed to import from Splynx")
|
||||||
|
elif automaticImportPowercode:
|
||||||
|
try:
|
||||||
|
importFromPowercode()
|
||||||
|
except:
|
||||||
|
print("Failed to import from Powercode")
|
||||||
|
|
||||||
def graphHandler():
|
def graphHandler():
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user