mn_utils_gem 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 905603381854f15dd4de3a4b418d071a15aa417b488aeb20e68152cc8690445d
4
- data.tar.gz: 5f39342c223ff9dc0f8724e5b6477be87d3c4f39c783acd1dbfc555a77c5aa62
3
+ metadata.gz: c233647ceb909d90fcddcab30b19819d749d2d82a0ae05c00b91fcb62e6498ae
4
+ data.tar.gz: 4c16da8fb1716345f068659a2043dc24848481ac05a6f09826fe845e4f80a9dc
5
5
  SHA512:
6
- metadata.gz: 8c1f933fc03757072e2f124530b3932bdee92dcf85067856792fc4d3ce7326c74575d240b84149c5b734ab101c7baa8c3678a29e308f4d4834175845009bc3fb
7
- data.tar.gz: 917994740f5ea00914e80131dd9935a3be178248a3c570ffc6c15e142eacf3f1c2e28607e4908cb7d8dad79f7f3a9ff25937c8c97af091148391c0fc17626556
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] = @_site_action_group_map[site_action]
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(payload)
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: payload[:_site_action],
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 = payload[:_site_action_group]
220
+ second_namespace = site_action_group
196
221
  cloudwatch_payload[:namespace] = "#{root_namespace}/#{second_namespace}"
197
- cloudwatch_payload[:metric_data][0][:dimensions][0][:value] = payload[:_site_hostname]
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
@@ -1,3 +1,3 @@
1
1
  module MnUtilsGem
2
- VERSION = "1.6.0"
2
+ VERSION = "1.7.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mn_utils_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shamim Mirzai