import sys # form management form = cgi.FieldStorage() #instance.py?query=check&client='iphone'&version=<version> # what king of query? query = form.getvalue('query', default="") # What type of client? client = form.getvalue('client', default="") # What version of client? version = form.getvalue('version', default=0) version = float(version) data={} if ('check' == query.lower()): data['check'] = version >= 1.0 and client.lower() == "iphone" if ('interfaces' == query.lower()): interfaces = [] for i in range(interface.numInterfaces()): interfaces.append(interface.uniqueName(i)) data['interfaces'] = interfaces if ('host' == query.lower()): data['host'] = {'version': ntop.version(),'os': ntop.os(),'uptime': ntop.uptime()} ntop.sendHTTPHeader(1) # 1 = HTML ntop.sendString(json.dumps(data, sort_keys=False, indent=4))
# What type of client? client = form.getvalue('client', default="") # What version of client? version = form.getvalue('version', default=0) version = float(version) # What interface to query data from? selectedInterface = form.getvalue('interface', default="") data = {} for i in range(interface.numInterfaces()): # Only include selected interface/s if ((len(selectedInterface) == 0) or (selectedInterface == interface.uniqueName(i))): # =============================== # L A Y O U T E M I T T E R # =============================== # Try to do a layout for the specified interface if any. if ('layout' == query.lower()): #inits a layout ( a serie of containers ) layout = Layout() # ========================== # A Container for top hosts # ========================== container = WidgetContainer({ 'type': WidgetContainer.__WidgetContainerTypeHorizontalScrolling__, 'id': 'tophosts', 'label': 'tophosts'
# What type of client? client = form.getvalue("client", default="") # What version of client? version = form.getvalue("version", default=0) version = float(version) # What interface to query data from? selectedInterface = form.getvalue("interface", default="") data = {} for i in range(interface.numInterfaces()): # Only include selected interface/s if (len(selectedInterface) == 0) or (selectedInterface == interface.uniqueName(i)): # =============================== # L A Y O U T E M I T T E R # =============================== # Try to do a layout for the specified interface if any. if "layout" == query.lower(): # inits a layout ( a serie of containers ) layout = Layout() # ========================== # A Container for top hosts # ========================== container = WidgetContainer( { "type": WidgetContainer.__WidgetContainerTypeHorizontalScrolling__, "id": "tophosts", "label": "tophosts",
info['address'] = addr if ((len(mode) == 0) or not (mode == "list")): stats = {} stats['pktsStats'] = interface.pktsStats(i) stats['bytesStats'] = interface.bytesStats(i) stats['throughputStats'] = interface.throughputStats(i) ip = {} ip['tcp'] = interface.tcpStats(i) ip['udp'] = interface.udpStats(i) ip['icmp'] = interface.icmpStats(i) ip['ip'] = interface.ipStats(i) stats['securityPkts'] = interface.securityPkts(i) stats['netflowStats'] = interface.netflowStats(i) stats['sflowStats'] = interface.sflowStats(i) stats['cpacketStats'] = interface.cpacketStats(i) stats['ip'] = ip info['stats'] = stats rsp[interface.uniqueName(i)] = info except Exception as inst: print type(inst) # the exception instance print inst.args # arguments stored in .args print inst # __str__ allows args to printed directly ntop.sendHTTPHeader(1) # 1 = HTML ntop.sendString(json.dumps(rsp, sort_keys=True, indent=4))
form = cgi.FieldStorage() ifname = form.getvalue('if', default="") topic = form.getvalue('topic', default="") rsp = {} try: for i in range(interface.numInterfaces()): # Only include selected interface/s if ((len(ifname) == 0) or (ifname == interface.name(i))): # initialize output dictionary rsp[interface.uniqueName(i)] = {} if (len(topic) == 0 or topic.lower() == "interface"): # interface data is a grouped table. info_metadata = { "type": "groupedtable", "title": "Generic Interface Information" } info = {} # interface info # formerly other info if_info = {} if_info['name'] = interface.name(i) if_info['humanName'] = interface.humanName(i) if_info['virtual'] = interface.virtual(i)
if((len(mode) == 0) or not(mode == "list")): stats = {} stats['pktsStats'] = interface.pktsStats(i) stats['bytesStats'] = interface.bytesStats(i) stats['throughputStats'] = interface.throughputStats(i) ip = {} ip['tcp'] = interface.tcpStats(i) ip['udp'] = interface.udpStats(i) ip['icmp'] = interface.icmpStats(i) ip['ip'] = interface.ipStats(i) stats['securityPkts'] = interface.securityPkts(i) stats['netflowStats'] = interface.netflowStats(i) stats['sflowStats'] = interface.sflowStats(i) stats['cpacketStats'] = interface.cpacketStats(i) stats['ip'] = ip info['stats'] = stats rsp[interface.uniqueName(i)] = info except Exception as inst: print type(inst) # the exception instance print inst.args # arguments stored in .args print inst # __str__ allows args to printed directly ntop.sendHTTPHeader(1) # 1 = HTML ntop.sendString(json.dumps(rsp, sort_keys=True, indent=4))
#instance.py?query=check&client='iphone'&version=<version> # what king of query? query = form.getvalue('query', default="") # What type of client? client = form.getvalue('client', default="") # What version of client? version = form.getvalue('version', default=0) version = float(version) data = {} if ('check' == query.lower()): data['check'] = version >= 1.0 and client.lower() == "iphone" if ('interfaces' == query.lower()): interfaces = [] for i in range(interface.numInterfaces()): interfaces.append(interface.uniqueName(i)) data['interfaces'] = interfaces if ('host' == query.lower()): data['host'] = { 'version': ntop.version(), 'os': ntop.os(), 'uptime': ntop.uptime() } ntop.sendHTTPHeader(1) # 1 = HTML ntop.sendString(json.dumps(data, sort_keys=False, indent=4))
form = cgi.FieldStorage(); ifname = form.getvalue('if', default="") topic = form.getvalue('topic', default="") rsp = {} try: for i in range(interface.numInterfaces()): # Only include selected interface/s if((len(ifname) == 0) or (ifname == interface.name(i))): # initialize output dictionary rsp[interface.uniqueName(i)] = {} if (len(topic) == 0 or topic.lower() == "interface"): # interface data is a grouped table. info_metadata = { "type":"groupedtable", "title":"Generic Interface Information" } info = {} # interface info # formerly other info if_info = {} if_info['name'] = interface.name(i) if_info['humanName'] = interface.humanName(i) if_info['virtual'] = interface.virtual(i) if_info['speed'] = interface.speed(i) if_info['mtu'] = interface.mtu(i) if_info['bpf'] = interface.bpf(i)