-
Notifications
You must be signed in to change notification settings - Fork 247
/
Copy pathserver_monitor.rb
102 lines (91 loc) · 2.97 KB
/
server_monitor.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#
# Cookbook:: newrelic
# Provider:: server_monitor
#
# Copyright:: (c) 2016, David Joos
#
# include helper methods
include NewRelic::Helpers
include NewRelic::ServerMonitorHelpers
action :install do
check_license
newrelic_repository
case node['platform_family']
when 'debian', 'rhel', 'fedora', 'amazon'
install_newrelic_service_linux
when 'windows'
install_newrelic_service_windows
end
end
action :remove do
case node['platform_family']
when 'debian', 'rhel', 'fedora', 'amazon'
remove_newrelic_service_linux
when 'windows'
remove_newrelic_service_windows
end
end
def install_newrelic_service_linux
package new_resource.service_name do
action new_resource.action
end
# configure your New Relic license key
template "#{new_resource.config_path}/nrsysmond.cfg" do
cookbook new_resource.cookbook
source new_resource.source
owner new_resource.config_file_user
group new_resource.config_file_group
mode '0640'
variables(
resource: new_resource
)
sensitive true
notifies new_resource.service_notify_action, "service[#{new_resource.service_name}]"
end
service new_resource.service_name do
supports status: true, start: true, stop: true, restart: true, enable: true
action new_resource.service_actions
end
update_newrelic_alert_policy_linux(new_resource.alert_policy_id, new_resource.hostname) if new_resource.alert_policy_id
end
def install_newrelic_service_windows
if node['kernel']['machine'] == 'x86_64'
windows_package 'New Relic Server Monitor' do
source "https://download.newrelic.com/windows_server_monitor/release/NewRelicServerMonitor_x64_#{new_resource.windows_version}.msi"
options "/L*v install.log /qn NR_LICENSE_KEY=#{new_resource.license}"
action new_resource.action
version new_resource.windows_version
checksum new_resource.windows64_checksum
end
else
windows_package 'New Relic Server Monitor' do
source "https://download.newrelic.com/windows_server_monitor/release/NewRelicServerMonitor_x86_#{new_resource.windows_version}.msi"
options "/L*v install.log /qn NR_LICENSE_KEY=#{new_resource.license}"
action new_resource.action
version new_resource.windows_version
checksum new_resource.windows32_checksum
end
end
# on Windows service creation/startup is done by the installer
end
def remove_newrelic_service_linux
update_newrelic_alert_policy_linux(new_resource.alert_policy_id, new_resource.hostname) if new_resource.alert_policy_id
package new_resource.service_name do
action new_resource.action
end
end
def remove_newrelic_service_windows
windows_package 'New Relic Server Monitor' do
action new_resource.action
end
end
def update_newrelic_alert_policy_linux(alert_policy_id, hostname = nil)
ruby_block 'Move server to newrelic decommissioned policy' do
block do
update_alert_policy(alert_policy_id, hostname)
end
not_if do
node['newrelic']['api_key'].empty?
end
end
end