dal

package
v4.2.6+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2016 License: MIT Imports: 22 Imported by: 0

README

Data Access Layer

(Definition from Wikipedia)

A data access layer (DAL) in computer software, is a layer of a computer program which provides simplified access to data stored in persistent storage of some kind, such as an entity-relational database. This acronym is prevalently used in Microsoft ASP.NET environments.

For example, the DAL might return a reference to an object (in terms of object-oriented programming) complete with its attributes instead of a row of fields from a database table. This allows the client (or user) modules to be created with a higher level of abstraction. This kind of model could be implemented by creating a class of data access methods that directly reference a corresponding set of database stored procedures. Another implementation could potentially retrieve or write records to or from a file system. The DAL hides this complexity of the underlying data store from the external world.

This directory is the equivalent of "models" directory in other web framework. Put all of you database logic here.

Documentation

Overview

Package dal is the Data Access Layer between the Application and PostgreSQL database.

Index

Constants

This section is empty.

Variables

View Source
var PROJECT_EPOCH = 1451606400

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	Base
}

func NewAccessToken

func NewAccessToken(db *sqlx.DB) *AccessToken

func (*AccessToken) AllAccessTokens

func (t *AccessToken) AllAccessTokens(tx *sqlx.Tx) ([]*AccessTokenRow, error)

AllAccessTokens returns all access tokens.

func (*AccessToken) AllByClusterID

func (t *AccessToken) AllByClusterID(tx *sqlx.Tx, clusterID int64) ([]*AccessTokenRow, error)

AllAccessTokens returns all access tokens by cluster id.

func (*AccessToken) Create

func (t *AccessToken) Create(tx *sqlx.Tx, userID, clusterID int64, level string) (*AccessTokenRow, error)

func (*AccessToken) GetByAccessToken

func (t *AccessToken) GetByAccessToken(tx *sqlx.Tx, token string) (*AccessTokenRow, error)

GetByAccessToken returns one record by token.

func (*AccessToken) GetByClusterID

func (t *AccessToken) GetByClusterID(tx *sqlx.Tx, clusterID int64) (*AccessTokenRow, error)

GetByClusterID returns one record by cluster_id.

func (*AccessToken) GetByID

func (t *AccessToken) GetByID(tx *sqlx.Tx, id int64) (*AccessTokenRow, error)

GetByID returns one record by id.

func (*AccessToken) GetByUserID

func (t *AccessToken) GetByUserID(tx *sqlx.Tx, userID int64) (*AccessTokenRow, error)

GetByUserID returns one record by user_id.

type AccessTokenRow

type AccessTokenRow struct {
	ID        int64  `db:"id"`
	UserID    int64  `db:"user_id"`
	ClusterID int64  `db:"cluster_id"`
	Token     string `db:"token"`
	Level     string `db:"level"` // read, write, execute
	Enabled   bool   `db:"enabled"`
}

type AgentLogPayload

type AgentLogPayload struct {
	Host struct {
		Name string
		Tags map[string]string
	}
	Data struct {
		Loglines []AgentLoglinePayload
		Filename string
	}
}

type AgentLoglinePayload

type AgentLoglinePayload struct {
	Created int64
	Content string
}

type AgentResourcePayload

type AgentResourcePayload struct {
	Data map[string]interface{}
	Host struct {
		Name string
		Tags map[string]string
	}
}

type Base

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

func (*Base) DeleteByClusterIDAndID

func (b *Base) DeleteByClusterIDAndID(tx *sqlx.Tx, clusterID, id int64) (result sql.Result, err error)

func (*Base) DeleteByID

func (b *Base) DeleteByID(tx *sqlx.Tx, id int64) (result sql.Result, err error)

func (*Base) DeleteFromTable

func (b *Base) DeleteFromTable(tx *sqlx.Tx, where string) (result sql.Result, err error)

func (*Base) InsertIntoTable

func (b *Base) InsertIntoTable(tx *sqlx.Tx, data map[string]interface{}) (sql.Result, error)

func (*Base) NewExplicitID

func (b *Base) NewExplicitID() int64

NewExplicitID uses UNIX timestamp in microseconds as ID.

func (*Base) UpdateByID

func (b *Base) UpdateByID(tx *sqlx.Tx, data map[string]interface{}, id int64) (result sql.Result, err error)

func (*Base) UpdateByKeyValueString

func (b *Base) UpdateByKeyValueString(tx *sqlx.Tx, data map[string]interface{}, key, value string) (result sql.Result, err error)

func (*Base) UpdateFromTable

func (b *Base) UpdateFromTable(tx *sqlx.Tx, data map[string]interface{}, where string) (result sql.Result, err error)

type BaseRow

type BaseRow struct {
}

func (*BaseRow) JSONAttrFloat64

func (br *BaseRow) JSONAttrFloat64(field sqlx_types.JSONText, attr string) float64

func (*BaseRow) JSONAttrString

func (br *BaseRow) JSONAttrString(field sqlx_types.JSONText, attr string) string

type Check

type Check struct {
	Base
}

func NewCheck

func NewCheck(db *sqlx.DB) *Check

func (*Check) AddTrigger

func (a *Check) AddTrigger(tx *sqlx.Tx, checkRow *CheckRow, trigger CheckTrigger) ([]CheckTrigger, error)

func (*Check) All

func (a *Check) All(tx *sqlx.Tx) ([]*CheckRow, error)

