Documentation
¶
Overview ¶
Package models contains the database models.
Index ¶
- func AuthMiddleware(next http.Handler) http.Handler
- func AuthSecretAgentMiddleware(next http.Handler) http.Handler
- func CheckIfAllowTo(user *User, allowTo string) error
- func CleanupMetrics(interval time.Duration) error
- func CreateAgent(secret, name, description string, tags map[string]string) error
- func CreateAgentTagByAgentID(agentID uuid.UUID, key string, value string) error
- func CreateUserToken(user *User) (string, error)
- func DeleteAgentTags(agentID uuid.UUID) error
- func DeleteAllSampleResults(sampleID string) error
- func DeleteExpiredMetrics() error
- func DeleteMetricBySampleID(sampleID string) error
- func DeleteOldMetrics(interval time.Duration) error
- func DeleteOldMetricsLabels(interval time.Duration) error
- func DeleteOldSampleResults(interval time.Duration) error
- func DeleteSample(sampleID string) error
- func GetAgentQuery() *gorm.DB
- func GetDistinctChecksumByName(name string) ([]string, error)
- func GetDistinctChecksumByNameAndSampleID(name, sampleID string) ([]string, error)
- func GetDistinctMetricName() ([]string, error)
- func GetDistinctMetricNameBySampleID(sampleID string) ([]string, error)
- func GetTotalSamples() int64
- func GetUserCount() int64
- func ProcessMetricsQueue()
- func SetupDB(dbType, dbPath, dbURI string)
- func UpdateAgent(agentID uuid.UUID, name, description string) error
- func VerifyUserToken(tokenString string) (jwt.Claims, error)
- type Agent
- type AgentTag
- type IScenario
- type Metric
- func GetMetricByChecksum(checksum, name string) (*Metric, error)
- func GetMetricByName(name string) (*Metric, error)
- func GetMetricsByNameAndSampleID(name, sampleID, checksum string, limit int) ([]Metric, error)
- func GetMetricsBySampleID(sampleID string) ([]Metric, error)
- func GetMetricsBySampleResultID(sampleResultID string) ([]Metric, error)
- type MetricLabel
- type MetricQueue
- type Permission
- type Sample
- func GetSampleByID(id string) (*Sample, error)
- func GetSamples() ([]Sample, error)
- func GetSamplesWithPagination(page, limit int) ([]Sample, error)
- func RegisterSample(name, descrption, kind string, sampleData []byte, user *User) (*Sample, error)
- func SearchSamples(name string) ([]Sample, error)
- func SearchSamplesWithPagination(name string, page, limit int) ([]Sample, error)
- func UpdateSample(id, name, descrption, kind string, sampleData []byte, user *User) (*Sample, error)
- type SampleResult
- type Scenario
- type ScenarioResult
- type Scenarios
- type Step
- type StepDefinition
- type StepParam
- type StepResult
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
AuthMiddleware Verify if user is logged
func AuthSecretAgentMiddleware ¶
AuthSecretAgentMiddleware auth secret agent middleware
func CheckIfAllowTo ¶
CheckIfAllowTo check if user has permission to execute
func CleanupMetrics ¶ added in v1.0.3
CleanupMetrics Cleanup metrics
func CreateAgent ¶
CreateAgent create a new agent
func CreateAgentTagByAgentID ¶
CreateAgentTagByAgentID create a new agent tag
func CreateUserToken ¶
CreateUserToken Generate a new login token
func DeleteAgentTags ¶
DeleteAgentTags delete agent tags
func DeleteAllSampleResults ¶ added in v1.2.0
DeleteAllSampleResults by sample id
func DeleteExpiredMetrics ¶
func DeleteExpiredMetrics() error
DeleteExpiredMetrics Delete all expired metrics
func DeleteMetricBySampleID ¶ added in v1.2.0
DeleteMetricBySampleID Delete metric by sample id
func DeleteOldMetrics ¶
DeleteOldMetrics Delete old metrics
func DeleteOldMetricsLabels ¶ added in v1.0.3
DeleteOldMetricsLabels Delete old metrics labels
func DeleteOldSampleResults ¶ added in v1.0.3
DeleteOldSampleResults Delete old scenario results
func DeleteSample ¶ added in v1.2.0
DeleteSample delete sample by id
func GetDistinctChecksumByName ¶
GetDistinctChecksumByName Get distinct checksum by name
func GetDistinctChecksumByNameAndSampleID ¶
GetDistinctChecksumByNameAndSampleID Get distinct metrics by name and sample id
func GetDistinctMetricName ¶
GetDistinctMetricName Get distinct metric name
func GetDistinctMetricNameBySampleID ¶
GetDistinctMetricNameBySampleID return distinct metric name by sample id
func UpdateAgent ¶
UpdateAgent update agent
Types ¶
type Agent ¶
type Agent struct { gorm.Model Name string Description string ID uuid.UUID `gorm:"primaryKey;type:char(36);"` Secret string `json:"-" gorm:"primaryKey;type:char(36);"` }
Agent model
func SearchAgentByName ¶
SearchAgentByName search agent by name
type AgentTag ¶
type AgentTag struct { gorm.Model ID uuid.UUID `gorm:"primaryKey;type:char(36);"` AgentID uuid.UUID Agent Agent `gorm:"foreignKey:AgentID" json:"-"` Key string Value string }
AgentTag model
type IScenario ¶
type IScenario interface { StartPrimitives() Init() RunStep(string, map[string]string) ([]Metric, error) RegisterStep(string, StepDefinition) Description() string GetScenarioDefinitions() map[string]StepDefinition }
IScenario Define scenario interface
type Metric ¶
type Metric struct { gorm.Model ID uuid.UUID `gorm:"primaryKey;type:char(36);"` Name string Value float64 Labels map[string]string `gorm:"-"` Description string SampleID string Expires time.Duration SampleResultID uuid.UUID `json:"-"` SampleResult *SampleResult `gorm:"foreignKey:SampleResultID" json:"-"` }
Metric definition
func GetMetricByChecksum ¶
GetMetricByChecksum Get one metric by checksum
func GetMetricByName ¶
GetMetricByName Get one metric by name
func GetMetricsByNameAndSampleID ¶
GetMetricsByNameAndSampleID Get metrics by name and sample id
func GetMetricsBySampleID ¶
GetMetricsBySampleID return metrics by sample id
func GetMetricsBySampleResultID ¶
GetMetricsBySampleResultID return metrics by sample result id
type MetricLabel ¶
type MetricLabel struct { gorm.Model Key string Value string Metric Metric `gorm:"foreignKey:MetricID" json:"-"` MetricID string }
MetricLabel definition
func GetMetricLabelByMetricID ¶
func GetMetricLabelByMetricID(id uuid.UUID) ([]MetricLabel, error)
GetMetricLabelByMetricID Get metric label by metric id
type MetricQueue ¶
type MetricQueue struct { AgentID string Sample Sample ScenarioResult ScenarioResult }
MetricQueue represent a metric queue
type Permission ¶
type Permission struct { gorm.Model ID uuid.UUID `gorm:"primaryKey;type:char(36);"` UserID uuid.UUID `json:"user"` User User `gorm:"foreignKey:UserID" json:"-"` AllowTo string }
Permission represents a permission
func AddPermission2User ¶
func AddPermission2User(user *User, allowTo string) (*Permission, error)
AddPermission2User add permission to user
func GetPermissionByUserAllowTo ¶
func GetPermissionByUserAllowTo(user *User, allowTo string) (*Permission, error)
GetPermissionByUserAllowTo get permission by user and allowTo
type Sample ¶
type Sample struct { gorm.Model `json:"-"` ID uuid.UUID `gorm:"primaryKey;type:char(36);"` Name string `json:"-"` OwnerID uuid.UUID `json:"-"` Owner User `gorm:"foreignKey:OwnerID" json:"-"` SampleData []byte `json:"-"` Checksum string Description string `json:"-"` Kind string `json:"-"` }
Sample represent a sample
func GetSampleByID ¶
GetSampleByID return sample by id
func GetSamplesWithPagination ¶
GetSamplesWithPagination return samples with pagination
func RegisterSample ¶
RegisterSample register sample
func SearchSamplesWithPagination ¶
SearchSamplesWithPagination search samples with pagination
func UpdateSample ¶
func UpdateSample(id, name, descrption, kind string, sampleData []byte, user *User) (*Sample, error)
UpdateSample update sample
func (*Sample) PushMetrics ¶
func (s *Sample) PushMetrics(ScenarioResult *ScenarioResult, agentID string) error
PushMetrics push metrics to database
func (*Sample) PushMetricsToQueue ¶
func (s *Sample) PushMetricsToQueue(ScenarioResult *ScenarioResult, agentID string)
PushMetricsToQueue push metrics to queue
type SampleResult ¶
type SampleResult struct { gorm.Model `json:"-"` ID uuid.UUID `gorm:"primaryKey;type:char(36);"` SampleID uuid.UUID `json:"-"` Sample Sample `gorm:"foreignKey:SampleID" json:"-"` StartDate time.Time EndDate time.Time Error string Agent Agent `gorm:"foreignKey:AgentID"` AgentID uuid.UUID }
SampleResult represent a sample result
func GetLastSampleResultBySampleID ¶
func GetLastSampleResultBySampleID(sampleID string) (*SampleResult, error)
GetLastSampleResultBySampleID return last sample result by sample id
func GetSampleResultBySampleIDWithLimit ¶
func GetSampleResultBySampleIDWithLimit(sampleID string, limit int) ([]*SampleResult, error)
GetSampleResultBySampleIDWithLimit return latest sample result by sample id
func GetSampleResults ¶
func GetSampleResults(sampleID string, limit int) ([]SampleResult, error)
GetSampleResults return sample results by sample id
type Scenario ¶
type Scenario struct { Kind string Steps []Step StepsDefinitions map[string]StepDefinition }
Scenario definition
func (*Scenario) Description ¶
Description Get scenario description
func (*Scenario) GetScenarioDefinitions ¶
func (s *Scenario) GetScenarioDefinitions() map[string]StepDefinition
GetScenarioDefinitions Get scenario definitions
func (*Scenario) RegisterStep ¶
func (s *Scenario) RegisterStep(name string, step StepDefinition)
RegisterStep Register step default method
func (*Scenario) StartPrimitives ¶
func (s *Scenario) StartPrimitives()
StartPrimitives Initialize primitive variables
type ScenarioResult ¶
type ScenarioResult struct { Scenario Scenario StartDate time.Time EndDate time.Time StepResults []*StepResult Error error `json:"-"` ErrorString string }
ScenarioResult is the result of a scenario
type Scenarios ¶
type Scenarios struct { Name string Description string Scenario Scenario ScrapeInterval time.Duration `yaml:"scrapeInterval"` }
Scenarios represent sample scenarios
func ReadScenariosYAML ¶
ReadScenariosYAML Read scenarios pointer from yaml
type StepDefinition ¶
type StepDefinition struct { Name string Description string Params []StepParam Fn stepFn `json:"-"` }
StepDefinition definition
type StepResult ¶
StepResult is the result of a step
type User ¶
type User struct { gorm.Model ID uuid.UUID `gorm:"primaryKey;type:char(36);"` Email string `gorm:"unique;primaryKey"` Password []byte `json:"-"` TwoFactorToken string `json:"-" gorm:"type:char(32)"` }
User Represent user
func CreateUser ¶
CreateUser Create a new username
func GetLoggedUser ¶
GetLoggedUser Return user by http header
func GetUserByEmail ¶
GetUserByEmail Get one user given an email
func (*User) Update2FAToken ¶ added in v1.0.5
Update2FAToken Update 2FA token
func (*User) UpdatePassword ¶ added in v1.0.5
UpdatePassword Update user password