Skip to content

Commit 6956259

Browse files
zak-pawelsrebhan
authored andcommitted
chore: Fix linter findings for revive:exported in plugins/inputs/[t-v]* (#16408)
(cherry picked from commit e57f48f)
1 parent 522c16d commit 6956259

28 files changed

+1057
-1071
lines changed

plugins/inputs/tacacs/tacacs.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import (
1919
"github.com/influxdata/telegraf/plugins/inputs"
2020
)
2121

22+
//go:embed sample.conf
23+
var sampleConfig string
24+
2225
type Tacacs struct {
2326
Servers []string `toml:"servers"`
2427
Username config.Secret `toml:"username"`
@@ -31,9 +34,6 @@ type Tacacs struct {
3134
authStart tacplus.AuthenStart
3235
}
3336

34-
//go:embed sample.conf
35-
var sampleConfig string
36-
3737
func (*Tacacs) SampleConfig() string {
3838
return sampleConfig
3939
}
@@ -74,7 +74,22 @@ func (t *Tacacs) Init() error {
7474
return nil
7575
}
7676

77-
func AuthenReplyToString(code uint8) string {
77+
func (t *Tacacs) Gather(acc telegraf.Accumulator) error {
78+
var wg sync.WaitGroup
79+
80+
for idx := range t.clients {
81+
wg.Add(1)
82+
go func(client *tacplus.Client) {
83+
defer wg.Done()
84+
acc.AddError(t.pollServer(acc, client))
85+
}(&t.clients[idx])
86+
}
87+
88+
wg.Wait()
89+
return nil
90+
}
91+
92+
func authenReplyToString(code uint8) string {
7893
switch code {
7994
case tacplus.AuthenStatusPass:
8095
return `AuthenStatusPass`
@@ -96,21 +111,6 @@ func AuthenReplyToString(code uint8) string {
96111
return "AuthenStatusUnknown(" + strconv.FormatUint(uint64(code), 10) + ")"
97112
}
98113

99-
func (t *Tacacs) Gather(acc telegraf.Accumulator) error {
100-
var wg sync.WaitGroup
101-
102-
for idx := range t.clients {
103-
wg.Add(1)
104-
go func(client *tacplus.Client) {
105-
defer wg.Done()
106-
acc.AddError(t.pollServer(acc, client))
107-
}(&t.clients[idx])
108-
}
109-
110-
wg.Wait()
111-
return nil
112-
}
113-
114114
func (t *Tacacs) pollServer(acc telegraf.Accumulator, client *tacplus.Client) error {
115115
// Create the fields for this metric
116116
tags := map[string]string{"source": client.Addr}
@@ -157,7 +157,7 @@ func (t *Tacacs) pollServer(acc telegraf.Accumulator, client *tacplus.Client) er
157157
defer session.Close()
158158
if reply.Status != tacplus.AuthenStatusGetUser {
159159
fields["responsetime_ms"] = time.Since(startTime).Milliseconds()
160-
fields["response_status"] = AuthenReplyToString(reply.Status)
160+
fields["response_status"] = authenReplyToString(reply.Status)
161161
acc.AddFields("tacacs", fields, tags)
162162
return nil
163163
}
@@ -174,7 +174,7 @@ func (t *Tacacs) pollServer(acc telegraf.Accumulator, client *tacplus.Client) er
174174
}
175175
if reply.Status != tacplus.AuthenStatusGetPass {
176176
fields["responsetime_ms"] = time.Since(startTime).Milliseconds()
177-
fields["response_status"] = AuthenReplyToString(reply.Status)
177+
fields["response_status"] = authenReplyToString(reply.Status)
178178
acc.AddFields("tacacs", fields, tags)
179179
return nil
180180
}
@@ -191,13 +191,13 @@ func (t *Tacacs) pollServer(acc telegraf.Accumulator, client *tacplus.Client) er
191191
}
192192
if reply.Status != tacplus.AuthenStatusPass {
193193
fields["responsetime_ms"] = time.Since(startTime).Milliseconds()
194-
fields["response_status"] = AuthenReplyToString(reply.Status)
194+
fields["response_status"] = authenReplyToString(reply.Status)
195195
acc.AddFields("tacacs", fields, tags)
196196
return nil
197197
}
198198

199199
fields["responsetime_ms"] = time.Since(startTime).Milliseconds()
200-
fields["response_status"] = AuthenReplyToString(reply.Status)
200+
fields["response_status"] = authenReplyToString(reply.Status)
201201
acc.AddFields("tacacs", fields, tags)
202202
return nil
203203
}

plugins/inputs/tail/multiline.go

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -10,76 +10,38 @@ import (
1010
"github.com/influxdata/telegraf/config"
1111
)
1212

13+
const (
14+
// previous => Append current line to previous line
15+
previous multilineMatchWhichLine = iota
16+
// next => next line will be appended to current line
17+
next
18+
)
19+
1320
// Indicates relation to the multiline event: previous or next
14-
type MultilineMatchWhichLine int
21+
type multilineMatchWhichLine int
1522

16-
type Multiline struct {
17-
config *MultilineConfig
23+
type multiline struct {
24+
config *multilineConfig
1825
enabled bool
1926
patternRegexp *regexp.Regexp
2027
quote byte
2128
inQuote bool
2229
}
2330

24-
type MultilineConfig struct {
31+
type multilineConfig struct {
2532
Pattern string `toml:"pattern"`
26-
MatchWhichLine MultilineMatchWhichLine `toml:"match_which_line"`
33+
MatchWhichLine multilineMatchWhichLine `toml:"match_which_line"`
2734
InvertMatch bool `toml:"invert_match"`
2835
PreserveNewline bool `toml:"preserve_newline"`
2936
Quotation string `toml:"quotation"`
3037
Timeout *config.Duration `toml:"timeout"`
3138
}
3239

33-
const (
34-
// Previous => Append current line to previous line
35-
Previous MultilineMatchWhichLine = iota
36-
// Next => Next line will be appended to current line
37-
Next
38-
)
39-
40-
func (m *MultilineConfig) NewMultiline() (*Multiline, error) {
41-
var r *regexp.Regexp
42-
43-
if m.Pattern != "" {
44-
var err error
45-
if r, err = regexp.Compile(m.Pattern); err != nil {
46-
return nil, err
47-
}
48-
}
49-
50-
var quote byte
51-
switch m.Quotation {
52-
case "", "ignore":
53-
m.Quotation = "ignore"
54-
case "single-quotes":
55-
quote = '\''
56-
case "double-quotes":
57-
quote = '"'
58-
case "backticks":
59-
quote = '`'
60-
default:
61-
return nil, errors.New("invalid 'quotation' setting")
62-
}
63-
64-
enabled := m.Pattern != "" || quote != 0
65-
if m.Timeout == nil || time.Duration(*m.Timeout).Nanoseconds() == int64(0) {
66-
d := config.Duration(5 * time.Second)
67-
m.Timeout = &d
68-
}
69-
70-
return &Multiline{
71-
config: m,
72-
enabled: enabled,
73-
patternRegexp: r,
74-
quote: quote,
75-
}, nil
76-
}
77-
78-
func (m *Multiline) IsEnabled() bool {
40+
func (m *multiline) isEnabled() bool {
7941
return m.enabled
8042
}
8143

82-
func (m *Multiline) ProcessLine(text string, buffer *bytes.Buffer) string {
44+
func (m *multiline) processLine(text string, buffer *bytes.Buffer) string {
8345
if m.matchQuotation(text) || m.matchString(text) {
8446
// Restore the newline removed by tail's scanner
8547
if buffer.Len() > 0 && m.config.PreserveNewline {
@@ -89,13 +51,13 @@ func (m *Multiline) ProcessLine(text string, buffer *bytes.Buffer) string {
8951
return ""
9052
}
9153

92-
if m.config.MatchWhichLine == Previous {
54+
if m.config.MatchWhichLine == previous {
9355
previousText := buffer.String()
9456
buffer.Reset()
9557
buffer.WriteString(text)
9658
text = previousText
9759
} else {
98-
// Next
60+
// next
9961
if buffer.Len() > 0 {
10062
if m.config.PreserveNewline {
10163
buffer.WriteString("\n")
@@ -109,16 +71,7 @@ func (m *Multiline) ProcessLine(text string, buffer *bytes.Buffer) string {
10971
return text
11072
}
11173

112-
func Flush(buffer *bytes.Buffer) string {
113-
if buffer.Len() == 0 {
114-
return ""
115-
}
116-
text := buffer.String()
117-
buffer.Reset()
118-
return text
119-
}
120-
121-
func (m *Multiline) matchQuotation(text string) bool {
74+
func (m *multiline) matchQuotation(text string) bool {
12275
if m.config.Quotation == "ignore" {
12376
return false
12477
}
@@ -146,46 +99,93 @@ func (m *Multiline) matchQuotation(text string) bool {
14699
return m.inQuote
147100
}
148101

149-
func (m *Multiline) matchString(text string) bool {
102+
func (m *multiline) matchString(text string) bool {
150103
if m.patternRegexp != nil {
151104
return m.patternRegexp.MatchString(text) != m.config.InvertMatch
152105
}
153106
return false
154107
}
155108

156-
func (w MultilineMatchWhichLine) String() string {
109+
func (m *multilineConfig) newMultiline() (*multiline, error) {
110+
var r *regexp.Regexp
111+
112+
if m.Pattern != "" {
113+
var err error
114+
if r, err = regexp.Compile(m.Pattern); err != nil {
115+
return nil, err
116+
}
117+
}
118+
119+
var quote byte
120+
switch m.Quotation {
121+
case "", "ignore":
122+
m.Quotation = "ignore"
123+
case "single-quotes":
124+
quote = '\''
125+
case "double-quotes":
126+
quote = '"'
127+
case "backticks":
128+
quote = '`'
129+
default:
130+
return nil, errors.New("invalid 'quotation' setting")
131+
}
132+
133+
enabled := m.Pattern != "" || quote != 0
134+
if m.Timeout == nil || time.Duration(*m.Timeout).Nanoseconds() == int64(0) {
135+
d := config.Duration(5 * time.Second)
136+
m.Timeout = &d
137+
}
138+
139+
return &multiline{
140+
config: m,
141+
enabled: enabled,
142+
patternRegexp: r,
143+
quote: quote,
144+
}, nil
145+
}
146+
147+
func flush(buffer *bytes.Buffer) string {
148+
if buffer.Len() == 0 {
149+
return ""
150+
}
151+
text := buffer.String()
152+
buffer.Reset()
153+
return text
154+
}
155+
156+
func (w multilineMatchWhichLine) String() string {
157157
switch w {
158-
case Previous:
158+
case previous:
159159
return "previous"
160-
case Next:
160+
case next:
161161
return "next"
162162
}
163163
return ""
164164
}
165165

166-
// UnmarshalTOML implements ability to unmarshal MultilineMatchWhichLine from TOML files.
167-
func (w *MultilineMatchWhichLine) UnmarshalTOML(data []byte) (err error) {
166+
// UnmarshalTOML implements ability to unmarshal multilineMatchWhichLine from TOML files.
167+
func (w *multilineMatchWhichLine) UnmarshalTOML(data []byte) (err error) {
168168
return w.UnmarshalText(data)
169169
}
170170

171171
// UnmarshalText implements encoding.TextUnmarshaler
172-
func (w *MultilineMatchWhichLine) UnmarshalText(data []byte) (err error) {
172+
func (w *multilineMatchWhichLine) UnmarshalText(data []byte) (err error) {
173173
s := string(data)
174174
switch strings.ToUpper(s) {
175175
case `PREVIOUS`, `"PREVIOUS"`, `'PREVIOUS'`:
176-
*w = Previous
176+
*w = previous
177177
return nil
178178

179179
case `NEXT`, `"NEXT"`, `'NEXT'`:
180-
*w = Next
180+
*w = next
181181
return nil
182182
}
183183
*w = -1
184184
return errors.New("unknown multiline MatchWhichLine")
185185
}
186186

187187
// MarshalText implements encoding.TextMarshaler
188-
func (w MultilineMatchWhichLine) MarshalText() ([]byte, error) {
188+
func (w multilineMatchWhichLine) MarshalText() ([]byte, error) {
189189
s := w.String()
190190
if s != "" {
191191
return []byte(s), nil

0 commit comments

Comments
 (0)