All returns all rows.

func (*Check) AllByClusterID

func (a *Check) AllByClusterID(tx *sqlx.Tx, clusterID int64) ([]*CheckRow, error)

AllByClusterID returns all rows by cluster_id.

func (*Check) AllSplitToDaemons

func (a *Check) AllSplitToDaemons(tx *sqlx.Tx, daemons []string) (map[string][]*CheckRow, error)

AllSplitToDaemons returns all rows divided into daemons equally.

func (*Check) Create

func (a *Check) Create(tx *sqlx.Tx, clusterID int64, data map[string]interface{}) (*CheckRow, error)

func (*Check) DeleteTrigger

func (a *Check) DeleteTrigger(tx *sqlx.Tx, checkRow *CheckRow, trigger CheckTrigger) ([]CheckTrigger, error)

func (*Check) GetByID

func (a *Check) GetByID(tx *sqlx.Tx, id int64) (*CheckRow, error)

GetByID returns one record by id.

func (*Check) UpdateTrigger

func (a *Check) UpdateTrigger(tx *sqlx.Tx, checkRow *CheckRow, trigger CheckTrigger) ([]CheckTrigger, error)

type CheckExpression

type CheckExpression struct {
	Type       string
	MinHost    int
	Metric     string
	Operator   string
	Value      float64
	PrevRange  int
	PrevAggr   string
	Search     string
	Protocol   string
	Port       string
	Headers    string
	Username   string
	Password   string
	HTTPMethod string
	HTTPBody   string
	Result     struct {
		Value         bool
		Message       string
		BadHostnames  []string
		GoodHostnames []string
	}
}

type CheckRow

type CheckRow struct {
	ID                    int64               `db:"id"`
	ClusterID             int64               `db:"cluster_id"`
	Name                  string              `db:"name"`
	Interval              string              `db:"interval"`
	IsSilenced            bool                `db:"is_silenced"`
	HostsQuery            string              `db:"hosts_query"`
	HostsList             sqlx_types.JSONText `db:"hosts_list"`
	Expressions           sqlx_types.JSONText `db:"expressions"`
	Triggers              sqlx_types.JSONText `db:"triggers"`
	LastResultHosts       sqlx_types.JSONText `db:"last_result_hosts"`
	LastResultExpressions sqlx_types.JSONText `db:"last_result_expressions"`
}

func (*CheckRow) BuildEmailTriggerContent

func (checkRow *CheckRow) BuildEmailTriggerContent(lastViolation *TSCheckRow, templateRoot string) (string, error)

func (*CheckRow) CheckHTTP

func (checkRow *CheckRow) CheckHTTP(hostname, scheme, port, method, user, pass string, headers map[string]string, body string) (resp *http.Response, err error)

func (*CheckRow) CheckPing

func (checkRow *CheckRow) CheckPing(hostname string) (outBytes []byte, err error)

func (*CheckRow) CheckSSH

func (checkRow *CheckRow) CheckSSH(hostname, port, user string) (outBytes []byte, err error)

func (*CheckRow) EvalExpressions

func (checkRow *CheckRow) EvalExpressions(dbs *config.DBConfig) ([]CheckExpression, bool, error)

EvalExpressions reduces the result of expression into a single true/false. 1st value: List of all CheckExpression containing results. 2nd value: The value of all expressions. 3rd value: Error

func (*CheckRow) EvalHTTPExpression

func (checkRow *CheckRow) EvalHTTPExpression(hostRows []*HostRow, expression CheckExpression) CheckExpression

func (*CheckRow) EvalLogDataExpression

func (checkRow *CheckRow) EvalLogDataExpression(dbs *config.DBConfig, hostRows []*HostRow, expression CheckExpression) CheckExpression

func (*CheckRow) EvalPingExpression

func (checkRow *CheckRow) EvalPingExpression(hostRows []*HostRow, expression CheckExpression) CheckExpression

func (*CheckRow) EvalRawHostDataExpression

func (checkRow *CheckRow) EvalRawHostDataExpression(hostRows []*HostRow, expression CheckExpression) CheckExpression

func (*CheckRow) EvalRelativeHostDataExpression

func (checkRow *CheckRow) EvalRelativeHostDataExpression(dbs *config.DBConfig, hostRows []*HostRow, expression CheckExpression) CheckExpression

func (*CheckRow) EvalSSHExpression

func (checkRow *CheckRow) EvalSSHExpression(hostRows []*HostRow, expression CheckExpression) CheckExpression

func (*CheckRow) GetExpressions

func (checkRow *CheckRow) GetExpressions() ([]CheckExpression, error)

func (*CheckRow) GetHostsList

func (checkRow *CheckRow) GetHostsList() ([]string, error)

func (*CheckRow) GetTriggers

func (checkRow *CheckRow) GetTriggers() []CheckTrigger

func (*CheckRow) RunEmailTrigger

func (checkRow *CheckRow) RunEmailTrigger(trigger CheckTrigger, lastViolation *TSCheckRow, violationsCount int, mailr *mailer.Mailer, appConfig config.GeneralConfig) (err error)

func (*CheckRow) RunPagerDutyTrigger

func (checkRow *CheckRow) RunPagerDutyTrigger(trigger CheckTrigger, lastViolation *TSCheckRow) (err error)

func (*CheckRow) RunSMSTrigger

func (checkRow *CheckRow) RunSMSTrigger(trigger CheckTrigger, lastViolation *TSCheckRow, violationsCount int, mailr *mailer.Mailer, appConfig config.GeneralConfig) (err error)

func (*CheckRow) RunTriggers

func (checkRow *CheckRow) RunTriggers(appConfig config.GeneralConfig, coreDB *sqlx.DB, tsCheckDB *sqlx.DB, mailr *mailer.Mailer) error

func (*CheckRow) UnmarshalTriggers

func (checkRow *CheckRow) UnmarshalTriggers() ([]CheckTrigger, error)

type CheckRowsWithError

type CheckRowsWithError struct {
	Checks []*CheckRow
	Error  error
}

type CheckTrigger

type CheckTrigger struct {
	ID                    int64
	LowViolationsCount    int64
	HighViolationsCount   int64
	CreatedIntervalMinute int64
	Action                CheckTriggerAction
}

type CheckTriggerAction

type CheckTriggerAction struct {
	Transport            string
	Email                string
	SMSPhone             string
	SMSCarrier           string
	PagerDutyServiceKey  string
	PagerDutyIncidentKey string
	PagerDutyDescription string
}

type Cluster

type Cluster struct {
	Base
}

func NewCluster

func NewCluster(db *sqlx.DB) *Cluster

func (*Cluster) All

func (c *Cluster) All(tx *sqlx.Tx) ([]*ClusterRow, error)

All returns all clusters rows.

func (*Cluster) AllByUserID

func (c *Cluster) AllByUserID(tx *sqlx.Tx, userId int64) ([]*ClusterRow, error)

AllByUserID returns all clusters rows by user ID.

func (*Cluster) AllSplitToDaemons

func (c *Cluster) AllSplitToDaemons(tx *sqlx.Tx, daemons []string) (map[string][]*ClusterRow, error)

AllSplitToDaemons returns all rows divided into daemons equally.

func (*Cluster) Create

func (c *Cluster) Create(tx *sqlx.Tx, creator *UserRow, name string) (*ClusterRow, error)

Create a cluster row record with default settings.

func (*Cluster) GetByID

func (c *Cluster) GetByID(tx *sqlx.Tx, id int64) (*ClusterRow, error)

GetByID returns one record by id.

func (*Cluster) RemoveMember

func (c *Cluster) RemoveMember(tx *sqlx.Tx, id int64, user *UserRow) error

RemoveMember from a cluster.

func (*Cluster) UpdateMember

func (c *Cluster) UpdateMember(tx *sqlx.Tx, id int64, user *UserRow, level string, enabled bool) error

UpdateMember adds or updates cluster member information.

type ClusterMember

type ClusterMember struct {
	ID      int64
	Email   string
	Level   string
	Enabled bool
}

type ClusterRow

type ClusterRow struct {
	ID            int64               `db:"id"`
	Name          string              `db:"name"`
	CreatorID     int64               `db:"creator_id"`
	CreatorEmail  string              `db:"creator_email"`
	DataRetention sqlx_types.JSONText `db:"data_retention"`
	Members       sqlx_types.JSONText `db:"members"`
}

func (*ClusterRow) GetDataRetention

func (cr *ClusterRow) GetDataRetention() map[string]int

GetDataRetention returns DataRetention in map

func (*ClusterRow) GetDeletedFromUNIXTimestampForInsert

func (cr *ClusterRow) GetDeletedFromUNIXTimestampForInsert(tableName string) int64

GetDeletedFromUNIXTimestampForInsert returns UNIX timestamp for timeseries data on insert.

func (*ClusterRow) GetDeletedFromUNIXTimestampForSelect

func (cr *ClusterRow) GetDeletedFromUNIXTimestampForSelect(tableName string) int64

GetDeletedFromUNIXTimestampForSelect returns UNIX timestamp from which data should be queried.

func (*ClusterRow) GetLevelByUserID

func (cr *ClusterRow) GetLevelByUserID(id int64) string

GetLevelByUserID returns a specific cluster member level keyed by user id.

func (*ClusterRow) GetMembers

func (cr *ClusterRow) GetMembers() []ClusterMember

GetMembers returns Members in map

type Graph

type Graph struct {
	Base
}

func NewGraph

func NewGraph(db *sqlx.DB) *Graph

func (*Graph) AllByClusterID

func (g *Graph) AllByClusterID(tx *sqlx.Tx, clusterID int64) ([]*GraphRow, error)

AllByClusterID returns all rows by cluster_id.

func (*Graph) AllGraphs

func (g *Graph) AllGraphs(tx *sqlx.Tx) ([]*GraphRow, error)

AllGraphs returns all rows.

func (*Graph) Create

func (g *Graph) Create(tx *sqlx.Tx, clusterID int64, data map[string]interface{}) (*GraphRow, error)

func (*Graph) DeleteMetricFromGraphs

func (g *Graph) DeleteMetricFromGraphs(tx *sqlx.Tx, clusterID, metricID int64) error

DeleteMetricFromGraphs deletes a particular metric from all rows by cluster_id.

func (*Graph) GetByClusterIDAndID

func (g *Graph) GetByClusterIDAndID(tx *sqlx.Tx, clusterID, id int64) (*GraphRow, error)

GetByClusterIDAndID returns one record by id.

func (*Graph) GetByID

func (g *Graph) GetByID(tx *sqlx.Tx, id int64) (*GraphRow, error)

