Documentation ¶
Index ¶
- type Env
- type KObjAction
- type Matcher
- type Mode
- type NetlinkConn
- type RuleDefinition
- type RuleDefinitions
- func (rs *RuleDefinitions) AddRule(r RuleDefinition)
- func (rs *RuleDefinitions) Compile() error
- func (rs RuleDefinitions) Evaluate(e UEvent) bool
- func (rs RuleDefinitions) EvaluateAction(a KObjAction) (match bool)
- func (rs RuleDefinitions) EvaluateEnv(e map[string]string) bool
- func (rs RuleDefinitions) String() string
- type UEvent
- type UEventConn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KObjAction ¶
type KObjAction string
const ( ADD KObjAction = "add" REMOVE KObjAction = "remove" CHANGE KObjAction = "change" MOVE KObjAction = "move" ONLINE KObjAction = "online" OFFLINE KObjAction = "offline" BIND KObjAction = "bind" UNBIND KObjAction = "unbind" )
func ParseKObjAction ¶
func ParseKObjAction(raw string) (a KObjAction, err error)
func (KObjAction) String ¶
func (a KObjAction) String() string
type NetlinkConn ¶
type NetlinkConn struct { Fd int Addr syscall.SockaddrNetlink }
Generic connection
type RuleDefinition ¶
type RuleDefinition struct { Action *string `json:"action,omitempty"` Env map[string]string `json:"env,omitempty"` // contains filtered or unexported fields }
func (*RuleDefinition) Compile ¶
func (r *RuleDefinition) Compile() error
Compile prepare rule definition to be able to Evaluate() an UEvent
func (RuleDefinition) Evaluate ¶
func (r RuleDefinition) Evaluate(e UEvent) bool
Evaluate return true if all condition match uevent and envs in rule exists in uevent
func (RuleDefinition) EvaluateAction ¶
func (r RuleDefinition) EvaluateAction(a KObjAction) bool
EvaluateAction return true if the action match
func (RuleDefinition) EvaluateEnv ¶
func (r RuleDefinition) EvaluateEnv(e map[string]string) bool
EvaluateEnv return true if all env match and exists
func (RuleDefinition) String ¶
func (r RuleDefinition) String() string
type RuleDefinitions ¶
type RuleDefinitions struct {
Rules []RuleDefinition
}
RuleDefinitions is like chained rule with OR operator
func (*RuleDefinitions) AddRule ¶
func (rs *RuleDefinitions) AddRule(r RuleDefinition)
func (*RuleDefinitions) Compile ¶
func (rs *RuleDefinitions) Compile() error
func (RuleDefinitions) Evaluate ¶
func (rs RuleDefinitions) Evaluate(e UEvent) bool
func (RuleDefinitions) EvaluateAction ¶
func (rs RuleDefinitions) EvaluateAction(a KObjAction) (match bool)
EvaluateAction return true if the action match
func (RuleDefinitions) EvaluateEnv ¶
func (rs RuleDefinitions) EvaluateEnv(e map[string]string) bool
EvaluateEnv return true if almost one env match all regexp
func (RuleDefinitions) String ¶
func (rs RuleDefinitions) String() string
type UEvent ¶
type UEvent struct { Action KObjAction KObj string Env map[string]string }
func ParseUEvent ¶
type UEventConn ¶
type UEventConn struct { NetlinkConn // Options MatchedUEventLimit int // allow to stop monitor mode after X event(s) matched by the matcher }
func (*UEventConn) Close ¶
func (c *UEventConn) Close() error
Close allow to close file descriptor and socket bound
func (*UEventConn) Connect ¶
func (c *UEventConn) Connect(mode Mode) (err error)
Connect allow to connect to system socket AF_NETLINK with family NETLINK_KOBJECT_UEVENT to catch events about block/char device see: - http://elixir.free-electrons.com/linux/v3.12/source/include/uapi/linux/netlink.h#L23 - http://elixir.free-electrons.com/linux/v3.12/source/include/uapi/linux/socket.h#L11
func (*UEventConn) Monitor ¶
Monitor run in background a worker to read netlink msg in loop and notify when msg receive inside a queue using channel. To be notified with only relevant message, use Matcher.
func (*UEventConn) ReadMsg ¶
func (c *UEventConn) ReadMsg() (msg []byte, err error)
ReadMsg allow to read an entire uevent msg
func (*UEventConn) ReadUEvent ¶
func (c *UEventConn) ReadUEvent() (*UEvent, error)
ReadMsg allow to read an entire uevent msg