database

package
v0.0.0-...-23032f1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2016 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package database handles a SQLite3 database and access methods for the specific needs of bashistdb.

Package database handles a SQLite3 database and access methods for the specific needs of bashistdb.

Index

Constants

View Source
const RFC3339alt = "2006-01-02T15:04:05-0700"

Golang's RFC3339 does not comply with all RFC3339 representations

View Source
const VERSION = "2.1"

VERSION is the database's schema supported version. If your database is older it will be automatically migrated. If it is newer you have to update your bashistdb copy.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database struct {
	*sql.DB
	// contains filtered or unexported fields
}

A Database holds a bashistdb database.

func New

func New() (Database, error)

New returns a new Database instance. It gets the filename for the database from the configuration package. If the file does not exist, it creates a new database. If it exists, it migrates it if it has an older schema version than current.

func (Database) AddFromBuffer

func (d Database) AddFromBuffer(r *bufio.Reader, user, host string) (stats string, e error)

AddFromBuffer reads from a buffered Reader and scans for lines that match history command's structure:

LINENUM RFC3339_DATETIME COMMAND

Upon succesful encounter it tries to store it to the database. It counts total lines read and lines failed to insert into the database —usually because they already exist. It reports the results in a sentence (stats string) because we don't anything fancier currently.

func (Database) AddRecord

func (d Database) AddRecord(user, host, command string, time time.Time) error

AddRecord tries to insert a new record in the database, if the record already exists, it updates the count Note: function isn't used anywhere, may need testing if used.

func (Database) ContentQuery

func (d Database) ContentQuery(qp conf.QueryParams) ([]byte, error)

ContentQuery returns matches of a row plus rows before or after the match. Think of it as grep -A(fter) / -B(efore) / -C(ontent) It works on 4 stages: 1. find matches and get their datetime 2. for each match, get the content asked by rowid 3. if the content of two matches overlap, join them 4. given the sets of rowids, get them from the database

func (Database) DefaultQuery

func (d Database) DefaultQuery(qp conf.QueryParams) ([]byte, error)

DefaultQuery returns history within the search criteria in the format requested

func (Database) DeleteRows

func (d Database) DeleteRows(qp conf.QueryParams) ([]byte, error)

DeleteRows deletes a range of rows.

func (Database) Demo

func (d Database) Demo(qp conf.QueryParams) (res []byte, e error)

Demo returns some stats from the database to showcase bashistdb.

func (Database) LastK

func (d Database) LastK(qp conf.QueryParams) ([]byte, error)

LastK returns the k most recent command lines in history

func (Database) LogConn

func (d Database) LogConn(remote net.Addr) (err error)

LogConn logs the remote's IP address and connection time into connlog table. Also if it can't find a reverse lookup for the IP address inside table rlookup, it performs it asynchronously. Reverse lookup may fail, but we don't care.

func (Database) ReturnRow

func (d Database) ReturnRow(qp conf.QueryParams) ([]byte, error)

ReturnRow returns a single row with no other data. It is useful to pipe to bash.

func (Database) RunQuery

func (d Database) RunQuery(p conf.QueryParams) ([]byte, error)

RunQuery is a wrapper around various queries.

func (Database) TopK

func (d Database) TopK(qp conf.QueryParams) ([]byte, error)

TopK returns the k most frequent command lines in history

func (Database) Users

func (d Database) Users(qp conf.QueryParams) (res []byte, e error)

Users returns unique user@host pairs from the database.

Jump to

Keyboard shortcuts

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