import urllib
import http.cookiejar
import ssl
import xml.etree.ElementTree as ET
import json
import argparse
from paepy.ChannelDefinition import CustomSensorResult

parser = argparse.ArgumentParser()
parser.add_argument("prtg", help="PRTG String")
args = parser.parse_args()
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
cookiejar = http.cookiejar.CookieJar()
cookiejar.clear_session_cookies()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookiejar),urllib.request.HTTPSHandler(context=context))

parameters = json.loads(args.prtg);
host = parameters.get('host')
user = parameters.get('linuxloginusername') 
password = parameters.get('linuxloginpassword') 
baseURL = 'https://' + host + ':8080'

url = baseURL + '/agent/login'
data = '<methodCall><methodName>login</methodName><params><param><value><struct><member><name>password</name><value><string>' + password +'</string></value></member><member><name>user</name><value><string>' + user + '</string></value></member><member><name>domain</name><value><string>Firebox-DB</string></value></member><member><name>uitype</name><value><string>2</string></value></member></struct></value></param></params></methodCall>'

req = urllib.request.Request(url, data.encode('utf-8'))
response = opener.open(req)
xmlUserInformation = response.read()

root = ET.fromstring(xmlUserInformation)
sid = root[0][0][0][0][0][1].text
csrfToken = root[0][0][0][0][1][1].text

url = baseURL + '/auth/login'
values = [('username', user),
          ('password', password),
          ('domain','Firebox-DB'),
          ('sid',sid),
          ('privilege',1),
          ('from_page','/')]

data = urllib.parse.urlencode(values)
req = urllib.request.Request(url=url,data=data.encode('utf-8'))
response = opener.open(req)

url = baseURL + '/dashboard/dboard_get_interfaces?id=undefined'
req = urllib.request.Request(url)
response = opener.open(req)

# Parse JSON
interfaces = json.loads(response.read().decode('utf8'));
xmlList = interfaces.get('interface_list');

# Parse XML
list = ET.fromstring(xmlList)
if list.getchildren()[0].tag == 'cluster':
    list = list.find('cluster').find('aggregate')
list_interfaces = list.find('network').find('interface_list')
list_interfaces = list.find('network').find('interface_list')

count_external_interfaces = 0
failed_interfaces = []
for interface in list_interfaces.getchildren():
    if interface.find('enabled').text == '1' and interface.find('zone').text == 'External':
        count_external_interfaces += 1
        if interface.find('wan_target_status').text == '0':
            failed_interfaces.append(interface.find('ifalias').text)

message = 'WAN Status: Error';
status = 2
if len(failed_interfaces) is 0:
    message = 'OK'
    status = 0

sensor = CustomSensorResult(message) 
sensor.add_channel(channel_name="Status",unit="Count",value=status,is_limit_mode=True,limit_max_error=0.5,limit_error_msg="At least one WAN is not available!", primary_channel=True)
sensor.add_channel(channel_name="Number of failed interfaces",unit="Count",value=len(failed_interfaces),is_limit_mode=True,limit_max_error=0.5)
print(sensor.get_json_result())

@@ -531,16 +531,54 @@
 kiejar),
+%0A                                     
 urllib.r
@@ -725,17 +725,16 @@
 ername')
- 
 %0Apasswor
@@ -773,17 +773,16 @@
 ssword')
- 
 %0AbaseURL
@@ -982,16 +982,17 @@
 ssword +
+ 
 '%3C/strin
@@ -1637,16 +1637,17 @@
 domain',
+ 
 'Firebox
@@ -1670,16 +1670,17 @@
  ('sid',
+ 
 sid),%0A  
@@ -1700,16 +1700,17 @@
 vilege',
+ 
 1),%0A    
@@ -1728,16 +1728,17 @@
 m_page',
+ 
 '/')%5D%0A%0Ad
@@ -1811,16 +1811,17 @@
 url=url,
+ 
 data=dat
@@ -2877,17 +2877,16 @@
 message)
- 
 %0Asensor.
@@ -2919,16 +2919,17 @@
 Status%22,
+ 
 unit=%22Co
@@ -2929,24 +2929,25 @@
 nit=%22Count%22,
+ 
 value=status
@@ -2947,16 +2947,17 @@
 =status,
+ 
 is_limit
@@ -2959,32 +2959,33 @@
 limit_mode=True,
+ 
 limit_max_error=
@@ -2988,16 +2988,36 @@
 ror=0.5,
+%0A                   
 limit_er
@@ -3146,16 +3146,17 @@
 rfaces%22,
+ 
 unit=%22Co
@@ -3160,16 +3160,17 @@
 %22Count%22,
+ 
 value=le
@@ -3190,16 +3190,36 @@
 rfaces),
+%0A                   
 is_limit
@@ -3229,16 +3229,17 @@
 de=True,
+ 
 limit_ma

Reformat code