~ubuntu-branches/ubuntu/natty/ntop/natty

« back to all changes in this revision

Viewing changes to www/Python/ntopTest.py

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2005-01-30 21:59:13 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050130215913-xc3ke963bw49b3k4
Tags: 2:3.0-5
* Updated README.Debian file so users will understand what to do at
  install, closes: #291794, #287802.
* Updated ntop init script to give better output.
* Also changed log directory from /var/lib/ntop to /var/log/ntop,
  closes: #252352.
* Quoted the interface list to allow whitespace, closes: #267248.
* Added a couple of logcheck ignores, closes: #269321, #269319.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import urllib, time
 
4
 
 
5
URL = "http://localhost:3000/dumpData.html?language=python"
 
6
 
 
7
print "Getting NTop stats in Python format"
 
8
statsText = ''
 
9
attempt = 1
 
10
# NTop takes a while to build the stats
 
11
while not statsText.count("hostNumIpAddress"):
 
12
        print "Attempt #" + str(attempt)
 
13
        try:
 
14
                statsText = urllib.urlopen(URL).read()
 
15
        except IOError:
 
16
                "NTop timed out, is it active?"
 
17
        assert statsText.count("ntopDict"), \
 
18
                "ntopDict not in output"
 
19
        assert attempt < 100, \
 
20
                "Could not get stats from NTop"
 
21
        attempt += 1
 
22
        # give it a little while
 
23
        time.sleep(2)
 
24
try:
 
25
        exec(statsText)
 
26
except:
 
27
        print "Problems interpreting the stats"
 
28
else:
 
29
        print "Found stats for the following hosts:"
 
30
        for host in ntopDict.keys():
 
31
                print host
 
32
print "All done."