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
// although they are in semi-structured format) to JSON.
//
package main
import (
......@@ -9,6 +8,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"os"
"regexp"
)
......@@ -52,15 +52,24 @@ func parseModSec(w io.Writer, line []byte) bool {
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() {
outw := os.Stdout
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Bytes()
if !parseModSec(outw, line) {
outw.Write(line)
io.WriteString(outw, "\n")
if parseModSec(outw, line) {
continue
}
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