mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Add files via upload
This commit is contained in:
84
LibreNMS_Integration.py
Normal file
84
LibreNMS_Integration.py
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
# Copyright (C) 2020 Robert Chacón
|
||||||
|
# This file is part of LibreQoS.
|
||||||
|
#
|
||||||
|
# LibreQoS is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# LibreQoS is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with LibreQoS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# _ _ _ ___ ____
|
||||||
|
# | | (_) |__ _ __ ___ / _ \ ___/ ___|
|
||||||
|
# | | | | '_ \| '__/ _ \ | | |/ _ \___ \
|
||||||
|
# | |___| | |_) | | | __/ |_| | (_) |__) |
|
||||||
|
# |_____|_|_.__/|_| \___|\__\_\\___/____/
|
||||||
|
# v.0.65-alpha
|
||||||
|
#
|
||||||
|
import requests
|
||||||
|
from ispConfig import orgLibreNMSxAuthToken, libreNMSBaseURL, libreNMSDeviceGroups
|
||||||
|
|
||||||
|
def pullLibreNMSDevices():
|
||||||
|
libreNMSDevicesToImport = []
|
||||||
|
url = libreNMSBaseURL + "/api/v0/devicegroups/"
|
||||||
|
headers = {'accept':'application/json', 'x-auth-token': orgLibreNMSxAuthToken}
|
||||||
|
r = requests.get(url, headers=headers)
|
||||||
|
allDevicesJSON = r.json()
|
||||||
|
#print(jsonData)
|
||||||
|
for group in allDevicesJSON['groups']:
|
||||||
|
groupName = group['name']
|
||||||
|
if groupName in libreNMSDeviceGroups:
|
||||||
|
if libreNMSDeviceGroups[groupName]['downloadMbps']:
|
||||||
|
url = libreNMSBaseURL + "/api/v0/devicegroups/" + groupName
|
||||||
|
headers = {'accept':'application/json', 'x-auth-token': orgLibreNMSxAuthToken}
|
||||||
|
r = requests.get(url, headers=headers)
|
||||||
|
group = r.json()['devices']
|
||||||
|
for device in group:
|
||||||
|
deviceID = device['device_id']
|
||||||
|
ipAddr, hostname = getLibreNMSDeviceInfo(deviceID)
|
||||||
|
thisShapedDevice = {
|
||||||
|
"identification": {
|
||||||
|
"name": ipAddr,
|
||||||
|
"hostname": hostname,
|
||||||
|
"ipAddr": ipAddr,
|
||||||
|
"mac": None,
|
||||||
|
"model": None,
|
||||||
|
"modelName": None,
|
||||||
|
"unmsSiteID": None,
|
||||||
|
"libreNMSSiteID": None
|
||||||
|
},
|
||||||
|
"qos": {
|
||||||
|
"downloadMbps": libreNMSDeviceGroups[groupName]['downloadMbps'],
|
||||||
|
"uploadMbps": libreNMSDeviceGroups[groupName]['uploadMbps'],
|
||||||
|
"accessPoint": None
|
||||||
|
},
|
||||||
|
}
|
||||||
|
print("Imported device from LibreNMS: " + hostname)
|
||||||
|
libreNMSDevicesToImport.append(thisShapedDevice)
|
||||||
|
return libreNMSDevicesToImport
|
||||||
|
|
||||||
|
def getLibreNMSDeviceInfo(deviceID):
|
||||||
|
#Get IP
|
||||||
|
url = libreNMSBaseURL + "/api/v0/devices/" + str(deviceID) + "/ip"
|
||||||
|
headers = {'accept':'application/json', 'x-auth-token': orgLibreNMSxAuthToken}
|
||||||
|
r = requests.get(url, headers=headers)
|
||||||
|
ipAddr = ''
|
||||||
|
for address in r.json()['addresses']:
|
||||||
|
thisIP = address['ipv4_address']
|
||||||
|
#Ignore internal CPE router IPs. This assumes your CPE router internal network IPs are 192.168.X.X
|
||||||
|
if '192.168' not in ipAddr:
|
||||||
|
ipAddr = thisIP
|
||||||
|
if '/' in ipAddr:
|
||||||
|
ipAddr = ipAddr.split('/')[0]
|
||||||
|
#Get hostname
|
||||||
|
url = libreNMSBaseURL + "/api/v0/devices/" + str(deviceID)
|
||||||
|
headers = {'accept':'application/json', 'x-auth-token': orgLibreNMSxAuthToken}
|
||||||
|
r = requests.get(url, headers=headers)
|
||||||
|
hostname = r.json()['devices'][0]['hostname']
|
||||||
|
return ((ipAddr, hostname))
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
# | | | | '_ \| '__/ _ \ | | |/ _ \___ \
|
# | | | | '_ \| '__/ _ \ | | |/ _ \___ \
|
||||||
# | |___| | |_) | | | __/ |_| | (_) |__) |
|
# | |___| | |_) | | | __/ |_| | (_) |__) |
|
||||||
# |_____|_|_.__/|_| \___|\__\_\\___/____/
|
# |_____|_|_.__/|_| \___|\__\_\\___/____/
|
||||||
# v.0.6-alpha
|
# v.0.65-alpha
|
||||||
#
|
#
|
||||||
import random
|
import random
|
||||||
import logging
|
import logging
|
||||||
@@ -29,7 +29,8 @@ from subprocess import PIPE
|
|||||||
import time
|
import time
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from UNMS_Integration import pullUNMSDevices
|
from UNMS_Integration import pullUNMSDevices
|
||||||
from ispConfig import fqOrCAKE, pipeBandwidthCapacityMbps, interfaceA, interfaceB, enableActualShellCommands, runShellCommandsAsSudo, importFromUNMS
|
from LibreNMS_Integration import pullLibreNMSDevices
|
||||||
|
from ispConfig import fqOrCAKE, pipeBandwidthCapacityMbps, interfaceA, interfaceB, enableActualShellCommands, runShellCommandsAsSudo, importFromUNMS, importFromLibreNMS
|
||||||
|
|
||||||
def shell(inputCommand):
|
def shell(inputCommand):
|
||||||
if enableActualShellCommands:
|
if enableActualShellCommands:
|
||||||
@@ -87,9 +88,11 @@ def refreshShapers():
|
|||||||
#Add specific test clients
|
#Add specific test clients
|
||||||
#clientsList.append((100, '100.65.1.1'))
|
#clientsList.append((100, '100.65.1.1'))
|
||||||
|
|
||||||
#Bring in clients from UCRM if enabled
|
#Bring in clients from UNMS or LibreNMS if enabled
|
||||||
if importFromUNMS:
|
if importFromUNMS:
|
||||||
shapableDevices.extend(pullUNMSDevices())
|
shapableDevices.extend(pullUNMSDevices())
|
||||||
|
if importFromLibreNMS:
|
||||||
|
shapableDevices.extend(pullLibreNMSDevices())
|
||||||
|
|
||||||
#Categorize Clients By IPv4 /16
|
#Categorize Clients By IPv4 /16
|
||||||
listOfSlash16SubnetsInvolved = []
|
listOfSlash16SubnetsInvolved = []
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
# | | | | '_ \| '__/ _ \ | | |/ _ \___ \
|
# | | | | '_ \| '__/ _ \ | | |/ _ \___ \
|
||||||
# | |___| | |_) | | | __/ |_| | (_) |__) |
|
# | |___| | |_) | | | __/ |_| | (_) |__) |
|
||||||
# |_____|_|_.__/|_| \___|\__\_\\___/____/
|
# |_____|_|_.__/|_| \___|\__\_\\___/____/
|
||||||
# v.0.6-alpha
|
# v.0.65-alpha
|
||||||
#
|
#
|
||||||
import requests
|
import requests
|
||||||
from ispConfig import orgUNMSxAuthToken, unmsBaseURL, deviceModelBlacklistEnabled
|
from ispConfig import orgUNMSxAuthToken, unmsBaseURL, deviceModelBlacklistEnabled
|
||||||
@@ -82,22 +82,3 @@ def getUNMSdevicesAtClientSite(siteID):
|
|||||||
headers = {'accept':'application/json', 'x-auth-token': orgUNMSxAuthToken}
|
headers = {'accept':'application/json', 'x-auth-token': orgUNMSxAuthToken}
|
||||||
r = requests.get(url, headers=headers)
|
r = requests.get(url, headers=headers)
|
||||||
return (r.json())
|
return (r.json())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
23
ispConfig.py
23
ispConfig.py
@@ -22,11 +22,32 @@ runShellCommandsAsSudo = False
|
|||||||
# Import customer QoS rules from UNMS
|
# Import customer QoS rules from UNMS
|
||||||
importFromUNMS = False
|
importFromUNMS = False
|
||||||
|
|
||||||
|
# Import customer QoS rules from LibreNMS
|
||||||
|
importFromLibreNMS = False
|
||||||
|
|
||||||
|
# Available on LibreNMS site as https://exampleLibreNMSsite.net/api-access
|
||||||
|
orgLibreNMSxAuthToken = ''
|
||||||
|
|
||||||
|
# Do not include trailing forward slash. For example https://exampleLibreNMSsite.net
|
||||||
|
libreNMSBaseURL = ''
|
||||||
|
|
||||||
|
# Which LibreNMS groups to import. Please create groups in LibreNMS to match these group names such as Plan A
|
||||||
|
libreNMSDeviceGroups = {
|
||||||
|
'Plan A': {
|
||||||
|
'downloadMbps': 25,
|
||||||
|
'uploadMbps': 3
|
||||||
|
},
|
||||||
|
'Plan B': {
|
||||||
|
'downloadMbps': 50,
|
||||||
|
'uploadMbps': 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Available under UNMS > Settings > Users
|
# Available under UNMS > Settings > Users
|
||||||
orgUNMSxAuthToken = ''
|
orgUNMSxAuthToken = ''
|
||||||
|
|
||||||
# Everything before /nms/. Use https:// For example: https://unms.exampleISP.com (no slash after)
|
# Everything before /nms/. Use https:// For example: https://unms.exampleISP.com (no slash after)
|
||||||
unmsBaseURL = ''
|
unmsBaseURL = ''
|
||||||
|
|
||||||
# For bridged CPE radios, you can exclude matching radio models from rate limiting
|
# For bridged CPE radios on UNMS, you can exclude matching radio models from rate limiting
|
||||||
deviceModelBlacklistEnabled = False
|
deviceModelBlacklistEnabled = False
|
||||||
|
|||||||
Reference in New Issue
Block a user