cmd

package
v0.0.0-...-d958fbe Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2023 License: MIT Imports: 44 Imported by: 0

Documentation

Overview

Package cmd Code generated by go-bindata. (@generated) DO NOT EDIT. sources: templates/index.html templates/load_log_form.go.html templates/searchpage.go.html

Index

Constants

View Source
const (
	TimeISO8601LayOut = "2006-01-02T15:04:05-0700"
	AUTimeLayout      = "02/01/2006 15:04:05 MST"
)

TimeISO8601LayOut

View Source
const (
	MillisPerSecond     = int64(time.Second / time.Millisecond)
	NanosPerMillisecond = int64(time.Millisecond / time.Nanosecond)
	NanosPerSecond      = int64(time.Second / time.Nanosecond)
)

Time handling

View Source
const MaxUploadSize = 4 * 1024 * 1024 * 1024
View Source
const MaxUploadSizeInMemory = 4 * 1024 * 1024 // 4 MB
View Source
const OauthGoogleUrlAPI = "https://www.googleapis.com/oauth2/v2/userinfo?access_token="
View Source
const Version = "79f27a5"

Variables

View Source
var CurrentYear, CurrentZone string

CurrentYear - CurrentZone - Used for timeadjust

View Source
var GoogleOauthConfig oauth2.Config

Scopes: OAuth 2.0 scopes provide a way to limit the amount of access that is granted to an access token.

View Source
var JenkinsLogDataPattern *regexp.Regexp
View Source
var PasswordFilterPtns []*regexp.Regexp
View Source
var ServerProtocol string

ServerProtocol -

View Source
var SessionStore *sessions.CookieStore

SessionStore -

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetFile

func AssetFile() http.FileSystem

AssetFile return a http.FileSystem instance that data backend by asset

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func CheckAuthorizedDomain

func CheckAuthorizedDomain(email string) bool

CheckAuthorizedDomain -

func CheckAuthorizedUser

func CheckAuthorizedUser(email string) bool

CheckAuthorizedUser -

func CreateHash

func CreateHash(key string) string

CreateHash - md5

func DatabaseMaintenance

func DatabaseMaintenance()

DatabaseMaintenance - all maintenance routine spawn off from here. Currently just delete the records older than the retention period to keep disk space usage managable. User can always use the sqlite command to export data into csv format and save it somewhere.

func DecodeJenkinsConsoleNote

func DecodeJenkinsConsoleNote(msg string) string

DecodeJenkinsConsoleNote - See https://github.com/LarrysGIT/Extract-Jenkins-Raw-Log/blob/master/README.md. Testing

func DeleteConfig

func DeleteConfig(key string)

DeleteConfig - delete the config key

func DoNagiosACK

func DoNagiosACK(Host, Service, User, Comment string) int

func DoNagiosDeleteAllComment

func DoNagiosDeleteAllComment(Host, Service string) int

func DoSQLSearch

func DoSQLSearch(q string, o *strings.Builder) (int, error)

DoSQLSearch - Execute the search in the database. Return the record counts and fill the string builder object.

func DoUploadLog

func DoUploadLog(w http.ResponseWriter, r *http.Request)

Present a simple form to allow user to create a log entry. Or upload a text file and parse log

func DumpPost

func DumpPost(w http.ResponseWriter, r *http.Request)

func FilterPassword

func FilterPassword(text string, passPtns []*regexp.Regexp) string

FilterPassword -

func GenerateDefaultConfig

func GenerateDefaultConfig(opt ...interface{}) (e error)

GenerateDefaultConfig -

func GenerateJWT

func GenerateJWT() (string, error)

func GetConfig

func GetConfig(key ...string) string

GetConfig - by key and return value. Give second arg as default value.

func GetConfigSave

func GetConfigSave(key ...string) string

GetConfigSave -

func GetDBConn

func GetDBConn() *sqlite3.Conn

GetDBConn -

func GetFormValue

func GetFormValue(r *http.Request, key ...string) string

GetFormValue -

func GetMuxValue

func GetMuxValue(r *http.Request, key ...string) string

GetMuxValue -

func GetQueryValue

func GetQueryValue(r *http.Request, key ...string) string

GetQueryValue -

func GetRequestValue

func GetRequestValue(r *http.Request, key ...string) string

GetRequestValue - Attempt to get a val by key from the request in all cases. First from the mux variables in the route path such as /dosomething/{var1}/{var2} Then check the query string values such as /dosomething?var1=x&var2=y Then check the form values if any Then check the default value if supplied to use as return value For performance we split each type into each function so it can be called independantly

func GetTwilioCall

func GetTwilioCall(myCallId string) (string, string)

GetTwilioCall - Get call info from the trace of events log. We utilize the field logfile to add the nagios host and service info for the Gather Action or anything later on to use.

func GetUserDataFromGoogle

func GetUserDataFromGoogle(code string) ([]byte, error)

GetUserDataFromGoogle -

func HandleMakeTwilioCall