GetByID returns one record by id.

func (*Graph) UpdateMetricsByClusterIDAndID

func (g *Graph) UpdateMetricsByClusterIDAndID(tx *sqlx.Tx, clusterID, id int64, metricsJSON []byte) (*GraphRow, error)

UpdateMetricsByClusterIDAndID updates metrics JSON and then returns record by id.

type GraphRow

type GraphRow struct {
	ID          int64               `db:"id"`
	ClusterID   int64               `db:"cluster_id"`
	Name        string              `db:"name"`
	Description string              `db:"description"`
	Range       string              `db:"range"`
	Metrics     sqlx_types.JSONText `db:"metrics"`
}

func (*GraphRow) MetricsFromJSON

func (gr *GraphRow) MetricsFromJSON() []*MetricRow

func (*GraphRow) MetricsFromJSONGroupByN

func (gr *GraphRow) MetricsFromJSONGroupByN(n int) [][]*MetricRow

func (*GraphRow) MetricsFromJSONGroupByThree

func (gr *GraphRow) MetricsFromJSONGroupByThree() [][]*MetricRow

type GraphRowsWithError

type GraphRowsWithError struct {
	Graphs []*GraphRow
	Error  error
}

type Host

type Host struct {
	Base
}

func NewHost

func NewHost(db *sqlx.DB) *Host

func (*Host) AllByClusterID

func (h *Host) AllByClusterID(tx *sqlx.Tx, clusterID int64) ([]*HostRow, error)

AllByClusterID returns all rows.

func (*Host) AllByClusterIDAndHostnames

func (h *Host) AllByClusterIDAndHostnames(tx *sqlx.Tx, clusterID int64, hostnames []string) ([]*HostRow, error)

AllByClusterIDAndHostnames returns all rows by hostnames.

func (*Host) AllByClusterIDAndUpdatedInterval

func (h *Host) AllByClusterIDAndUpdatedInterval(tx *sqlx.Tx, clusterID int64, updatedInterval string) ([]*HostRow, error)

AllByClusterIDAndUpdatedInterval returns all rows.

func (*Host) AllByClusterIDQueryAndUpdatedInterval

func (h *Host) AllByClusterIDQueryAndUpdatedInterval(tx *sqlx.Tx, clusterID int64, resourcedQuery, updatedInterval string) ([]*HostRow, error)

AllByClusterIDQueryAndUpdatedInterval returns all rows by resourced query.

func (*Host) AllCompactByClusterIDQueryAndUpdatedInterval

func (h *Host) AllCompactByClusterIDQueryAndUpdatedInterval(tx *sqlx.Tx, clusterID int64, resourcedQuery, updatedInterval string) ([]*HostRow, error)

AllCompactByClusterIDQueryAndUpdatedInterval returns all rows by resourced query.

func (*Host) CountByClusterIDAndUpdatedInterval

func (h *Host) CountByClusterIDAndUpdatedInterval(tx *sqlx.Tx, clusterID int64, updatedInterval string) (int, error)

CountByClusterIDAndUpdatedInterval returns the count of all rows.

func (*Host) CreateOrUpdate

func (h *Host) CreateOrUpdate(tx *sqlx.Tx, accessTokenRow *AccessTokenRow, jsonData []byte) (*HostRow, error)

CreateOrUpdate performs insert/update for one host data.

func (*Host) GetByHostname

func (h *Host) GetByHostname(tx *sqlx.Tx, hostname string) (*HostRow, error)

GetByHostname returns record by hostname.

func (*Host) GetByID

func (h *Host) GetByID(tx *sqlx.Tx, id int64) (*HostRow, error)

GetByID returns record by id.

func (*Host) UpdateMasterTagsByID

func (h *Host) UpdateMasterTagsByID(tx *sqlx.Tx, id int64, tags map[string]interface{}) error

UpdateMasterTagsByID updates master tags by ID.

type HostRow

type HostRow struct {
	ID            int64               `db:"id" json:"-"`
	AccessTokenID int64               `db:"access_token_id" json:"-"`
	ClusterID     int64               `db:"cluster_id"`
	Hostname      string              `db:"hostname"`
	Updated       time.Time           `db:"updated"`
	Tags          sqlx_types.JSONText `db:"tags" json:",omitempty"`
	MasterTags    sqlx_types.JSONText `db:"master_tags" json:",omitempty"`
	Data          sqlx_types.JSONText `db:"data" json:",omitempty"`
}

func (*HostRow) DataAsFlatKeyValue

func (h *HostRow) DataAsFlatKeyValue() map[string]map[string]interface{}

func (*HostRow) GetClusterID

func (h *HostRow) GetClusterID() int64

func (*HostRow) GetHostname

func (h *HostRow) GetHostname() string

func (*HostRow) GetMasterTags

func (h *HostRow) GetMasterTags() map[string]interface{}

func (*HostRow) GetTags

func (h *HostRow) GetTags() map[string]string

type HostRowsWithError

type HostRowsWithError struct {
	Hosts []*HostRow
	Error error
}

type InsertResult

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

func (*InsertResult) LastInsertId

func (ir *InsertResult) LastInsertId() (int64, error)

func (*InsertResult) RowsAffected

func (ir *InsertResult) RowsAffected() (int64, error)

type Metadata

type Metadata struct {
	Base
}

func NewMetadata

