Browse Source

Re-eanble CMX.

Joe Clarke 1 year ago
parent
commit
3d124a8a74

+ 17 - 16
automation/cmx/cmx-map/cmx.py

@@ -5,7 +5,7 @@
 import requests
 import sys
 import json
-from requests.packages.urllib3.exceptions import InsecureRequestWarning
+from requests.packages.urllib3.exceptions import InsecureRequestWarning  # type: ignore
 from flask import Flask
 from flask import abort
 from flask_restful import Api
@@ -13,13 +13,12 @@ from flask_restful import Resource
 from flask_restful import reqparse
 from flask import send_file
 from pathlib import Path
-from io import StringIO
 from io import BytesIO
 from ipaddress import IPv6Address
 import os
 import traceback
-import CLEUCreds
-from cleu.config import Config as C
+import CLEUCreds  # type: ignore
+from cleu.config import Config as C  # type: ignore
 
 
 from PIL import Image, ImageDraw
@@ -41,6 +40,7 @@ def after_request(response):
 
 cmxBaseUrl = C.CMX
 cmxAuth = (CLEUCreds.CMX_USERNAME, CLEUCreds.CMX_PASSWORD)
+cmxMapAuth = (CLEUCreds.CMX_MAP_USERNAME, CLEUCreds.CMX_PASSWORD)
 PORT = 8002
 
 imgDir = "maps/"
@@ -54,11 +54,11 @@ for filename in markerFiles:
     # markerW, markerH = marker.size
 
 apiUri = {
-    "mac": "/api/location/v2/clients?macAddress=",
-    "ip": "/api/location/v2/clients?ipAddress=",
+    "mac": "/api/location/v3/clients?macAddress=",
+    "ip": "/api/location/v3/clients?ipAddress=",
     "map": "/api/config/v1/maps/imagesource/",
-    "ssid": "/api/location/v2/clients/?include=metadata&pageSize=1000&page=",
-    "count": "/api/location/v2/clients/count",
+    "ssid": "/api/location/v3/clients/?include=metadata&pageSize=1000&page=",
+    "count": "/api/location/v3/clients/count",
     "floors": "/api/config/v1/maps",
     "tag": "/api/location/v1/tags/",
 }
@@ -74,7 +74,7 @@ def serve_pil_image(pil_img):
 def getMap(imageName):
     imgFile = Path(imgDir + imageName)
     if not imgFile.is_file():
-        respImg = requests.get(cmxBaseUrl + apiUri["map"] + imageName, auth=cmxAuth, verify=False, stream=True)
+        respImg = requests.get(cmxBaseUrl + apiUri["map"] + imageName, auth=cmxMapAuth, verify=False, stream=True)
         if respImg.status_code == 200:
             with open(str(imgFile), "wb") as f:
                 for chunk in respImg:
@@ -82,7 +82,7 @@ def getMap(imageName):
 
 
 def getAllFloorMaps():
-    response = requests.get(cmxBaseUrl + apiUri["floors"], auth=cmxAuth, verify=False)
+    response = requests.get(cmxBaseUrl + apiUri["floors"], auth=cmxMapAuth, verify=False)
     floorList = {}
     if response and response != "":
         try:
@@ -106,12 +106,12 @@ def getAllFloorMaps():
 class CMX(Resource):
     def get(self):
         parser = reqparse.RequestParser()
-        parser.add_argument("ip", help="IP address of the endpoint")
-        parser.add_argument("ipv6", help="IPv6 address of the endpoint")
-        parser.add_argument("mac", help="MAC address of the endpoint")
-        parser.add_argument("marker", help="Marker used to display the location of the endpoint", default="marker")
-        parser.add_argument("size", help="Size of the image returned")
-        parser.add_argument("tag", help="Asset tag MAC address")
+        parser.add_argument("ip", location="args", help="IP address of the endpoint")
+        parser.add_argument("ipv6", location="args", help="IPv6 address of the endpoint")
+        parser.add_argument("mac", location="args", help="MAC address of the endpoint")
+        parser.add_argument("marker", location="args", help="Marker used to display the location of the endpoint", default="marker")
+        parser.add_argument("size", location="args", help="Size of the image returned")
+        parser.add_argument("tag", location="args", help="Asset tag MAC address")
 
         args = parser.parse_args()
         response = ""
@@ -169,6 +169,7 @@ class CMX(Resource):
                 else:
                     abort(404, "Requested element not found")
             except Exception as inst:
+                traceback.print_exc()
                 print("Unexpected error with request= {} | error : {}".format(response.text, inst), file=sys.stderr)
                 return {"response": str(response.text), "error": str(inst)}, 500
 

+ 16 - 16
automation/cmx/cmx-map/requirements.txt

@@ -1,16 +1,16 @@
-aniso8601==8.0.0
-certifi==2019.11.28
-chardet==3.0.4
-Click==7.0
-Flask==1.1.1
-Flask-RESTful==0.3.7
-idna==2.8
-itsdangerous==1.1.0
-Jinja2==2.10.3
-MarkupSafe==1.1.1
-Pillow==6.2.1
-pytz==2019.3
-requests==2.22.0
-six==1.13.0
-urllib3==1.25.7
-Werkzeug==0.16.0
+aniso8601
+certifi
+chardet
+Click
+Flask
+Flask-RESTful
+idna
+itsdangerous
+Jinja2
+MarkupSafe
+Pillow
+pytz
+requests
+six
+urllib3
+Werkzeug

+ 6 - 5
automation/config/cleu/config.py

@@ -17,13 +17,14 @@ class Config:
     DHCP_BASE = "https://dc1-dhcp.{}:8443/web-services/rest/resource".format(DNS_DOMAIN)
     MONITORING = "cl-monitoring." + DNS_DOMAIN
     DHCP_SERVER = "dc1-dhcp." + DNS_DOMAIN
-    #PI = "cl-pi." + DNS_DOMAIN
-    def DNACS(dom, dnacs = [f"dnac-0{x}" for x in range(1, 5)]):
+    # PI = "cl-pi." + DNS_DOMAIN
+    def DNACS(dom, dnacs=[f"dnac-0{x}" for x in range(1, 5)]):
         return [f"{d}.{dom}" for d in dnacs]
+
     DNACS = DNACS(DNS_DOMAIN)
-    #SDA_BASE = "https://sdacleur20." + DNS_DOMAIN
-    #CMX_GW = "http://cl-freebsd.{}:8002/api/v0.1/cmx".format(DNS_DOMAIN)
-    #CMX = "https://cl-cmx-1." + DNS_DOMAIN
+    # SDA_BASE = "https://sdacleur20." + DNS_DOMAIN
+    CMX_GW = "http://cl-freebsd.{}:8002/api/v0.1/cmx".format(DNS_DOMAIN)
+    CMX = "https://cl-cmx." + DNS_DOMAIN
     TOOL = "tool." + DNS_DOMAIN
     TOOL_BASE = "https://{}/Port/Switchport.aspx?".format(TOOL)
     AD_DOMAIN = "ad." + DNS_DOMAIN