func HandleMakeTwilioCall(w http.ResponseWriter, r *http.Request)

func HandleNagiosDeleteAllComment

func HandleNagiosDeleteAllComment(w *http.ResponseWriter, r *http.Request)

func HandleNagiosHostACK

func HandleNagiosHostACK(w *http.ResponseWriter, r *http.Request)

func HandleNagiosServiceACK

func HandleNagiosServiceACK(w *http.ResponseWriter, r *http.Request)

func HandlePagerDutyEvent

func HandlePagerDutyEvent(w http.ResponseWriter, r *http.Request)

func HandleRequests

func HandleRequests()

HandleRequests -

func HandleSNSEvent

func HandleSNSEvent(w http.ResponseWriter, r *http.Request)

HandleSNSEvent - From/To/action

func InsertLog

func InsertLog(data []byte)

InsertLog -

func IsBasicAuth

func IsBasicAuth(endpoint func(http.ResponseWriter, *http.Request), username, password, realm string) http.Handler

func IsEOF

func IsEOF(filename string, seek int64) bool

IsEOF - NOt sure why tail does not provide this test.

func LoadConfig

func LoadConfig(fPath string) (e error)

LoadConfig - Load all config/global regex pattern required

func LoadTailPosition

func LoadTailPosition(tailFileName string, cfg *TailLogConfig) int64

LoadTailPosition -

func LoadTemplate

func LoadTemplate(tFilePath string) string

LoadTemplate - Run this command to create the bindata.go go-bindata -fs -pkg cmd -o cmd/bindata.go -nomemcopy templates go get -u github.com/go-bindata/go-bindata/...

func MakeTwilioCall

func MakeTwilioCall(myCallId, reqAction, Body, From, To, Host, Service, gatherMenuStr string) error

func MsToTime

func MsToTime(ms int64) time.Time

MsToTime -

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func NsToTime

func NsToTime(ns int64) time.Time

NsToTime -

func OauthGoogleCallback

func OauthGoogleCallback(w http.ResponseWriter, r *http.Request)

OauthGoogleCallback -

func OauthGoogleLogin

func OauthGoogleLogin(w http.ResponseWriter, r *http.Request)

OauthGoogleLogin -

func ParseAWSCloudWatchLogEvent

func ParseAWSCloudWatchLogEvent(appNameStr string)

ParseAWSCloudWatchLogEvent - Input from os.stdin as a json string with the format describe in aws cloudwatch logevent. It is the output of command such as aws logs get-log-events --log-group-name /aws/ecs/int --log-stream-name errcd-wa-int/errcd-wa-task/1bd0169e-2013-4964-96fa-8c18819ffa62 --profile errcd_wa --region ap-southeast-2 We parse it and ship it to out log server.

func ParseAlertKey

func ParseAlertKey(alertKey string) (string, string, string)

func ParseTimeAdjust

func ParseTimeAdjust(adjustStr string) string

ParseTimeAdjust - take a timeadjust and parse its meaning. Use the go time formatting eg. if it hits '2006' then it will replace it with current year. Similar. If string is not any of the go date layout then it is pass though as is. There are 5 tokens: Jan 02 15:04:05 2006 MST that we support

func ParseTimeRange

func ParseTimeRange(durationStr, tz string) (time.Time, time.Time)

ParseTimeRange - return a time range start/end based on now back to the Duration.

func ProcessACKEvent

func ProcessACKEvent(w *http.ResponseWriter, bodyDataByte []byte)

func ProcessCommand

func ProcessCommand(w http.ResponseWriter, r *http.Request)

func ProcessLog

func ProcessLog(w http.ResponseWriter, r *http.Request)

func ProcessNagiosCommand

func ProcessNagiosCommand(w http.ResponseWriter, r *http.Request)

ProcessNagiosCommand - entry point taken for /nagios/{command}. We will route each command to the real handler

func ProcessResolvedEvent

func ProcessResolvedEvent(w *http.ResponseWriter, bodyDataByte []byte)

func ProcessSearchLog

func ProcessSearchLog(w http.ResponseWriter, r *http.Request)

ProcessSearchLog -

func ProcessSearchLogByID

func ProcessSearchLogByID(w http.ResponseWriter, r *http.Request)

ProcessSearchLogByID - Take an ID and search for record surrounding including the current rec with time span of 10 minutes

func ProcessTailLines

func ProcessTailLines(cfg *TailLogConfig, tail *tail.Tail)

ProcessTailLines -

func ProcessTwilioCallEvent

func ProcessTwilioCallEvent(w http.ResponseWriter, r *http.Request)

func ProcessTwilioGatherEvent

func ProcessTwilioGatherEvent(w http.ResponseWriter, r *http.Request)

func ReadUserIP

func ReadUserIP(r *http.Request) string

ReadUserIP - parse the userIP:port from the request

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func RunCommand

func RunCommand(cmdName ...string) string

RunCommand -

func RunNagiosCheckCommand

