Skip to content

Commit

Permalink
Using the extended log file format for HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
danielquinn committed Dec 15, 2015
1 parent ac3f481 commit b955a65
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
44 changes: 43 additions & 1 deletion ripe/atlas/tools/renderers/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,54 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from ..helpers.colours import colourise

from .base import Renderer as BaseRenderer
from .base import Result


class Renderer(BaseRenderer):
"""
We're abusing the Extended Log File Format here to render the result,
amending it to include a few things not originally specified in the W3C
Working Draft: http://www.w3.org/TR/WD-logfile.html Namely:
http-version, header-bytes, and body-bytes
"""

RENDERS = [BaseRenderer.TYPE_HTTP]
COLOURS = {
"2": "green",
"3": "blue",
"4": "yellow",
"5": "red"
}

def on_result(self, result, probes=None):
print("Not ready yet\n")
r = "#Version: 1.0\n#Date: {}\n#Fields: {}\n".format(
result.created.strftime("%Y-%m-%d %H:%M:%S"),
"cs-method cs-uri c-ip s-ip sc-status time-taken http-version "
"header-bytes body-bytes"
)
for response in result.responses:
r += self._colourise_by_status(
"{} {} {} {} {} {} {} {} {}\n".format(
result.method,
result.uri,
response.source_address,
response.destination_address,
response.code,
response.response_time,
response.version,
response.head_size,
response.body_size
),
response.code
)

return Result(r + "\n", result.probe_id)

def _colourise_by_status(self, output, status):
try:
return colourise(output, self.COLOURS[str(status)[0]])
except (IndexError, KeyError):
return colourise(output, "red")
2 changes: 2 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .helpers import TestArgumentTypeHelper
from .renderers import (
TestPingRenderer,
TestHttpRenderer,
TestSSLConsistency,
TestAggregatePing,
TestRawRenderer,
Expand All @@ -37,6 +38,7 @@
TestReportCommand,
TestArgumentTypeHelper,
TestPingRenderer,
TestHttpRenderer,
TestSSLConsistency,
TestAggregatePing,
TestRawRenderer,
Expand Down
2 changes: 2 additions & 0 deletions tests/renderers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from .ping import TestPingRenderer
from .http import TestHttpRenderer
from .aggregate_ping import TestAggregatePing
from .ssl_consistency import TestSSLConsistency
from .raw import TestRawRenderer

__all__ = [
TestPingRenderer,
TestHttpRenderer,
TestAggregatePing,
TestSSLConsistency
]

0 comments on commit b955a65

Please sign in to comment.