mn_utils_gem 1.1.0 → 1.2.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: 12c6e704cbba282538ead6cfb866b2a9c94dd2cfe907de8475a5da6c26b02aa4
4
- data.tar.gz: 559c7e24aaadfb5ef9ef21ad6f4386e0ffa0343719f7d9f979acd7dde3893887
3
+ metadata.gz: 0bfaddce902d1f38bc5e8abc3708880acd17c21e91143283e7bd45b7ba37a27b
4
+ data.tar.gz: f340e14f587deb77c76d98f6ccb2420d25d5ebb2ad9459518252fc5814791774
5
5
  SHA512:
6
- metadata.gz: a5541301eef6d03c5007545ea9caa38fcecac11c18fdb52c460cd26982608a6ed05cd00fc00a5f353a5ad47c9bf5458adaa760f45c522b48f4b8bb72c1ded66f
7
- data.tar.gz: 326e3d390324ccab7fc784044b87a5732815d0c77fd489a0bfa00cdf654dc959a312156a4a4d59ab065e40d3fdcce31b8ca44485ed5a1019e4634cbcc732d87f
6
+ metadata.gz: 5aa796e32d4083d2123c1be55f33c46abeff43e4b5c35688f6e2c48c70f73153b37483512c7129f4c407d767fa61713ae06fdd07222591b5db521d25769b6e98
7
+ data.tar.gz: e3ce4b9f9f276b9df07e0e704ef4287f39d6025cdb554a78690ab7bec8c8b94ef42e74f988acdab0442e891ff2b6b18a725f836b49d073713d0a3790f7b76d0f
@@ -83,6 +83,22 @@ module MnUtils
83
83
  unless value.is_a?(String)
84
84
  end
85
85
 
86
+ # validate required environment variables if we are in production
87
+ if ENV.key?( 'CLOUDWATCH_ROOT_NAMESPACE') \
88
+ || ENV.key?('GRAYLOG_GELF_UDP_HOST') \
89
+ || ENV.key?('GRAYLOG_GELF_UDP_PORT')
90
+ raise ArgumentError, "ENV['CLOUDWATCH_ROOT_NAMESPACE'] is required" \
91
+ unless ENV.key? 'CLOUDWATCH_ROOT_NAMESPACE'
92
+ raise ArgumentError, "ENV['GRAYLOG_GELF_UDP_HOST'] is required" \
93
+ unless ENV.key? 'GRAYLOG_GELF_UDP_HOST'
94
+ raise ArgumentError, "ENV['GRAYLOG_GELF_UDP_PORT'] is required" \
95
+ unless ENV.key? 'GRAYLOG_GELF_UDP_PORT'
96
+ raise ArgumentError, "ENV['SITE_HOSTNAME'] is required" \
97
+ unless ENV.key? 'SITE_HOSTNAME'
98
+ raise ArgumentError, "ENV['SRV_CODE'] is required" \
99
+ unless ENV.key? 'SRV_CODE'
100
+ end
101
+
86
102
  # setup the full payload
87
103
  full_payload = payload.dup
88
104
  full_payload[:short_message] = message
@@ -114,28 +130,27 @@ module MnUtils
114
130
  end
115
131
 
116
132
  def send_to_cloudwatch(payload)
117
- metric_name = payload[:_site_action]
118
- metric_data = [{
119
- metric_name: metric_name,
120
- value: 1,
121
- unit: "Count"
122
- }]
133
+ cloudwatch_payload = {
134
+ namespace: "mn/test",
135
+ metric_data: [{
136
+ metric_name: payload[:_site_action],
137
+ dimensions: [{
138
+ name: "site_hostname",
139
+ value: "localhost"
140
+ }],
141
+ value: 1,
142
+ unit: "Count"
143
+ }]
144
+ }
123
145
  if ENV.key? ('CLOUDWATCH_ROOT_NAMESPACE')
124
146
  root_namespace = ENV['CLOUDWATCH_ROOT_NAMESPACE']
125
147
  second_namespace = payload[:_site_action_group]
126
- namespace = "#{root_namespace}/#{second_namespace}"
127
- dimension_value = payload[:_site_hostname]
148
+ cloudwatch_payload[:namespace] = "#{root_namespace}/#{second_namespace}"
149
+ cloudwatch_payload[:metric_data][0][:dimensions][0][:value] = payload[:_site_hostname]
128
150
  cw = Aws::CloudWatch::Client.new
129
- cw.put_metric_data({
130
- namespace: namespace,
131
- dimensions: [{
132
- name: "site_hostname",
133
- value: dimension_value
134
- }],
135
- metric_data: metric_data
136
- })
151
+ cw.put_metric_data(cloudwatch_payload)
137
152
  else
138
- Rails.logger.debug("Payload for Cloudwatch: #{metric_data}")
153
+ Rails.logger.debug("Payload for Cloudwatch: #{cloudwatch_payload}")
139
154
  end
140
155
  rescue Exception => e
141
156
  Rails.logger.error e
@@ -1,3 +1,3 @@
1
1
  module MnUtilsGem
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mn_utils_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shamim Mirzai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-03 00:00:00.000000000 Z
11
+ date: 2019-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gelf