v2

package
v0.0.0-...-a0c03a0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

It is based on `InVisionApp/go-health`

Copyright 2019 Cisco Systems, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (

	// Value errors.
	ErrOIDNotFound      = Error("OID not present in trap vars.")
	ErrUnknownAs        = Error("Unknown v2.snmp.As type.")
	ErrNoneNumericalOID = Error("Numerical OID expected..")

	// Concatenate errors.
	ErrPathIsNotDir = Error("Path is not a directory.")

	// Mod errors.
	ErrInvalidOperation = Error("Operation not possible for given Mod.")
	ErrKeyMissing       = Error("Key missing in mod.")

	// Alert Generator errors.
	ErrConfigNotFound   = Error("Unknown config.")
	ErrNoMatch          = Error("No alert matched in alert config.")
	ErrUnknownEventType = Error("Unknown event type specified.")

	// Counter errors.
	ErrCounterCreateFailed  = Error("Failed to create counter.")
	ErrCounterDestroyFailed = Error("Failed to remove counter.")

	// CounterVec errors.
	ErrCounterVecCreateFailed   = Error("Failed to create counter vector.")
	ErrHistogramVecCreateFailed = Error("Failed to create histogram vector.")
)
View Source
const AMTimeFormat = "2006-01-02T15:04:05.000Z07:00"

RFC3339 with milliseconds. Time format expected by Alertmanager.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	Hostname    string `json:"hostname,omitempty"`
	ID          string `json:"id,omitempty"`
	EphemeralID string `json:"ephemeral_id,omitempty"`
	Type        string `json:"type,omitempty"`
	Version     string `json:"version,omitempty"`
}

type Alert

type Alert struct {
	Labels       map[string]string `json:"labels"`
	Annotations  map[string]string `json:"annotations"`
	StartsAt     time.Time         `json:"startsAt"`
	EndsAt       time.Time         `json:"endsAt"`
	GeneratorURL string            `json:"generatorURL"`
}

Represents Alertmanager alert.

type AppStatus

type AppStatus struct {
	ApiVersion  string         `json:"apiVersion"`
	Description string         `json:"description"`
	Links       AppStatusLinks `json:"links"`
	Status      string         `json:"status"`
}
type AppStatusLinks struct {
	About string `json:"about"`
}

type Cacher

type Cacher interface {
	Read(io.Reader, interface{}) error
	Write(io.Writer, interface{}) error
}

Cache data

type Client

type Client http.Client

Represents HTTP client

type Concatenate

type Concatenate interface {
	Concat() (io.Reader, error) // Join all configs in given Dir.
}

Interface to merge all configs in conf.d dir.

type Counter

type Counter interface {
	Create() error
	Incr() error
	Destroy() error
}

Counter is a Domain Type that represents the options for creating a counter. It is based on `prometheus/Counter`

type CounterVector

type CounterVector interface {
	Create([]string) error        // Labels.
	Incr(map[string]string) error // map[Label]Value
}

CounterVector is a Domain Type that represents the options for creating a CounterVec. It is based on `prometheus/CounterVec`

type Decoder

type Decoder interface {
	Decode(io.Reader) error
}

Decode configs in *_config.go

type Document

type Document struct {
	ApiVersion string   `json:"apiVersion,omitempty"`
	Kind       string   `json:"kind,omitempty"`
	Receipts   Receipts `json:"receipts,omitempty"`
}

type Ecs

type Ecs struct {
	Version string `json:"version,omitempty"`
}

type Encoder

type Encoder interface {
	Encode(io.Writer) error
}

Encode configs in *_config.go

type Error

type Error string

Error represents an OF error.

func (Error) Error

func (e Error) Error() string

Error returns the error as a string.

type Filebeat

type Filebeat struct {
	Agent     Agent              `json:"agent,omitempty"`
	Ecs       Ecs                `json:"ecs,omitempty"`
	Input     PostableEventInput `json:"input,omitempty"`
	Host      Host               `json:"host,omitempty"`
	Log       Log                `json:"log,omitempty"`
	Message   string             `json:"message,omitempty"`
	Version   string             `json:"@version,omitempty"`
	Timestamp string             `json:"@timestamp,omitempty"`
}

type Graceful

type Graceful interface {
	Start() error
	Stop() error
}

Methods required to implement graceful.

type HTTPConfig

type HTTPConfig struct {
	ListenAddress string
	ReadTimeout   time.Duration
	WriteTimeout  time.Duration
}

type Handler

type Handler interface {
	ServeHTTP(ResponseWriter, Request)
}

Represents HTTP handler

type HealthChecker

type HealthChecker interface {
	Start() error
	Stop() error
	AddURL(name string, urlTarget string, timeout time.Duration) error
	State(urlTarget string) error
}

type HistogramVector

type HistogramVector interface {
	Create([]string) error            // Labels.
	Observed([]string, float64) error // []LabelValues, seconds
}

HistogramVector is a Domain Type that represents the options for creating a HistogramVector is based on `prometheus/HistogramVector`

type Host

type Host struct {
	Name string `json:"name,omitempty"`
}

type Log

type Log struct {
	Offset int32   `json:"offset,omitempty"`
	File   LogFile `json:"file,omitempty"`
}

type LogFile

type LogFile struct {
	Path string `json:"path,omitempty"`
}

type Logger

type Logger interface {
	Fatalf(message string, args ...interface{})
	Panicf(message string, args ...interface{})
	Debugf(message string, args ...interface{})
	Errorf(message string, args ...interface{})
	Infof(message string, args ...interface{})
	LogLevel() string
	SetLevel(string)
	Tracef(message string, args ...interface{})
	Warningf(message string, args ...interface{})

	WithError(error) Logger
	WithField(string, interface{}) Logger
	WithFields(map[string]interface{}) Logger

	SetOutput(io.Writer)
}

