Home

Awesome

Documentation Go Report Card

Go Suricata Client

Gosuricata is a Go client library for interacting with suricata using the unix socket

Prerequisites

Installation

Go get the library

go get github.com/ks2211/go-suricata

Usage

package main

import (
    "github.com/ks2211/go-suricata/client"
    "log"
)

func main() {
    // create the client passing the path to the socket
    // defaults are provided
    s, err := client.NewSocket("/path/to/socket")
    if err != nil {
        log.Fatalf("Error conn %v", err)
    }
    defer s.Close()
    // use the client to run command methods
    commands, err := s.CommandListCommand()
    if err != nil {
        log.Fatalf("Error command list %v", err)
    }
    log.Println("COMMANDS", commands)
    runningMode, err := s.RunningModeCommand()
    if err != nil {
        log.Fatalf("error running mode %v", err)
    }
    log.Println("RUN MODE", runningMode)
    // run a command manually--note you will have to pass in a struct/map/interface
    // the type can be marshalled into json
    r, err := s.DoCommand("some-command", struct{
        Field string `json:"field"`
    }{
        "test"
    })
    if err != nil {
        log.Fatalf("error running command %v", err)
    }
    // handle response
    retData := map[string]interface{} // or struct
    if err := json.Unmarshal(r.Message, &retData); err != nil {
        log.Fatalf("error unmarshal data %v", err)
    }
    log.Println("response", r.Status, retData)
}

Design

The way the library/client is set up:

{
    "status": "OK|NOK",
    "message": {}|""
}
resp, err := s.DoCommand("command-list", nil)
if err != nil {
    // handle err
}
fmt.Println(string(resp.Message)) // prints string of json
response := struct{
    FieldA string `json:"field_a"`
}{}
if err := json.Unmarshal(resp.Message, &response); err != nil {
    // handle err
}
// work with the response

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Testing

IN PROGRESS

TODO