func NewMetadata(db *sqlx.DB) *Metadata

func (*Metadata) AllByClusterID

func (metadata *Metadata) AllByClusterID(tx *sqlx.Tx, clusterID int64) ([]*MetadataRow, error)

AllByClusterID returns all metadata rows.

func (*Metadata) CreateOrUpdate

func (metadata *Metadata) CreateOrUpdate(tx *sqlx.Tx, clusterID int64, key string, data []byte) (*MetadataRow, error)

CreateOrUpdate performs insert/update for one metadata data.

func (*Metadata) DeleteByClusterIDAndKey

func (metadata *Metadata) DeleteByClusterIDAndKey(tx *sqlx.Tx, clusterID int64, key string) (*MetadataRow, error)

DeleteByClusterIDAndKey updates record by cluster_id and key.

func (*Metadata) GetByClusterIDAndKey

func (metadata *Metadata) GetByClusterIDAndKey(tx *sqlx.Tx, clusterID int64, key string) (*MetadataRow, error)

GetByClusterIDAndKey returns record by cluster_id and key.

func (*Metadata) UpdateByClusterIDAndKey

func (metadata *Metadata) UpdateByClusterIDAndKey(tx *sqlx.Tx, clusterID int64, key string, data []byte) (*MetadataRow, error)

UpdateByClusterIDAndKey updates record by cluster_id and key.

type MetadataRow

type MetadataRow struct {
	ClusterID int64               `db:"cluster_id" json:"-"`
	Key       string              `db:"key"`
	Data      sqlx_types.JSONText `db:"data"`
}

func (*MetadataRow) DataString

func (metadataRow *MetadataRow) DataString() string

type Metric

type Metric struct {
	Base
}

func NewMetric

func NewMetric(db *sqlx.DB) *Metric

func (*Metric) AllByClusterID

func (d *Metric) AllByClusterID(tx *sqlx.Tx, clusterID int64) ([]*MetricRow, error)

AllByClusterID returns all rows.

func (*Metric) AllByClusterIDAsMap

func (d *Metric) AllByClusterIDAsMap(tx *sqlx.Tx, clusterID int64) (map[string]int64, error)

AllByClusterIDAsMap returns all rows.

func (*Metric) CreateOrUpdate

func (d *Metric) CreateOrUpdate(tx *sqlx.Tx, clusterID int64, key string) (*MetricRow, error)

func (*Metric) GetByClusterIDAndKey

func (d *Metric) GetByClusterIDAndKey(tx *sqlx.Tx, clusterID int64, key string) (*MetricRow, error)

GetByClusterIDAndKey returns one record by cluster_id and key.

func (*Metric) GetByID

func (d *Metric) GetByID(tx *sqlx.Tx, id int64) (*MetricRow, error)

GetByID returns one record by id.

type MetricRow

type MetricRow struct {
	ID        int64  `db:"id"`
	ClusterID int64  `db:"cluster_id"`
	Key       string `db:"key"`
}

type MetricRowsWithError

type MetricRowsWithError struct {
	Metrics []*MetricRow
	Error   error
}

type MetricsMapWithError

type MetricsMapWithError struct {
	MetricsMap map[string]int64
	Error      error
}

type SavedQuery

type SavedQuery struct {
	Base
}

func NewSavedQuery

func NewSavedQuery(db *sqlx.DB) *SavedQuery

func (*SavedQuery) AllByClusterID

func (sq *SavedQuery) AllByClusterID(tx *sqlx.Tx, clusterID int64) ([]*SavedQueryRow, error)

AllByClusterID returns all saved_query rows.

func (*SavedQuery) AllByClusterIDAndType

func (sq *SavedQuery) AllByClusterIDAndType(tx *sqlx.Tx, clusterID int64, savedQueryType string) ([]*SavedQueryRow, error)

AllByClusterIDAndType returns all saved_query rows.

func (*SavedQuery) CreateOrUpdate

func (sq *SavedQuery) CreateOrUpdate(tx *sqlx.Tx, accessTokenRow *AccessTokenRow, savedQueryType, savedQuery string) (*SavedQueryRow, error)

CreateOrUpdate performs insert/update for one savedQuery data.

func (*SavedQuery) GetByAccessTokenAndQuery

func (sq *SavedQuery) GetByAccessTokenAndQuery(tx *sqlx.Tx, accessTokenRow *AccessTokenRow, savedQueryType, savedQuery string) (*SavedQueryRow, error)

GetByAccessTokenAndQuery returns record by savedQuery.

func (*SavedQuery) GetByID

func (sq *SavedQuery) GetByID(tx *sqlx.Tx, id int64) (*SavedQueryRow, error)

GetByID returns record by id.

type SavedQueryRow

type SavedQueryRow struct {
	ID        int64  `db:"id"`
	UserID    int64  `db:"user_id"`
	ClusterID int64  `db:"cluster_id"`
	Type      string `db:"type"`
	Query     string `db:"query"`
}

type SavedQueryRowsWithError

type SavedQueryRowsWithError struct {
	SavedQueries []*SavedQueryRow
	Error        error
}

type TSBase

type TSBase struct {
	Base
}

func (*TSBase) DeleteDeleted

func (ts *TSBase) DeleteDeleted(tx *sqlx.Tx, clusterID int64) error

DeleteDeleted deletes all "deleted" records.

type TSCheck

type TSCheck struct {
	TSBase
}

