[output after] { "stats.count.unknown": 2,
"stats.count.unknown_jobs": [
数组类型统一用raw.*名字。
Thanks, Fengguang
"crystal.613986", "crystal.613985" ], "stats.count.success_jobs": [ "crystal.597093", "crystal.597090" ] }
Signed-off-by: Lu Kaiyi 2392863668@qq.com
lib/es_jobs.rb | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/lib/es_jobs.rb b/lib/es_jobs.rb index a90b1ba..c536fe3 100644 --- a/lib/es_jobs.rb +++ b/lib/es_jobs.rb @@ -18,10 +18,10 @@ class ESJobs @refine_jobs = [] @jobs = {} @stats_level = {
0 => 'stats.success',
1 => 'stats.unknown',
2 => 'stats.warning',
3 => 'stats.has_error'
0 => 'success',
1 => 'unknown',
2 => 'warning',
} set_defaults deal_jobs3 => 'has_error'
@@ -123,6 +123,22 @@ class ESJobs return 0 end
- def compact_hash(prefix, result)
- result.each do |key, value|
if prefix.empty?
prefix_key = "#{key}"
else
prefix_key = "#{prefix}.#{key}"
end
if value.is_a? Hash
compact_hash(prefix_key, value)
else
@results[prefix_key] = value
end
- end
- end
- def output result = { 'stats.count' => @stats['stats.count']
@@ -134,6 +150,8 @@ class ESJobs
@result['stats_filter_result'] = @stats_filter_result unless @stats_filter.empty? @result.merge!(result)
- puts JSON.pretty_generate(@result)
- @results = {}
- compact_hash('', @result)
- puts JSON.pretty_generate(@results) end
end
2.23.0