tum 1 年之前
父節點
當前提交
46576eabd0
共有 4 個文件被更改,包括 45 次插入22 次删除
  1. 34 14
      app/backend/views.py
  2. 7 4
      app/exfo/lib.py
  3. 2 2
      app/templates/base.html
  4. 2 2
      app/templates/base_raw.html

+ 34 - 14
app/backend/views.py

@@ -1,6 +1,6 @@
1 1
 from django.shortcuts import render, redirect
2 2
 from backend.mongodb import db
3
-from exfo.lib import Exfo, Mikrotik
3
+from exfo.lib import Exfo, Mikrotik, SLA_MAP
4 4
 from pprint import pprint
5 5
 
6 6
 from ttp import ttp
@@ -334,15 +334,23 @@ def gen_report_notebook():
334 334
         if not d['sla_name']:
335 335
             continue 
336 336
 
337
-        sla_splt = d['sla_name'].split('-')
337
+        # sla_splt = d['sla_name'].split('-')
338
+        sla_splt = d['verifier_name'].split('_')
338 339
         if len(sla_splt) > 1:
339
-            reg_cond = f'(?=^pppoe-out)(?=.*{sla_splt[0]})(?=.*{sla_splt[-1]})'
340
+            # reg_cond = f'(?=^pppoe-out)(?=.*{sla_splt[0]})(?=.*{sla_splt[-1]})'
341
+            # reg_cond = f'(?=^pppoe-out)(?=.*{sla_splt[-1]})'
342
+            reg_cond = f'(?=.*pppoe-out)(?=.*{sla_splt[-1]})'
340 343
 
341 344
             pprint(reg_cond)
342
-            temp_addr = list(c2.find({'ts': {'$lte': utc, '$gte': yest }, 'interface': {'$regex': reg_cond,  '$not': { '$regex': '^pppoe-out5'}, '$options': 'i' }, 'invalid': 'false'}).sort("ts", -1))
345
+            # temp_addr = list(c2.find({'ts': {'$lte': utc, '$gte': yest }, 'interface': {'$regex': reg_cond,  '$not': { '$regex': '^pppoe-out5'}, '$options': 'i' }, 'invalid': 'false'}).sort("ts", -1))
346
+            temp_addr = list(c2.find({'ts': {'$lte': utc, '$gte': yest }, 'interface': {'$regex': reg_cond, '$options': 'i' }, 'invalid': 'false'}).sort("ts", -1))
347
+            # temp_addr = list(c2.find({'interface': {'$regex': reg_cond, '$options': 'i' }, 'invalid': 'false'}).sort("ts", -1))
348
+            pprint("-------")
343 349
             pprint("temp addr")
344 350
             pprint(d['sla_name'])
345
-            # //pprint(temp_addr)
351
+            
352
+            pprint(temp_addr)
353
+            
346 354
             target_address = None
347 355
             if temp_addr:
348 356
                 target_address = temp_addr[0]
@@ -422,8 +430,12 @@ def gen_report(request):
422 430
         report_link = f'/media/{fn}'
423 431
 
424 432
     try:
425
-        mk_ips = mkt.call_remote("ip/route") 
426
-        mk_address = mkt.call_remote("ip/address") 
433
+        mk_ips = []
434
+        mk_address = []
435
+        for v in SLA_MAP.values():
436
+            mkt = Mikrotik(v)
437
+            mk_ips.append(mkt.call_remote("ip/route")) 
438
+            mk_address.append(mkt.call_remote("ip/address"))
427 439
     except:
428 440
         mk_ips = []
429 441
         mk_address = []
@@ -436,12 +448,19 @@ def gen_report(request):
436 448
 def mikro_dump_task():
437 449
     #look at only pppoe only ( excloude pppoe5 )
438 450
     col  = db['ip_address']
439
-    mk_address = mkt.call_remote("ip/address") 
440
-    for i in mk_address:
441
-        temp = {'ts': datetime.utcnow()}
442
-        temp = temp | i
443
-        col.insert_one(temp)
444
-    pprint("dump ip complete")
451
+    pprint(SLA_MAP.values())
452
+    for v in SLA_MAP.values():
453
+        for v0 in v.split(','):
454
+            mkt = Mikrotik(v0)
455
+            try:
456
+                mk_address = mkt.call_remote("ip/address") 
457
+                for i in mk_address:
458
+                    temp = {'ts': datetime.utcnow()}
459
+                    temp = temp | i
460
+                    col.insert_one(temp)
461
+                pprint("dump ip complete")
462
+            except Exception as e:
463
+                pprint(e)
445 464
 
446 465
 @shared_task
447 466
 def gen_report_task():
@@ -455,7 +474,8 @@ def gen_report_task():
455 474
     else:
456 475
         pprint(f"dump = {r.status_code}")
457 476
 
458
-    r = requests.get(f'http://web:8000/backend/gen_report/?sla_name=BNG-144-VLAN20-Public&sla_name=BNG-144-VLAN10-Private&sla_name=BRAS-88-VLAN20-Public&sla_name=BRAS-88-VLAN10-Private&genReport=Gen+Report', timeout=None)
477
+    # r = requests.get(f'http://web:8000/backend/gen_report/?sla_name=BNG-144-VLAN20-Public&sla_name=BNG-144-VLAN10-Private&sla_name=BRAS-88-VLAN20-Public&sla_name=BRAS-88-VLAN10-Private&genReport=Gen+Report', timeout=None)
478
+    r = requests.get(f'http://web:8000/backend/gen_report/?genReport=Gen+Report', timeout=None)
459 479
     if r.status_code == 200:
460 480
         pprint("genreport OK")
461 481
     else:

+ 7 - 4
app/exfo/lib.py

@@ -121,15 +121,14 @@ SLA_MAP = {
121 121
         "RBI BV-110":"61.7.161.162",	
122 122
         "NSN":"61.7.161.164",	
123 123
         "CBI":"61.7.161.163",	
124
-        "CMI":"61.7.161.171",	
124
+        "CMI":"61.7.161.171,61.7.161.172",	
125 125
         "HYI":"61.7.161.180",	
126 126
         "NMA":"61.7.161.179",	
127 127
         "CRI":"61.7.161.178",	
128 128
         "SNI":"61.7.161.177",	
129 129
         "SPI":"61.7.161.175",	
130 130
         "PTY BV-110":"61.7.161.174",	
131
-        "PTY":"61.7.161.159",	
132
-        "PTY":"61.7.161.161",	
131
+        "PTY":"61.7.161.159,61.7.161.161",	
133 132
         "PLK":"61.7.161.169",	
134 133
         "HYI _BV-100":"61.7.161.168",	
135 134
         "CMI BV-110":"61.7.161.167",	
@@ -147,10 +146,14 @@ class Mikrotik:
147 146
       'Authorization': 'Basic YWRtaW46RGlnaXRpbnNfMDE='
148 147
     }
149 148
 
149
+    def __init__(self, ip=None):
150
+        if ip:
151
+            self.BASE_URL = f"https://{ip}/rest/"
152
+
150 153
     def call_remote(self, cmd, payload={}):
151 154
         url = self.BASE_URL + cmd
152 155
         pprint(url)
153
-        response = requests.get(url, auth=self.basic,  data=payload, verify=False)
156
+        response = requests.get(url, auth=self.basic,  data=payload, verify=False, timeout=3)
154 157
         return response.json()
155 158
 
156 159
 

+ 2 - 2
app/templates/base.html

@@ -7,7 +7,7 @@
7 7
     <meta name="description" content="">
8 8
     <meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
9 9
     <meta name="generator" content="Hugo 0.84.0">
10
-    <title>Dashboard Template · Bootstrap v5.0</title>
10
+    <title>Network Report System</title>
11 11
 
12 12
     <link rel="canonical" href="https://getbootstrap.com/docs/5.0/examples/dashboard/">
13 13
 
@@ -43,7 +43,7 @@
43 43
   <body>
44 44
     
45 45
 <header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
46
-  <a class="navbar-brand col-md-3 col-lg-2 me-0 px-3" href="#">Company name</a>
46
+  <a class="navbar-brand col-md-3 col-lg-2 me-0 px-3" href="#">Network Report System</a>
47 47
   <button class="navbar-toggler position-absolute d-md-none collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#sidebarMenu" aria-controls="sidebarMenu" aria-expanded="false" aria-label="Toggle navigation">
48 48
     <span class="navbar-toggler-icon"></span>
49 49
   </button>

+ 2 - 2
app/templates/base_raw.html

@@ -7,7 +7,7 @@
7 7
     <meta name="description" content="">
8 8
     <meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
9 9
     <meta name="generator" content="Hugo 0.84.0">
10
-    <title>Dashboard Template · Bootstrap v5.0</title>
10
+    <title>Network Report System</title>
11 11
 
12 12
     <link rel="canonical" href="https://getbootstrap.com/docs/5.0/examples/dashboard/">
13 13
 
@@ -43,7 +43,7 @@
43 43
   <body>
44 44
     
45 45
 <header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
46
-  <a class="navbar-brand col-md-3 col-lg-2 me-0 px-3" href="#">Company name</a>
46
+  <a class="navbar-brand col-md-3 col-lg-2 me-0 px-3" href="#">Network Report System</a>
47 47
   <button class="navbar-toggler position-absolute d-md-none collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#sidebarMenu" aria-controls="sidebarMenu" aria-expanded="false" aria-label="Toggle navigation">
48 48
     <span class="navbar-toggler-icon"></span>
49 49
   </button>