mn_utils_gem 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mn_utils_gem/site_action.rb +31 -6
- data/lib/mn_utils_gem/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c233647ceb909d90fcddcab30b19819d749d2d82a0ae05c00b91fcb62e6498ae
|
4
|
+
data.tar.gz: 4c16da8fb1716345f068659a2043dc24848481ac05a6f09826fe845e4f80a9dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 026c351ad8e12472d2fc0651e5c0f8706aca912764983976bb51a41fabce8b891028bb5d9ab4260e969c778f666f603c1ba22beb1d1f083ba2b7a0d5de774421
|
7
|
+
data.tar.gz: dbcfb61093ac5200db3756a3abee4b6853754d2db488f18211c5d55903dcde77b5ce91d473e44ab57fafba91bfebf5b38d76ca584d9b26d4336e9d297b1c1d0c
|
@@ -83,6 +83,10 @@ module MnUtilsLogging
|
|
83
83
|
:admin_email_success,
|
84
84
|
:admin_email_fail,
|
85
85
|
],
|
86
|
+
email: [
|
87
|
+
:send_email_success,
|
88
|
+
:send_email_fail
|
89
|
+
],
|
86
90
|
misc: [
|
87
91
|
:unknown_email_success,
|
88
92
|
:unknown_email_fail
|
@@ -147,10 +151,12 @@ module MnUtilsLogging
|
|
147
151
|
unless ENV.key? 'SRV_CODE'
|
148
152
|
end
|
149
153
|
|
154
|
+
site_action_group = @_site_action_group_map[site_action]
|
155
|
+
|
150
156
|
# setup the full payload
|
151
157
|
full_payload = payload.dup
|
152
158
|
full_payload[:short_message] = message
|
153
|
-
full_payload[:_site_action_group] =
|
159
|
+
full_payload[:_site_action_group] = site_action_group
|
154
160
|
full_payload[:_site_action] = site_action
|
155
161
|
|
156
162
|
# add other data to the payload if available
|
@@ -161,7 +167,26 @@ module MnUtilsLogging
|
|
161
167
|
|
162
168
|
# send it off
|
163
169
|
send_to_graylog full_payload
|
164
|
-
send_to_cloudwatch full_payload
|
170
|
+
send_to_cloudwatch(site_action_group, site_action, full_payload[:_site_hostname])
|
171
|
+
end
|
172
|
+
|
173
|
+
def log_metric_only(site_action)
|
174
|
+
|
175
|
+
# validate the parameters
|
176
|
+
raise ArgumentError, 'site_action must be a symbol' \
|
177
|
+
unless site_action.is_a?(Symbol)
|
178
|
+
raise ArgumentError, 'site_action value is not in allowed list' \
|
179
|
+
unless @_site_action_group_map.key? site_action
|
180
|
+
|
181
|
+
# validate required environment variables if we are in production
|
182
|
+
if ENV.key?( 'CLOUDWATCH_ROOT_NAMESPACE')
|
183
|
+
raise ArgumentError, "ENV['SITE_HOSTNAME'] is required" \
|
184
|
+
unless ENV.key? 'SITE_HOSTNAME'
|
185
|
+
end
|
186
|
+
|
187
|
+
site_action_group = @_site_action_group_map[site_action]
|
188
|
+
|
189
|
+
send_to_cloudwatch(site_action_group, site_action, ENV['SITE_HOSTNAME'])
|
165
190
|
end
|
166
191
|
|
167
192
|
private
|
@@ -177,11 +202,11 @@ module MnUtilsLogging
|
|
177
202
|
Rails.logger.error e
|
178
203
|
end
|
179
204
|
|
180
|
-
def send_to_cloudwatch(
|
205
|
+
def send_to_cloudwatch(site_action_group, site_action, site_hostname)
|
181
206
|
cloudwatch_payload = {
|
182
207
|
namespace: "mn/test",
|
183
208
|
metric_data: [{
|
184
|
-
metric_name:
|
209
|
+
metric_name: site_action,
|
185
210
|
dimensions: [{
|
186
211
|
name: "site_hostname",
|
187
212
|
value: "localhost"
|
@@ -192,9 +217,9 @@ module MnUtilsLogging
|
|
192
217
|
}
|
193
218
|
if ENV.key? ('CLOUDWATCH_ROOT_NAMESPACE')
|
194
219
|
root_namespace = ENV['CLOUDWATCH_ROOT_NAMESPACE']
|
195
|
-
second_namespace =
|
220
|
+
second_namespace = site_action_group
|
196
221
|
cloudwatch_payload[:namespace] = "#{root_namespace}/#{second_namespace}"
|
197
|
-
cloudwatch_payload[:metric_data][0][:dimensions][0][:value] =
|
222
|
+
cloudwatch_payload[:metric_data][0][:dimensions][0][:value] = site_hostname
|
198
223
|
cw = Aws::CloudWatch::Client.new
|
199
224
|
cw.put_metric_data(cloudwatch_payload)
|
200
225
|
else
|
data/lib/mn_utils_gem/version.rb
CHANGED