db

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const SQLCheckForTrigramExtension = `SELECT COUNT(*) FROM pg_available_extensions WHERE name = 'pg_trgm';`

SQLCheckForTrigramExtension is an SQL query to check whether the trigram extension is available.

View Source
const SQLCopy = `COPY "%s" (ts, payload) FROM STDIN WITH CSV DELIMITER E'\t' QUOTE E'\b'`

SQLCopy is an SQL/DDL clause to bulk insert a chunk of JSON into the database

View Source
const SQLCreate = `` /* 150-byte string literal not displayed */

SQLCreate is an SQL/DDL clause to create a new event table

View Source
const SQLGenericQuery = `` /* 130-byte string literal not displayed */

SQLGenericQuery is the main kind of query used to pull out event metadata.

View Source
const SQLGetTableSizes = `SELECT relname as table,
 pg_total_relation_size(relid) as size
 FROM pg_catalog.pg_statio_user_tables
 ORDER BY 1 DESC;`

SQLGetTableSizes is an SQL query to obtain the names of tables in the current schema and their size in bytes.

View Source
const SQLIndex = `` /* 315-byte string literal not displayed */

SQLIndex is an SQL/DDL clause to create indexes on event tables

View Source
const SQLQueryAllEvents = `` /* 2131-byte string literal not displayed */

SQLQueryAllEvents is a plpgsql function to enable queries over all hourly tables Example: SELECT COUNT(*) FROM all_events_query('WHERE trigram_string(payload) LIKE ”%%foo%%”');

View Source
const SQLTrigramFunction = `` /* 1241-byte string literal not displayed */

SQLTrigramFunction is a plpgsql function to pull out indexable content from event JSON

Variables

View Source
var INDEXES = map[string]([]mgo.Index){
	"dns": []mgo.Index{

		mgo.Index{
			Key:        []string{"dns.rrname"},
			Background: true,
		},
		mgo.Index{
			Key:        []string{"timestamp"},
			Background: true,
		},
	},
	"fileinfo": []mgo.Index{
		mgo.Index{
			Key: []string{"src_ip",
				"dest_ip"},
			Background: true,
		},
		mgo.Index{
			Key: []string{"fileinfo.filename",
				"fileinfo.md5"},
			Background: true,
		},
		mgo.Index{
			Key:        []string{"timestamp"},
			Background: true,
		},
	},
	"flow": []mgo.Index{
		mgo.Index{
			Key: []string{"src_ip",
				"dest_ip"},
			Background: true,
		},
		mgo.Index{
			Key:        []string{"timestamp"},
			Background: true,
		},
	},
	"http": []mgo.Index{
		mgo.Index{
			Key: []string{"src_ip",
				"dest_ip"},
			Background: true,
		},
		mgo.Index{
			Key: []string{"http.hostname",
				"http.http_user_agent"},
			Background: true,
		},
		mgo.Index{
			Key:        []string{"$text:http.url"},
			Background: true,
		},
		mgo.Index{
			Key:        []string{"timestamp"},
			Background: true,
		},
	},
	"alert": []mgo.Index{
		mgo.Index{
			Key: []string{"src_ip",
				"dest_ip"},
			Background: true,
		},
		mgo.Index{
			Key:        []string{"$text:alert.payload_printable"},
			Background: true,
		},
		mgo.Index{
			Key:        []string{"timestamp"},
			Background: true,
		},
	},
	"smtp": []mgo.Index{
		mgo.Index{
			Key: []string{"src_ip",
				"dest_ip"},
			Background: true,
		},
		mgo.Index{
			Key: []string{"smtp.helo",
				"smtp.mail_from",
				"smtp.rcpt_to"},
			Background: true,
		},
		mgo.Index{
			Key:        []string{"email.attachment"},
			Background: true,
		},
		mgo.Index{
			Key:        []string{"timestamp"},
			Background: true,
		},
	},
	"tls": []mgo.Index{
		mgo.Index{
			Key: []string{"src_ip",
				"dest_ip"},
			Background: true,
		},
		mgo.Index{
			Key: []string{"tls.subject",
				"tls.issuerdn",
				"tls.fingerprint"},
			Background: true,
		},
		mgo.Index{
			Key:        []string{"timestamp"},
			Background: true,
		},
	},
	"misc": []mgo.Index{
		mgo.Index{
			Key: []string{"src_ip",
				"dest_ip"},
			Background: true,
		},
		mgo.Index{
			Key:        []string{"timestamp"},
			Background: true,
		},
	},
}

