Skip to content

Commit 571a1dd

Browse files
committed
Fixes get_api_settings()
1 parent 321bdad commit 571a1dd

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

sensu_plugin/handler.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,29 +110,31 @@ def bail(self, msg):
110110

111111
def get_api_settings(self):
112112
'''
113-
Return a hash of API settings derived first from ENV['sensu_api_url']
113+
Return a dict of API settings derived first from ENV['SENSU_API_URL']
114114
if set, then Sensu config `api` scope if configured, and finally
115115
falling back to to ipv4 localhost address on default API port.
116116
117117
return dict
118118
'''
119119

120-
sensu_api_url = os.environ.get('sensu_api_url')
120+
sensu_api_url = os.environ.get('SENSU_API_URL')
121121
if sensu_api_url:
122122
uri = urlparse(sensu_api_url)
123-
self.api_settings = {
123+
api_settings = {
124124
'host': '{0}//{1}'.format(uri.scheme, uri.hostname),
125125
'port': uri.port,
126126
'user': uri.username,
127127
'password': uri.password
128128
}
129129
else:
130-
self.api_settings = self.settings.get('api', {})
131-
self.api_settings['host'] = self.api_settings.get(
130+
api_settings = self.settings.get('api', {})
131+
api_settings['host'] = api_settings.get(
132132
'host', '127.0.0.1')
133-
self.api_settings['port'] = self.api_settings.get(
133+
api_settings['port'] = api_settings.get(
134134
'port', 4567)
135135

136+
return api_settings
137+
136138
# API requests
137139
def api_request(self, method, path):
138140
'''
@@ -148,7 +150,7 @@ def api_request(self, method, path):
148150

149151
domain = self.api_settings['host']
150152
uri = 'http://{}:{}{}'.format(domain, self.api_settings['port'], path)
151-
if self.api_settings['user'] and self.api_settings['password']:
153+
if self.api_settings.get('user') and self.api_settings.get('password'):
152154
auth = (self.api_settings['user'], self.api_settings['password'])
153155
else:
154156
auth = ()

0 commit comments

Comments
 (0)