Skip to content

Commit

Permalink
Adding mode to alert's LogHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
yosiat committed Apr 4, 2016
1 parent e30ec41 commit 8f100d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ func (a *AlertNode) handleLog(l *pipeline.LogHandler, ad *AlertData) {
a.logger.Println("E! failed to marshal alert data json", err)
return
}
f, err := os.OpenFile(l.FilePath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0600)
f, err := os.OpenFile(l.FilePath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(l.Mode))
if err != nil {
a.logger.Println("E! failed to open file for alert logging", err)
return
Expand Down
17 changes: 17 additions & 0 deletions pipeline/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const defaultMessageTmpl = "{{ .ID }} is {{ .Level }}"
// Default template for constructing a details message.
const defaultDetailsTmpl = "{{ json . }}"

// Default log mode for file
const defaultLogFileMode = 0600

// An AlertNode can trigger an event of varying severity levels,
// and pass the event to alert handlers. The criteria for triggering
// an alert is specified via a [lambda expression](/kapacitor/v0.11/tick/expr/).
Expand Down Expand Up @@ -428,11 +431,22 @@ type ExecHandler struct {
// Log JSON alert data to file. One event per line.
// Must specify the absolute path to the log file.
// It will be created if it does not exist.
// Example:
// stream
// |alert()
// .log('/tmp/alert')
//
// Example:
// stream
// |alert()
// .log('/tmp/alert')
// .mode(0644)
// tick:property
func (a *AlertNode) Log(filepath string) *LogHandler {
log := &LogHandler{
AlertNode: a,
FilePath: filepath,
Mode: defaultLogFileMode,
}
a.LogHandlers = append(a.LogHandlers, log)
return log
Expand All @@ -446,6 +460,9 @@ type LogHandler struct {
// It will be created if it does not exist.
// tick:ignore
FilePath string

// File's mode and permissions, default is 0600
Mode int64
}

// Send alert to VictorOps.
Expand Down

0 comments on commit 8f100d6

Please sign in to comment.