Documentation
¶
Overview ¶
Package splunk includes Splunk Enterprise implementation of Gnomock Preset interface. This Preset can be passed to gnomock.StartPreset function to create a configured Splunk container to use in tests.
Splunk image is relatively heavy (larger than 1.5GB), and its startup time is longer than usual. Using this container may make the tests much longer
Index ¶
Examples ¶
Constants ¶
const ( // CollectorPort is the name of a port exposed by Splunk Collector CollectorPort string = "collector" // APIPort is the name of a port exposed by Splunk API APIPort string = "api" // WebPort is the name of a port exposed by Splunk web UI WebPort string = "web" )
Variables ¶
This section is empty.
Functions ¶
func Ingest ¶ added in v0.4.0
Ingest adds the provided events to splunk container. Use the same password you provided in WithPassword. Send as many events as you like, this function only returns when all the events were indexed, or when the context is timed out
func Preset ¶
Preset creates a new Gnomock Splunk preset. This preset includes a Splunk specific healthcheck function, default Splunk image and ports, and allows to optionally ingest initial logs
Example ¶
package main
import (
"fmt"
"sort"
"time"
"github.com/orlangure/gnomock"
mocksplunk "github.com/orlangure/gnomock-splunk"
)
func main() {
events := []mocksplunk.Event{
{
Event: "action=foo",
Index: "events",
Source: "app",
SourceType: "http",
Time: time.Now().UnixNano(),
},
{
Event: "action=bar",
Index: "events",
Source: "app",
SourceType: "http",
Time: time.Now().UnixNano(),
},
}
p := mocksplunk.Preset(
mocksplunk.WithVersion("latest"),
mocksplunk.WithLicense(true),
mocksplunk.WithPassword("12345678"),
mocksplunk.WithValues(events),
mocksplunk.WithInitTimeout(time.Second*10),
)
// created container now includes two events in "events" index
container, err := gnomock.Start(p)
fmt.Println("error:", err)
fmt.Println(len(container.Ports), "exposed ports:")
defer func() {
_ = gnomock.Stop(container)
}()
// Port numbers as well as container address are non-deterministic, so they
// are skipped in this example. The usage would be:
//
// container.Address("web")
// container.Address("api")
portNames := make([]string, 0)
for portName := range container.Ports {
portNames = append(portNames, portName)
}
sort.Strings(portNames)
fmt.Println(portNames)
}
Output: error: <nil> 3 exposed ports: [api collector web]
Types ¶
type Event ¶
type Event struct {
// Event is the actual log entry. Can be any format
Event string `json:"event"`
// Index is the name of index to ingest the log into. If the index does not
// exist, it will be created
Index string `json:"index"`
// Source will be used as "source" value of this event in Splunk
Source string `json:"source"`
// SourceType will be used as "sourcetype" value of this event in Splunk
SourceType string `json:"sourcetype"`
// Time represents event timestamp in seconds, milliseconds or nanoseconds
// (and maybe even in microseconds, whatever splunk recognizes)
Time int64 `json:"time"`
}
Event is a type used during Splunk initialization. Pass events to WithValues to ingest them into the container before the control over it is passed to the caller
type Option ¶
type Option func(*P)
Option is an optional configuration of this Gnomock preset. Use available Options to configure the container
func WithInitTimeout ¶ added in v0.2.1
WithInitTimeout sets the duration to wait before giving up on trying to initialize this Splunk container. This option is only useful when WithValues is used. Default value is 5 seconds
func WithLicense ¶
WithLicense lets the user choose to accept Splunk enterprise license (see more at https://hub.docker.com/_/splunk-enterprise). Failure to accept the license will prevent Splunk container from starting
func WithPassword ¶
WithPassword sets admin password in Splunk container. Use this password to connect to the container when it is ready. Note that Splunk has password requirements. Failure to meet those will prevent the container from starting (see defaults at https://docs.splunk.com/Documentation/Splunk/latest/Security/Configurepasswordsinspecfile)
func WithValues ¶
WithValues initializes Splunk with the provided values as log entries
func WithValuesFile ¶ added in v0.4.1
WithValuesFile sets file name to use as a source of initial events to ingest. These events are ingested first, followed by any other events sent using WithValues
func WithVersion ¶ added in v0.2.2
WithVersion sets splunk version (see https://hub.docker.com/r/splunk/splunk/tags) for available versions
type P ¶ added in v0.4.0
type P struct {
Values []Event `json:"values"`
ValuesFile string `json:"values_file"`
AcceptLicense bool `json:"accept_license"`
AdminPassword string `json:"admin_password"`
InitTimeout time.Duration `json:"init_timeout"`
Version string `json:"version"`
}
P is a Gnomock Preset implementation of Splunk
func (*P) Image ¶ added in v0.4.0
Image returns an image that should be pulled to create this container
func (*P) Ports ¶ added in v0.4.0
func (p *P) Ports() gnomock.NamedPorts
Ports returns ports that should be used to access this container