Documentation ¶
Index ¶
- Constants
- Variables
- func AlertPredicatesFromFilter(filter map[string][]string) ([]predicate.Alert, error)
- func BuildAlertRequestFromFilter(alerts *ent.AlertQuery, filter map[string][]string) (*ent.AlertQuery, error)
- func BuildDecisionRequestWithFilter(query *ent.DecisionQuery, filter map[string][]string) (*ent.DecisionQuery, error)
- func GetIpsFromIpRange(host string) (int64, int64, error)
- func IP2Int(ip net.IP) uint32
- func Int2ip(nn uint32) net.IP
- func IsIpv4(host string) bool
- func LastAddress(n *net.IPNet) net.IP
- func ParseDuration(d string) (time.Duration, error)
- type Client
- func (c *Client) AcquireLock(name string) error
- func (c *Client) AcquirePullCAPILock() error
- func (c *Client) AlertsCountPerScenario(filters map[string][]string) (map[string]int, error)
- func (c *Client) BouncerUpdateBaseMetrics(bouncerName string, bouncerType string, baseMetrics models.BaseMetrics) error
- func (c *Client) BulkDeleteBouncers(bouncers []*ent.Bouncer) (int, error)
- func (c *Client) BulkDeleteWatchers(machines []*ent.Machine) (int, error)
- func (c *Client) CountActiveDecisionsByValue(decisionValue string) (int, error)
- func (c *Client) CountDecisionsByValue(decisionValue string) (int, error)
- func (c *Client) CountDecisionsSinceByValue(decisionValue string, since time.Time) (int, error)
- func (c *Client) CreateAlert(machineID string, alertList []*models.Alert) ([]string, error)
- func (c *Client) CreateBouncer(name string, ipAddr string, apiKey string, authType string) (*ent.Bouncer, error)
- func (c *Client) CreateMachine(machineID *string, password *strfmt.Password, ipAddress string, ...) (*ent.Machine, error)
- func (c *Client) CreateMetric(generatedType metric.GeneratedType, generatedBy string, receivedAt time.Time, ...) (*ent.Metric, error)
- func (c *Client) CreateOrUpdateAlert(machineID string, alertItem *models.Alert) (string, error)
- func (c *Client) DeleteAlertByID(id int) error
- func (c *Client) DeleteAlertGraph(alertItem *ent.Alert) error
- func (c *Client) DeleteAlertGraphBatch(alertItems []*ent.Alert) (int, error)
- func (c *Client) DeleteAlertWithFilter(filter map[string][]string) (int, error)
- func (c *Client) DeleteBouncer(name string) error
- func (c *Client) DeleteDecisionById(decisionID int) ([]*ent.Decision, error)
- func (c *Client) DeleteDecisions(decisions []*ent.Decision) (int, error)
- func (c *Client) DeleteDecisionsWithFilter(filter map[string][]string) (string, []*ent.Decision, error)
- func (c *Client) DeleteWatcher(name string) error
- func (c *Client) ExpireDecisionByID(decisionID int) (int, []*ent.Decision, error)
- func (c *Client) ExpireDecisions(decisions []*ent.Decision) (int, error)
- func (c *Client) ExpireDecisionsWithFilter(filter map[string][]string) (string, []*ent.Decision, error)
- func (c *Client) FlushAgentsAndBouncers(agentsCfg *csconfig.AuthGCCfg, bouncersCfg *csconfig.AuthGCCfg) error
- func (c *Client) FlushAlerts(MaxAge string, MaxItems int) error
- func (c *Client) FlushOrphans()
- func (c *Client) GetActiveDecisionsTimeLeftByValue(decisionValue string) (time.Duration, error)
- func (c *Client) GetAlertByID(alertID int) (*ent.Alert, error)
- func (c *Client) GetBouncerUsageMetricsByName(bouncerName string) ([]*ent.Metric, error)
- func (c *Client) GetConfigItem(key string) (*string, error)
- func (c *Client) GetLPUsageMetricsByMachineID(machineId string) ([]*ent.Metric, error)
- func (c *Client) IsLocked(err error) bool
- func (c *Client) IsMachineRegistered(machineID string) (bool, error)
- func (c *Client) ListBouncers() ([]*ent.Bouncer, error)
- func (c *Client) ListMachines() ([]*ent.Machine, error)
- func (c *Client) MachineUpdateBaseMetrics(machineID string, baseMetrics models.BaseMetrics, hubItems models.HubItems, ...) error
- func (c *Client) MarkUsageMetricsAsSent(ids []int) error
- func (c *Client) QueryAlertWithFilter(filter map[string][]string) ([]*ent.Alert, error)
- func (c *Client) QueryAllDecisionsWithFilters(filters map[string][]string) ([]*ent.Decision, error)
- func (c *Client) QueryBouncersInactiveSince(t time.Time) ([]*ent.Bouncer, error)
- func (c *Client) QueryDecisionCountByScenario() ([]*DecisionsByScenario, error)
- func (c *Client) QueryDecisionWithFilter(filter map[string][]string) ([]*ent.Decision, error)
- func (c *Client) QueryExpiredDecisionsSinceWithFilters(since *time.Time, filters map[string][]string) ([]*ent.Decision, error)
- func (c *Client) QueryExpiredDecisionsWithFilters(filters map[string][]string) ([]*ent.Decision, error)
- func (c *Client) QueryMachineByID(machineID string) (*ent.Machine, error)
- func (c *Client) QueryMachinesInactiveSince(t time.Time) ([]*ent.Machine, error)
- func (c *Client) QueryNewDecisionsSinceWithFilters(since *time.Time, filters map[string][]string) ([]*ent.Decision, error)
- func (c *Client) QueryPendingMachine() ([]*ent.Machine, error)
- func (c *Client) ReleaseLock(name string) error
- func (c *Client) ReleaseLockWithTimeout(name string, timeout int) error
- func (c *Client) ReleasePullCAPILock() error
- func (c *Client) SelectBouncer(apiKeyHash string) (*ent.Bouncer, error)
- func (c *Client) SelectBouncerByName(bouncerName string) (*ent.Bouncer, error)
- func (c *Client) SetConfigItem(key string, value string) error
- func (c *Client) StartFlushScheduler(config *csconfig.FlushDBCfg) (*gocron.Scheduler, error)
- func (c *Client) TotalAlerts() (int, error)
- func (c *Client) UpdateBouncerIP(ipAddr string, id int) error
- func (c *Client) UpdateBouncerLastPull(lastPull time.Time, id int) error
- func (c *Client) UpdateBouncerTypeAndVersion(bType string, version string, id int) error
- func (c *Client) UpdateCommunityBlocklist(alertItem *models.Alert) (int, int, int, error)
- func (c *Client) UpdateMachineIP(ipAddr string, ID int) error
- func (c *Client) UpdateMachineLastHeartBeat(machineID string) error
- func (c *Client) UpdateMachineScenarios(scenarios string, ID int) error
- func (c *Client) UpdateMachineVersion(ipAddr string, ID int) error
- func (c *Client) ValidateMachine(machineID string) error
- type DecisionsByScenario
Constants ¶
const ( CAPIPullLockTimeout = 10 CapiPullLockName = "pullCAPI" )
const ( CapiMachineID = types.CAPIOrigin CapiListsMachineID = types.ListOrigin )
Variables ¶
var ( UserExists = errors.New("user already exist") UserNotExists = errors.New("user doesn't exist") HashError = errors.New("unable to hash") InsertFail = errors.New("unable to insert row") QueryFail = errors.New("unable to query") UpdateFail = errors.New("unable to update") DeleteFail = errors.New("unable to delete") ItemNotFound = errors.New("object not found") ParseTimeFail = errors.New("unable to parse time") ParseDurationFail = errors.New("unable to parse duration") MarshalFail = errors.New("unable to marshal") UnmarshalFail = errors.New("unable to unmarshal") BulkError = errors.New("unable to insert bulk") ParseType = errors.New("unable to parse type") InvalidIPOrRange = errors.New("invalid ip address / range") InvalidFilter = errors.New("invalid filter") )
Functions ¶
func AlertPredicatesFromFilter ¶ added in v1.4.2
func BuildAlertRequestFromFilter ¶ added in v1.0.0
func BuildAlertRequestFromFilter(alerts *ent.AlertQuery, filter map[string][]string) (*ent.AlertQuery, error)
func BuildDecisionRequestWithFilter ¶ added in v1.0.0
func BuildDecisionRequestWithFilter(query *ent.DecisionQuery, filter map[string][]string) (*ent.DecisionQuery, error)
func GetIpsFromIpRange ¶ added in v1.0.0
GetIpsFromIpRange takes a CIDR range and returns the start and end IP
func LastAddress ¶ added in v1.0.0
Stolen from : https://github.com/llimllib/ipaddress/ Return the final address of a net range. Convert to IPv4 if possible, otherwise return an ipv6
Types ¶
type Client ¶ added in v1.0.0
type Client struct { Ent *ent.Client CTX context.Context Log *log.Logger CanFlush bool Type string WalMode *bool // contains filtered or unexported fields }
func (*Client) AcquireLock ¶ added in v1.6.1
func (*Client) AcquirePullCAPILock ¶ added in v1.6.1
func (*Client) AlertsCountPerScenario ¶ added in v1.4.0
func (*Client) BouncerUpdateBaseMetrics ¶ added in v1.6.3
func (*Client) BulkDeleteBouncers ¶ added in v1.5.3
func (*Client) BulkDeleteWatchers ¶ added in v1.5.3
func (*Client) CountActiveDecisionsByValue ¶ added in v1.6.2
func (*Client) CountDecisionsByValue ¶ added in v1.4.0
func (*Client) CountDecisionsSinceByValue ¶ added in v1.4.0
func (*Client) CreateAlert ¶ added in v1.0.0
func (*Client) CreateBouncer ¶ added in v1.0.0
func (*Client) CreateMachine ¶ added in v1.0.0
func (*Client) CreateMetric ¶ added in v1.6.3
func (*Client) CreateOrUpdateAlert ¶ added in v1.5.0
CreateOrUpdateAlert is specific to PAPI : It checks if alert already exists, otherwise inserts it if alert already exists, it checks it associated decisions already exists if some associated decisions are missing (ie. previous insert ended up in error) it inserts them
func (*Client) DeleteAlertByID ¶ added in v1.4.2
func (*Client) DeleteAlertGraph ¶ added in v1.0.0
func (*Client) DeleteAlertGraphBatch ¶ added in v1.2.1
func (*Client) DeleteAlertWithFilter ¶ added in v1.0.0
func (*Client) DeleteBouncer ¶ added in v1.0.0
func (*Client) DeleteDecisionById ¶ added in v1.0.0
func (*Client) DeleteDecisions ¶ added in v1.6.3
DeleteDecisions removes a list of decisions from the database It returns the number of impacted decisions for the CAPI/PAPI
func (*Client) DeleteDecisionsWithFilter ¶ added in v1.0.0
func (*Client) DeleteWatcher ¶ added in v1.0.0
func (*Client) ExpireDecisionByID ¶ added in v1.6.3
ExpireDecision set the expiration of a decision to now()
func (*Client) ExpireDecisions ¶ added in v1.6.3
ExpireDecisions sets the expiration of a list of decisions to now() It returns the number of impacted decisions for the CAPI/PAPI
func (*Client) ExpireDecisionsWithFilter ¶ added in v1.6.3
func (c *Client) ExpireDecisionsWithFilter(filter map[string][]string) (string, []*ent.Decision, error)
ExpireDecisionsWithFilter updates the expiration time to now() for the decisions matching the filter, and returns the updated items
func (*Client) FlushAgentsAndBouncers ¶ added in v1.4.0
func (*Client) FlushAlerts ¶ added in v1.0.0
func (*Client) FlushOrphans ¶ added in v1.1.0
func (c *Client) FlushOrphans()
func (*Client) GetActiveDecisionsTimeLeftByValue ¶ added in v1.6.2
func (*Client) GetAlertByID ¶ added in v1.0.0
func (*Client) GetBouncerUsageMetricsByName ¶ added in v1.6.3
func (*Client) GetConfigItem ¶ added in v1.5.0
func (*Client) GetLPUsageMetricsByMachineID ¶ added in v1.6.3
func (*Client) IsMachineRegistered ¶ added in v1.0.0
func (*Client) ListBouncers ¶ added in v1.0.0
func (*Client) ListMachines ¶ added in v1.0.0
func (*Client) MachineUpdateBaseMetrics ¶ added in v1.6.3
func (*Client) MarkUsageMetricsAsSent ¶ added in v1.6.3
func (*Client) QueryAlertWithFilter ¶ added in v1.0.0
func (*Client) QueryAllDecisionsWithFilters ¶ added in v1.1.0
func (*Client) QueryBouncersInactiveSince ¶ added in v1.6.3
func (*Client) QueryDecisionCountByScenario ¶ added in v1.4.0
func (c *Client) QueryDecisionCountByScenario() ([]*DecisionsByScenario, error)
func (*Client) QueryDecisionWithFilter ¶ added in v1.0.0
func (*Client) QueryExpiredDecisionsSinceWithFilters ¶ added in v1.1.0
func (*Client) QueryExpiredDecisionsWithFilters ¶ added in v1.1.0
func (*Client) QueryMachineByID ¶ added in v1.0.0
func (*Client) QueryMachinesInactiveSince ¶ added in v1.6.3
func (*Client) QueryNewDecisionsSinceWithFilters ¶ added in v1.1.0
func (*Client) QueryPendingMachine ¶ added in v1.0.0
func (*Client) ReleaseLock ¶ added in v1.6.1
func (*Client) ReleaseLockWithTimeout ¶ added in v1.6.1
func (*Client) ReleasePullCAPILock ¶ added in v1.6.1
func (*Client) SelectBouncer ¶ added in v1.0.0
func (*Client) SelectBouncerByName ¶ added in v1.4.0
func (*Client) SetConfigItem ¶ added in v1.5.0
func (*Client) StartFlushScheduler ¶ added in v1.0.0
func (*Client) TotalAlerts ¶ added in v1.0.0
func (*Client) UpdateBouncerIP ¶ added in v1.0.0
func (*Client) UpdateBouncerLastPull ¶ added in v1.0.0
func (*Client) UpdateBouncerTypeAndVersion ¶ added in v1.0.0
func (*Client) UpdateCommunityBlocklist ¶ added in v1.2.0
UpdateCommunityBlocklist is called to update either the community blocklist (or other lists the user subscribed to) it takes care of creating the new alert with the associated decisions, and it will as well deleted the "older" overlapping decisions: 1st pull, you get decisions [1,2,3]. it inserts [1,2,3] 2nd pull, you get decisions [1,2,3,4]. it inserts [1,2,3,4] and will try to delete [1,2,3,4] with a different alert ID and same origin