Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit f4d5b6c

Browse files
author
Gavin M. Roy
committed
Handle HTTP requests the same way
1 parent 1ec2605 commit f4d5b6c

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

Diff for: newrelic_plugin_agent/plugins/apache_httpd.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ def add_datapoints(self, stats):
7676

7777
@property
7878
def apache_stats_url(self):
79+
if 'scheme' not in self.config:
80+
self.config['scheme'] = 'http'
7981
return '%(scheme)s://%(host)s:%(port)s%(path)s?auto' % self.config
8082

8183
def fetch_data(self):
@@ -84,10 +86,13 @@ def fetch_data(self):
8486
:rtype: str
8587
8688
"""
89+
kwargs = {'url': self.apache_stats_url,
90+
'verify': self.config.get('verify_ssl_cert', True)}
91+
if 'username' in self.config and 'password' in self.config:
92+
kwargs['auth'] = (self.config['username'], self.config['password'])
93+
8794
try:
88-
response = requests.get(self.apache_stats_url,
89-
verify=self.config.get('verify_ssl_cert',
90-
True))
95+
response = requests.get(**kwargs)
9196
except requests.ConnectionError as error:
9297
LOGGER.error('Error polling ApacheHTTPD: %s', error)
9398
return {}
@@ -105,8 +110,6 @@ def fetch_data(self):
105110
def poll(self):
106111
LOGGER.info('Polling ApacheHTTPD via %s', self.apache_stats_url)
107112
start_time = time.time()
108-
if 'scheme' not in self.config:
109-
self.config['scheme'] = 'http'
110113
self.derive = dict()
111114
self.gauge = dict()
112115
self.rate = dict()

Diff for: newrelic_plugin_agent/plugins/nginx.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,23 @@ def add_datapoints(self, stats):
5959

6060
@property
6161
def nginx_stats_url(self):
62-
return 'http://%(host)s:%(port)s/%(path)s' % self.config
62+
if 'scheme' not in self.config:
63+
self.config['scheme'] = 'http'
64+
return '%{scheme}://%(host)s:%(port)s/%(path)s' % self.config
6365

6466
def fetch_data(self):
6567
"""Fetch the data from the Nginx server for the specified data type
6668
6769
:rtype: str
6870
6971
"""
72+
kwargs = {'url': self.nginx_stats_url,
73+
'verify': self.config.get('verify_ssl_cert', True)}
74+
if 'username' in self.config and 'password' in self.config:
75+
kwargs['auth'] = (self.config['username'], self.config['password'])
76+
7077
try:
71-
response = requests.get(self.nginx_stats_url,
72-
verify=self.config.get('verify_ssl_cert',
73-
True))
78+
response = requests.get(**kwargs)
7479
except requests.ConnectionError as error:
7580
LOGGER.error('Error polling Nginx: %s', error)
7681
return {}

Diff for: newrelic_plugin_agent/plugins/rabbitmq.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,9 @@ def rabbitmq_base_url(self):
417417
:rtype: str
418418
419419
"""
420-
port = self.config.get('port',self.DEFAULT_PORT)
421-
secure = self.config.get('secure',False)
422-
host = self.config.get('host',self.DEFAULT_HOST)
420+
port = self.config.get('port', self.DEFAULT_PORT)
421+
secure = self.config.get('secure', False)
422+
host = self.config.get('host', self.DEFAULT_HOST)
423423
if secure:
424424
return 'https://' + host + ':' + str(port) + '/api'
425425
else:

Diff for: newrelic_plugin_agent/plugins/riak.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,23 @@ def add_datapoints(self, stats):
174174

175175
@property
176176
def riak_stats_url(self):
177-
return 'http://%(host)s:%(port)s/stats' % self.config
177+
if 'scheme' not in self.config:
178+
self.config['scheme'] = 'http'
179+
return '%{scheme}://%(host)s:%(port)s/stats' % self.config
178180

179181
def fetch_data(self):
180182
"""Fetch the data from the Riak server for the specified data type
181183
182184
:rtype: dict
183185
184186
"""
187+
kwargs = {'url': self.riak_stats_url,
188+
'verify': self.config.get('verify_ssl_cert', True)}
189+
if 'username' in self.config and 'password' in self.config:
190+
kwargs['auth'] = (self.config['username'], self.config['password'])
191+
185192
try:
186-
response = requests.get(self.riak_stats_url,
187-
verify=self.config.get('verify_ssl_cert',
188-
True))
193+
response = requests.get(**kwargs)
189194
except requests.ConnectionError as error:
190195
LOGGER.error('Error polling Riak: %s', error)
191196
return {}

0 commit comments

Comments
 (0)