database

package
v0.0.0-...-9e7e4f5 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2019 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const MAXFLOAT64 float64 = 9007199254740991 // 2^53-1

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

func NewDB

func NewDB(conn *sql.DB) DB

NewDB constructs a new DB from a SQL database connection.

func Open

func Open(dbname, user, password, host string, port int, sslmode string) (db DB, err error)

Connect opens a connection to the database and returns a handler

func (*DB) ActionByID

func (db *DB) ActionByID(id float64) (a mig.Action, err error)

ActionByID retrieves an action from the database using its ID If the query fails, the returned action will have ID -1

func (*DB) ActionMetaByID

func (db *DB) ActionMetaByID(id float64) (a mig.Action, err error)

ActionMetaByID retrieves the metadata fields of an action from the database using its ID

func (*DB) ActiveAgentsByQueue

func (db *DB) ActiveAgentsByQueue(queueloc string, pointInTime time.Time) (agents []mig.Agent, err error)

ActiveAgentsByQueue retrieves an array of agents identified by their QueueLoc value

func (*DB) ActiveAgentsByTarget

func (db *DB) ActiveAgentsByTarget(target string) (agents []mig.Agent, err error)

ActiveAgentsByTarget runs a search for all agents that match a given target string. For safety, it does so in a transaction that runs as a readonly user.

func (*DB) ActiveInvestigatorsPubKeys

func (db *DB) ActiveInvestigatorsPubKeys() (keys [][]byte, err error)

ActiveInvestigators returns a slice of investigators keys marked as active

func (*DB) AgentByID

func (db *DB) AgentByID(id float64) (agent mig.Agent, err error)

AgentByID returns a single agent identified by its ID

func (*DB) AgentByQueueAndPID

func (db *DB) AgentByQueueAndPID(queueloc string, pid int) (agent mig.Agent, err error)

AgentByQueueAndPID returns a single agent that is located at a given queueloc and has a given PID

func (*DB) AgentsActiveSince

func (db *DB) AgentsActiveSince(pointInTime time.Time) (agents []mig.Agent, err error)

AgentsActiveSince returns an array of Agents that have sent a heartbeat between a point in time and now

func (*DB) AllLoadersFromManifestID

func (db *DB) AllLoadersFromManifestID(mid float64) (ret []mig.LoaderEntry, err error)

Return all the loader entries that match the targeting string for manifest mid

func (*DB) Close

func (db *DB) Close()

func (*DB) CommandByID

func (db *DB) CommandByID(id float64) (cmd mig.Command, err error)

CommandByID retrieves a command from the database using its ID

func (*DB) CommandsByActionID

func (db *DB) CommandsByActionID(actionid float64) (commands []mig.Command, err error)

func (*DB) CompareLoaderExpectEnv

func (db *DB) CompareLoaderExpectEnv(lid float64) error

If any expected environment has been set on a loader entry, this function validates the environment submitted by the loader matches that expected query string; returns an error if not

func (*DB) CountDisappearedEndpoints

func (db *DB) CountDisappearedEndpoints(pointInTime time.Time) (sum float64, err error)

CountDisappearedEndpoints a count of endpoints that have disappeared over a given period

func (*DB) CountDoubleAgents

func (db *DB) CountDoubleAgents() (sum float64, err error)

CountDoubleAgents counts the number of endpoints that run more than one agent

func (*DB) CountFlappingEndpoints

func (db *DB) CountFlappingEndpoints() (sum float64, err error)

CountFlappingEndpoints a count of endpoints that have restarted their agent recently

func (*DB) CountIdleEndpoints

func (db *DB) CountIdleEndpoints() (sum float64, err error)

CountIdleEndpoints retrieves a count of unique endpoints that have idle agents and do not have an online agent

func (*DB) CountNewEndpoints

func (db *DB) CountNewEndpoints(recent, old time.Time) (sum float64, err error)

CountNewEndpointsretrieves a count of new endpoints that started after `pointInTime`

func (*DB) CountOnlineEndpoints

func (db *DB) CountOnlineEndpoints() (sum float64, err error)

CountOnlineEndpoints retrieves a count of unique endpoints that have online agents

func (*DB) FinishAction

func (db *DB) FinishAction(a mig.Action) (err error)

FinishAction updates the action fields to mark it as done

func (*DB) FinishCommand

func (db *DB) FinishCommand(cmd mig.Command) (err error)

FinishCommand updates a command into the database unless its status is already set to 'success'. If the status has already been set to "success" (maybe by a concurrent scheduler), do not update further. this prevents scheduler A from expiring a command that has already succeeded and been returned to scheduler B.

func (*DB) GetActionCounters

func (db *DB) GetActionCounters(aid float64) (counters mig.ActionCounters, err error)

func (*DB) GetAgentsStats

func (db *DB) GetAgentsStats(limit int) (stats []mig.AgentsStats, err error)

GetAgentsStats retrieves the latest agents statistics. limit controls how many rows of statistics are returned

func (*DB) GetDisappearedEndpoints

func (db *DB) GetDisappearedEndpoints(oldest time.Time) (queues []string, err error)

GetDisappearedEndpoints retrieves a list of queues from endpoints that are no longer active

func (*DB) GetLoaderAuthDetails

func (db *DB) GetLoaderAuthDetails(prefix string) (lad mig.LoaderAuthDetails, err error)

Return a loader ID and hashed key given a prefix string

func (*DB) GetLoaderEntryID

func (db *DB) GetLoaderEntryID(key string) (ret float64, err error)

Return a loader entry ID given a loader key

func (*DB) GetLoaderFromID

func (db *DB) GetLoaderFromID(lid float64) (ret mig.LoaderEntry, err error)

Return a loader entry given an ID

func (*DB) GetLoaderName

func (db *DB) GetLoaderName(id float64) (ret string, err error)

Return a loader name given an ID

func (*DB) GetManifestFromID

func (db *DB) GetManifestFromID(mid float64) (ret mig.ManifestRecord, err error)

Return the entire contents of manifest ID mid from the database

func (*DB) GetSchedulerInvestigator

func (db *DB) GetSchedulerInvestigator() (inv mig.Investigator, err error)

GetSchedulerInvestigator returns the first active scheduler investigator

func (*DB) GetSchedulerPrivKey

func (db *DB) GetSchedulerPrivKey() (key []byte, err error)

GetSchedulerPrivKey returns the first active private key found for user migscheduler

func (*DB) InsertAction

func (db *DB) InsertAction(a mig.Action) (err error)

InsertAction writes an action into the database.

func (*DB) InsertAgent

func (db *DB) InsertAgent(agt mig.Agent, useTx *sql.Tx) (err error)

InsertAgent creates a new agent in the database

If useTx is not nil, the transaction will be used instead of the standard connection

func (*DB) InsertCommand

func (db *DB) InsertCommand(cmd mig.Command, agt mig.Agent) (err error)

InsertCommand writes a command into the database

func (*DB) InsertCommands

func (db *DB) InsertCommands(cmds []mig.Command) (insertCount int64, err error)

InsertCommands writes an array of commands into the database

func (*DB) InsertInvestigator

func (db *DB) InsertInvestigator(inv mig.Investigator) (iid float64, err error)

InsertInvestigator creates a new investigator in the database and returns its ID, or an error if the insertion failed, or if the investigator already exists

func (*DB) InsertOrUpdateAction

func (db *DB) InsertOrUpdateAction(a mig.Action) (inserted bool, err error)

InsertOrUpdateAction looks for an existing action in DB and update it, or insert a new one if none is found

func (*DB) InsertSchedulerInvestigator

func (db *DB) InsertSchedulerInvestigator(inv mig.Investigator) (iid float64, err error)

InsertSchedulerInvestigator creates a new migscheduler investigator in the database and returns its ID, or an error if the insertion failed, or if the investigator already exists

func (*DB) InsertSignature

func (db *DB) InsertSignature(aid, iid float64, sig string) (err error)

InsertSignature create an entry in the signatures tables that map an investigator to an action and a signature

func (*DB) InvestigatorAPIKeyAuthHelpers

func (db *DB) InvestigatorAPIKeyAuthHelpers() (ret []mig.InvestigatorAPIAuthHelper, err error)

Returns a set of InvestigatorAPIAuthHelper structs that the API can utilize to authorize requests containing the X-MIGAPIKEY header

func (*DB) InvestigatorByActionID

func (db *DB) InvestigatorByActionID(aid float64) (invs []mig.Investigator, err error)

InvestigatorByActionID returns the list of investigators that signed a given action

func (*DB) InvestigatorByFingerprint

func (db *DB) InvestigatorByFingerprint(fp string) (inv mig.Investigator, err error)

InvestigatorByFingerprint searches the database for an investigator that has a given fingerprint

func (*DB) InvestigatorByID

func (db *DB) InvestigatorByID(iid float64) (inv mig.Investigator, err error)

InvestigatorByID searches the database for an investigator with a given ID

func (*DB) LastActions

func (db *DB) LastActions(limit int) (actions []mig.Action, err error)

LastActions retrieves the last X actions by time from the database

func (*DB) ListMultiAgentsQueues

func (db *DB) ListMultiAgentsQueues(pointInTime time.Time) (queues []string, err error)

ListMultiAgentsQueues retrieves an array of queues that have more than one active agent

func (*DB) LoaderAdd

func (db *DB) LoaderAdd(le mig.LoaderEntry, hashkey []byte, salt []byte) (newle mig.LoaderEntry, err error)

Add a new loader entry to the database; the hashed loader key should be provided as hashkey

func (*DB) LoaderUpdateExpect

func (db *DB) LoaderUpdateExpect(lid float64, eenv string) (err error)

Update loader expect fields

func (*DB) LoaderUpdateKey

func (db *DB) LoaderUpdateKey(lid float64, hashkey []byte, salt []byte) (err error)

Change loader key, hashkey should be the hashed version of the key component

func (*DB) LoaderUpdateStatus

func (db *DB) LoaderUpdateStatus(lid float64, status bool) (err error)

Enable or disable a loader entry in the database

func (*DB) ManifestAdd

func (db *DB) ManifestAdd(mr mig.ManifestRecord) (err error)

Add a new manifest record to the database

func (*DB) ManifestAddSignature

func (db *DB) ManifestAddSignature(mid float64, sig string, invid float64, reqsig int) (err error)

Add a signature to the database for an existing manifest

func (*DB) ManifestClearSignatures

func (db *DB) ManifestClearSignatures(mid float64) (err error)

Clear existing signatures for a manifest record

func (*DB) ManifestDisable

func (db *DB) ManifestDisable(mid float64) (err error)

Disable a manifest record

func (*DB) ManifestIDFromLoaderID

func (db *DB) ManifestIDFromLoaderID(lid float64) (ret float64, err error)

Given a loader ID, identify which manifest is applicable to return to this loader in a manifest request

func (*DB) ManifestUpdateStatus

func (db *DB) ManifestUpdateStatus(mid float64, reqsig int) (err error)

Update the status of a manifest based on the number of signatures it has, reqsig is passed as an argument that indicates the number of signatures a manifest must have to be considered active

func (*DB) MarkAgentDestroyed

func (db *DB) MarkAgentDestroyed(agent mig.Agent) (err error)

MarkAgentDestroyed updated the status and destructiontime of an agent in the database

func (*DB) MarkIdleAgents

func (db *DB) MarkIdleAgents(pointInTime time.Time) (err error)

MarkIdleAgents updates the status of online agents that have not sent a heartbeat since pointInTime

func (*DB) MarkOfflineAgents

func (db *DB) MarkOfflineAgents(pointInTime time.Time) (err error)

MarkOfflineAgents updates the status of idle agents that have not sent a heartbeat since pointInTime

func (*DB) ReplaceRefreshedAgent

func (db *DB) ReplaceRefreshedAgent(agt mig.Agent) (err error)

