[How] ansible_stats_openeuler < ${job_output}
Signed-off-by: Wang Chenglong 18509160991@163.com --- stats/ansible_test | 100 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 90 insertions(+), 10 deletions(-)
diff --git a/stats/ansible_test b/stats/ansible_test index 4c7d07b3e..f31771e5c 100755 --- a/stats/ansible_test +++ b/stats/ansible_test @@ -1,15 +1,95 @@ #!/usr/bin/env ruby
+require 'json' + 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 + line = line.gsub(/'/, ' ') + ansible_stats_error = `echo '#{line}' |grep -E 'FAILED! |failed: .*}$' | awk -F'=>' '{$1="";print $0}'` + next if ansible_stats_error.empty? + + a = JSON.load(ansible_stats_error) + unless a['msg'].nil? + + # When running some plug-in, the file was not found + if a['msg'].match(/No file was found when using (.+)./) + puts "files.error.no-file-was-found-when-using.#{$1}: 1" + puts "files.error.no-file-was-found-when-using.#{$1}.message: #{ansible_stats_error}" + end + + # No such command + if a['msg'].match(/No such file or directory: b (.+) :/) + puts "command.error.no-such-file-or-directory.#{$1}: 1" + puts "command.error.no-such-file-or-directory.#{a['cmd']}.message: #{ansible_stats_error}" + end + + # The URL of the RPM is invalid + if a['msg'].match(/Failure downloading (.+), /) + puts "download.error.http-error-404 [#{$1}]: 1" + puts "download.error.http-error-404 [#{$1}]: #{ansible_stats_error}" + end + + # Failed to download the yum repodata + if a['msg'].match(/Failed to download metadata for repo (.+) :/) + puts "download.error.failed-to-download-metadata.#{$1}: 1" + puts "download.error.failed-to-download-metadata.#{$1}.message: #{ansible_stats_error}" + end + + if a['msg'].match(/Failed to download packages: Cannot download (.+):/) + puts "download.error.failed-to-download-package.#{$1}: 1" + puts "download.error.failed-to-download-package.#{$1}.message: #{ansible_stats_error}" + end + + # The task includes an option with an undefined variable. + if a['msg'].match(/: (.+) is undefined/) + puts "syntax.error.an-undefined-variable.#{$1}: 1" + puts "syntax.error.an-undefined-variable.#{$1}.message: #{ansible_stats_error}" + end + + # The command runing error. + if a['msg'].match(/non-zero return code/) + puts "command.error[#{a['cmd']}]: 1" + puts "command.error [#{a['cmd']}].message: #{ansible_stats_error}" + end + + # Some service could not fand the requested host. + if a['msg'].match(/Could not find the requested service (.+): host/) + puts "request.error.could-not-find-service-host.#{$1}: 1" + puts "request.error.could-not-find-service-host.#{$1}.messgae: #{ansible_stats_error}" + end + + # Unable to start some services + if a['msg'].match(/Unable to start service (.+):/) + puts "service.error.unable-to-star-service.#{$1}: 1" + puts "service.error.unable-to-star-service.#{$1}.message: #{ansible_stats_error}" + end + + # Some role in not sipported this system + if a['msg'].match(/(.+) is not supported/) + puts "system.error.not-supported.#{$1.gsub(/ /, '-')}: 1" + puts "system.error.not-supported.message: #{ansible_stats_error}" + end + + # failed to create temporary content file: The read operation timed out. + if a['msg'].match(/The read operation timed out/) + puts 'connection.error.read-timed-out: 1' + puts "connection.error.read-timed-out.message: #{ansible_stats_error}" + end + end + + unless a['failures'].nil? + a['failures'].each do |items| + # Failed to install some of the specified packages. + items.match(/No package (.+) available/) + puts "yum.error.no-package-match.#{$1}: 1" + puts "yum.error.no-package-match.#{$1}.message: #{line}" + end + end + + next if a['message'].nil? + + # Could not find or access ansible yaml. + if a['message'].to_s.match(/Could not find or access (.+) /) + puts "yaml.error.not-find-yml.#{$1}: 1" + puts "yaml.error.not-find-yml.#{$1}.message: #{ansible_stats_error}" end end
On Thu, Feb 18, 2021 at 09:07:40AM +0800, Wang Chenglong wrote:
[How] ansible_stats_openeuler < ${job_output}
Signed-off-by: Wang Chenglong 18509160991@163.com
stats/ansible_test | 100 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 90 insertions(+), 10 deletions(-)
diff --git a/stats/ansible_test b/stats/ansible_test index 4c7d07b3e..f31771e5c 100755 --- a/stats/ansible_test +++ b/stats/ansible_test
- ansible_stats_error = `echo '#{line}' |grep -E 'FAILED! |failed: .*}$' | awk -F'=>' '{$1="";print $0}'`
^ ^ add blank add blank
- # The task includes an option with an undefined variable.
no need to add full stop
- # The command runing error.
ditto
- # Some service could not fand the requested host.
ditto
fand -> find
puts "service.error.unable-to-star-service.#{$1}: 1"
star -> start
puts "service.error.unable-to-star-service.#{$1}.message: #{ansible_stats_error}"
ditto
Thanks, Yong
On Thu, Feb 18, 2021 at 09:24:40AM +0800, Wang Yong wrote:
On Thu, Feb 18, 2021 at 09:07:40AM +0800, Wang Chenglong wrote:
[How] ansible_stats_openeuler < ${job_output}
Signed-off-by: Wang Chenglong 18509160991@163.com
stats/ansible_test | 100 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 90 insertions(+), 10 deletions(-)
diff --git a/stats/ansible_test b/stats/ansible_test index 4c7d07b3e..f31771e5c 100755 --- a/stats/ansible_test +++ b/stats/ansible_test
- ansible_stats_error = `echo '#{line}' |grep -E 'FAILED! |failed: .*}$' | awk -F'=>' '{$1="";print $0}'`
^ ^ add blank add blank
Ok.
The second blank is necessary.
- # The task includes an option with an undefined variable.
no need to add full stop
Ok.
- # The command runing error.
ditto
ok
- # Some service could not fand the requested host.
ditto
ok
fand -> find
ok
puts "service.error.unable-to-star-service.#{$1}: 1"
star -> start
ok
puts "service.error.unable-to-star-service.#{$1}.message: #{ansible_stats_error}"
ditto
Thanks, Yong
On Thu, Feb 18, 2021 at 09:07:40AM +0800, Wang Chenglong wrote:
[How] ansible_stats_openeuler < ${job_output}
Signed-off-by: Wang Chenglong 18509160991@163.com
stats/ansible_test | 100 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 90 insertions(+), 10 deletions(-)
diff --git a/stats/ansible_test b/stats/ansible_test index 4c7d07b3e..f31771e5c 100755 --- a/stats/ansible_test +++ b/stats/ansible_test @@ -1,15 +1,95 @@ #!/usr/bin/env ruby
+require 'json'
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
- line = line.gsub(/'/, ' ')
- ansible_stats_error = `echo '#{line}' |grep -E 'FAILED! |failed: .*}$' | awk -F'=>' '{$1="";print $0}'`
- next if ansible_stats_error.empty?
- a = JSON.load(ansible_stats_error)
- unless a['msg'].nil?
保持原来的 case line .. when ... 代码会更好。 line从msg里来。
Thanks, Fengguang
On Thu, Feb 18, 2021 at 10:37:11AM +0800, Wu Fengguang wrote:
On Thu, Feb 18, 2021 at 09:07:40AM +0800, Wang Chenglong wrote:
[How] ansible_stats_openeuler < ${job_output}
Signed-off-by: Wang Chenglong 18509160991@163.com
stats/ansible_test | 100 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 90 insertions(+), 10 deletions(-)
diff --git a/stats/ansible_test b/stats/ansible_test index 4c7d07b3e..f31771e5c 100755 --- a/stats/ansible_test +++ b/stats/ansible_test @@ -1,15 +1,95 @@ #!/usr/bin/env ruby
+require 'json'
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
- line = line.gsub(/'/, ' ')
- ansible_stats_error = `echo '#{line}' |grep -E 'FAILED! |failed: .*}$' | awk -F'=>' '{$1="";print $0}'`
- next if ansible_stats_error.empty?
- a = JSON.load(ansible_stats_error)
- unless a['msg'].nil?
保持原来的 case line .. when ... 代码会更好。 line从msg里来。
ok
Thanks, Fengguang