Skip to content

Commit cad1530

Browse files
committed
Prevent to exit daemon when OpenStack input plugin Init() is failed #49
1 parent f7ba41a commit cad1530

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

plugins/inputs/openstack/openstack.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ type OpenStack struct {
9393
diag map[string]interface{}
9494
openstackProjects map[string]projects.Project
9595
openstackServices map[string]services.Service
96+
97+
// Locally condition
98+
isGather bool
9699
}
97100

98101
// containsService indicates whether a particular service is enabled
@@ -121,6 +124,18 @@ func (*OpenStack) SampleConfig() string {
121124

122125
// Init : initialize performs any necessary initialization functions
123126
func (o *OpenStack) Init() error {
127+
err := o.initOSP()
128+
if err != nil {
129+
o.Log.Error(err)
130+
o.isGather = false
131+
} else {
132+
o.isGather = true
133+
}
134+
135+
return nil
136+
}
137+
138+
func (o *OpenStack) initOSP() error {
124139
if len(o.EnabledServices) == 0 {
125140
o.EnabledServices = []string{"services", "projects", "hypervisors", "flavors", "networks", "volumes"}
126141
}
@@ -201,6 +216,10 @@ func (o *OpenStack) Init() error {
201216
// Gather gathers resources from the OpenStack API and accumulates metrics. This
202217
// implements the Input interface.
203218
func (o *OpenStack) Gather(acc telegraf.Accumulator) error {
219+
if !o.isGather {
220+
return fmt.Errorf("Unable to gather OpenStack metrics because the initialization of it's plugin is failed")
221+
}
222+
204223
if !o.AllTenants {
205224
page, err := projects.List(o.identity, &projects.ListOpts{}).AllPages()
206225
if err != nil {

0 commit comments

Comments
 (0)