convert to using pybindxml for scraping zone/server information from bind in server zone list
This commit is contained in:
parent
c2daf46358
commit
d8900c4075
|
@ -10,6 +10,7 @@ Packages:
|
||||||
|
|
||||||
* [Django](http://www.djangoproject.com)
|
* [Django](http://www.djangoproject.com)
|
||||||
* Python Modules
|
* Python Modules
|
||||||
|
* [pybindxml](https://pypi.python.org/pypi?name=pybindxml&:action=display): This is a shared library I wrote to scrape and stick into Python dict objects various server/zone data from a BIND DNS server.
|
||||||
* [python-beautifulsoup](http://www.crummy.com/software/BeautifulSoup/)
|
* [python-beautifulsoup](http://www.crummy.com/software/BeautifulSoup/)
|
||||||
* [python-dnspython](http://www.dnspython.org/)
|
* [python-dnspython](http://www.dnspython.org/)
|
||||||
* [python-sqlite](http://docs.python.org/2/library/sqlite3.html) (If you will be using Sqlite for server and key storage)
|
* [python-sqlite](http://docs.python.org/2/library/sqlite3.html) (If you will be using Sqlite for server and key storage)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import urllib2
|
||||||
|
|
||||||
# 3rd Party
|
# 3rd Party
|
||||||
from BeautifulSoup import BeautifulStoneSoup as BS
|
from BeautifulSoup import BeautifulStoneSoup as BS
|
||||||
|
from pybindxml import reader as bindreader
|
||||||
import dns.exception
|
import dns.exception
|
||||||
import dns.query
|
import dns.query
|
||||||
import dns.tsig
|
import dns.tsig
|
||||||
|
@ -70,28 +71,9 @@ class BindServer(models.Model):
|
||||||
String zone_class,
|
String zone_class,
|
||||||
String zone_serial }
|
String zone_serial }
|
||||||
"""
|
"""
|
||||||
zone_req = urllib2.Request("http://%s:%s" % (self.hostname, self.statistics_port))
|
zone_data = bindreader.BindXmlReader(host=self.hostname, port=self.statistics_port)
|
||||||
try:
|
zone_data.get_stats()
|
||||||
http_request = urllib2.urlopen(zone_req)
|
return zone_data
|
||||||
except urllib2.URLError, err:
|
|
||||||
raise exceptions.ZoneException(err)
|
|
||||||
|
|
||||||
return_array = []
|
|
||||||
xmloutput = http_request.read()
|
|
||||||
mysoup = BS(xmloutput)
|
|
||||||
views = mysoup.findAll("view")
|
|
||||||
for view in views:
|
|
||||||
view_name = view.find("name").string
|
|
||||||
for zone in view.findAll("zone"):
|
|
||||||
zone_name, zone_class = zone.find("name").string.split("/")
|
|
||||||
zone_serial = zone.find("serial").string
|
|
||||||
if zone_class == "IN":
|
|
||||||
return_array.append({"view_name" : view_name,
|
|
||||||
"zone_name" : zone_name,
|
|
||||||
"zone_class" : zone_class,
|
|
||||||
"zone_serial" : zone_serial })
|
|
||||||
|
|
||||||
return return_array
|
|
||||||
|
|
||||||
def list_zone_records(self, zone_name):
|
def list_zone_records(self, zone_name):
|
||||||
""" List all records in a specific zone.
|
""" List all records in a specific zone.
|
||||||
|
|
|
@ -10,19 +10,19 @@ Server Zone List for {{ dns_server }}
|
||||||
<tr>
|
<tr>
|
||||||
<th>Zone</th>
|
<th>Zone</th>
|
||||||
<th>View</th>
|
<th>View</th>
|
||||||
<th>Class</th>
|
|
||||||
<th>Serial Number</th>
|
<th>Serial Number</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for current_zone in zone_array %}
|
{% for current_zone, cz_data in zone_array.stats.zone_stats.iteritems %}
|
||||||
|
{% for current_view, cv_data in cz_data.iteritems %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<a href="{% url "zone_list" dns_server=dns_server zone_name=current_zone.zone_name %}"> {{ current_zone.zone_name }}</a>
|
<a href="{% url "zone_list" dns_server=dns_server zone_name=current_zone %}"> {{ current_zone }}</a>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ current_zone.view_name }}</td>
|
<td>{{ current_view }}</td>
|
||||||
<td>{{ current_zone.zone_class }}</td>
|
<td>{{ cv_data.serial }}</td>
|
||||||
<td>{{ current_zone.zone_serial }}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{% endblock body %}
|
{% endblock body %}
|
||||||
|
|
|
@ -23,6 +23,12 @@ except ImportError:
|
||||||
print "Package is typically called 'python-dnspython.'\n"
|
print "Package is typically called 'python-dnspython.'\n"
|
||||||
errors += 1
|
errors += 1
|
||||||
|
|
||||||
|
try:
|
||||||
|
import pybindxml
|
||||||
|
except ImportError:
|
||||||
|
print "Could not import pybindxml. This is a required module for Binder.\n"
|
||||||
|
errors += 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import flup
|
import flup
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
Loading…
Reference in New Issue