http

package
v1.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

README

Http Input Plugin

The http input plugin serves requests on the configured address. This plugin requires a parser.

Unlike the httpl input, this plugin fully reads the request body before the parsing stage and also takes URL-encoded request parameters into account.

The plugin's behavior can be configured using on_* parameters.

This plugin produces events with the request path as the routing key (or the matched pattern if paths is configured), a server label containing the configured address, a sender label containing the request's RemoteAddr, and a method label containing the request's HTTP method.

[!TIP]
This plugin may write its own metrics

Configuration

[[inputs]]
  [inputs.http]
    # if true, plugin server writes it's own metrics
    enable_metrics = false

    # address and port to host HTTP listener on
    address = ":9900"

    # optional paths to listen
    # if not configured, `/` will be used
    paths = [ "/http.input/{uid}/push", "/http.input/{id}/put" ]

    # optional path values to set as events labels if exists
    path_values = [ "uid", "id" ]

    # number of maximum simultaneous connections
    max_connections = 10

    # maximum duration before timing out read of the request
    read_timeout = "10s"

    # maximum duration before timing out write of the response
    write_timeout = "10s"

    # optional basic auth credentials
    # if both set, requests with wrong credentials will be rejected with `401 Unauthorized`
    basic_username = "user"
    basic_password = "pass"

    # allowed incoming requests methods, POST, PUT, GET
    allowed_methods = [ "POST", "PUT" ]

    # if not empty, plugin will try to save request parameters 
    # in events body at the specified path
    query_params_to = "."

    # if true, server waits for events to be delivered
    # before responding to a client
    wait_for_delivery = false

    # if configured, an event id will be set by data from path
    # expected format - "type:path"
    id_from = "field:path.to.id"

    ## TLS configuration
    # if true, TLS listener will be used
    tls_enable = false
    # service key and certificate
    tls_key_file = "/etc/neptunus/key.pem"
    tls_cert_file = "/etc/neptunus/cert.pem"
    # one or more allowed client CA certificate file names to
    # enable mutually authenticated TLS connections
    tls_allowed_cacerts = [ "/etc/neptunus/clientca.pem" ]
    # minimum and maximum TLS version accepted by the service
    # not limited by default
    tls_min_version = "TLS12"
    tls_max_version = "TLS13"

    # response if all events successfully accepted by plugin
    # body may be an fmt template where param is an events count
    [inputs.http.on_success]
      code = 200
      body = "accepted events: %v"

    # response if body parsing failed
    # body may be an fmt template where param is error returned by parser
    [inputs.http.on_parser_error]
      code = 400
      body = "parsing failed: %v"

    # response if request method is not in "allowed_methods"
    [inputs.http.on_wrong_method]
      code = 405
      body = "method not allowed"

    # response if request request path not in configured paths
    [inputs.http.on_wrong_path]
      code = 404
      body = "not found"

    # response if basic auth failed
    [inputs.http.on_failed_auth]
      code = 401
      body = "unauthorized"

    # response if any other error occurred
    # body may be an fmt template where param is occurred error
    [inputs.http.on_other_error]
      code = 500
      body = "internal error occured: %v"

    # a "label name <- header" map
    # if request header exists, it will be saved as configured label
    [inputs.http.labelheaders]
      length = "Content-Length"
      encoding = "Content-Type"

    [inputs.http.parser]
      type = "json"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Http

type Http struct {
	*core.BaseInput `mapstructure:"-"`
	EnableMetrics   bool              `mapstructure:"enable_metrics"`
	Address         string            `mapstructure:"address"`
	Paths           []string          `mapstructure:"paths"`
	PathValues      []string          `mapstructure:"path_values"`
	ReadTimeout     time.Duration     `mapstructure:"read_timeout"`
	WriteTimeout    time.Duration     `mapstructure:"write_timeout"`
	WaitForDelivery bool              `mapstructure:"wait_for_delivery"`
	AllowedMethods  []string          `mapstructure:"allowed_methods"`
	QueryParamsTo   string            `mapstructure:"query_params_to"`
	MaxConnections  int               `mapstructure:"max_connections"`
	LabelHeaders    map[string]string `mapstructure:"labelheaders"`

	OnSuccess     OnResult `mapstructure:"on_success"`
	OnParserError OnResult `mapstructure:"on_parser_error"`
	OnWrongMethod OnResult `mapstructure:"on_wrong_method"`
	OnWrongPath   OnResult `mapstructure:"on_wrong_path"`
	OnFailedAuth  OnResult `mapstructure:"on_failed_auth"`
	OnOtherError  OnResult `mapstructure:"on_other_error"`

	*basic.BasicAuth        `mapstructure:",squash"`
	*ider.Ider              `mapstructure:",squash"`
	*pkgtls.TLSServerConfig `mapstructure:",squash"`
	// contains filtered or unexported fields
}

func (*Http) Close

func (i *Http) Close() error

func (*Http) Init

func (i *Http) Init() error

func (*Http) Run

func (i *Http) Run()

func (*Http) ServeHTTP

func (i *Http) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Http) SetParser

func (i *Http) SetParser(p core.Parser)

func (*Http) Stop added in v1.13.0

func (i *Http) Stop()

type OnResult added in v1.13.0

type OnResult struct {
	Code int
	Body string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL