Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from zallison/baseline_settings
Baseline settings
- Loading branch information
Showing
8 changed files
with
144 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env python | ||
|
||
"""Cache""" | ||
|
||
from twisted.names.cache import CacheResolver | ||
|
||
|
||
class Cache(CacheResolver): | ||
|
||
foghorn = None | ||
peer_address = None | ||
|
||
def query(self, query, timeout=0): | ||
self.foghorn.run_hook("query", self.peer_address, query) | ||
resp = CacheResolver.query(self, query, timeout) | ||
if resp and self.foghorn: | ||
self.foghorn.run_hook("cache", query) | ||
return resp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
""" base --- hooks for foghornd """ | ||
|
||
import logging | ||
from foghornd.plugins.hooks import HooksBase | ||
from datetime import datetime, timedelta | ||
|
||
""" | ||
This module exposes hooks allowing plugins to extend the | ||
functionality of foghorn. This base module contains stubs of all the | ||
hooks available. Please check the documentation for each hook for | ||
more information | ||
""" | ||
|
||
|
||
class Stats(HooksBase): | ||
"""Hooks for foghorn""" | ||
last = datetime.now() | ||
lists = {} | ||
timeout = 60 # How often to print messages | ||
|
||
class TimedList(list): | ||
def __init__(self, timeout=60): | ||
self.timeout = timeout | ||
|
||
def _clearold(self): | ||
oldtime = datetime.now() - timedelta(seconds=self.timeout) | ||
self[:] = [x for x in self if x["time"] > oldtime] | ||
|
||
def append(self, obj): | ||
list.append(self, {"time": datetime.now(), "obj": obj}) | ||
self._clearold() | ||
|
||
def checkstat(self, name): | ||
try: | ||
self.lists[name].append(1) | ||
except KeyError: | ||
self.lists[name] = self.TimedList() | ||
self.lists[name].append(1) | ||
|
||
if datetime.now() - timedelta(seconds=self.timeout) > self.last: | ||
for log in self.lists.keys(): | ||
self.lists[log]._clearold() | ||
self.foghorn.logging.info("{} rate: {} per minute".format(log, len(self.lists[log]))) | ||
self.last = datetime.now() | ||
|
||
def query(self, peer, query): | ||
"""Called for every query before processing""" | ||
self.checkstat("query") | ||
|
||
def failed_acl(self, peer, query): | ||
"""A query has failed the ACL""" | ||
self.checkstat("failed_acl") | ||
|
||
def no_acl(self, peer, query): | ||
"""A query type has no ACL""" | ||
self.checkstat("no_acl") | ||
|
||
def passed(self, peer, query): | ||
"""A query type has passed greylisting""" | ||
self.checkstat("passed") | ||
|
||
def upstream_error(self, peer, query): | ||
"""Failure resolving this query""" | ||
self.checkstat("upstream_error") | ||
|
||
def sinkhole(self, peer, query): | ||
"""A query will be sinkholed""" | ||
self.checkstat("sinkhole") | ||
|
||
def refused(self, peer, query): | ||
"""A query has been refused""" | ||
self.checkstat("refused") | ||
|
||
def whitelist(self, peer, query): | ||
"""A query has passed the whitelist""" | ||
self.checkstat("whitelist") | ||
|
||
def blacklist(self, peer, query): | ||
"""A query has failed the blacklist""" | ||
self.checkstat("blacklist") | ||
|
||
def greylist_passed(self, peer, query, msg): | ||
"""A query has failed the blacklist""" | ||
self.checkstat("greylist_passed") | ||
|
||
def greylist_failed(self, peer, query, msg): | ||
"""A query has failed the blacklist""" | ||
self.checkstat("greylist_failed") | ||
|
||
def cache(self, query): | ||
self.checkstat("cache") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters