rules

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionTypeSMTP  = "smtp"
	ActionTypeSMPP  = "smpp"
	ActionTypeAlarm = "alarm"

	OperatorAND = "AND"
	OperatorOR  = "OR"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	ID   string `json:"id"`
	Type string `json:"type"`
}

type Condition

type Condition struct {
	Field      string   `json:"field"`
	Comparator string   `json:"comparator"`
	Threshold  *float64 `json:"threshold"`
}

type Rule

type Rule struct {
	ID          string
	GroupID     string
	Name        string
	Description string
	Conditions  []Condition
	Operator    string
	Actions     []Action
}

type RuleRepository

type RuleRepository interface {
	// Save persists multiple rules. Rules are saved using a transaction.
	// If one rule fails then none will be saved.
	// Successful operation is indicated by a non-nil error response.
	Save(ctx context.Context, rules ...Rule) ([]Rule, error)

	// RetrieveByID retrieves a rule having the provided identifier.
	RetrieveByID(ctx context.Context, id string) (Rule, error)

	// RetrieveByThing retrieves rules assigned to a certain thing.
	RetrieveByThing(ctx context.Context, thingID string, pm apiutil.PageMetadata) (RulesPage, error)

	// RetrieveByGroup retrieves rules assigned to a certain group.
	RetrieveByGroup(ctx context.Context, groupID string, pm apiutil.PageMetadata) (RulesPage, error)

	// RetrieveThingIDsByRule retrieves all thing IDs that have the given rule assigned.
	RetrieveThingIDsByRule(ctx context.Context, ruleID string) ([]string, error)

	// Update performs an update to the existing rule. A non-nil error is
	// returned to indicate operation failure.
	Update(ctx context.Context, r Rule) error

	// Remove removes the rules having the provided identifiers.
	Remove(ctx context.Context, ids ...string) error

	// Assign assigns rules to the specified thing.
	Assign(ctx context.Context, thingID string, ruleIDs ...string) error

	// Unassign removes rules from the specified thing.
	Unassign(ctx context.Context, thingID string, ruleIDs ...string) error
}

type RulesPage

type RulesPage struct {
	Total uint64
	Rules []Rule
}

type Service

type Service interface {
	// CreateRules creates rules.
	CreateRules(ctx context.Context, token, groupID string, rules ...Rule) ([]Rule, error)

	// ListRulesByThing retrieves a paginated list of rules by thing.
	ListRulesByThing(ctx context.Context, token, thingID string, pm apiutil.PageMetadata) (RulesPage, error)

	// ListRulesByGroup retrieves a paginated list of rules by group.
	ListRulesByGroup(ctx context.Context, token, groupID string, pm apiutil.PageMetadata) (RulesPage, error)

	// ListThingIDsByRule retrieves a list of thing IDs attached to the given rule ID.
	ListThingIDsByRule(ctx context.Context, token, ruleID string) ([]string, error)

	// ViewRule retrieves a specific rule by its ID.
	ViewRule(ctx context.Context, token, id string) (Rule, error)

	// UpdateRule updates the rule identified by the provided ID.
	UpdateRule(ctx context.Context, token string, rule Rule) error

	// RemoveRules removes the rules identified with the provided IDs.
	RemoveRules(ctx context.Context, token string, ids ...string) error

	// AssignRules assigns rules to a specific thing.
	AssignRules(ctx context.Context, token, thingID string, ruleIDs ...string) error

	// UnassignRules removes rule assignments from a specific thing.
	UnassignRules(ctx context.Context, token, thingID string, ruleIDs ...string) error

	// Publish publishes messages on a topic related to a certain rule action
	Publish(ctx context.Context, message protomfx.Message) error
}

Service specifies an API for managing rules.

func New

New instantiates the rules service implementation.

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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