Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow modifications to reported hostnames #160

Closed
handigarde opened this issue Jan 19, 2016 · 5 comments
Closed

Allow modifications to reported hostnames #160

handigarde opened this issue Jan 19, 2016 · 5 comments

Comments

@handigarde
Copy link

Related to #1

Hosts may show up as duplicates in infrastructure list, with puppet metrics only intermittently reporting. Some cases have included a workaround specific to each case, but these workarounds need to be included each time the puppet module is updated

@olivielpeau olivielpeau changed the title Allow modifications to hostname through module Allow modifications to reported hostnames Jan 19, 2016
@olivielpeau
Copy link
Member

We have a patch that allows applying a regex to the hostnames reported by puppet: https://gist.github.com/LeoCavaille/264d0f7cf27b0d7e2bb3.

It's a good approach for simple cases, but we should investigate if it could be improved on or if we could use another approach.

@ee99ee
Copy link

ee99ee commented Jan 21, 2016

👍

@aruetten
Copy link

We had a similar issue and used in the end the following patch:

@@ -13,6 +13,12 @@ Puppet::Reports.register_report(:datadog_reports) do
   raise(Puppet::ParseError, "Datadog report config file #{configfile} not readable") unless File.exist?(configfile)
   config = YAML.load_file(configfile)
   API_KEY = config[:datadog_api_key]
+  HOSTNAME_EXTRACTION_REGEX = config[:hostname_extraction_regex]
+  unless HOSTNAME_EXTRACTION_REGEX.empty?
+      HOSTNAME_EXTRACTION_REGEX = Regexp.new HOSTNAME_EXTRACTION_REGEX
+  else
+      HOSTNAME_EXTRACTION_REGEX = nil
+  end

   desc <<-DESC
   Send notification of metrics to Datadog
@@ -38,6 +44,12 @@ Puppet::Reports.register_report(:datadog_reports) do
   def process
     @summary = self.summary
     @msg_host = self.host
+    unless HOSTNAME_EXTRACTION_REGEX.nil?
+        m = @msg_host.match(HOSTNAME_EXTRACTION_REGEX)
+        unless m[1].nil?
+            @msg_host = m[1]
+        end
+    end

     event_title = ''
     alert_type = ''

and the following regexp '^(.*?)\.'

@diranged
Copy link

This is a great patch -- I'd love to see it pushed to the project so we can use it without forking the project ourselves.

@LeoCavaille
Copy link
Member

@diranged I can try to rebase that to apply it to the current master. Will open a PR.

LeoCavaille added a commit to LeoCavaille/puppet-datadog-agent that referenced this issue Mar 30, 2016
Fixes DataDog#160.

This option is a string regex which can be enabled and used to extract
the hostname from puppet hostname strings with a capture group.
It is useful for people that have specific puppet hostnames and that
would like to sanitize them before reporting those in Datadog.
LeoCavaille added a commit to LeoCavaille/puppet-datadog-agent that referenced this issue Apr 11, 2016
Fixes DataDog#160.

This option is a string regex which can be enabled and used to extract
the hostname from puppet hostname strings with a capture group.
It is useful for people that have specific puppet hostnames and that
would like to sanitize them before reporting those in Datadog.
truthbk pushed a commit that referenced this issue Apr 12, 2016
Fixes #160.

This option is a string regex which can be enabled and used to extract
the hostname from puppet hostname strings with a capture group.
It is useful for people that have specific puppet hostnames and that
would like to sanitize them before reporting those in Datadog.
cegeka-jenkins pushed a commit to cegeka/puppet-datadog_agent that referenced this issue Jan 31, 2018
Fixes DataDog#160.

This option is a string regex which can be enabled and used to extract
the hostname from puppet hostname strings with a capture group.
It is useful for people that have specific puppet hostnames and that
would like to sanitize them before reporting those in Datadog.
cegeka-jenkins pushed a commit to cegeka/puppet-datadog_agent that referenced this issue Jan 31, 2018
Fixes DataDog#160.

This option is a string regex which can be enabled and used to extract
the hostname from puppet hostname strings with a capture group.
It is useful for people that have specific puppet hostnames and that
would like to sanitize them before reporting those in Datadog.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants