Documentation ¶
Overview ¶
Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0
Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0
Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0
Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0
Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0
Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0
Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0
Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0
Index ¶
- Constants
- Variables
- func CloseQuietly(file io.Closer)
- func CopyFile(src, dest string) error
- func DebugStackf(format string, args ...interface{})
- func ExpBackoff(base, max time.Duration, count uint32) time.Duration
- func FileMD5(filename string) (hash []byte, err error)
- func FlattenJson(parentKey string, data map[string]interface{}, jsonMap map[string]interface{}) map[string]interface{}
- func GenerateMD5(data string) ([]byte, error)
- func GetEnv(key string, dfault string, combineWith ...string) string
- func GetLinuxDistro() int
- func GetLinuxOSInfo() (info map[string]string, err error)
- func GetOS() int
- func HostEtc(combineWith ...string) string
- func HostProc(combineWith ...string) string
- func HostSys(combineWith ...string) string
- func HostVar(combineWith ...string) string
- func IsAmazonOS() bool
- func IsDockerRunning() bool
- func LogStructureDetails(logEntry log.Entry, sample interface{}, name, phase string, ...)
- func ObfuscateSensitiveData(value string) (matched, isField bool, result string)
- func ObfuscateSensitiveDataFromArray(data []string) []string
- func ObfuscateSensitiveDataFromError(originalError error) (obfuscateError error)
- func ObfuscateSensitiveDataFromMap(data map[string]string) map[string]string
- func ObfuscateSensitiveDataFromString(originalString string) (obfuscateString string)
- func ReadFirstLine(filename string) string
- func RemoveEmptyAndDuplicateEntries(entries []string) []string
- func RunCommand(command string, stdin string, arguments ...string) (string, error)
- func SanitizeCommandLine(cmd string) string
- func SanitizeFileName(fileName string) string
- func SanitizeJson(jsonMap map[string]interface{}) map[string]interface{}
- type Command
- type Docker
- type DockerClient
- type NoCacheEntry
- type PersistentSocketTransport
- type ServiceDetails
Constants ¶
const ( // Specific flavors of Linux LINUX_UNKNOWN = iota LINUX_DEBIAN LINUX_REDHAT LINUX_AWS_REDHAT LINUX_SUSE // Major OS families OS_OSX OS_WINDOWS OS_LINUX OS_UNKNOWN LINUX_COREOS FREEBSD )
const ( MaxBackoffErrorCount = 31 // The Maximum size of the cache used to store sanitized file names. SanitizeFileNameCacheSize = 1000 )
const (
// file path without etc prefix, use host etc in init to get appropriate prefix
DefaultLinuxOsReleasePath = "/os-release"
)
Variables ¶
var ( JsonFilesRegexp = regexp.MustCompile("^[^~]+.json$") HiddenField = "<HIDDEN>" )
var (
ErrNoDockerd = errors.New("no active docker instance found")
)
var ISO8601RE = regexp.MustCompile(`(\d{4})-(\d{2})-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})([zZ]|[\+|-]\d{2}:\d{2})`)
var SensitiveKeys = []string{"key", "secret", "password", "token", "passphrase", "credential"}
Functions ¶
func CloseQuietly ¶
func DebugStackf ¶
func DebugStackf(format string, args ...interface{})
DebugStackf logs a formatted debug message with information of the invokers' stacktrace. This function makes sure that no memory is generated if logger level lower to log.DebugLevel. This function is aimed only to debug messages from functions that can be invoked from multiple parts of the code.
func ExpBackoff ¶
Calculates the backoff as a function of the base and the maximum intervals, and the count of retries
func FlattenJson ¶
func GenerateMD5 ¶
Helper to compute the MD5 digest of a particular string
func GetEnv ¶
GetEnv retrieves the environment variable key. If it does not exist it returns the default. From gopsutil
func GetLinuxOSInfo ¶
func IsAmazonOS ¶
func IsAmazonOS() bool
Detect whether the host is running Amazon Linux by looking for known AWS Linux OS files.
func IsDockerRunning ¶
func IsDockerRunning() bool
func LogStructureDetails ¶
func LogStructureDetails(logEntry log.Entry, sample interface{}, name, phase string, optionalFields logrus.Fields)
LogStructureDetails transforms a Go structure into json and logs it as a payload trace
func ObfuscateSensitiveData ¶
ObfuscateSensitiveData is used to detect sensitive data like tokens/passwords etc and replace them by *. e.g. NRIA_CUSTOM_PASSWORD=1234 => NRIA_CUSTOM_PASSWORD=*
/usr/bin/custom_cmd -pwd 1234 -arg2 abc => /usr/bin/custom_cmd -pwd * -arg2 abc
func ObfuscateSensitiveDataFromArray ¶
ObfuscateSensitiveDataFromArray will is used to detect sensitive data like tokens/passwords etc and replace them by *. If a value is matched and is considered a field(matched but no tokens/passwords founded) the next value will be considered related so obfuscated.
func ObfuscateSensitiveDataFromMap ¶
ObfuscateSensitiveDataFromMap will is used to detect sensitive data like tokens/passwords etc and replace them by *. If a key is matched is considered a field(matched but no tokens/passwords founded) the value will be obfuscated.
func ReadFirstLine ¶
ReadFirstLine will return just the first line of the file.
func RemoveEmptyAndDuplicateEntries ¶
RemoveEmptyAndDuplicateEntries removes the empty and duplicate entries of a string slice, keeping the original order of the input slice
func RunCommand ¶
func SanitizeCommandLine ¶
Cleans the command line to remove wrappers like quotation marks.
func SanitizeFileName ¶
Removes the next characters from a string so the resulting string can be used as a file name in any major operating system (Unix/Linux, Windows and Mac). - slash (/): folder separator in Unix - backslash (\): folder separator in Windows - colon (:): mountpoint drive in Windows - asterisk (*): wilcard in Unix and Windows - question mark (?): wildcard in Unix and Windows - quote ("): beginning and end of filename containing spaces in Windows - less than (<): redirect input - greater than (>): redirect output - vertical bar (|): software pipelining in Unix and Windows
func SanitizeJson ¶
Types ¶
type Command ¶
func NewCommand ¶
type DockerClient ¶
type DockerClient struct {
// contains filtered or unexported fields
}
func (*DockerClient) ContainerTop ¶
func (dc *DockerClient) ContainerTop(containerID string) (titles []string, processes [][]string, err error)
func (*DockerClient) Containers ¶
func (dc *DockerClient) Containers() ([]types.Container, error)
func (*DockerClient) Initialize ¶
func (dc *DockerClient) Initialize(apiVersion string) (err error)
type NoCacheEntry ¶
type NoCacheEntry struct{}
func (NoCacheEntry) Error ¶
func (self NoCacheEntry) Error() string
type PersistentSocketTransport ¶
type PersistentSocketTransport struct {
// contains filtered or unexported fields
}
func NewSocketTransport ¶
func NewSocketTransport(path string) (*PersistentSocketTransport, error)
type ServiceDetails ¶
type ServiceDetails struct { Pid string `json:"pid"` Ppid string `json:"ppid"` Uids string `json:"uids"` // proc/pid/status Gids string `json:"gids"` // proc/pid/status Listening string `json:"listen_socks"` // combination of /proc/pid/fds and /proc/net/(tcp|udp) Started time.Time `json:"-"` }
func GetPidDetails ¶
func GetPidDetails(pid int) (d ServiceDetails, err error)