Skip to content

Instantly share code, notes, and snippets.

@arunk-s

arunk-s/main.go Secret

Last active August 12, 2016 15:25
Show Gist options
  • Save arunk-s/a5814d7faded57420e35338514ce38d2 to your computer and use it in GitHub Desktop.
Save arunk-s/a5814d7faded57420e35338514ce38d2 to your computer and use it in GitHub Desktop.
Run Mig Audit module directly
package main
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"mig.ninja/mig/modules"
"mig.ninja/mig/modules/audit"
)
func main() {
var (
paramargs = `{"class":"parameters", "parameters":{"rulefilepath": "audit.rules.json", "outputsockets": ["/tmp/unix.sock"], "serveraddress": "http://requestb.in/10ebgkt1"}}`
out string
pretty = true
)
infd := bufio.NewReader(bytes.NewBuffer([]byte(paramargs)))
// instantiate and call module
// run := modules.Available["audit"].NewRun()
moduler := audit.GetInstance()
run := moduler.NewRun()
out = run.Run(infd)
if pretty {
var modres modules.Result
err := json.Unmarshal([]byte(out), &modres)
if err != nil {
panic(err)
}
out = ""
if _, ok := run.(modules.HasResultsPrinter); ok {
outRes, err := run.(modules.HasResultsPrinter).PrintResults(modres, false)
if err != nil {
panic(err)
}
for _, resLine := range outRes {
out += fmt.Sprintf("%s\n", resLine)
}
} else {
out = fmt.Sprintf("[error] no printer available for module '%s'\n", "audit")
}
}
fmt.Println(out)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment