Skip to content

Commit

Permalink
improve detection of nginx error log severities
Browse files Browse the repository at this point in the history
  • Loading branch information
def committed Feb 29, 2024
1 parent 5c87010 commit 39110d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion level.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,15 @@ func GuessLevel(line string) Level {
return LevelWarning
case "erro":
return LevelError
case "crit", "fata":
case "crit":
return LevelCritical
case "emer", "fata", "aler":
if l >= 5 {
switch sf[:5] {
case "emerg", "fatal", "alert":
return LevelCritical
}
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions level_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ func TestGuessLevel(t *testing.T) {
assert.Equal(t, LevelError, GuessLevel("[06:23:18 ERR] message"))
assert.Equal(t, LevelCritical, GuessLevel("[06:23:18 FTL] message"))

assert.Equal(t, LevelCritical, GuessLevel(`2024/02/29 11:01:03 [emerg] 1#1: duplicate location "/loc-path" in /etc/nginx/conf.d/default.conf:33`))
assert.Equal(t, LevelCritical, GuessLevel(`nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)`))
assert.Equal(t, LevelCritical, GuessLevel(`2022/05/14 07:08:37 [crit] 6689#6689: *16721837 SSL_do_handshake() failed (SSL: error:1420918C:SSL routines:tls_early_post_process_client_hello:version too low) while SSL handshaking`))
assert.Equal(t, LevelError, GuessLevel(`2009/01/01 19:45:44 [error] 29874#0: *98 open() "/var/www/one/nonexistent.html" failed (2: No such file or directory), client: 11.22.33.44, server: one.org, request: "GET /nonexistent.html HTTP/1.1", host: "one.org"`))
}

0 comments on commit 39110d8

Please sign in to comment.