Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to decode Unicode Escape of multibyte strings #226

Conversation

sky-joker
Copy link
Contributor

SUMMARY

This PR is to fix to decode Unicode Escape of multibyte strings in an importing template content.
If using Python2, this module hasn't decoded Unicode Escape until now.
Exporting template data with this module (or zabbix_template_info) and a copy module creates a file with multibyte strings encoded as a byte string (Unicode Escape).
So, a garbled text occurs(byte strings) on Zabbix after to import using that.
This issue only occurs in Python2.

fixes: #225

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

plugins/modules/zabbix_template.py

ADDITIONAL INFORMATION

@codecov
Copy link

codecov bot commented Sep 16, 2020

Codecov Report

Merging #226 (8f4b4eb) into main (21284a5) will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #226      +/-   ##
==========================================
+ Coverage   77.17%   77.18%   +0.01%     
==========================================
  Files          19       19              
  Lines        2681     2683       +2     
  Branches      687      687              
==========================================
+ Hits         2069     2071       +2     
  Misses        409      409              
  Partials      203      203              
Impacted Files Coverage Δ
...ommunity/zabbix/plugins/modules/zabbix_template.py 76.74% <0.00%> (+0.18%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cf05ec8...8f4b4eb. Read the comment docs.

@sky-joker sky-joker force-pushed the fix_zabbix_template_unicode_escape_decode_patch branch from 952aeef to 38538e1 Compare September 17, 2020 14:21
@D3DeFi D3DeFi added bug Something isn't working module The issue or pull request is related to Zabbix module labels Oct 22, 2020
Copy link
Contributor

@D3DeFi D3DeFi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, this looks good. However, I would still like a confirmation from related bug issue that it solves the problem.

@D3DeFi
Copy link
Contributor

D3DeFi commented Jan 4, 2021

@sky-joker can you rebase please? Do you think we can merge without confirmation from the related issue? Would like to get this into 1.2.0 also

@sky-joker sky-joker force-pushed the fix_zabbix_template_unicode_escape_decode_patch branch from 38538e1 to baddbab Compare January 4, 2021 12:07
@sky-joker
Copy link
Contributor Author

@D3DeFi

rebase done :)

@D3DeFi
Copy link
Contributor

D3DeFi commented Jan 5, 2021

After testing this myself with English/Non-English words and Python2.7/3.8 both with and without this patch I confirm it is working as inteded. Good job @sky-joker ! Very nice and clean patch

@sky-joker
Copy link
Contributor Author

Thank you @D3DeFi !

@sky-joker sky-joker deleted the fix_zabbix_template_unicode_escape_decode_patch branch January 5, 2021 14:40
@elrondvega
Copy link
Contributor

This is breaking one of my templates. I have a json template with
"key": "logrt[\"/file.log\",\"r.*t=([0-9.]+)\",,,skip,\\1]"

removing the
template_content = codecs.decode(template_content, 'unicode-escape')
line fixes it.

@elrondvega
Copy link
Contributor

Here is an example template that I'm trying to import that fails.

{
    "zabbix_export": {
        "version": "5.2",
        "date": "2021-01-13T17:38:21Z",
        "templates": [
            {
                "template": "test",
                "name": "test",
                "description": "test",
                "groups": [
                    {
                        "name": "test"
                    }
                ],
                "items": [
                    {
                        "name": "test",
                        "type": "ZABBIX_ACTIVE",
                        "key": "logrt[\"/test.*test.log\",\"test.*total=([0-9.]+)\",,,skip,\\1]"
                    }
                ]
            }
        ]
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module The issue or pull request is related to Zabbix module
Projects
None yet
3 participants