[How] ansible_stats_openeuler < ${job_output}
Signed-off-by: Wang Chenglong 18509160991@163.com --- stats/ansible_test | 135 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 124 insertions(+), 11 deletions(-)
diff --git a/stats/ansible_test b/stats/ansible_test index 4c7d07b3e..bd60a3ebc 100755 --- a/stats/ansible_test +++ b/stats/ansible_test @@ -1,15 +1,128 @@ #!/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 parse_msg_1(ansible_failed_json) + case ansible_failed_json.chomp + + # When running some plug-in, the file was not found + when /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_failed_info}" + + # {"changed": false, "cmd": "csf -v", "msg": "[Errno 2] No such file or directory: b'csf': b'csf'", "rc": 2} + when /No such file or directory: b (.+) :/ + puts "error.no-such-file-or-directory.#{$1}: 1" + puts "error.no-such-file-or-directory.#{$1}.message: #{@ansible_failed_info}" + + # The task includes an option with an undefined variable + when /: (.+) is undefined/ + puts "syntax.error.an-undefined-variable.#{$1}: 1" + puts "syntax.error.an-undefined-variable.#{$1}.message: #{@ansible_failed_info}" + + # {"changed": true, "cmd": ["packaging/installer/install-required-packages.sh", "--non-interactive", "netdata"], + # "msg": "non-zero return code", "rc": 1} + when /non-zero return code/ + puts "error.non-zero-return-code.#{ansible_failed_json}: 1" + puts "error.non-zero-return-code.#{ansible_failed_json}.message: #{@ansible_failed_info}" + + # Some service could not find the requested host + when /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_failed_info}" + + # Unable to start some services + when /Unable to start service (.+):/ + puts "service.error.unable-to-start-service.#{$1}: 1" + puts "service.error.unable-to-start-service.#{$1}.message: #{@ansible_failed_info}" + end +end + +def parse_msg_2(ansible_failed_json) + case ansible_failed_json.chomp + + # {"changed": false, "msg": "Failed to download packages: Cannot download 7.10.2/filebeat-7.10.2-aarch64.rpm: + # All mirrors were tried", "results": []} + when /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_failed_info}" + + # {"changed": false, "msg": "Failure downloading https://rpms.remirepo.net/enterprise/remi-release-20.rpm, + # HTTP Error 404: Not Found"} + when /Failure downloading (.+), / + puts "download.error.Failure-downloading.[#{$1}]: 1" + puts "download.error.Failure-downloading.[#{$1}]: #{@ansible_failed_info}" + + # Failed to download the yum repodata + # {"changed": false, "msg": "Failed to download metadata for repo 'docker-ce-stable': Cannot download repomd.xml", + # "rc": 1, "results": []} + when /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_failed_info}" + + # Some role in not sipported this system + # {"changed": false, "msg": "Distribution openEuler is not supported by this role!"} + when /(.+) is not supported/ + puts "system.error.not-supported.#{$1.gsub(/ /, '-')}: 1" + puts "system.error.not-supported.message: #{@ansible_failed_info}" + + # failed to create temporary content file: The read operation timed out. + when /The read operation timed out/ + puts 'connection.error.read-timed-out: 1' + puts "connection.error.read-timed-out.message: #{@ansible_failed_info}" end end + +def parse_failures(ansible_failed_json) + ansible_failed_json.each do |items| + case items.chomp + # Failed to install some of the specified packages. + # {"changed": false, "failures": ["No package erlang available."], "msg": + # "Failed to install some of the specified packages", "rc": 1, "results": []} + when /No package (.+) available/ + puts "yum.error.no-package-available.#{$1}: 1" + puts "yum.error.no-package-available.#{$1}.message: #{@ansible_failed_info}" + end + end +end + +def parse_message(ansible_failed_json) + case ansible_failed_json.chomp + + # Could not find or access ansible yaml + # {"ansible_facts": {}, "ansible_included_var_files": [], "changed": false, "message": + # "Could not find or access 'openEuler.yml' Searched in: + # /root/.ansible/roles/ansible-unzip/vars/openEuler.yml /root/.ansible/roles/ansible-unzip/openEuler.yml i + # /root/.ansible/roles/ansible-unzip/tasks/vars/openEuler.yml /root/.ansible/roles/ansible-unzip/tasks/openEuler.yml + # /root/.ansible/vars/openEuler.yml /root/.ansible/openEuler.yml on the Ansible Controller. + # If you are using a module and expect the file to exist on the remote, see the remote_src option"} + when /Could not find or access (.+) / + puts "yaml.error.not-find-or-access-yaml.#{$1}: 1" + puts "yaml.error.not-find-or-access-yaml.#{$1}.message: #{@ansible_failed_info}" + end +end + +def common_error_id(line) + line = line.chomp + line.gsub(/'/, ' ') + line.gsub(/{%/, ' ') + line.gsub(/%}/, ' ') + line.gsub(/{},/, '[],') + line.gsub(/\n\t/, ' ') + line +end + +while (line = STDIN.gets) + line = common_error_id(line) + next unless line =~ /(FAILED!|failed:).*({.*})/ + + @ansible_failed_info = $2 + next if @ansible_failed_info.empty? + + ansible_failed_json = JSON.load(@ansible_failed_info) + + parse_msg_1 ansible_failed_json['msg'] unless ansible_failed_json['msg'].nil? + parse_msg_2 ansible_failed_json['msg'] unless ansible_failed_json['msg'].nil? + parse_failures ansible_failed_json['failures'] unless ansible_failed_json['failures'].nil? + parse_message ansible_failed_json['message'] unless ansible_failed_json['message'].nil? +end
On Sat, Feb 20, 2021 at 11:29:31AM +0800, Wang Chenglong wrote:
[How] ansible_stats_openeuler < ${job_output}
Signed-off-by: Wang Chenglong 18509160991@163.com
stats/ansible_test | 135 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 124 insertions(+), 11 deletions(-)
diff --git a/stats/ansible_test b/stats/ansible_test index 4c7d07b3e..bd60a3ebc 100755 --- a/stats/ansible_test +++ b/stats/ansible_test @@ -1,15 +1,128 @@ #!/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 parse_msg_1(ansible_failed_json)
- case ansible_failed_json.chomp
- # When running some plug-in, the file was not found
- when /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_failed_info}"
- # {"changed": false, "cmd": "csf -v", "msg": "[Errno 2] No such file or directory: b'csf': b'csf'", "rc": 2}
- when /No such file or directory: b (.+) :/
- puts "error.no-such-file-or-directory.#{$1}: 1"
- puts "error.no-such-file-or-directory.#{$1}.message: #{@ansible_failed_info}"
- # The task includes an option with an undefined variable
- when /: (.+) is undefined/
- puts "syntax.error.an-undefined-variable.#{$1}: 1"
- puts "syntax.error.an-undefined-variable.#{$1}.message: #{@ansible_failed_info}"
- # {"changed": true, "cmd": ["packaging/installer/install-required-packages.sh", "--non-interactive", "netdata"],
- # "msg": "non-zero return code", "rc": 1}
- when /non-zero return code/
- puts "error.non-zero-return-code.#{ansible_failed_json}: 1"
- puts "error.non-zero-return-code.#{ansible_failed_json}.message: #{@ansible_failed_info}"
- # Some service could not find the requested host
- when /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_failed_info}"
- # Unable to start some services
- when /Unable to start service (.+):/
- puts "service.error.unable-to-start-service.#{$1}: 1"
- puts "service.error.unable-to-start-service.#{$1}.message: #{@ansible_failed_info}"
- end
+end
+def parse_msg_2(ansible_failed_json)
- case ansible_failed_json.chomp
- # {"changed": false, "msg": "Failed to download packages: Cannot download 7.10.2/filebeat-7.10.2-aarch64.rpm:
- # All mirrors were tried", "results": []}
- when /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_failed_info}"
- # {"changed": false, "msg": "Failure downloading https://rpms.remirepo.net/enterprise/remi-release-20.rpm,
- # HTTP Error 404: Not Found"}
- when /Failure downloading (.+), /
- puts "download.error.Failure-downloading.[#{$1}]: 1"
- puts "download.error.Failure-downloading.[#{$1}]: #{@ansible_failed_info}"
- # Failed to download the yum repodata
- # {"changed": false, "msg": "Failed to download metadata for repo 'docker-ce-stable': Cannot download repomd.xml",
- # "rc": 1, "results": []}
- when /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_failed_info}"
- # Some role in not sipported this system
==> is not supported in this system or delete this comment, the error message is obvious.
- # {"changed": false, "msg": "Distribution openEuler is not supported by this role!"}
- when /(.+) is not supported/
- puts "system.error.not-supported.#{$1.gsub(/ /, '-')}: 1"
- puts "system.error.not-supported.message: #{@ansible_failed_info}"
- # failed to create temporary content file: The read operation timed out.
- when /The read operation timed out/
- puts 'connection.error.read-timed-out: 1'
- puts "connection.error.read-timed-out.message: #{@ansible_failed_info}" end
end
+def parse_failures(ansible_failed_json)
- ansible_failed_json.each do |items|
- case items.chomp
- # Failed to install some of the specified packages.
- # {"changed": false, "failures": ["No package erlang available."], "msg":
- # "Failed to install some of the specified packages", "rc": 1, "results": []}
- when /No package (.+) available/
puts "yum.error.no-package-available.#{$1}: 1"
puts "yum.error.no-package-available.#{$1}.message: #{@ansible_failed_info}"
- end
- end
+end
+def parse_message(ansible_failed_json)
- case ansible_failed_json.chomp
- # Could not find or access ansible yaml
- # {"ansible_facts": {}, "ansible_included_var_files": [], "changed": false, "message":
- # "Could not find or access 'openEuler.yml' Searched in:
- # /root/.ansible/roles/ansible-unzip/vars/openEuler.yml /root/.ansible/roles/ansible-unzip/openEuler.yml i
- # /root/.ansible/roles/ansible-unzip/tasks/vars/openEuler.yml /root/.ansible/roles/ansible-unzip/tasks/openEuler.yml
- # /root/.ansible/vars/openEuler.yml /root/.ansible/openEuler.yml on the Ansible Controller.
- # If you are using a module and expect the file to exist on the remote, see the remote_src option"}
- when /Could not find or access (.+) /
- puts "yaml.error.not-find-or-access-yaml.#{$1}: 1"
- puts "yaml.error.not-find-or-access-yaml.#{$1}.message: #{@ansible_failed_info}"
- end
+end
+def common_error_id(line)
- line = line.chomp
- line.gsub(/'/, ' ')
- line.gsub(/{%/, ' ')
- line.gsub(/%}/, ' ')
- line.gsub(/{},/, '[],')
- line.gsub(/\n\t/, ' ')
- line
+end
+while (line = STDIN.gets)
- line = common_error_id(line)
- next unless line =~ /(FAILED!|failed:).*({.*})/
- @ansible_failed_info = $2
- next if @ansible_failed_info.empty?
- ansible_failed_json = JSON.load(@ansible_failed_info)
- parse_msg_1 ansible_failed_json['msg'] unless ansible_failed_json['msg'].nil?
- parse_msg_2 ansible_failed_json['msg'] unless ansible_failed_json['msg'].nil?
- parse_failures ansible_failed_json['failures'] unless ansible_failed_json['failures'].nil?
- parse_message ansible_failed_json['message'] unless ansible_failed_json['message'].nil?
+end
2.23.0
On Sat, Feb 20, 2021 at 12:01:27PM +0800, Li Ping wrote:
On Sat, Feb 20, 2021 at 11:29:31AM +0800, Wang Chenglong wrote:
[How] ansible_stats_openeuler < ${job_output}
Signed-off-by: Wang Chenglong 18509160991@163.com
stats/ansible_test | 135 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 124 insertions(+), 11 deletions(-)
diff --git a/stats/ansible_test b/stats/ansible_test index 4c7d07b3e..bd60a3ebc 100755 --- a/stats/ansible_test +++ b/stats/ansible_test @@ -1,15 +1,128 @@ #!/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 parse_msg_1(ansible_failed_json)
- case ansible_failed_json.chomp
- # When running some plug-in, the file was not found
- when /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_failed_info}"
- # {"changed": false, "cmd": "csf -v", "msg": "[Errno 2] No such file or directory: b'csf': b'csf'", "rc": 2}
- when /No such file or directory: b (.+) :/
- puts "error.no-such-file-or-directory.#{$1}: 1"
- puts "error.no-such-file-or-directory.#{$1}.message: #{@ansible_failed_info}"
- # The task includes an option with an undefined variable
- when /: (.+) is undefined/
- puts "syntax.error.an-undefined-variable.#{$1}: 1"
- puts "syntax.error.an-undefined-variable.#{$1}.message: #{@ansible_failed_info}"
- # {"changed": true, "cmd": ["packaging/installer/install-required-packages.sh", "--non-interactive", "netdata"],
- # "msg": "non-zero return code", "rc": 1}
- when /non-zero return code/
- puts "error.non-zero-return-code.#{ansible_failed_json}: 1"
- puts "error.non-zero-return-code.#{ansible_failed_json}.message: #{@ansible_failed_info}"
- # Some service could not find the requested host
- when /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_failed_info}"
- # Unable to start some services
- when /Unable to start service (.+):/
- puts "service.error.unable-to-start-service.#{$1}: 1"
- puts "service.error.unable-to-start-service.#{$1}.message: #{@ansible_failed_info}"
- end
+end
+def parse_msg_2(ansible_failed_json)
- case ansible_failed_json.chomp
- # {"changed": false, "msg": "Failed to download packages: Cannot download 7.10.2/filebeat-7.10.2-aarch64.rpm:
- # All mirrors were tried", "results": []}
- when /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_failed_info}"
- # {"changed": false, "msg": "Failure downloading https://rpms.remirepo.net/enterprise/remi-release-20.rpm,
- # HTTP Error 404: Not Found"}
- when /Failure downloading (.+), /
- puts "download.error.Failure-downloading.[#{$1}]: 1"
- puts "download.error.Failure-downloading.[#{$1}]: #{@ansible_failed_info}"
- # Failed to download the yum repodata
- # {"changed": false, "msg": "Failed to download metadata for repo 'docker-ce-stable': Cannot download repomd.xml",
- # "rc": 1, "results": []}
- when /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_failed_info}"
- # Some role in not sipported this system
==> is not supported in this system or delete this comment, the error message is obvious.
ok
Thanks, Chenglong
- # {"changed": false, "msg": "Distribution openEuler is not supported by this role!"}
- when /(.+) is not supported/
- puts "system.error.not-supported.#{$1.gsub(/ /, '-')}: 1"
- puts "system.error.not-supported.message: #{@ansible_failed_info}"
- # failed to create temporary content file: The read operation timed out.
- when /The read operation timed out/
- puts 'connection.error.read-timed-out: 1'
- puts "connection.error.read-timed-out.message: #{@ansible_failed_info}" end
end
+def parse_failures(ansible_failed_json)
- ansible_failed_json.each do |items|
- case items.chomp
- # Failed to install some of the specified packages.
- # {"changed": false, "failures": ["No package erlang available."], "msg":
- # "Failed to install some of the specified packages", "rc": 1, "results": []}
- when /No package (.+) available/
puts "yum.error.no-package-available.#{$1}: 1"
puts "yum.error.no-package-available.#{$1}.message: #{@ansible_failed_info}"
- end
- end
+end
+def parse_message(ansible_failed_json)
- case ansible_failed_json.chomp
- # Could not find or access ansible yaml
- # {"ansible_facts": {}, "ansible_included_var_files": [], "changed": false, "message":
- # "Could not find or access 'openEuler.yml' Searched in:
- # /root/.ansible/roles/ansible-unzip/vars/openEuler.yml /root/.ansible/roles/ansible-unzip/openEuler.yml i
- # /root/.ansible/roles/ansible-unzip/tasks/vars/openEuler.yml /root/.ansible/roles/ansible-unzip/tasks/openEuler.yml
- # /root/.ansible/vars/openEuler.yml /root/.ansible/openEuler.yml on the Ansible Controller.
- # If you are using a module and expect the file to exist on the remote, see the remote_src option"}
- when /Could not find or access (.+) /
- puts "yaml.error.not-find-or-access-yaml.#{$1}: 1"
- puts "yaml.error.not-find-or-access-yaml.#{$1}.message: #{@ansible_failed_info}"
- end
+end
+def common_error_id(line)
- line = line.chomp
- line.gsub(/'/, ' ')
- line.gsub(/{%/, ' ')
- line.gsub(/%}/, ' ')
- line.gsub(/{},/, '[],')
- line.gsub(/\n\t/, ' ')
- line
+end
+while (line = STDIN.gets)
- line = common_error_id(line)
- next unless line =~ /(FAILED!|failed:).*({.*})/
- @ansible_failed_info = $2
- next if @ansible_failed_info.empty?
- ansible_failed_json = JSON.load(@ansible_failed_info)
- parse_msg_1 ansible_failed_json['msg'] unless ansible_failed_json['msg'].nil?
- parse_msg_2 ansible_failed_json['msg'] unless ansible_failed_json['msg'].nil?
- parse_failures ansible_failed_json['failures'] unless ansible_failed_json['failures'].nil?
- parse_message ansible_failed_json['message'] unless ansible_failed_json['message'].nil?
+end
2.23.0
- # When running some plug-in, the file was not found
- when /No file was found when using (.+)./
- puts "files.error.no-file-was-found-when-using.#{$1}: 1"
=> No-file-was-found-when-using-...
别搞一堆花样出来。 尽量保持原始形式,仅仅替换掉" "等特殊字符。
$1 里的特殊字符需要转义!
- puts "files.error.no-file-was-found-when-using.#{$1}.message: #{@ansible_failed_info}"
ditto for all other error messages.
Thanks, Fengguang
On Sat, Feb 20, 2021 at 11:29:31AM +0800, Wang Chenglong wrote:
[How] ansible_stats_openeuler < ${job_output}
Signed-off-by: Wang Chenglong 18509160991@163.com
stats/ansible_test | 135 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 124 insertions(+), 11 deletions(-)
diff --git a/stats/ansible_test b/stats/ansible_test index 4c7d07b3e..bd60a3ebc 100755 --- a/stats/ansible_test +++ b/stats/ansible_test @@ -1,15 +1,128 @@ #!/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'
xxxx() { id = common_error_id $1 puts id: 1 puts id.message: $1 }
+def parse_msg_1(ansible_failed_json)
- case ansible_failed_json.chomp
- # When running some plug-in, the file was not found
- when /(No file was found when using .+)./
xxxx $1
- puts "files.error.no-file-was-found-when-using.#{$1}: 1"
- puts "files.error.no-file-was-found-when-using.#{$1}.message: #{@ansible_failed_info}"
- # {"changed": false, "cmd": "csf -v", "msg": "[Errno 2] No such file or directory: b'csf': b'csf'", "rc": 2}
- when /No such file or directory: b (.+) :/
- # The task includes an option with an undefined variable
- when /: (.+) is undefined/
xxxx $1
Thanks, Fengguang
- puts line
+require 'json'
+def parse_msg_1(ansible_failed_json)
- case ansible_failed_json.chomp
no need to add .chomp if you don't match line end: $.
- # When running some plug-in, the file was not found
- when /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_failed_info}"
- # {"changed": false, "cmd": "csf -v", "msg": "[Errno 2] No such file or directory: b'csf': b'csf'", "rc": 2}
- when /No such file or directory: b (.+) :/
- puts "error.no-such-file-or-directory.#{$1}: 1"
- puts "error.no-such-file-or-directory.#{$1}.message: #{@ansible_failed_info}"
- # The task includes an option with an undefined variable
- when /: (.+) is undefined/
- puts "syntax.error.an-undefined-variable.#{$1}: 1"
- puts "syntax.error.an-undefined-variable.#{$1}.message: #{@ansible_failed_info}"
- # {"changed": true, "cmd": ["packaging/installer/install-required-packages.sh", "--non-interactive", "netdata"],
- # "msg": "non-zero return code", "rc": 1}
- when /non-zero return code/
- puts "error.non-zero-return-code.#{ansible_failed_json}: 1"
- puts "error.non-zero-return-code.#{ansible_failed_json}.message: #{@ansible_failed_info}"
- # Some service could not find the requested host
- when /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_failed_info}"
- # Unable to start some services
- when /Unable to start service (.+):/
- puts "service.error.unable-to-start-service.#{$1}: 1"
- puts "service.error.unable-to-start-service.#{$1}.message: #{@ansible_failed_info}"
- end
+end
+def parse_msg_2(ansible_failed_json)
- case ansible_failed_json.chomp
it seems that parse_msg_1 and parse_msg_2 is separated from one, it's better puts the same one case test in one method.
Thanks, Luan Shengde
- # {"changed": false, "msg": "Failed to download packages: Cannot download 7.10.2/filebeat-7.10.2-aarch64.rpm:
- # All mirrors were tried", "results": []}
- when /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_failed_info}"
- # {"changed": false, "msg": "Failure downloading https://rpms.remirepo.net/enterprise/remi-release-20.rpm,
- # HTTP Error 404: Not Found"}
- when /Failure downloading (.+), /
- puts "download.error.Failure-downloading.[#{$1}]: 1"
- puts "download.error.Failure-downloading.[#{$1}]: #{@ansible_failed_info}"
- # Failed to download the yum repodata
- # {"changed": false, "msg": "Failed to download metadata for repo 'docker-ce-stable': Cannot download repomd.xml",
- # "rc": 1, "results": []}
- when /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_failed_info}"
- # Some role in not sipported this system
- # {"changed": false, "msg": "Distribution openEuler is not supported by this role!"}
- when /(.+) is not supported/
- puts "system.error.not-supported.#{$1.gsub(/ /, '-')}: 1"
- puts "system.error.not-supported.message: #{@ansible_failed_info}"
- # failed to create temporary content file: The read operation timed out.
- when /The read operation timed out/
- puts 'connection.error.read-timed-out: 1'
- puts "connection.error.read-timed-out.message: #{@ansible_failed_info}" end
end
+def parse_failures(ansible_failed_json)
- ansible_failed_json.each do |items|
- case items.chomp
- # Failed to install some of the specified packages.
- # {"changed": false, "failures": ["No package erlang available."], "msg":
- # "Failed to install some of the specified packages", "rc": 1, "results": []}
- when /No package (.+) available/
puts "yum.error.no-package-available.#{$1}: 1"
puts "yum.error.no-package-available.#{$1}.message: #{@ansible_failed_info}"
- end
- end
+end
+def parse_message(ansible_failed_json)
- case ansible_failed_json.chomp
- # Could not find or access ansible yaml
- # {"ansible_facts": {}, "ansible_included_var_files": [], "changed": false, "message":
- # "Could not find or access 'openEuler.yml' Searched in:
- # /root/.ansible/roles/ansible-unzip/vars/openEuler.yml /root/.ansible/roles/ansible-unzip/openEuler.yml i
- # /root/.ansible/roles/ansible-unzip/tasks/vars/openEuler.yml /root/.ansible/roles/ansible-unzip/tasks/openEuler.yml
- # /root/.ansible/vars/openEuler.yml /root/.ansible/openEuler.yml on the Ansible Controller.
- # If you are using a module and expect the file to exist on the remote, see the remote_src option"}
- when /Could not find or access (.+) /
- puts "yaml.error.not-find-or-access-yaml.#{$1}: 1"
- puts "yaml.error.not-find-or-access-yaml.#{$1}.message: #{@ansible_failed_info}"
- end
+end
+def common_error_id(line)
- line = line.chomp
- line.gsub(/'/, ' ')
- line.gsub(/{%/, ' ')
- line.gsub(/%}/, ' ')
- line.gsub(/{},/, '[],')
- line.gsub(/\n\t/, ' ')
- line
+end
+while (line = STDIN.gets)
- line = common_error_id(line)
- next unless line =~ /(FAILED!|failed:).*({.*})/
- @ansible_failed_info = $2
- next if @ansible_failed_info.empty?
- ansible_failed_json = JSON.load(@ansible_failed_info)
- parse_msg_1 ansible_failed_json['msg'] unless ansible_failed_json['msg'].nil?
- parse_msg_2 ansible_failed_json['msg'] unless ansible_failed_json['msg'].nil?
- parse_failures ansible_failed_json['failures'] unless ansible_failed_json['failures'].nil?
- parse_message ansible_failed_json['message'] unless ansible_failed_json['message'].nil?
+end
2.23.0
On Mon, Feb 22, 2021 at 11:45:08AM +0800, Luan Shengde wrote:
- puts line
+require 'json'
+def parse_msg_1(ansible_failed_json)
- case ansible_failed_json.chomp
no need to add .chomp if you don't match line end: $.
Ok.
- when /Unable to start service (.+):/
- puts "service.error.unable-to-start-service.#{$1}: 1"
- puts "service.error.unable-to-start-service.#{$1}.message: #{@ansible_failed_info}"
- end
+end
+def parse_msg_2(ansible_failed_json)
- case ansible_failed_json.chomp
it seems that parse_msg_1 and parse_msg_2 is separated from one, it's better puts the same one case test in one method.
I know. but if puts them in one method, the rubocop will warning: ansible_test:11:1: C:Metrics/CyclomaticComplexity: Cyclomatic complexity for parse_msg_1 is too high. [12/7] def parse_msg_1(ansible_failed_json) ...
Thanks, Chenglong
Thanks, Luan Shengde