sysloger

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: MIT Imports: 8 Imported by: 0

README

ngr-sysloger

Syslog sending wrapper (with custom CEF formatter) Supports UnixFormatter, RFC3164Formatter, RFC5424Formatter, DefaultFormatter from origin github.com/RackSec/srslog

import

import "github.com/NGRsoftlab/ngr-sysloger"

example (see _test files)

	
    header := CefHeader{
		Version:            0,
		DeviceVendor:       "Test",
		DeviceProduct:      "TestProd",
		DeviceVersion:      "1.0",
		DeviceEventClassId: "testing",
		Name:               "TEST",
		Severity:           "Low",
	}

	testMap := map[string]interface{}{
		"src":                      "HOOOST",
		"requestClientApplication": "Test-cli",
	}

	// for CEFFormatter
	testData, err := MakeCefString(header, testMap, false, true, false)
	if err != nil {
		log.Fatal(err)
	}

	err = SendSingleSyslogMsg(SyslogParams{
		Level:    5,
		Host:     "127.0.0.1",
		Port:     "555",
		Protocol: "tcp",
		Priority: 0,
		Tag:      "test",
		//NeedTls:  false,
		//TlsConf:  &tl,
	},
		CEFFormatter,
		testData)
	if err != nil {
		log.Fatal("Bad TestSendSingleSyslogMsg: ", err)
	}

Documentation

Overview

Copyright 2020 NGR Softlab

Copyright 2020 NGR Softlab

Index

Constants

View Source
const (
	SimpleLevel = iota // just write
	DebugLevel
	InfoLevel
	WarningLevel
	ErrorLevel
	AlertLevel
	CriticalLevel
)

Syslog levels

Variables

This section is empty.

Functions

func CEFFormatter

func CEFFormatter(p syslog.Priority, hostname, tag, content string) string

CEFFormatter custom Formatter for CEF (for github.com/RackSec/srslog lib)

func CheckKey added in v1.0.3

func CheckKey(testKey string) bool

func GetLongNameByShort added in v1.0.1

func GetLongNameByShort(longName string) string

func GetShortNameByLong added in v1.0.1

func GetShortNameByLong(shortName string) string

func MakeCefString

func MakeCefString(header CefHeader, contentMap map[string]interface{}, keysAreLong, useDefault, useCustom bool) (string, error)

MakeCefString making CEF string from custom header params and content map

func NewSyslogWriter

func NewSyslogWriter(params SyslogParams, formatter syslog.Formatter) (*syslog.Writer, error)

NewSyslogWriter create new syslog writer with params and custom formatter

func NewSyslogWriterWithTimeout added in v1.0.6

func NewSyslogWriterWithTimeout(params SyslogParams, formatter syslog.Formatter, timeout time.Duration) (*syslog.Writer, error)

NewSyslogWriterWithTimeout create new syslog writer with params and custom formatter + timeout

func SendListToSyslog

func SendListToSyslog(params SyslogParams, formatter syslog.Formatter, msgList []string) error

SendListToSyslog - Send list of msgs to syslog

func SendListToSyslogWithTimeout added in v1.0.6

func SendListToSyslogWithTimeout(params SyslogParams, formatter syslog.Formatter, msgList []string, timeout time.Duration) error

SendListToSyslogWithTimeout - Send list of msgs to syslog with timeout

func SendSingleSyslogMsg

func SendSingleSyslogMsg(params SyslogParams, formatter syslog.Formatter, msg string) error

SendSingleSyslogMsg - Send single syslog msg

func SendSingleSyslogMsgWithTimeout added in v1.0.6

func SendSingleSyslogMsgWithTimeout(params SyslogParams, formatter syslog.Formatter, msg string, timeout time.Duration) error

SendSingleSyslogMsgWithTimeout - Send single syslog msg with timeout

Types

type CefHeader

type CefHeader struct {
	Version                                    int
	DeviceVendor, DeviceProduct, DeviceVersion string
	DeviceEventClassId                         string
	Name                                       string
	Severity                                   string
}

CefHeader CEF header parameters

type FieldInfo added in v1.0.1

type FieldInfo struct {
	FullName    string `json:"full_name"`
	ShortName   string `json:"short_name"`
	DataType    string `json:"data_type"`
	Length      int64  `json:"length"`
	Description string `json:"description"`
}

type SyslogParams

type SyslogParams struct {
	Level    int    `json:"level"`    // syslog level info/error/fatal
	Host     string `json:"host"`     // host to send
	Port     int    `json:"port"`     // port to send
	Protocol string `json:"protocol"` // tcp\udp

	Priority syslog.Priority
	Tag      string `json:"tag"` // syslog tag

	NeedTls bool
	TlsConf *tls.Config
}

SyslogParams syslog dial params

Jump to

Keyboard shortcuts

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