| 32 | }) |
| 33 | |
| 34 | func (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 | |
| 74 | func (s *DummyPlugin) Configure(_ context.Context, config *protobufs.Config) (*protobufs.Empty, error) { |
| 75 | d := PluginConfig{} |