func NewTSCheck

func NewTSCheck(db *sqlx.DB) *TSCheck

func (*TSCheck) AllViolationsByClusterIDCheckIDAndInterval

func (ts *TSCheck) AllViolationsByClusterIDCheckIDAndInterval(tx *sqlx.Tx, clusterID, CheckID, createdIntervalMinute, deletedFrom int64) ([]*TSCheckRow, error)

AllViolationsByClusterIDCheckIDAndInterval returns all ts_checks rows since last good marker.

func (*TSCheck) Create

func (ts *TSCheck) Create(tx *sqlx.Tx, clusterID, CheckID int64, result bool, expressions []CheckExpression, deletedFrom int64) error

Create a new record.

func (*TSCheck) LastByClusterIDCheckIDAndLimit

func (ts *TSCheck) LastByClusterIDCheckIDAndLimit(tx *sqlx.Tx, clusterID, checkID, limit int64) ([]*TSCheckRow, error)

LastByClusterIDCheckIDAndLimit returns a row by cluster_id, check_id and result.

func (*TSCheck) LastByClusterIDCheckIDAndResult

func (ts *TSCheck) LastByClusterIDCheckIDAndResult(tx *sqlx.Tx, clusterID, checkID int64, result bool) (*TSCheckRow, error)

LastByClusterIDCheckIDAndResult returns a row by cluster_id, check_id and result.

type TSCheckRow

type TSCheckRow struct {
	ClusterID   int64               `db:"cluster_id"`
	CheckID     int64               `db:"check_id"`
	Created     time.Time           `db:"created"`
	Deleted     time.Time           `db:"deleted"`
	Result      bool                `db:"result"`
	Expressions sqlx_types.JSONText `db:"expressions"`
}

func (*TSCheckRow) GetExpressionsWithoutError

func (tsCheckRow *TSCheckRow) GetExpressionsWithoutError() []CheckExpression

type TSEvent

type TSEvent struct {
	TSBase
}

func NewTSEvent

func NewTSEvent(db *sqlx.DB) *TSEvent

func (*TSEvent) AllBandsByClusterIDAndCreatedFromRangeForHighchart

func (ts *TSEvent) AllBandsByClusterIDAndCreatedFromRangeForHighchart(tx *sqlx.Tx, clusterID, from, to, deletedFrom int64) ([]TSEventHighchartLinePayload, error)

AllBandsByClusterIDAndCreatedFromRangeForHighchart returns all rows with time stretch between created_from and created_to.

func (*TSEvent) AllLinesByClusterIDAndCreatedFromRangeForHighchart

func (ts *TSEvent) AllLinesByClusterIDAndCreatedFromRangeForHighchart(tx *sqlx.Tx, clusterID, from, to, deletedFrom int64) ([]TSEventHighchartLinePayload, error)

AllLinesByClusterIDAndCreatedFromRangeForHighchart returns all rows given created_from range.

func (*TSEvent) Create

func (ts *TSEvent) Create(tx *sqlx.Tx, id, clusterID, fromUnix, toUnix int64, description string, deletedFrom int64) (*TSEventRow, error)

Create a new record.

func (*TSEvent) CreateFromJSON

func (ts *TSEvent) CreateFromJSON(tx *sqlx.Tx, id, clusterID int64, jsonData []byte, deletedFrom int64) (*TSEventRow, error)

func (*TSEvent) DeleteDeleted

func (ts *TSEvent) DeleteDeleted(tx *sqlx.Tx, clusterID int64) error

DeleteDeleted deletes all record older than x days ago.

func (*TSEvent) GetByID

func (ts *TSEvent) GetByID(tx *sqlx.Tx, id int64) (*TSEventRow, error)

GetByID returns record by id.

type TSEventCreatePayload

type TSEventCreatePayload struct {
	From        int64  `json:"from"`
	To          int64  `json:"to"`
	Description string `json:"description"`
}

type TSEventHighchartLinePayload

type TSEventHighchartLinePayload struct {
	ID          int64  `json:"ID"`
	CreatedFrom int64  `json:"CreatedFrom"`
	CreatedTo   int64  `json:"CreatedTo"`
	Description string `json:"Description"`
}

type TSEventRow

type TSEventRow struct {
	ID          int64     `db:"id"`
	ClusterID   int64     `db:"cluster_id"`
	CreatedFrom time.Time `db:"created_from"`
	CreatedTo   time.Time `db:"created_to"`
	Deleted     time.Time `db:"deleted"`
	Description string    `db:"description"`
}

type TSLog

type TSLog struct {
	TSBase
}

func NewTSLog

func NewTSLog(db *sqlx.DB) *TSLog

func (*TSLog) AllByClusterIDAndRange

func (ts *TSLog) AllByClusterIDAndRange(tx *sqlx.Tx, clusterID int64, from, to, deletedFrom int64) ([]*TSLogRow, error)

AllByClusterIDAndRange returns all logs withing time range.

func (*TSLog) AllByClusterIDRangeAndQuery

func (ts *TSLog) AllByClusterIDRangeAndQuery(tx *sqlx.Tx, clusterID int64, from, to int64, resourcedQuery string, deletedFrom int64) ([]*TSLogRow, error)

AllByClusterIDRangeAndQuery returns all rows by cluster id, unix timestamp range, and resourced query.

func (*TSLog) CountByClusterIDFromTimestampHostAndQuery