Replace an existing agent in the database with newer environment information. This should be called when we receive a heartbeat for an active agent, but the refresh time indicates newer environment information exists.

func (*DB) SearchActions

func (db *DB) SearchActions(p search.Parameters) (actions []mig.Action, err error)

SearchActions returns an array of actions that match search parameters

func (*DB) SearchAgents

func (db *DB) SearchAgents(p search.Parameters) (agents []mig.Agent, err error)

SearchAgents returns an array of agents that match search parameters

func (*DB) SearchCommands

func (db *DB) SearchCommands(p search.Parameters, doFoundAnything bool) (commands []mig.Command, err error)

SearchCommands returns an array of commands that match search parameters

func (*DB) SearchInvestigators

func (db *DB) SearchInvestigators(p search.Parameters) (investigators []mig.Investigator, err error)

SearchInvestigators returns an array of investigators that match search parameters

func (*DB) SearchLoaders

func (db *DB) SearchLoaders(p search.Parameters) (lrecords []mig.LoaderEntry, err error)

func (*DB) SearchManifests

func (db *DB) SearchManifests(p search.Parameters) (mrecords []mig.ManifestRecord, err error)

func (*DB) SetMaxOpenConns

func (db *DB) SetMaxOpenConns(n int)

func (*DB) SetupRunnableActions

func (db *DB) SetupRunnableActions() (actions []mig.Action, err error)

SetupRunnableActions retrieves actions that are ready to run. This function is designed to run concurrently across multiple schedulers, by update the status of the action at the same time as retrieving it. It returns an array of actions rady to be run.

func (*DB) StoreAgentsStats

func (db *DB) StoreAgentsStats(stats mig.AgentsStats) (err error)

StoreAgentsStats store a new row of agents statistics and sets the timestamp to the current time

func (*DB) SumIdleAgentsByVersion

func (db *DB) SumIdleAgentsByVersion() (sum []mig.AgentsVersionsSum, err error)

SumIdleAgentsByVersion retrieves a sum of idle agents grouped by version and excludes endpoints where an online agent is running

func (*DB) SumOnlineAgentsByVersion

func (db *DB) SumOnlineAgentsByVersion() (sum []mig.AgentsVersionsSum, err error)

SumOnlineAgentsByVersion retrieves a sum of online agents grouped by version

func (*DB) UpdateAction

func (db *DB) UpdateAction(a mig.Action) (err error)

UpdateAction stores updated action fields into the database.

func (*DB) UpdateActionStatus

func (db *DB) UpdateActionStatus(a mig.Action) (err error)

UpdateActionStatus updates the status of an action

func (*DB) UpdateAgentHeartbeat

func (db *DB) UpdateAgentHeartbeat(agt mig.Agent) (err error)

UpdateAgentHeartbeat updates the heartbeat timestamp of an agent in the database unless the agent has been marked as destroyed

func (*DB) UpdateInvestigatorAPIKey

func (db *DB) UpdateInvestigatorAPIKey(inv mig.Investigator, key []byte, salt []byte) (err error)

UpdateInvestigatorAPIKey enables or disabled a standard API key for an investigator

func (*DB) UpdateInvestigatorPerms

func (db *DB) UpdateInvestigatorPerms(inv mig.Investigator) (err error)

func (*DB) UpdateInvestigatorStatus

func (db *DB) UpdateInvestigatorStatus(inv mig.Investigator) (err error)

UpdateInvestigatorStatus updates the status of an investigator

func (*DB) UpdateLoaderEntry

func (db *DB) UpdateLoaderEntry(lid float64, agt mig.Agent) (err error)

Update a given loader entry using supplied agent information (e.g., provided during a manifest request by a loader instance

func (*DB) UpdateRunningAction

func (db *DB) UpdateRunningAction(a mig.Action) (err error)

UpdateRunningAction stores updated time and counters on a running action

func (*DB) UpdateSentCommand

func (db *DB) UpdateSentCommand(cmd mig.Command) (err error)

UpdateSentCommand updates a command into the database, unless its status is already set to 'success'

type IDs

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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