func RunNagiosCheckCommand(cmdName string)

RunNagiosCheckCommand - This will return based on nagios plugin specs

func SaveTailPosition

func SaveTailPosition(t *tail.Tail, cfg *TailLogConfig)

SaveTailPosition -

func SearchLog

func SearchLog(keyword string, o *strings.Builder, sortorder, duration, tz string) (int, error)

SearchLog -

func SendAWSLogEvents

func SendAWSLogEvents(evts []*cloudwatchlogs.FilteredLogEvent, appNameStr string, timeMark int64, conn *sqlite3.Conn) int64

SendAWSLogEvents - Store the last End time in the event list

func SendLine

func SendLine(timeHarvest, timeParsed time.Time, hostStr, appNameStr, logFile, msgStr string) bool

SendLine -

func SendProcessCommand

func SendProcessCommand(w http.ResponseWriter, r *http.Request)

func SetConfig

func SetConfig(key, val string)

SetConfig - Set a config key with value

func SetUpLogDatabase

func SetUpLogDatabase()

SetUpLogDatabase -

func StartAWSCloudwatchLogOnePrefix

func StartAWSCloudwatchLogOnePrefix(logGroupName string, cl *cloudwatchlogs.CloudWatchLogs, filterEvtInput cloudwatchlogs.FilterLogEventsInput, sleepDuration time.Duration)

StartAWSCloudwatchLogOnePrefix -

func StartAWSCloudwatchLogPolling

func StartAWSCloudwatchLogPolling(cfg *AWSLogConfig)

StartAWSCloudwatchLogPolling -

func StartAllAWSCloudwatchLogPolling

func StartAllAWSCloudwatchLogPolling(c chan os.Signal)

func StartServer

func StartServer()

StartServer - We may spawn other listener within this func

func TailLog

func TailLog(cfg *TailLogConfig, c chan os.Signal)

TailLog -

func TailOneGlob

func TailOneGlob(cfg *TailLogConfig, globPtn string, c chan os.Signal)

TailOneGlob -

func TailOnePath

func TailOnePath(cfg *TailLogConfig, logFile string, c chan os.Signal)

TailOnePath -

func Ternary

func Ternary(cond bool, first, second interface{}) interface{}

func TestTailLog

func TestTailLog(cfg tail.Config, logFile string)

TestTailLog -

Types

type AWSLogConfig

type AWSLogConfig struct {
	LoggroupName string
	StreamPrefix []string
	FilterPtn    string
	Profile      string
	Region       string
	Period       string
}

AWSLogConfig -

type AppConfig

type AppConfig struct {
	Serverdomain           string
	Port                   int //Server mode - Port to listen for web gui, log harvesting and Command executor
	Commands               []Command
	JwtKey                 string
	Logfiles               []LogFile
	Serverurl              string //Client mode - URL to ship log to or to send command to be executed
	Logdbpath              string
	Dbtimeout              string
	Sslcert                string
	Sslkey                 string
	PasswordFilterPatterns []string `yaml:"passwordfilterpatterns"`
	AppGoogleClientID      string
	AppGoogleClientSecret  string
	Sessionkey             string
	AuthorizedDomain       map[string]bool
	AWSLogs                []AWSLogConfig
	IgnoreCertificateCheck bool
	LogRetention           string
	LetsEncryptEnabled     bool
	LetsEncryptEmail       string
}

AppConfig -

var Config AppConfig

Config - Global

type Command

type Command struct {
	Name string
	Path string
}

Command -

type LogData

type LogData struct {
	Timestamp   int64
	Datelog     int64
	Host        string
	Application string
	Logfile     string
	Message     string
}

LogData -

func SaveDumpData

func SaveDumpData(host, application, logfile, message string) *LogData

For debugging purposes only. The endpoint handler can temporary call this to examine the data structure

type LogFile

type LogFile struct {
	Name            string //Must be unique within a host running this app. Used to save the tail pos
	Paths           []string
	Timelayout      string   //Parse the match below into go time object
	Timepattern     string   //extract the timestamp part into a timeStr which is fed into the Timelayout
	Timeadjust      string   //If the time extracted string miss some info (like year or zone etc) this string will be appended to the string. If it contains a golang timelayout token with one extra space at the end of the string (eg. '2004 ') then these token will be parsed as the current for example year.
	Timestrreplace  []string //Do search/replace the capture before parse time. As go does not support , aas sec fraction this is to work around for this case.
	Pattern         string   //will be matched to extract the HOSTNAME APP-NAME MSG part of the line.
	Multilineptn    string   //detect if the line is part of the previous line
	Excludepatterns []string //If log line match this pattern it will be excluded
	Includepatterns []string
	Appname         string //Overrite the appname of the logfile if not empty
}

LogFile -

type TailLogConfig

type TailLogConfig struct {
	LogFile
	SeekOffset int64
	TailConfig tail.Config
}

TailLogConfig -

Jump to

Keyboard shortcuts

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