MCPcopy
hub / github.com/crowdsecurity/crowdsec / Notify

Method Notify

cmd/notification-dummy/main.go:34–72  ·  view source on GitHub ↗
(_ context.Context, notification *protobufs.Notification)

Source from the content-addressed store, hash-verified

32})
33
34func (s *DummyPlugin) Notify(_ context.Context, notification *protobufs.Notification) (*protobufs.Empty, error) {
35 name := notification.GetName()
36 cfg, ok := s.PluginConfigByName[name]
37
38 if !ok {
39 return nil, fmt.Errorf("invalid plugin config name %s", name)
40 }
41
42 if cfg.LogLevel != "" {
43 logger.SetLevel(hclog.LevelFromString(cfg.LogLevel))
44 }
45
46 logger.Info(fmt.Sprintf("received signal for %s config", name))
47
48 text := notification.GetText()
49
50 logger.Debug(text)
51
52 if cfg.OutputFile != "" {
53 f, err := os.OpenFile(cfg.OutputFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
54 if err != nil {
55 logger.Error(fmt.Sprintf("Cannot open notification file: %s", err))
56 }
57
58 if _, err := f.WriteString(text + "\n"); err != nil {
59 f.Close()
60 logger.Error(fmt.Sprintf("Cannot write notification to file: %s", err))
61 }
62
63 err = f.Close()
64 if err != nil {
65 logger.Error(fmt.Sprintf("Cannot close notification file: %s", err))
66 }
67 }
68
69 fmt.Fprintln(os.Stdout, text)
70
71 return &protobufs.Empty{}, nil
72}
73
74func (s *DummyPlugin) Configure(_ context.Context, config *protobufs.Config) (*protobufs.Empty, error) {
75 d := PluginConfig{}

Callers

nothing calls this directly

Calls 7

SetLevelMethod · 0.80
GetTextMethod · 0.80
GetNameMethod · 0.65
ErrorMethod · 0.65
InfoMethod · 0.45
DebugMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected