mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-03 04:07:52 +00:00
added more parsing
This commit is contained in:
@@ -19,6 +19,7 @@ import logging
|
|||||||
import time
|
import time
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import websocket
|
import websocket
|
||||||
|
import re
|
||||||
try:
|
try:
|
||||||
import thread
|
import thread
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -28,29 +29,34 @@ import LANforge
|
|||||||
from LANforge import LFRequest
|
from LANforge import LFRequest
|
||||||
from LANforge import LFUtils
|
from LANforge import LFUtils
|
||||||
from LANforge.LFUtils import NA
|
from LANforge.LFUtils import NA
|
||||||
|
|
||||||
|
ignore=[
|
||||||
|
"scan finished",
|
||||||
|
"scan started"
|
||||||
|
"CTRL-EVENT-SCAN-STARTED",
|
||||||
|
"-EVENT-SSID-TEMP-DISABLED",
|
||||||
|
"new station",
|
||||||
|
"del station",
|
||||||
|
"ping",
|
||||||
|
"deleted-alert",
|
||||||
|
]
|
||||||
|
interesting=[
|
||||||
|
"Trying to authenticate",
|
||||||
|
"auth: timed out",
|
||||||
|
"link DOWN",
|
||||||
|
"link UP",
|
||||||
|
'wifi-event'
|
||||||
|
]
|
||||||
|
|
||||||
|
rebank = {
|
||||||
|
"ifname" : re.compile("IFNAME=(\S+)")
|
||||||
|
}
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
def main():
|
def main():
|
||||||
host = "ct524-debbie.jbr.candelatech.com"
|
host = "ct524-debbie.jbr.candelatech.com"
|
||||||
base_url = "ws://%s:8081"%host
|
base_url = "ws://%s:8081"%host
|
||||||
websock = None
|
websock = None
|
||||||
|
|
||||||
ignore=(
|
|
||||||
"scan finished",
|
|
||||||
"scan started"
|
|
||||||
"CTRL-EVENT-SCAN-STARTED",
|
|
||||||
"CTRL-EVENT-SSID-TEMP-DISABLED",
|
|
||||||
"new station",
|
|
||||||
"delstation",
|
|
||||||
"ping",
|
|
||||||
)
|
|
||||||
interesting=(
|
|
||||||
"Trying to authenticate",
|
|
||||||
"auth: timed out",
|
|
||||||
'link DOWN',
|
|
||||||
'link UP',
|
|
||||||
'wifi-event'
|
|
||||||
)
|
|
||||||
|
|
||||||
# open websocket
|
# open websocket
|
||||||
start_websocket(base_url, websock)
|
start_websocket(base_url, websock)
|
||||||
if (websock is not None):
|
if (websock is not None):
|
||||||
@@ -61,9 +67,11 @@ def main():
|
|||||||
|
|
||||||
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
|
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
|
||||||
def sock_filter(wsock, text):
|
def sock_filter(wsock, text):
|
||||||
debug = 1
|
global ignore
|
||||||
|
global interesting
|
||||||
|
global rebank
|
||||||
|
debug = 0
|
||||||
for test in ignore:
|
for test in ignore:
|
||||||
print (".")
|
|
||||||
if (test in text):
|
if (test in text):
|
||||||
if (debug):
|
if (debug):
|
||||||
print (" ignoring ",text)
|
print (" ignoring ",text)
|
||||||
@@ -71,21 +79,48 @@ def sock_filter(wsock, text):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
message = json.loads(text)
|
message = json.loads(text)
|
||||||
#if (("time" in message) and ("timestamp" in message)):
|
if (("time" in message) and ("timestamp" in message)):
|
||||||
# return
|
return
|
||||||
|
if ("event_type" in message):
|
||||||
|
if (message["is_alert"]):
|
||||||
|
print ("alert: ", message["details"]);
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
print ("event: ", message["details"]);
|
||||||
|
return
|
||||||
|
|
||||||
if ("wifi-event" in message):
|
if ("wifi-event" in message):
|
||||||
for test in ignore:
|
for test in ignore:
|
||||||
if (test in message["wifi-event"]):
|
if (test in message["wifi-event"]):
|
||||||
|
if (debug):
|
||||||
|
print (" ignoring ",text)
|
||||||
return;
|
return;
|
||||||
print (message["wifi-event"], "\n")
|
#group = rebank["ifname"].match(message["wifi-event"]).group()
|
||||||
|
#if (group):
|
||||||
|
# print ("IFname: ",group)
|
||||||
|
|
||||||
|
if ("disconnected" in message["wifi-event"]):
|
||||||
|
print ("Station down")
|
||||||
|
return
|
||||||
|
if ("Trying to authenticate" in message["wifi-event"]):
|
||||||
|
print ("station authenticating")
|
||||||
|
return
|
||||||
|
print ("wifi-event: ", message["wifi-event"])
|
||||||
else:
|
else:
|
||||||
print ("\nUnhandled: ")
|
print ("\nUnhandled: ")
|
||||||
LFUtils.debug_printer.pprint(message)
|
LFUtils.debug_printer.pprint(message)
|
||||||
|
|
||||||
except Exception:
|
except json.JSONDecodeError as derr:
|
||||||
print ("# ----- Not JSON: ----- ----- ----- ----- ----- ----- ----- ----- ----- -----\n")
|
print ("# ----- Decode err: ----- ----- ----- ----- ----- ----- ----- ----- ----- -----")
|
||||||
print (text)
|
print (text)
|
||||||
print ("# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----\n")
|
print (derr)
|
||||||
|
print ("# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----")
|
||||||
|
return
|
||||||
|
except Exception as ex:
|
||||||
|
print ("# ----- Not JSON: ----- ----- ----- ----- ----- ----- ----- ----- ----- -----")
|
||||||
|
print (text)
|
||||||
|
print (ex)
|
||||||
|
print ("# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----")
|
||||||
return
|
return
|
||||||
|
|
||||||
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
|
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
|
||||||
|
|||||||
Reference in New Issue
Block a user