Skip to content
Snippets Groups Projects
Commit c4d01410 authored by ale's avatar ale
Browse files

Make modsec_logger exit on write failure

parent 9fd17e4a
No related branches found
No related tags found
No related merge requests found
Pipeline #60852 failed
// Tool to rewrite mod_security2 logs (very difficult to parse // Tool to rewrite mod_security2 logs (very difficult to parse
// although they are in semi-structured format) to JSON. // although they are in semi-structured format) to JSON.
//
package main package main
import ( import (
...@@ -9,6 +8,7 @@ import ( ...@@ -9,6 +8,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"log"
"os" "os"
"regexp" "regexp"
) )
...@@ -52,15 +52,24 @@ func parseModSec(w io.Writer, line []byte) bool { ...@@ -52,15 +52,24 @@ func parseModSec(w io.Writer, line []byte) bool {
return true return true
} }
func writeLine(w io.Writer, line byte) error {
if _, err := w.Write(line); err != nil {
return err
}
return io.WriteString(w, "\n")
}
func main() { func main() {
outw := os.Stdout outw := os.Stdout
scanner := bufio.NewScanner(os.Stdin) scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() { for scanner.Scan() {
line := scanner.Bytes() line := scanner.Bytes()
if !parseModSec(outw, line) { if parseModSec(outw, line) {
outw.Write(line) continue
io.WriteString(outw, "\n") }
if err := writeLine(outw, line); err != nil {
log.Fatal(err)
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment