Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
firstline1
titlewireless.py
linenumberstrue
#!/usr/bin/python

import subprocess
import datetime
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

def return_command_output(command):
    proc = subprocess.Popen(command, stdout = subprocess.PIPE, shell = True)
    (out, err) = proc.communicate()
    out_without_carriage_return = out.rstrip('\n')
    return out_without_carriage_return

def parse_iwconfig():
    command1 = "sudo iwconfig wlan0 | grep \"Link Quality\""
    command1_output = return_command_output(command1)
    command1_output = ' '.join(command1_output.split())
    command1_parsed = command1_output.split(" ")
    link_quality = command1_parsed[1].split("=")[1]
    link_quality = link_quality.split("/")[0]
    signal_level = command1_parsed[3].split("=")[1]
    command2 = "sudo iwconfig wlan0 | grep \"Tx-Power\""
    command2_output = return_command_output(command2)
    command2_output = ' '.join(command2_output.split())
    command2_parsed = command2_output.split(" ")
    bit_rate = command2_parsed[1].split("=")[1]
    tx_power = command2_parsed[3].split("=")[1]

    timestamp = int(datetime.datetime.now().strftime("%s")) * 1000
    probeNo = "WHP_NUMBER"

    headers = {'content-type':"application/json"}
    data = "{\"timestamp\":" + str(timestamp) + ", \"bitRate\":" + bit_rate + ", \"txPower\":" + tx_power + ", \"linkQuality\":" + link_quality + ", \"signalLevel\":" + signal_level + ", \"probeNo\":\"" + probeNo + "\"}"
    try:
        session = requests.Session()
        session.verify = False
        session.post(url='https://WAS_FQDN:8443/wifimon/probes/', data=data, headers=headers, timeout=15)
    except:
        pass
    return None

if __name__ == "__main__":
    parse_iwconfig()

User has to edit lines 31 and 38 according to their setupthe network configuration of the key WiFiMon components. In line 31, "WHP_NUMBER" should match the number assigned to the testtools of the particular WiFiMon Hardware Probe (WHP), e.g. for the WHP assigned the number 1, the value should be "1". Assigning numbers to WHPs is possible by appropriately setting the testtool attribute included in the websites monitored by them. More information related to assigning number to WHPs is available in the WiFiMon Test Server installation guide. In line 38, "WAS_FQDN" should match the FQDN of the WiFiMon Analysis Server (WAS) responsible for processing the wireless performance metrics of the WHP. The above code block assumes that the WAS uses the WiFiMon Secure Agent. In case of using the WiFiMon Non-Secure Agent, the URL of line 38 should be modified; instead of " https ", the WiFiMon Non-Secure Agent requires "http" and the port on which the WAS listens is "9000" instead of "8443"port 8443. It is possible to use http in which case WAS listens on port 9000 instead of 8443.

That's all! At this point you may (optionally) unplug the keyboard, the mouse and the monitor and let the WHP measure the performance of your wireless network!