Methods required for a logger.

type Logstash

type Logstash struct {
	Tags []string `json:"tags,omitempty"`
}

type MIB

type MIB struct {
	Name        string
	Description string
	Units       string
}

Represents MIB description.

type MIBRegistry

type MIBRegistry interface {
	// Return MIB for given OID.
	MIB(string) *MIB

	// Return MIB for given OID.
	// Translate each node in OID to its corresponding name, if MIB has its definition, else use the number.
	// Ex : 1.3.6.1.2.1.11.19 -> iso.org.dod.internet.mgmt.mib-2.snmp.snmpInTraps.
	//      1.3.6.1.2.1.11.19.54334 -> iso.org.dod.internet.mgmt.mib-2.snmp.snmpInTraps.54334.
	String(string) string

	// Translate the last node to its name. Ex: 1.3.6.1.2.1.11.19 -> snmpInTraps.
	ShortString(string) string

	// Load given map[oid]MIB into registry.
	Load(map[string]MIB) error
}

type Measurer

type Measurer interface {
	Measure(ResponseWriter, Request, func(ResponseWriter, Request))
}

Represents HTTP Response code/time measurements

type Notifier

type Notifier interface {
	Notify(*[]Alert) error
}

type PostAlertsParams

type PostAlertsParams struct {
	Alerts []Alert

	Context    context.Context
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Represents Alertmanager postAlerts params.

type PostableEvent

type PostableEvent struct {
	Agent      Agent              `json:"agent,omitempty"`
	ApiVersion string             `json:"apiVersion,omitempty"`
	Document   Document           `json:"document,omitempty"`
	Ecs        Ecs                `json:"ecs,omitempty"`
	Input      PostableEventInput `json:"input,omitempty"`
	Host       Host               `json:"host,omitempty"`
	Log        Log                `json:"log,omitempty"`
	Message    string             `json:"message,omitempty"`
	Version    string             `json:"@version,omitempty"`
	Tags       []string           `json:"tags,omitempty"`
	Timestamp  string             `json:"@timestamp,omitempty"`
}

type PostableEventInput

type PostableEventInput struct {
	Type string `json:"type,omitempty"`
}

type Receipts

type Receipts struct {
	Filebeat  Filebeat  `json:"filebeat,omitempty"`
	Logstash  Logstash  `json:"logstash,omitempty"`
	Snmptrapd Snmptrapd `json:"snmptrapd,omitempty"`
}

type Request

type Request *http.Request

type ResponseWriter

type ResponseWriter interface {
	Header() http.Header
	Write([]byte) (int, error)
	WriteHeader(int)
	StatusCode() int
}

Represents HTTP ResponseWriter

type SNMPConfig

type SNMPConfig struct {
	Application    string
	AMAddress      string
	AMTimeout      time.Duration
	SNMPMibsDir    string
	CacheFile      string
	ListenAddress  string
	ConfigDir      string
	Version        string
	Throttle       bool
	PostTime       int
	SleepTime      int
	SendTime       int
	DryRun         bool
	LogUnknown     bool
	ForwardUnknown bool
}

Represents SNMP settings.

type SchemaLoader

type SchemaLoader interface {
	Load([]byte) error
}

Defines schema loader

type SchemaValidator

type SchemaValidator interface {
	ValidateYAML([]byte) error
	ValidateJSON([]byte) error
}

Defines schema Validator

type Serve

type Serve interface {
	ListenAndServe() error
	Shutdown() error
	Handle(string, Handler)
	HandleFunc(string, func(ResponseWriter, Request))
}

Represents HTTP server components

type Server

type Server struct {
	Srv *http.Server
	Mux *http.ServeMux
	G   Graceful
	M   Measurer
}

type Snmptrapd

type Snmptrapd struct {
	Timestamp   string     `json:"timestamp,omitempty"`
	Source      TrapSource `json:"source,omitempty"`
	Vars        []TrapVar  `json:"vars,omitempty"`
	PduSecurity string     `json:"pduSecurity,omitempty"`
}

type TrapSource

type TrapSource struct {
	Address                string `json:"address"`
	Hostname               string `json:"hostname"`
	InternetLayerProtocol  string `json:"internetLayerProtocol"`
	Port                   string `json:"port"`
	TransportLayerProtocol string `json:"transportLayerProtocol"`
}

type TrapVar

type TrapVar struct {
	Value string `json:"value"`
	Type  string `json:"type"`
	Oid   string `json:"oid"`
}

type UUIDGen

type UUIDGen interface {
	UUID() string
}

Represents UUID generator.

type Watcher

type Watcher interface {
	Watch() error
	Unwatch() error
}

Interface to watch for file/dir changes or syskill signals.

type Writer

type Writer interface {
	// Write a response object to the ResponseWriter with status code 200.
	Write(w ResponseWriter, r Request, e interface{})

	// WriteCode writes a response object to the ResponseWriter and sets a response code.
	WriteCode(w ResponseWriter, r Request, code int, e interface{})

	// WriteCreated writes a response object to the ResponseWriter with status code 201 and
	// the Location header set to location.
	WriteCreated(w ResponseWriter, r Request, location string, e interface{})

	// WriteError writes an error to ResponseWriter and tries to extract the error's status code by
	// asserting statusCodeCarrier. If the error does not implement statusCodeCarrier, the status code
	// is set to 500.
	WriteError(w ResponseWriter, r Request, err interface{})

	// WriteErrorCode writes an error to ResponseWriter and forces an error code.
	WriteErrorCode(w ResponseWriter, r Request, code int, err interface{})
}

Writer is a helper to write arbitrary data to a ResponseWriter

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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