Skip to content

Commit

Permalink
Add support for custom endpoints
Browse files Browse the repository at this point in the history
Added new configuration properties:
* ec2_endpoint_url
* monitoring_endpoint_url
that allow to override URLs used for
communicating with AWS API.
  • Loading branch information
sopel39 committed Dec 5, 2018
1 parent de8765f commit a63dfbd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ The default location of the configuration file used by collectd-cloudwatch plugi
* __credentials_path__ - Used to point to AWS account configuration file
* __region__ - Manual override for [region](http://docs.aws.amazon.com/general/latest/gr/rande.html#cw_region) used to publish metrics
* __host__ - Manual override for EC2 Instance ID and Host information propagated by collectd
* __ec2_endpoint_url__ - Manual override for EC2 endpoint
* __monitoring_endpoint_url__ - Manual override for Monitoring endpoint
* __proxy_server_name__ - Manual override for proxy server name, used by plugin to connect aws cloudwatch at *.amazonaws.com.
* __proxy_server_port__ - Manual override for proxy server port, used by plugin to connect aws cloudwatch at *.amazonaws.com.
* __enable_high_resolution_metrics__ - The storage resolution is for high resolution support
Expand Down
12 changes: 10 additions & 2 deletions src/cloudwatch/modules/configuration/confighelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ def _load_hostname(self):
" Using host information provided by Collectd.")

def _set_ec2_endpoint(self):
""" Creates endpoint from region information """
""" Creates endpoint from region information (if the endpoint not explicitly set via ec2_endpoint_url) """
if self.config_reader.ec2_endpoint_url:
self.ec2_endpoint = self.config_reader.ec2_endpoint_url
return

if self.region is "localhost":
self.ec2_endpoint = "http://" + self.region + "/"
elif self.region.startswith("cn-"):
Expand Down Expand Up @@ -179,7 +183,11 @@ def _load_flush_interval_in_seconds(self):
self._LOGGER.warning("flush_interval_in_seconds in configuration is invalid: " + str(self.config_reader.flush_interval_in_seconds) + " use the default value: " + self.flush_interval_in_seconds)

def _set_endpoint(self):
""" Creates endpoint from region information """
""" Creates endpoint from region information (if the endpoint not explicitly set via monitoring_endpoint_url) """
if self.config_reader.monitoring_endpoint_url:
self.endpoint = self.config_reader.monitoring_endpoint_url
return

if self.region is "localhost":
self.endpoint = "http://" + self.region + "/"
elif self.region.startswith("cn-"):
Expand Down
4 changes: 4 additions & 0 deletions src/cloudwatch/modules/configuration/configreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class ConfigReader(object):
PROXY_SERVER_PORT_KEY = "proxy_server_port"
ENABLE_HIGH_DEFINITION_METRICS = "enable_high_resolution_metrics"
FLUSH_INTERVAL_IN_SECONDS = "flush_interval_in_seconds"
EC2_ENDPOINT_URL = "ec2_endpoint_url"
MONITORING_ENDPOINT_URL = "monitoring_endpoint_url"

def __init__(self, config_path):
self.config_path = config_path
Expand Down Expand Up @@ -78,3 +80,5 @@ def _parse_config_file(self):
self.push_asg = self.reader_utils.try_get_boolean(self.PUSH_ASG_KEY, self._PUSH_ASG_DEFAULT_VALUE)
self.push_constant = self.reader_utils.try_get_boolean(self.PUSH_CONSTANT_KEY, self._PUSH_CONSTANT_DEFAULT_VALUE)
self.constant_dimension_value = self.reader_utils.get_string(self.CONSTANT_DIMENSION_KEY)
self.ec2_endpoint_url = self.reader_utils.get_string(self.EC2_ENDPOINT_URL)
self.monitoring_endpoint_url = self.reader_utils.get_string(self.MONITORING_ENDPOINT_URL)

0 comments on commit a63dfbd

Please sign in to comment.