Skip to content

Commit

Permalink
Allowlist Error Messages (#907)
Browse files Browse the repository at this point in the history
* allow certain error logs
  • Loading branch information
aphralG authored Oct 23, 2024
1 parent 8e5666c commit bb48036
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/plugins/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ var (
re.MustCompile(`.*\[alert\].*`),
re.MustCompile(`.*\[crit\].*`),
}
warningRegex = re.MustCompile(`.*\[warn\].*`)
warningRegex = re.MustCompile(`.*\[warn\].*`)
ignoreErrorList = re.MustCompile(`.*(usage report| license expired).*`)
)

// Nginx is the metadata of our nginx binary
Expand Down Expand Up @@ -619,13 +620,13 @@ func (n *Nginx) tailLog(logFile string, errorChannel chan string) {
for {
select {
case d := <-data:
if warningRegex.MatchString(d) && n.config.Nginx.TreatWarningsAsErrors {
if warningRegex.MatchString(d) && n.config.Nginx.TreatWarningsAsErrors && !ignoreErrorList.MatchString(d) {
errorChannel <- d
return
}

for _, errorRegex := range reloadErrorList {
if errorRegex.MatchString(d) {
if errorRegex.MatchString(d) && !ignoreErrorList.MatchString(d) {
errorChannel <- d
return
}
Expand Down
18 changes: 18 additions & 0 deletions src/plugins/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,24 @@ func TestNginx_monitorLog(t *testing.T) {
treatWarningsAsErrors: false,
expected: "",
},
{
name: "ignore error log: usage report ",
errorLog: "2025/06/25 15:08:04 [error] 123456#123456: certificate verify error: (10:certificate has expired) during usage report",
treatWarningsAsErrors: false,
expected: "",
},
{
name: "ignore error log: license expired ",
errorLog: "2025/06/25 15:07:24 [alert] 123456#123456: license expired; the grace period will end in 71 days",
treatWarningsAsErrors: false,
expected: "",
},
{
name: "ignore error log: usaage report 400",
errorLog: "2024/12/25 15:00:04 [error] 123456#123456: server returned 400 during usage report",
treatWarningsAsErrors: false,
expected: "",
},
}

for _, test := range tests {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bb48036

Please sign in to comment.