logranger

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

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

Go to latest
Published: Nov 28, 2025 License: MIT Imports: 20 Imported by: 0

README

Logranger

GoDoc Go Report Card REUSE status buy ma a coffee

Note: Logranger is still WIP

Introduction

Logranger is a powerful and intelligent log processing tool written in Go. Its main purpose is to efficiently process a large number of incoming syslog messages, enabling you filter for specific events and perform actions based on the received events.

Features

  • Efficient log processing: Logranger is based on the performand go-parsesyslog package and can handle and analyze large volumes of syslog messages without compromising on its speed or performance.
  • Powerful rule-based filtering: You can filter for log events based on a rules that specify regular expressions to match the events.
  • Customization: Logranger is easily customizable. Its easy to implement plugin interface allows you to write your own plugins to perform custom actions with your events.
  • Custom templates: Matched (or sub-matched) event log messages can be processed using Go's versatile templating language.

Plugins

By default Logranger ships with a varity of action plugins:

  • File action: Store the matched (or a sub-match) event log messages in a file. The file can be used in overwrite or append mode.

License

Logranger is released under the MIT License.

Support

If you encounter any problems while using Logranger, please create an issue in this repository. We appreciate any feedback or suggestions for improving Logranger.

Documentation

Index

Constants

View Source
const (
	// LogErrKey is the keyword used in slog for error messages
	LogErrKey = "error"
)

Variables

View Source
var ErrCertConfigEmpty = errors.New("certificate and key paths are required for listener type: TLS")

ErrCertConfigEmpty is returned if a TLS listener is configured but ot certificate or key paths are set

Functions

func NewConnectionID

func NewConnectionID() string

NewConnectionID generates a new unique message ID using a random number generator and returns it as a hexadecimal string.

func NewListener

func NewListener(config *Config) (net.Listener, error)

NewListener initializes and returns a net.Listener based on the provided configuration. It takes a pointer to a Config struct as a parameter. Returns the net.Listener and an error if any occurred during initialization.

Types

type Config

type Config struct {
	// Server holds server specific configuration values
	Server struct {
		PIDFile  string `fig:"pid_file" default:"/var/run/logranger.pid"`
		RuleFile string `fig:"rule_file" default:"etc/logranger.rules.toml"`
	}
	Listener struct {
		ListenerUnix struct {
			Path string `fig:"path" default:"/var/tmp/logranger.sock"`
		} `fig:"unix"`
		ListenerTCP struct {
			Addr string `fig:"addr" default:"0.0.0.0"`
			Port uint   `fig:"port" default:"9099"`
		} `fig:"tcp"`
		ListenerTLS struct {
			Addr     string `fig:"addr" default:"0.0.0.0"`
			Port     uint   `fig:"port" default:"9099"`
			CertPath string `fig:"cert_path"`
			KeyPath  string `fig:"key_path"`
		} `fig:"tls"`
		Type ListenerType `fig:"type" default:"unix"`
	} `fig:"listener"`
	Log struct {
		Level    string `fig:"level" default:"info"`
		Extended bool   `fig:"extended"`
	} `fig:"log"`
	Parser struct {
		Type    string        `fig:"type" validate:"required"`
		Timeout time.Duration `fig:"timeout" default:"500ms"`
	} `fig:"parser"`
	// contains filtered or unexported fields
}

Config holds all the global configuration settings that are parsed by fig

func NewConfig

func NewConfig(path, file string) (*Config, error)

NewConfig creates a new instance of the Config object by reading and loading configuration values. It takes in the file path and file name of the configuration file as parameters. It returns a pointer to the Config object and an error if there was a problem reading or loading the configuration.

type Connection

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

Connection represents a connection to a network resource.

func NewConnection

func NewConnection(netConn net.Conn) *Connection

NewConnection creates a new Connection object with the provided net.Conn. The Connection object holds a reference to the provided net.Conn, along with an ID string, bufio.Reader, and bufio.Writer. It returns a pointer to the created Connection object.

type ListenerType

type ListenerType uint

ListenerType is an enumeration wrapper for the different listener types

const (
	// ListenerUnix is a constant of type ListenerType that represents a UNIX listener.
	ListenerUnix ListenerType = iota
	// ListenerTCP is a constant representing the type of listener that uses TCP protocol.
	ListenerTCP
	// ListenerTLS is a constant of type ListenerType that represents a TLS listener.
	ListenerTLS
)

func (ListenerType) String

func (l ListenerType) String() string

String satisfies the fmt.Stringer interface for the ListenerType type

func (*ListenerType) UnmarshalString

func (l *ListenerType) UnmarshalString(value string) error

UnmarshalString satisfies the fig.StringUnmarshaler interface for the ListenerType type

type Rule

type Rule struct {
	ID        string         `fig:"id" validate:"required"`
	Regexp    *regexp.Regexp `fig:"regexp" validate:"required"`
	HostMatch *regexp.Regexp `fig:"host_match"`
	Actions   map[string]any `fig:"actions"`
}

Rule represents a rule with its properties.

type Ruleset

type Ruleset struct {
	Rule []Rule `fig:"rule"`
}

Ruleset represents a collection of rules.

func NewRuleset

func NewRuleset(config *Config) (*Ruleset, error)

NewRuleset initializes a new Ruleset based on the provided Config. It reads the rule file specified in the Config, validates the file's existence, and loads the Ruleset using the fig library. It checks for duplicate rules and returns an error if any duplicates are found. If all operations are successful, it returns the created Ruleset and no error.

type Server

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

Server is the main server struct

func New

func New(config *Config) (*Server, error)

New creates a new instance of Server based on the provided Config

func (*Server) HandleConnection

func (s *Server) HandleConnection(connection *Connection)

HandleConnection handles a single connection by parsing and processing log messages. It logs debug information about the connection and measures the processing time. It closes the connection when done, and logs any error encountered during the process.

func (*Server) Listen

func (s *Server) Listen()

Listen handles incoming connections and processes log messages.

func (*Server) ReloadConfig

func (s *Server) ReloadConfig(path, file string) error

ReloadConfig reloads the configuration of the Server with the specified path and filename. It creates a new Config using the NewConfig method and updates the Server's conf field. It also reloads the configured Ruleset. If an error occurs while reloading the configuration, an error is returned.

func (*Server) Run

func (s *Server) Run() error

Run starts the logranger Server by creating a new listener using the NewListener method and calling RunWithListener with the obtained listener.

func (*Server) RunWithListener

func (s *Server) RunWithListener(listener net.Listener) error

RunWithListener sets the listener for the server and performs some additional tasks for initializing the server. It creates a PID file, writes the process ID to the file, and listens for connections. It returns an error if any of the initialization steps fail.

Directories

Path Synopsis
cmd
server command

Jump to

Keyboard shortcuts

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