-
Notifications
You must be signed in to change notification settings - Fork 2
/
command.go
33 lines (29 loc) · 827 Bytes
/
command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package inputs
import (
"fmt"
"os"
"os/user"
"strings"
"github.com/hexbotio/hex/models"
"github.com/hexbotio/hex/parse"
)
// Command struct
type Command struct {
}
// Read function
func (x Command) Read(inputMsgs chan<- models.Message, config models.Config) {
hostname, _ := os.Hostname()
user, _ := user.Current()
input, debug := parse.Flag(config.Command, "--debug")
if strings.TrimSpace(input) != "" {
message := models.NewMessage()
message.Attributes["hex.service"] = "command"
message.Attributes["hex.hostname"] = hostname
message.Attributes["hex.user"] = user.Username
message.Attributes["hex.input"] = input
message.Debug = debug
config.Logger.Debug("Command Input - ID:" + message.Attributes["hex.id"])
config.Logger.Trace(fmt.Sprintf("Message: %+v", message))
inputMsgs <- message
}
}