The result of ansible_test are counted and recorded in the ES. query it with the 'es-jobs' command.
sum.stats.ansible_test.error.Unsupported-pkg-mgr-This-role-is-depends-on-apt-yum-or-pkgng: 1 raw.stats.ansible_test.error.Unsupported-pkg-mgr-This-role-is-depends-on-apt-yum-or-pkgng.message: ["{"changed": false, "msg": "Unsupported pkg mgr. This role is depends on apt, yum, or pkgng."}"]
Signed-off-by: Wang Chenglong 18509160991@163.com --- stats/ansible_test | 55 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 11 deletions(-)
diff --git a/stats/ansible_test b/stats/ansible_test index 4c7d07b3e..38d6e278c 100755 --- a/stats/ansible_test +++ b/stats/ansible_test @@ -1,15 +1,48 @@ #!/usr/bin/env ruby
-while (line = STDIN.gets) - case line.chomp! - when /ok=(\d+)\s+changed=(\d+)\s+unreachable=(\d+)\s+failed=(\d+)\s+skipped=(\d+)\s+rescued=(\d+)\s+ignored=(\d+)/ - puts "ansible_test.total.nr_ok: #{$1}" - puts "ansible_test.total.nr_changed: #{$2}" - puts "ansible_test.total.nr_failed: #{$4}" - puts "ansible_test.total.nr_skipped: #{$5}" - puts "ansible_test.total.nr_rescued: #{$6}" - puts "ansible_test.total.nr_ignored: #{$7}" - when /playbook_run_on_fail/ - puts line +require 'json' + +def output_error(error_msg) + return if error_msg.nil? + + if error_msg.is_a? Array + error_msg.each do |i| + error_id = common_error_id i + puts "error.#{error_id}: 1" + puts "error.#{error_id}.message: #{@ansible_failed_info}" + end + else + error_id = common_error_id error_msg + puts "error.#{error_id}: 1" + puts "error.#{error_id}.message: #{@ansible_failed_info}" end end + +def common_error_id(line) + line.gsub!(/\n|\t/, '.') + line =`echo "#{line}"|awk -F'.' '{print $1}'` + line.gsub!(/:/, '') # error.:-'__mysql_packages'-is-undefined: 1 + line.gsub!(/^/, '') + line.gsub!(/.|,/, '') + line.gsub!(/<|>/, '') # error.Request-failed-<urlopen-error-timed-out>: 1 + line.gsub!(/'/, '') # Failed-to-download-metadata-for-repo-'dockerrepo: 1 + line.gsub!(/!/, '') # Distribution-openEuler-is-not-supported-by-this-role!: 1 + line.gsub!(/ /, '-') + line.gsub!(/-+/, '-') # Replace multiple consecutive '-' with a single one + line = line.chomp + line +end + +while (line = STDIN.gets) + next unless line =~ /(FAILED!|failed:).*=>(.*)/ + + @ansible_failed_info = $2 + next if @ansible_failed_info.empty? + + ansible_failed_json = JSON.parse @ansible_failed_info + + output_error ansible_failed_json['msg'] + output_error ansible_failed_json['message'] + output_error ansible_failed_json['cmd'] + output_error ansible_failed_json['failures'] +end
end end
+def common_error_id(line)
- line.gsub!(/\n|\t/, '.')
- line =`echo "#{line}"|awk -F'.' '{print $1}'`
- line.gsub!(/:/, '') # error.:-'__mysql_packages'-is-undefined: 1
- line.gsub!(/^/, '')
- line.gsub!(/.|,/, '')
- line.gsub!(/<|>/, '') # error.Request-failed-<urlopen-error-timed-out>: 1
- line.gsub!(/'/, '') # Failed-to-download-metadata-for-repo-'dockerrepo: 1
- line.gsub!(/!/, '') # Distribution-openEuler-is-not-supported-by-this-role!: 1
- line.gsub!(/ /, '-')
- line.gsub!(/-+/, '-') # Replace multiple consecutive '-' with a single one
what do you want to keep with so many gsub lines? case you want to keep word characters, you can use: line.gsub!(/[^\w]/, '') if you want to keep some other characters, you can add it in [], example: line.gsub!(/[^\w]"./, '')
Thanks, Luan Shengde
- line = line.chomp
- line
+end
+while (line = STDIN.gets)
- next unless line =~ /(FAILED!|failed:).*=>(.*)/
- @ansible_failed_info = $2
- next if @ansible_failed_info.empty?
- ansible_failed_json = JSON.parse @ansible_failed_info
- output_error ansible_failed_json['msg']
- output_error ansible_failed_json['message']
- output_error ansible_failed_json['cmd']
- output_error ansible_failed_json['failures']
+end
2.23.0
On Mon, Mar 15, 2021 at 09:52:28AM +0800, Luan Shengde wrote:
end end
+def common_error_id(line)
- line.gsub!(/\n|\t/, '.')
- line =`echo "#{line}"|awk -F'.' '{print $1}'`
- line.gsub!(/:/, '') # error.:-'__mysql_packages'-is-undefined: 1
- line.gsub!(/^/, '')
- line.gsub!(/.|,/, '')
- line.gsub!(/<|>/, '') # error.Request-failed-<urlopen-error-timed-out>: 1
- line.gsub!(/'/, '') # Failed-to-download-metadata-for-repo-'dockerrepo: 1
- line.gsub!(/!/, '') # Distribution-openEuler-is-not-supported-by-this-role!: 1
- line.gsub!(/ /, '-')
- line.gsub!(/-+/, '-') # Replace multiple consecutive '-' with a single one
what do you want to keep with so many gsub lines? case you want to keep word characters, you can use: line.gsub!(/[^\w]/, '')
Yea, This is a good idea.
if you want to keep some other characters, you can add it in [], example: line.gsub!(/[^\w]"./, '')
ok.
Thanks, Chenglong
Thanks, Luan Shengde
- line = line.chomp
- line
+end
+while (line = STDIN.gets)
- next unless line =~ /(FAILED!|failed:).*=>(.*)/
- @ansible_failed_info = $2
- next if @ansible_failed_info.empty?
- ansible_failed_json = JSON.parse @ansible_failed_info
- output_error ansible_failed_json['msg']
- output_error ansible_failed_json['message']
- output_error ansible_failed_json['cmd']
- output_error ansible_failed_json['failures']
+end
2.23.0