INDEXES assigns index parameters to each collection, denoted by the corresponding event type

View Source
var MAXCOLLSIZEFRACTIONS = map[string]float64{
	"dns":      0.25,
	"http":     0.2,
	"flow":     0.25,
	"smtp":     0.05,
	"ssh":      0.05,
	"alert":    0.05,
	"tls":      0.05,
	"stats":    0.02,
	"misc":     0.03,
	"fileinfo": 0.05,
}

MAXCOLLSIZEFRACTIONS are the proportions of the general space cap to be assigned to the collections for each event type -- used to determine limits for capped collections

View Source
var TYPES = []string{
	"alert", "dns", "fileinfo", "flow",
	"http", "smtp", "ssh", "stats",
	"tls", "misc",
}

TYPES are event types/collections supported by us

Functions

This section is empty.

Types

type DummySlurper

type DummySlurper struct{}

DummySlurper is a slurper that just consumes entries with no action.

func (*DummySlurper) Finish

func (s *DummySlurper) Finish()

Finish is a null operation in the DummySlurper implementation.

func (*DummySlurper) Run

func (s *DummySlurper) Run(eventchan chan types.Entry)

Run starts a DummySlurper.

type MongoSlurper

type MongoSlurper struct {
	User         string
	Password     string
	Host         string
	Database     string
	TypeDispatch map[string](chan types.Entry)
	ChunkSize    int
	MaxSize      int64
	Logger       *log.Entry
}

MongoSlurper is a Slurper that stores events in an MongoDB database.

func MakeMongoSlurper

func MakeMongoSlurper(host string, database string, user string, password string, chunkSize int, maxSize int64) *MongoSlurper

MakeMongoSlurper creates a new MongoSlurper instance.

func (*MongoSlurper) Finish

func (s *MongoSlurper) Finish()

Finish is a null operation in the MongoSlurper implementation.

func (*MongoSlurper) Run

func (s *MongoSlurper) Run(eventchan chan types.Entry)

Run starts a MongoSlurper.

type PostgresSlurper

type PostgresSlurper struct {
	DB               *pg.DB
	LastRotatedTime  time.Time
	IndexChan        chan string
	CurrentTableName string
	RotationInterval time.Duration
	MaxTableSize     int64
	ChunkSize        int
	Logger           *log.Entry
}

PostgresSlurper is a Slurper that stores events in an PostgreSQL database.

func MakePostgresSlurper

func MakePostgresSlurper(host string, database string, user string,
	password string, rotationInterval time.Duration,
	maxTableSize int64, chunkSize int) *PostgresSlurper

MakePostgresSlurper creates a new PostgresSlurper instance.

func (*PostgresSlurper) Finish

func (s *PostgresSlurper) Finish()

Finish is a null operation in the PostgresSlurper implementation.

func (*PostgresSlurper) Run

func (s *PostgresSlurper) Run(eventchan chan types.Entry)

Run starts a PostgresSlurper.

type Slurper

type Slurper interface {
	Run(chan types.Entry)
	Finish()
}

Slurper is an interface for a worker that can be started (Run()) with a given channel delivering Entries, storing them in an associated data store. Finish() can be used to finalize any state. TODO implement proper start/stop (atm 'hard' stop by exit()ing)

Jump to

Keyboard shortcuts

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