frontreport

package module
v2.2.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2017 License: BSD-2-Clause-Views Imports: 0 Imported by: 4

README

Build Status Go Report Card

What is this tool for?

Frontreport is useful only if you have an existing infrastructure for backend log aggregation. For example, we use ELK stack with RabbitMQ as a broker on top. So, your logging infrastructure may look like this:

Backend application → Logstash → RabbitMQ → Elastic RabbitMQ River → Elastic → Kibana

You may want to reuse this infrastructure to collect frontend logs from browsers of your visitors. So, you need to replace Logstash in the above scheme with something fast that can validate incoming JSON and manage high load by batching documents.

Frontreport does all that. Resulting architecture is something like:

Browser → Frontreport → RabbitMQ → Elastic RabbitMQ River → Elastic → Kibana

See code for details or ask us on Gitter.

Usage

Usage:
  frontreport [OPTIONS]

Application Options:
  -p, --port=            port to listen (default: 8888) [$FRONTREPORT_PORT]
  -a, --amqp=            AMQP connection string (default: amqp://guest:guest@localhost:5672/) [$FRONTREPORT_AMQP]
  -l, --logfile=         log file name (writes to stdout if not specified) [$FRONTREPORT_LOGFILE]
  -g, --graphite=        Graphite connection string for internal metrics [$FRONTREPORT_GRAPHITE]
  -r, --graphite-prefix= prefix for Graphite metrics [$FRONTREPORT_GRAPHITE_PREFIX]
  -v, --version          print version and exit

Help Options:
  -h, --help             Show this help message

What can you collect from browsers?

  1. CSP violation reports. CSP stands for Content Security Policy. Send reports to /csp, /csp/, /_reports/csp or basically any URL that contains substring csp.
  2. HPKP violation reports. HPKP stands for HTTP Public Key Pinning. URL must contain substring pkp.
  3. StacktraceJS reports. StacktraceJS is a JS library that collects unified stacktrace reports from any browser. URL must contain substring stacktracejs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSPReport

type CSPReport struct {
	Report
	Body struct {
		DocumentURI        string `json:"document-uri"`
		Referrer           string `json:"referrer"`
		BlockedURI         string `json:"blocked-uri"`
		ViolatedDirective  string `json:"violated-directive"`
		EffectiveDirective string `json:"effective-directive"`
		OriginalPolicy     string `json:"original-policy"`
	} `json:"csp-report"`
}

CSPReport is a Content Security Policy report as per http://www.w3.org/TR/CSP/

func (CSPReport) GetType

func (c CSPReport) GetType() string

GetType returns report type

type Logger

type Logger interface {
	Log(...interface{}) error
}

Logger is a simple logging wrapper interface

type MetricCounter

type MetricCounter interface {
	Inc(int64)
}

MetricCounter is a simple counter

type MetricHistogram

type MetricHistogram interface {
	Update(int64)
}

MetricHistogram is a simple histogram

type MetricStorage

type MetricStorage interface {
	RegisterHistogram(string) MetricHistogram
	RegisterCounter(string) MetricCounter
}

MetricStorage is a way to store internal application metrics

type PKPReport

type PKPReport struct {
	Report
	DateTime                  string   `json:"date-time"`
	Hostname                  string   `json:"hostname"`
	Port                      int      `json:"port"`
	EffectiveExpirationDate   string   `json:"effective-expiration-date"`
	IncludeSubdomains         bool     `json:"include-subdomains"`
	NotedHostname             string   `json:"noted-hostname"`
	ServedCertificateChain    []string `json:"served-certificate-chain"`
	ValidatedCertificateChain []string `json:"validated-certificate-chain"`
	KnownPins                 []string `json:"known-pins"`
}

PKPReport is a Public Key Pinning report as per https://tools.ietf.org/html/draft-ietf-websec-key-pinning-21

func (PKPReport) GetType

func (p PKPReport) GetType() string

GetType returns report type

type Report

type Report struct {
	Timestamp string `json:"@timestamp"`
	Host      string `json:"frontreport-host"`
}

Report is a generic report type (they don't have much in common)

func (*Report) SetHost

func (r *Report) SetHost(h string)

SetHost sets hostname to tell apart reports from different sites

func (*Report) SetTimestamp

func (r *Report) SetTimestamp(ts string)

SetTimestamp sets timestamp for Elastic default sorting

type ReportStorage

type ReportStorage interface {
	AddReport(Reportable)
}

ReportStorage is a way to store incoming reports

type Reportable

type Reportable interface {
	GetType() string
	SetTimestamp(string)
	SetHost(string)
}

Reportable structs can be saved to Elastic - their Type defines index to save to; - they can hold Timestamp for Elastic to sort on.

type Service added in v1.1.0

type Service interface {
	Start() error
	Stop() error
}

Service is started and stopped in main function, which assembles services into a working application

type StacktraceJSReport

type StacktraceJSReport struct {
	Report
	Message string `json:"message"`
	Stack   []struct {
		FunctionName string `json:"functionName"`
		FileName     string `json:"fileName"`
		LineNumber   int    `json:"lineNumber"`
		ColumnNumber int    `json:"columnNumber"`
	} `json:"stack"`

	// These fields are not a part of StacktraceJS specification, but are useful for error reports
	Browser *struct {
		Name    string `json:"name,omitempty"`
		Version string `json:"version,omitempty"`
	} `json:"browser,omitempty"`
	OS *struct {
		Name    string `json:"name,omitempty"`
		Version string `json:"version,omitempty"`
	} `json:"os,omitempty"`
	URL       string `json:"url,omitempty"`
	UserID    string `json:"userId,omitempty"`
	StackHash string `json:"stackHash,omitempty"`
	ScriptURL string `json:"scriptUrl,omitempty"`
}

StacktraceJSReport is a universal browser stacktrace format as per https://github.com/stacktracejs/stacktrace.js#stacktracereportstackframes-url-message--promisestring

func (StacktraceJSReport) GetType

func (s StacktraceJSReport) GetType() string

GetType returns report type

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL