-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from newrelic/dev
Release v0.4.0
- Loading branch information
Showing
41 changed files
with
799 additions
and
882 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,9 @@ | ||
module github.com/newrelic/csec-go-agent | ||
|
||
go 1.17 | ||
go 1.18 | ||
|
||
require ( | ||
github.com/dlclark/regexp2 v1.9.0 | ||
github.com/gorilla/websocket v1.5.0 | ||
github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b | ||
github.com/k2io/hookingo v1.0.3 | ||
github.com/mackerelio/go-osstat v0.2.4 | ||
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 | ||
github.com/sirupsen/logrus v1.9.0 | ||
github.com/struCoder/pidusage v0.2.1 | ||
) | ||
|
||
require ( | ||
github.com/stretchr/testify v1.8.2 // indirect | ||
golang.org/x/arch v0.3.0 // indirect | ||
golang.org/x/sys v0.7.0 // indirect | ||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect | ||
) | ||
|
||
exclude ( | ||
github.com/stretchr/testify v1.7.0 // indirect | ||
github.com/stretchr/testify v1.7.1 // indirect | ||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect | ||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect | ||
github.com/k2io/hookingo v1.0.5 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2020 New Relic Corporation. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package security_logs | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
) | ||
|
||
var initLogger = DefaultLogger(true) | ||
|
||
func init_initLogger(initlogFileName, logFilepath string, pid int) { | ||
|
||
rotateFileHook, writer, err := NewRotateFileHook(RotateFileConfig{ | ||
Filename: filepath.Join(logFilepath, initlogFileName), | ||
Filepath: logFilepath, | ||
MaxSize: 50, // megabytes | ||
MaxBackups: 2, | ||
BaseLogFilename: initlogFileName, | ||
}) | ||
|
||
UpdateLogger(writer, "INFO", pid, initLogger, rotateFileHook, err) | ||
} | ||
|
||
func InitLogger() *logFile { | ||
return initLogger | ||
} | ||
|
||
func EndStage(stageId, logs interface{}) { | ||
print := fmt.Sprintf("[STEP-%s] %s", stageId, logs) | ||
PrintInitlog(print) | ||
} | ||
func PrintInitlog(logs interface{}) { | ||
initLogger.Infoln(logs) | ||
} | ||
|
||
func PrintInitErrolog(logs string) { | ||
initLogger.Errorln(logs) | ||
} | ||
func PrintWarnlog(logs string) { | ||
initLogger.Warnln(logs) | ||
} | ||
func Disableinitlogs() { | ||
initLogger.isActive = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright 2020 New Relic Corporation. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package security_logs | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"log" | ||
) | ||
|
||
type logFile struct { | ||
logger *log.Logger | ||
isDebugMode bool | ||
mode string | ||
isActive bool | ||
cache []interface{} | ||
iscache bool | ||
rotateFileHook *RotateFileHook | ||
isDefault bool | ||
} | ||
|
||
type Logger interface { | ||
Errorln(...interface{}) | ||
Warnln(...interface{}) | ||
Infoln(...interface{}) | ||
Debugln(...interface{}) | ||
} | ||
|
||
// New creates a basic Logger. | ||
func UpdateLogger(w io.Writer, mode string, pid int, logF *logFile, rotateFileHook *RotateFileHook, isDefault bool) { | ||
logF.logger = log.New(w, fmt.Sprintf("%d", pid), log.Ldate|log.Ltime|log.Lmsgprefix|log.LstdFlags|log.LUTC|log.Lshortfile) | ||
logF.isActive = true | ||
logF.iscache = false | ||
logF.rotateFileHook = rotateFileHook | ||
logF.isDefault = isDefault | ||
logF.setLevel(mode) | ||
logF.cleanCache() | ||
return | ||
} | ||
|
||
func DefaultLogger(iscache1 bool) *logFile { | ||
logF := &logFile{isActive: false, iscache: iscache1, isDefault: true} | ||
return logF | ||
} | ||
|
||
func (f *logFile) fire(level string, msg ...interface{}) { | ||
logm := fmt.Sprintln(msg...) | ||
|
||
if level == "ERROR" { | ||
errLevel := fmt.Sprintf("\x1b[%dm%s\x1b[0m", 31, "ERROR") | ||
logm = fmt.Sprintf(" [%s] %s", errLevel, logm) | ||
} else { | ||
logm = fmt.Sprintf(" [%s] %s", level, logm) | ||
} | ||
|
||
if f.iscache && f.logger == nil { | ||
f.cache = append(f.cache, logm) | ||
} | ||
|
||
if !f.isActive || f.logger == nil { | ||
return | ||
} | ||
|
||
if f.rotateFileHook != nil { | ||
logm = f.rotateFileHook.Fire(logm, level, f.isDefault) | ||
} | ||
|
||
f.logger.Output(3, logm) | ||
} | ||
|
||
func (f *logFile) Errorln(msg ...interface{}) { | ||
f.fire("ERROR", msg...) | ||
} | ||
func (f *logFile) Warnln(msg ...interface{}) { | ||
f.fire("WARN", msg...) | ||
} | ||
func (f *logFile) Infoln(msg ...interface{}) { | ||
f.fire("INFO", msg...) | ||
} | ||
func (f *logFile) Info(msg ...interface{}) { | ||
f.fire("INFO", msg...) | ||
} | ||
func (f *logFile) Debugln(msg ...interface{}) { | ||
if f.isDebugMode { | ||
f.fire("DEBUG", msg...) | ||
} | ||
} | ||
func (f *logFile) DebugEnabled() bool { return f.isDebugMode } | ||
|
||
func (f *logFile) setLevel(mode string) { | ||
if f.isDefault { | ||
f.isDebugMode = false | ||
} else if mode == "DEBUG" { | ||
f.isDebugMode = true | ||
} | ||
f.mode = mode | ||
} | ||
|
||
func (f *logFile) cleanCache() { | ||
for i := range f.cache { | ||
f.logger.Output(3, fmt.Sprintf("%s", f.cache[i])) | ||
} | ||
f.cache = make([]interface{}, 0) | ||
} |
Oops, something went wrong.