Created
May 11, 2017 22:26
-
-
Save mapledyne/e1e7de66ab4da37654dfd5d3a0f3473c to your computer and use it in GitHub Desktop.
datadog attribute chef file excerpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def iis_sites | |
require 'win32ole' | |
web_admin = WIN32OLE.connect('winmgmts:root\\WebAdministration') | |
site = web_admin.InstancesOf('Site') | |
site | |
rescue WIN32OLERuntimeError | |
[] | |
end | |
def service_exists(service) | |
require 'win32/service' | |
# interesting services: Iisadmin, Msftpsvc (FTP), Smtpsvc (SMTP), | |
# W3svc (WWW publishing / IIS) | |
::Win32::Service.exists?(service) | |
end | |
if node['platform'] == 'windows' | |
site_list = [] | |
iis_sites.each do |s| | |
site_list.push(s.Name) | |
end | |
if site_list.count > 0 | |
default['datadog']['iis']['instances'] = [{ 'host' => 'localhost', | |
'sites' => site_list }] | |
end | |
service_list = [] | |
process_list = [] | |
if service_exists('ServiceToWatch') | |
service_list.push('ServiceToWatch') | |
process_list.push('ServiceToWatch.SvcHost.exe') # the actual process name | |
end | |
if service_list.count > 0 | |
default['datadog']['windows_service']['instances'] = [{ 'host' => '.', | |
'services' => service_list}] | |
default['datadog']['process']['instances'] = [] | |
process_list.each do |p| | |
default['datadog']['process']['instances'].push('name' => p, | |
'search_string' => [p]) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment