bgpmon

package module
v0.0.0-...-891f3ce Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2019 License: BSD-2-Clause Imports: 7 Imported by: 0

README

GoDoc Build Status Go Report Card

BGPmon is a client server application to store and analyze large amounts of BGP data.

Installation

Requirements

  1. Golang > 1.11
  2. make
  3. to store message a db backend (Postgresql >= 9.5)

Running make will create two binaries under bin. To run the daemon, run:

bgpmond conf-file

To succesfully store messages in a database please have a Postgresql with a user that has access to write create tables on a database and reflect that configuration in the config file.

Example client commands

The client works over RPC, so the rpc module must be started in order for the client to work.

To show configured sessions on the server

bgpmon listAvailable sessions

To open a configured session

bgpmon open session LocalPostgres -s sID

To write MRT files

bgpmon write sID mrtFiles...

To close a session

bgpmon close session sID

To see available modules and the options required to run them

bgpmon listAvailable modules

Example config file

DebugOut = "stdout"
ErrorOut = "stderr"

# Sessions represent the possible database backends
[Sessions]
#this will configure an available session named LocalPostgres
[Sessions.LocalPostgres]
Type = "postgres"
Hosts = ["localhost"]
Database = "bgpmon"
User = "bgpmon"
Password = "bgpmon"
WorkerCt = 4 #the maximum amount of concurrent workers
DBTimeoutSecs = 120 #maximum lifetime seconds for a DB operation

# Modules represent modules to run on startup
# Multiple modules of the same type can be instantiated with
# different IDs
[Modules]
# RPC exposes the basic bgpmond operation over an RPC interface that
# consumes and produces protocol buffers defined in the netsec-protobufs
# repository /bgpmon
[Modules.rpc1]
Type="rpc"
Args="-address :12289 -timeoutsecs 240"

# pprof enables the http profiler at an address specified by Args
[Modules.pprof1]
Type="pprof"
Args="-address localhost:6969"

# Nodes represent operator provided information for nodes involved in
# BGP transactions
# If there are already saved nodes in the database that conflict with the
# configuration, the configuration is preferred
[Nodes]
[Nodes."128.223.51.102"]
Name="routeviews2"
IsCollector=true
DumpDurationMinutes=1440
Descritption="routeviews.org routeviews2 collector"

Documentation

Overview

Package bgpmon provides the core interfaces for developing bgpmon client programs and modules.

Index

Constants

View Source
const (
	// A task will run until it's finished. It will only be deallocated by
	// the server when it calls its own FinishFunc.
	ModuleTask = iota

	// A daemon will run constantly, and won't stop until it is closed by
	// the server. If it encounters an error, it can call its FinishFunc
	// to be deallocated early.
	ModuleDaemon
)

Types of modules.

Variables

This section is empty.

Functions

func RegisterModule

func RegisterModule(handle ModuleHandler)

RegisterModule adds a module type to a list of known modules. Once a module maker is registered, the server can create and launch modules of this type

Types

type BgpmondServer

type BgpmondServer interface {
	// OpenSession opens a session of type sType, which must come from the config file.
	// The ID of this session is sID, which is used to interact with this
	// session, and wc is the worker count, or 0, to use a default wc of 1.
	OpenSession(sType, sID string, wc int) error

	// ListSessionTypes returns types which can be opened on the server. These are
	// defined in netsec-protobus, but the name of a SessionType returned
	// here should be a valid sType for OpenSession.
	ListSessionTypes() []*pb.SessionType

	// ListSessions returns a slice of currently active sesions on the server.
	// Each session handle includes a name, a session type, and a pointer to the
	// underlying session.
	ListSessions() []SessionHandle

	// CloseSession attempts to close active session with the provided session ID.
	// If that ID does not exist, or that session fails to close, this will return
	// an error.
	CloseSession(string) error

	// OpenWriteStream tries to open a write stream on the provided session ID with
	// the provided type. If the session doesn't exist or the WriteStream fails to
	// open, this will return an error.
	OpenWriteStream(string, db.SessionType) (db.WriteStream, error)

	// OpenReadStream tries to open a read stream on the provided session ID with
	// the provided type and filter options. If the session doesn't exist or the ReadStream
	// fails to open, this will return an error.
	OpenReadStream(string, db.SessionType, db.FilterOptions) (db.ReadStream, error)

	// RunModule will launch the module specified with mType with the ID mID. opts will
	// be passed to the modules Run function.
	RunModule(mType string, mID string, opts map[string]string) error

	// ListModuleTypes will return a slice of ModuleInfo specifying the type of module
	// and the options it accepts.
	ListModuleTypes() []ModuleInfo

	// ListRunningModules returns a slice of the active modules on the server.
	// OpenModuleInfo describes the modules type, options, and status.
	ListRunningModules() []OpenModuleInfo

	// CloseModule attempts to close an active module with the provided ID. If that ID
	// does not exist, or the module fails to close, this will return an error.
	CloseModule(string) error

	// Close will close all active modules, then all active sessions.
	Close() error
}

BgpmondServer is the interface for interacting with a server instance. It provides functions to open and close sessions and modules, and get data on the state on the server.

func NewServer

func NewServer(conf config.Configer) (BgpmondServer, error)

NewServer creates a BgpmondServer instance from a configuration. It loads session types from the configuration, and launches any modules specified. It returns an error if a module type is specified that isn't registered with the server.

func NewServerFromFile

func NewServerFromFile(fName string) (BgpmondServer, error)

NewServerFromFile does the same thing as NewServer, but loads the configuration from a specified file name. Returns an error if the file can't be parsed, or specifies an invalid module.

type Module

type Module interface {
	// Run starts the module, and is guaranteed to launch in a separate
	// goroutine. Args can be used to pass any information the module
	// needs.
	Run(args map[string]string)

	// GetType should return one of the module types defined above.
	GetType() int

	// GetName returns a string to identify the module type. Each
	// instance of a module should share the same name.
	GetName() string

	// GetInfo returns a struct containing info that describes the
	// running module.
	GetInfo() OpenModuleInfo

	// Stop is called to prematurely cancel a running module. The
	// module should be deallocated just after calling this. Stop
	// should be blocking until it knows the module has been stopped.
	Stop() error
}

Module describes a service that can be started by the server. It can interact with the server in any way, including opening sessions, streams, and other modules.

type ModuleHandler

type ModuleHandler struct {
	Info  ModuleInfo
	Maker ModuleMaker
}

ModuleHandler wraps the info and maker types. It's used to store modules globally, and as the argument to register new modules.

type ModuleInfo

type ModuleInfo struct {
	Type        string
	Description string
	Opts        string
}

ModuleInfo is used to describe an available module. It should include the type of the module, a description, and a description of the opts that the module uses.

type ModuleMaker

type ModuleMaker func(BgpmondServer, util.Logger) Module

ModuleMaker is a function to instantiate a module. It is given a handle to the BgpmondServer, and a logger to print information.

type OpenModuleInfo

type OpenModuleInfo struct {
	Type   string
	ID     string
	Status string
}

OpenModuleInfo describes an actively running module. It should include the type of the module, the ID, and a string describing the status of the module. Modules don't keep track of their own ID, so that field must be populated by the server.

func NewOpenModuleInfo

func NewOpenModuleInfo(modType string, status string) OpenModuleInfo

NewOpenModuleInfo returns an info struct with a type and a status, and leaves the ID to be populated by something else.

type SessionHandle

type SessionHandle struct {
	Name     string
	SessType *pb.SessionType
	Session  *db.Session
}

SessionHandle is used to return information on an open session.

Directories

Path Synopsis
cmd
bgpmon
The bgpmon command is the RPC client for the bgpmon server.
The bgpmon command is the RPC client for the bgpmon server.
bgpmon/cmd
Package cmd is the package that provides implementations for the bgpmon client commands.
Package cmd is the package that provides implementations for the bgpmon client commands.
bgpmond
The bgpmond command launches the bgpmon server with a provided configuration file.
The bgpmond command launches the bgpmon server with a provided configuration file.
Package config defines the constants and functions necessary to parse configuration files for bgpmon
Package config defines the constants and functions necessary to parse configuration files for bgpmon
Package db is responsible for the communication between the database backends and the bgpmon daemon.
Package db is responsible for the communication between the database backends and the bgpmon daemon.
Package modules defines commonly used modules for bgpmon.
Package modules defines commonly used modules for bgpmon.
Package util defines miscellaneous functions used in multiple parts of bgpmon or other projects
Package util defines miscellaneous functions used in multiple parts of bgpmon or other projects

Jump to

Keyboard shortcuts

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