forked from choria-io/machine-room
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugins.go
80 lines (69 loc) · 2.75 KB
/
plugins.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) R.I. Pienaar and the Choria Project contributors
//
// SPDX-License-Identifier: Apache-2.0
package machineroom
import (
"fmt"
"sync"
"github.com/choria-io/go-choria/aagent/data/machinedata"
archivewatcher "github.com/choria-io/go-choria/aagent/watchers/archivewatcher"
"github.com/choria-io/go-choria/aagent/watchers/execwatcher"
"github.com/choria-io/go-choria/aagent/watchers/filewatcher"
"github.com/choria-io/go-choria/aagent/watchers/kvwatcher"
"github.com/choria-io/go-choria/aagent/watchers/metricwatcher"
"github.com/choria-io/go-choria/aagent/watchers/nagioswatcher"
"github.com/choria-io/go-choria/aagent/watchers/pluginswatcher"
"github.com/choria-io/go-choria/aagent/watchers/schedulewatcher"
"github.com/choria-io/go-choria/aagent/watchers/timerwatcher"
"github.com/choria-io/go-choria/plugin"
golangrpc "github.com/choria-io/go-choria/providers/agent/mcorpc/golang"
provisioner "github.com/choria-io/go-choria/providers/agent/mcorpc/golang/provision"
"github.com/choria-io/go-choria/providers/data/golang/choriadata"
"github.com/choria-io/go-choria/scout/data/scoutdata"
"github.com/choria-io/machine-room/internal/autoagents/machinesmanager"
"github.com/sirupsen/logrus"
)
var (
defaultPlugins = map[string]plugin.Pluggable{
"choria_provision": provisioner.ChoriaPlugin(),
"agent_provider_golang": golangrpc.ChoriaPlugin(),
"watcher_archive": archivewatcher.ChoriaPlugin(),
"watcher_exec": execwatcher.ChoriaPlugin(),
"watcher_file": filewatcher.ChoriaPlugin(),
"watcher_kv": kvwatcher.ChoriaPlugin(),
"watcher_metric": metricwatcher.ChoriaPlugin(),
"watcher_nagios": nagioswatcher.ChoriaPlugin(),
"watcher_plugins": pluginswatcher.ChoriaPlugin(),
"watcher_schedule": schedulewatcher.ChoriaPlugin(),
"watcher_timer": timerwatcher.ChoriaPlugin(),
"machine_plugins_manager": machines_manager.ChoriaPlugin(),
"data_choria": choriadata.ChoriaPlugin(),
"data_machine": machinedata.ChoriaPlugin(),
"data_scout": scoutdata.ChoriaPlugin(),
}
mu sync.Mutex
loaded bool
)
func loadPlugins(opts *Options, log *logrus.Entry) error {
mu.Lock()
defer mu.Unlock()
if loaded {
return nil
}
loaded = true
for k, v := range defaultPlugins {
log.Infof("Registering plugin %s %s: %s", v.PluginType().String(), k, v.PluginName())
err := plugin.Register(k, v)
if err != nil {
return fmt.Errorf("plugin %v failed: %v", v.PluginName(), err)
}
}
for k, v := range opts.Plugins {
err := plugin.Register(k, v)
if err != nil {
log.Infof("Registering plugin %s %s: %s", v.PluginType().String(), k, v.PluginName())
return fmt.Errorf("plugin %v failed: %v", k, err)
}
}
return nil
}