func (ts *TSLog) CountByClusterIDFromTimestampHostAndQuery(tx *sqlx.Tx, clusterID int64, from int64, hostname, resourcedQuery string, deletedFrom int64) (int64, error)

CountByClusterIDFromTimestampHostAndQuery returns count by cluster id, from unix timestamp, host, and resourced query.

func (*TSLog) Create

func (ts *TSLog) Create(tx *sqlx.Tx, clusterID int64, hostname string, tags map[string]string, loglines []AgentLoglinePayload, filename string, deletedFrom int64) (err error)

Create a new record.

func (*TSLog) CreateFromJSON

func (ts *TSLog) CreateFromJSON(tx *sqlx.Tx, clusterID int64, jsonData []byte, deletedFrom int64) error

func (*TSLog) LastByClusterID

func (ts *TSLog) LastByClusterID(tx *sqlx.Tx, clusterID int64) (*TSLogRow, error)

LastByClusterID returns the last row by cluster id.

type TSLogRow

type TSLogRow struct {
	ClusterID int64               `db:"cluster_id"`
	Created   time.Time           `db:"created"`
	Deleted   time.Time           `db:"deleted"`
	Hostname  string              `db:"hostname"`
	Tags      sqlx_types.JSONText `db:"tags"`
	Filename  string              `db:"filename"`
	Logline   string              `db:"logline"`
}

func (*TSLogRow) GetTags

func (tsr *TSLogRow) GetTags() map[string]string

type TSLogRowsWithError

type TSLogRowsWithError struct {
	TSLogRows []*TSLogRow
	Error     error
}

type TSMetric

type TSMetric struct {
	TSBase
}

func NewTSMetric

func NewTSMetric(db *sqlx.DB) *TSMetric

func (*TSMetric) AggregateEveryXMinutes

func (ts *TSMetric) AggregateEveryXMinutes(tx *sqlx.Tx, clusterID int64, minutes int) ([]*TSMetricSelectAggregateRow, error)

func (*TSMetric) AggregateEveryXMinutesPerHost

func (ts *TSMetric) AggregateEveryXMinutesPerHost(tx *sqlx.Tx, clusterID int64, minutes int) ([]*TSMetricSelectAggregateRow, error)

func (*TSMetric) AllByMetricIDAndRange

func (ts *TSMetric) AllByMetricIDAndRange(tx *sqlx.Tx, clusterID, metricID int64, from, to, deletedFrom int64) ([]*TSMetricRow, error)

func (*TSMetric) AllByMetricIDAndRangeForHighchart

func (ts *TSMetric) AllByMetricIDAndRangeForHighchart(tx *sqlx.Tx, clusterID, metricID, from, to, deletedFrom int64) ([]*TSMetricHighchartPayload, error)

func (*TSMetric) AllByMetricIDHostAndRange

func (ts *TSMetric) AllByMetricIDHostAndRange(tx *sqlx.Tx, clusterID, metricID int64, host string, from, to, deletedFrom int64) ([]*TSMetricRow, error)

func (*TSMetric) AllByMetricIDHostAndRangeForHighchart

func (ts *TSMetric) AllByMetricIDHostAndRangeForHighchart(tx *sqlx.Tx, clusterID, metricID int64, host string, from, to, deletedFrom int64) (*TSMetricHighchartPayload, error)

func (*TSMetric) Create

func (ts *TSMetric) Create(tx *sqlx.Tx, clusterID, metricID int64, host, key string, value float64, deletedFrom int64) error

Create a new record.

func (*TSMetric) CreateByHostRow

func (ts *TSMetric) CreateByHostRow(tx *sqlx.Tx, hostRow *HostRow, metricsMap map[string]int64, deletedFrom int64) error

func (*TSMetric) GetAggregateXMinutesByHostnameAndKey

func (ts *TSMetric) GetAggregateXMinutesByHostnameAndKey(tx *sqlx.Tx, clusterID int64, minutes int, hostname, key string) (*TSMetricSelectAggregateRow, error)

type TSMetricAggr15m

type TSMetricAggr15m struct {
	TSBase
}

func NewTSMetricAggr15m

func NewTSMetricAggr15m(db *sqlx.DB) *TSMetricAggr15m

func (*TSMetricAggr15m) AllByMetricIDAndRange

func (ts *TSMetricAggr15m) AllByMetricIDAndRange(tx *sqlx.Tx, clusterID, metricID, from, to, deletedFrom int64) ([]*TSMetricAggr15mRow, error)

func (*TSMetricAggr15m) AllByMetricIDAndRangeForHighchart

func (ts *TSMetricAggr15m) AllByMetricIDAndRangeForHighchart(tx *sqlx.Tx, clusterID, metricID, from, to, deletedFrom int64, aggr string) ([]*TSMetricHighchartPayload, error)

func (*TSMetricAggr15m) AllByMetricIDHostAndRange

func (ts *TSMetricAggr15m) AllByMetricIDHostAndRange(tx *sqlx.Tx, clusterID, metricID int64, host string, from, to, deletedFrom int64) ([]*TSMetricAggr15mRow, error)

func (*TSMetricAggr15m) AllByMetricIDHostAndRangeForHighchart

func (ts *TSMetricAggr15m) AllByMetricIDHostAndRangeForHighchart(tx *sqlx.Tx, clusterID, metricID int64, host string, from, to, deletedFrom int64, aggr string) ([]*TSMetricHighchartPayload, error)

func (*TSMetricAggr15m) CreateByHostRow

func (ts *TSMetricAggr15m) CreateByHostRow(tx *sqlx.Tx, hostRow *HostRow, metricsMap map[string]int64, selectAggrRows []*TSMetricSelectAggregateRow, deletedFrom int64) error

CreateByHostRow creates new rows given host data.

func (*TSMetricAggr15m) CreateByHostRowPerHost

func (ts *TSMetricAggr15m) CreateByHostRowPerHost(tx *sqlx.Tx, hostRow *HostRow, metricsMap map[string]int64, selectAggrRows []*TSMetricSelectAggregateRow, deletedFrom int64) error

CreateByHostRowPerHost creates new rows given host data per host.

func (*TSMetricAggr15m) InsertOrUpdate

func (ts *TSMetricAggr15m) InsertOrUpdate(tx *sqlx.Tx, clusterID, metricID int64, metricKey string, selectAggrRow *TSMetricSelectAggregateRow, deletedFrom int64) (err error)

InsertOrUpdate a new record.

func (*TSMetricAggr15m) InsertOrUpdateMany

func (ts *TSMetricAggr15m) InsertOrUpdateMany(tx *sqlx.Tx, clusterID, metricID int64, metricKey string, selectAggrRows []*TSMetricSelectAggregateRow, deletedFrom int64) (err error)

InsertOrUpdateMany multiple records.

func (*TSMetricAggr15m) TransformForHighchart

func (ts *TSMetricAggr15m) TransformForHighchart(tx *sqlx.Tx, tsMetricRows []*TSMetricAggr15mRow, aggr string) ([]*TSMetricHighchartPayload, error)

type TSMetricAggr15mRow

type TSMetricAggr15mRow struct {
	ClusterID int64          `db:"cluster_id"`
	MetricID  int64          `db:"metric_id"`
	Created   time.Time      `db:"created"`
	Deleted   time.Time      `db:"deleted"`
	Key       string         `db:"key"`
	Host      sql.NullString `db:"host"`
	Avg       float64        `db:"avg"`
	Max       float64        `db:"max"`
	Min       float64        `db:"min"`
	Sum       float64        `db:"sum"`
}

type TSMetricHighchartPayload

type TSMetricHighchartPayload struct {
	Name string          `json:"name"`
	Data [][]interface{} `json:"data"`
}

type TSMetricRow

type TSMetricRow struct {
	ClusterID int64     `db:"cluster_id"`
	MetricID  int64     `db:"metric_id"`
	Created   time.Time `db:"created"`
	Deleted   time.Time `db:"deleted"`
	Key       string    `db:"key"`
	Host      string    `db:"host"`
	Value     float64   `db:"value"`
}

type TSMetricSelectAggregateRow

type TSMetricSelectAggregateRow struct {
	ClusterID   int64   `db:"cluster_id"`
	CreatedUnix int64   `db:"created_unix"`
	Key         string  `db:"key"`
	Host        string  `db:"host"`
	Avg         float64 `db:"avg"`
	Max         float64 `db:"max"`
	Min         float64 `db:"min"`
	Sum         float64 `db:"sum"`
}

type User

type User struct {
	Base
}

func NewUser

func NewUser(db *sqlx.DB) *User

func (*User) AllUsers

func (u *User) AllUsers(tx *sqlx.Tx) ([]*UserRow, error)

AllUsers returns all user rows.

func (*User) GetByEmail

func (u *User) GetByEmail(tx *sqlx.Tx, email string) (*UserRow, error)

GetByEmail returns record by email.

func (*User) GetByEmailVerificationToken

func (u *User) GetByEmailVerificationToken(tx *sqlx.Tx, emailVerificationToken string) (*UserRow, error)

GetByEmailVerificationToken returns record by email_verification_token.

func (*User) GetByID

func (u *User) GetByID(tx *sqlx.Tx, id int64) (*UserRow, error)

GetByID returns record by id.

func (*User) GetUserByEmailAndPassword

func (u *User) GetUserByEmailAndPassword(tx *sqlx.Tx, email, password string) (*UserRow, error)

GetByEmail returns record by email but checks password first.

func (*User) Signup

func (u *User) Signup(tx *sqlx.Tx, email, password, passwordAgain string) (*UserRow, error)

Signup create a new record of user.

func (*User) SignupRandomPassword

func (u *User) SignupRandomPassword(tx *sqlx.Tx, email string) (*UserRow, error)

SignupRandomPassword create a new record of user with random password.

func (*User) UpdateEmailAndPasswordById

func (u *User) UpdateEmailAndPasswordById(tx *sqlx.Tx, userId int64, email, password, passwordAgain string) (*UserRow, error)

UpdateEmailAndPasswordById updates user email and password.

func (*User) UpdateEmailVerification

func (u *User) UpdateEmailVerification(tx *sqlx.Tx, emailVerificationToken string) (*UserRow, error)

UpdateEmailVerification acknowledge email verification.

type UserRow

type UserRow struct {
	ID                     int64          `db:"id"`
	Email                  string         `db:"email"`
	Password               string         `db:"password"`
	EmailVerificationToken sql.NullString `db:"email_verification_token"`
	EmailVerified          bool           `db:"email_verified"`
}

Jump to

Keyboard shortcuts

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