grok

package module
v0.0.0-...-bc78e91 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2015 License: Apache-2.0 Imports: 7 Imported by: 4

README

GoDoc Build Status Coverage Status Documentation Status

grok

simple library to use/parse grok patterns with go

Installation

Make sure you have the a working Go environment.

go get github.com/gemsi/grok

Use in your project

import "github.com/gemsi/grok"

Example

package main

import (
	"fmt"

	"github.com/gemsi/grok"
)

func main() {
	g := grok.New()
	values, _ := g.Parse("%{COMMONAPACHELOG}", `127.0.0.1 - - [23/Apr/2014:22:58:32 +0200] "GET /index.php HTTP/1.1" 404 207`)

	for k, v := range values {
		fmt.Printf("%+15s: %s\n", k, v)
	}
}

output:

       response: 404
          bytes: 207
               : 207
       HOSTNAME: 127.0.0.1
       USERNAME: -
       MONTHDAY: 23
        request: /index.php
      BASE10NUM: 207
           IPV6: 
           auth: -
      timestamp: 23/Apr/2014:22:58:32 +0200
           verb: GET
    httpversion: 1.1
           TIME: 22:58:32
           HOUR: 22
COMMONAPACHELOG: 127.0.0.1 - - [23/Apr/2014:22:58:32 +0200] "GET /index.php HTTP/1.1" 404 207
       clientip: 127.0.0.1
             IP: 
          ident: -
          MONTH: Apr
           YEAR: 2014
         SECOND: 32
            INT: +0200
           IPV4: 
         MINUTE: 58
     rawrequest: 

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Grok

type Grok struct {
	// contains filtered or unexported fields
}

Grok Type

func New

func New() *Grok

New returns a Grok struct

func (*Grok) AddPattern

func (g *Grok) AddPattern(name string, pattern string)

AddPattern add a named pattern to grok

func (*Grok) AddPatternsFromPath

func (g *Grok) AddPatternsFromPath(path string) error

AddPatternsFromPath loads grok patterns from a file or files from a directory

func (*Grok) Match

func (g *Grok) Match(pattern, text string) (bool, error)

Match returns true when text match the compileed pattern

func (*Grok) Parse

func (g *Grok) Parse(pattern string, text string) (map[string]string, error)

Parse returns a string map with captured string based on provided pattern over the text

func (*Grok) ParseToMultiMap

func (g *Grok) ParseToMultiMap(pattern string, text string) (map[string][]string, error)

ParseToMultiMap works just like Parse, except that it allows to map multiple values to the same capture name.

Jump to

Keyboard shortcuts

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