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 +4 -4
- data/lib/mn_utils_gem/site_action.rb +32 -17
- data/lib/mn_utils_gem/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bfaddce902d1f38bc5e8abc3708880acd17c21e91143283e7bd45b7ba37a27b
|
4
|
+
data.tar.gz: f340e14f587deb77c76d98f6ccb2420d25d5ebb2ad9459518252fc5814791774
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
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
|
-
|
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: #{
|
153
|
+
Rails.logger.debug("Payload for Cloudwatch: #{cloudwatch_payload}")
|
139
154
|
end
|
140
155
|
rescue Exception => e
|
141
156
|
Rails.logger.error e
|
data/lib/mn_utils_gem/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2019-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gelf
|