mirror of
https://github.com/bettercap/bettercap
synced 2025-07-12 08:07:00 -07:00
Decimal support for events.stream.output.rotate.when
This commit is contained in:
parent
fc7d8d22b4
commit
251dbb3ef2
4 changed files with 28 additions and 6 deletions
|
@ -21,7 +21,7 @@ type rotation struct {
|
|||
Compress bool
|
||||
Format string
|
||||
How string
|
||||
Period int
|
||||
Period float64
|
||||
}
|
||||
|
||||
type EventsStream struct {
|
||||
|
@ -147,9 +147,9 @@ func NewEventsStream(s *session.Session) *EventsStream {
|
|||
"",
|
||||
"Datetime format to use for log rotation file names."))
|
||||
|
||||
stream.AddParam(session.NewIntParameter("events.stream.output.rotate.when",
|
||||
"10485760",
|
||||
"File size or time duration in seconds for log rotation."))
|
||||
stream.AddParam(session.NewDecimalParameter("events.stream.output.rotate.when",
|
||||
"10",
|
||||
"File size (in MB) or time duration (in seconds) for log rotation."))
|
||||
|
||||
stream.AddParam(session.NewBoolParameter("events.stream.http.request.dump",
|
||||
"false",
|
||||
|
@ -193,7 +193,7 @@ func (s *EventsStream) Configure() (err error) {
|
|||
return err
|
||||
} else if err, s.rotation.How = s.StringParam("events.stream.output.rotate.how"); err != nil {
|
||||
return err
|
||||
} else if err, s.rotation.Period = s.IntParam("events.stream.output.rotate.when"); err != nil {
|
||||
} else if err, s.rotation.Period = s.DecParam("events.stream.output.rotate.when"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ func (s *EventsStream) doRotation() {
|
|||
doRotate := false
|
||||
if info, err := s.output.Stat(); err == nil {
|
||||
if s.rotation.How == "size" {
|
||||
doRotate = info.Size() >= int64(s.rotation.Period)
|
||||
doRotate = float64(info.Size()) >= float64(s.rotation.Period*1024*1024)
|
||||
} else if s.rotation.How == "time" {
|
||||
doRotate = info.ModTime().Unix()%int64(s.rotation.Period) == 0
|
||||
}
|
||||
|
|
|
@ -109,6 +109,20 @@ func (m SessionModule) IntParam(name string) (error, int) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func (m SessionModule) DecParam(name string) (error, float64) {
|
||||
if p, found := m.params[name]; found {
|
||||
if err, v := p.Get(m.Session); err != nil {
|
||||
return err, 0
|
||||
} else {
|
||||
return nil, v.(float64)
|
||||
}
|
||||
|
||||
} else {
|
||||
return fmt.Errorf("Parameter %s does not exist.", name), 0
|
||||
}
|
||||
}
|
||||
|
||||
func (m SessionModule) BoolParam(name string) (error, bool) {
|
||||
if err, v := m.params[name].Get(m.Session); err != nil {
|
||||
return err, false
|
||||
|
|
|
@ -18,6 +18,7 @@ const (
|
|||
STRING ParamType = iota
|
||||
BOOL = iota
|
||||
INT = iota
|
||||
FLOAT = iota
|
||||
)
|
||||
|
||||
type ModuleParam struct {
|
||||
|
@ -57,6 +58,10 @@ func NewIntParameter(name string, def_value string, desc string) *ModuleParam {
|
|||
return NewModuleParameter(name, def_value, INT, "^[\\d]+$", desc)
|
||||
}
|
||||
|
||||
func NewDecimalParameter(name string, def_value string, desc string) *ModuleParam {
|
||||
return NewModuleParameter(name, def_value, FLOAT, "^[\\d]+(\\.\\d+)?$", desc)
|
||||
}
|
||||
|
||||
func (p ModuleParam) Validate(value string) (error, interface{}) {
|
||||
if p.Validator != nil {
|
||||
if !p.Validator.MatchString(value) {
|
||||
|
@ -78,6 +83,9 @@ func (p ModuleParam) Validate(value string) (error, interface{}) {
|
|||
} else if p.Type == INT {
|
||||
i, err := strconv.Atoi(value)
|
||||
return err, i
|
||||
} else if p.Type == FLOAT {
|
||||
i, err := strconv.ParseFloat(value, 64)
|
||||
return err, i
|
||||
}
|
||||
|
||||
return fmt.Errorf("Unhandled module parameter type %d.", p.Type), nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue