loglib

package
v0.0.0-...-d735682 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2013 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package loglib implements some remote logging mechanisms

Index

Constants

View Source
const (
	// EMERGENCY is the highest level
	EMERGENCY = LogLevel(iota)
	// ALERT is the alert level
	ALERT
	// CRITICAL syslog level
	CRITICAL
	// ERROR syslog level
	ERROR
	// WARNING syslog level
	WARNING
	// NOTICE syslog level
	NOTICE
	// INFO syslog level
	INFO
	// DEBUG syslog level
	DEBUG
)
View Source
const ElasticSearchPathPrefix = "/woodchuck/gelf"

ElasticSearchPathPrefix is the path prefix storing data in ElasticSearch

Variables

View Source
var LevelNames = [8]string{"EMERGENCY", "ALERT", "CRITICAL", "ERROR",
	"WARNING", "NOTICE", "INFO", "DEBUG"}

LevelNames is the names of the levels

View Source
var StoreCh chan *Message

StoreCh is the channel for messages to be stored

View Source
var (
	//TransportConfig is the configset for transportation settings
	TransportConfig = config.NewConfigSet("transportation settings", config.ExitOnError)
)

Functions

func BuildAlerters

func BuildAlerters(tree ConfigTree) (destinations map[string]Alerter, err error)

BuildAlerters builds the alerters map from the config tree

func BuildMatchers

func BuildMatchers(tree ConfigTree) (matchers map[string]Matcher, err error)

BuildMatchers builds the matchers from the configuration

func Call

func Call(uri, username, password, name string, args ...interface{}) (
	interface{}, *xmlrpc.Fault, error)

Call is an xmlrpc.Call, but without gzip and Basic Auth and strips non-xml

func FromGelfJSON

func FromGelfJSON(text []byte, m *Message) error

FromGelfJSON reads the GELF JSON into the message

func ListenGelfHTTP

func ListenGelfHTTP(port int, ch chan<- *Message) error

ListenGelfHTTP listens on the given HTTP port for multipart/form POST requests such as curl -v -F timestamp=$(date '+%s') -F short=abraka -F host=$(hostname) -F full=dabra -F facility=proba -F level=6 http://unowebprd:12203/

func ListenGelfTCP

func ListenGelfTCP(port int, ch chan<- *Message) error

ListenGelfTCP listen on the given TCP port for full, possibly compressed GELF messages put every message into the channel

func ListenGelfUDP

func ListenGelfUDP(port int, ch chan<- *Message) error

ListenGelfUDP listens on the given UDP port for possibly chunked GELF messages put every complete message into the channel

func NewEmailSender

func NewEmailSender(from, hostport, auth string) (es emailSender)

NewEmailSender returns a new EmailSender

func NewMantisSender

func NewMantisSender() (ms *mantisSender)

NewMantisSender returns a new Mantis sender

func NewRateLimiter

func NewRateLimiter(eviction time.Duration) *nextMap

NewRateLimiter implements a simple time-evicted rate-limiting map

func NewTwilio

func NewTwilio(from, sid, token string) twilioClient

NewTwilio returns a new Twilio SMS transport

func UnboxGelf

func UnboxGelf(rc io.ReadCloser, m *gelf.Message) (err error)

UnboxGelf unboxes a GELF message: decompress and decode from JSON

Types

type Alerter

type Alerter interface {
	Send(*Message, SenderProvider) error
}

Alerter is a message sender interface

type ConfigTree

type ConfigTree interface {
	// Get the value at key in the TomlTree. Key is a dot-separated path (e.g. a.b.c). Returns nil if the path does not exist in the tree.
	Get(key string) interface{}
	// Keys returns the keys of the toplevel tree. Warning: this is a costly operation.
	Keys() []string
}

ConfigTree is an interface for configuration tree (think TOML)

type ElasticSearch

type ElasticSearch struct {
	URL *url.URL
	// contains filtered or unexported fields
}

ElasticSearch context

func NewElasticSearch

func NewElasticSearch(urls string, ttld int) *ElasticSearch

NewElasticSearch returns a new ElasticSearch message store

func (ElasticSearch) Store

func (es ElasticSearch) Store(m *Message) (*esResponse, error)

Store stores a message

type EmailSender

type EmailSender interface {
	Send(to []string, subject string, body []byte) error
}

EmailSender is the email sender interface (multiple to, a subject and a []byte body)

type LogLevel

type LogLevel int

LogLevel is the logging level, copied from syslog

type MantisSender

type MantisSender interface {
	Send(uri, subject, body string) (int, error)
}

MantisSender is an interface for an issue tracker injector

type Matcher

type Matcher interface {
	Match(m *Message) bool
}

Matcher is an interface for message filtering (matching)

type Message

type Message gelf.Message

Message is a gelf.Message wrapper

func AsMessage

func AsMessage(gm *gelf.Message) *Message

AsMessage is a type conversion + some fixes

func (*Message) Fix

func (m *Message) Fix()

Fix fixes some GELF quirks (_full_message => Full)

func (*Message) Long

func (m *Message) Long() string

Long returns a short representation of the message

func (*Message) MarshalJSON

func (m *Message) MarshalJSON() ([]byte, error)

MarshalJSON returns the message marshaled to JSON

func (*Message) String

func (m *Message) String() string

String returns a short representation of the message

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON into the message

type RateLimiter

type RateLimiter interface {
	Put(time.Duration, string) bool
}

RateLimiter is an interface for a time-evicted rate-limiting map

type Rule

type Rule struct {
	Name string
	If   []Matcher
	Then []Alerter
}

Rule has a name, some conditions (If) and some consequences (Then) The If Matchers chained with AND

func BuildRules

func BuildRules(tree ConfigTree, matchers map[string]Matcher, alerters map[string]Alerter) (rules []Rule, err error)

BuildRules builds the rules from the config and the already compiled matchers and alerters

func (Rule) Do

func (rul Rule) Do(m *Message, s SenderProvider) (err error)

Do does what the Then consequences contain. returns all consequenses, joined

func (Rule) Match

func (rul Rule) Match(m *Message) bool

Match AND-matches all If conditions

type SMSSender

type SMSSender interface {
	Send(to, message string) error
}

SMSSender is the SMS sender interface (just to and from)

type SenderProvider

type SenderProvider interface {
	GetSMSSender(string) SMSSender
	GetEmailSender(string) EmailSender
	GetMantisSender(string) MantisSender
}

SenderProvider is an interface for returning the specific senders

type Server

type Server struct {
	Rules    []Rule
	Matchers map[string]Matcher
	Alerters map[string]Alerter
	// contains filtered or unexported fields
}

Server is the server context

func LoadConfig

func LoadConfig(transports, filters string) (s *Server, err error)

LoadConfig loads the config read from the transports and filters TOML files

func (Server) GetEmailSender

func (s Server) GetEmailSender(txt string) EmailSender

GetEmailSender returns the EmailSender, if not above rate limit

func (Server) GetMantisSender

func (s Server) GetMantisSender(txt string) MantisSender

GetMantisSender returns the MantisSender, if not above rate limit

func (Server) GetSMSSender

func (s Server) GetSMSSender(txt string) SMSSender

GetSMSSender returns the SMSSender, implementing rate limiting

func (*Server) Serve

func (s *Server) Serve()

Serve receives messages

func (*Server) Start

func (s *Server) Start()

Start starts the needed support goroutines

Jump to

Keyboard shortcuts

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