-
Notifications
You must be signed in to change notification settings - Fork 308
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
Wechat alerter #355
Wechat alerter #355
Conversation
Signed-off-by: daiwei <[email protected]>
Signed-off-by: daiwei <[email protected]>
Signed-off-by: daiwei <[email protected]>
Signed-off-by: daiwei <[email protected]>
Signed-off-by: daiwei <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! I've left some minor comments and suggestions.
docs/source/ruletypes.rst
Outdated
|
||
Optional: | ||
|
||
``wechat_to_party`` & ``wechat_to_user`` & ``wechat_to_tag``: There must be one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this to the Required
section and rephrase to:
'One of wechat_to_party
, wechat_to_user
, or wechat_to_tag
'
docs/source/ruletypes.rst
Outdated
|
||
``wechat_to_party`` & ``wechat_to_user`` & ``wechat_to_tag``: There must be one. | ||
|
||
``wechat_msgtype``: Wechat msgtype, default to ``text``. ``textcard``, ``markdown``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: 'default to' should be 'defaults to' here and on the next four items.
``wechat_msgtype``: Wechat msgtype, default to ``text``. ``textcard``, ``markdown``. | |
``wechat_msgtype``: Wechat msgtype, defaults to ``text``. ``textcard``, ``markdown``. |
|
||
``wechat_msgtype``: Wechat msgtype, default to ``text``. ``textcard``, ``markdown``. | ||
|
||
``wechat_textcard_url``: Wechat textcard url while ``wechat_msgtype`` is ``textcard``, default to ``null_url``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``wechat_textcard_url``: Wechat textcard url while ``wechat_msgtype`` is ``textcard``, default to ``null_url``. | |
``wechat_textcard_url``: Wechat textcard url while ``wechat_msgtype`` is ``textcard``, defaults to ``null_url``. |
docs/source/ruletypes.rst
Outdated
|
||
``wechat_textcard_url``: Wechat textcard url while ``wechat_msgtype`` is ``textcard``, default to ``null_url``. | ||
|
||
``wechat_enable_duplicate_check``: ``enable_duplicate_check``, default to ``0``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``wechat_enable_duplicate_check``: ``enable_duplicate_check``, default to ``0``. | |
``wechat_enable_duplicate_check``: ``enable_duplicate_check``, defaults to ``0``. |
docs/source/ruletypes.rst
Outdated
|
||
``wechat_enable_duplicate_check``: ``enable_duplicate_check``, default to ``0``. | ||
|
||
``wechat_duplicate_check_interval``: ``duplicate_check_interval``, default to ``1800``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``wechat_duplicate_check_interval``: ``duplicate_check_interval``, default to ``1800``. | |
``wechat_duplicate_check_interval``: ``duplicate_check_interval``, defaults to ``1800``. |
tests/alerters/wechat_test.py
Outdated
def test_wechat_required_error(wechat_corp_id, wechat_secret, wechat_agent_id, expected_data): | ||
try: | ||
rule = { | ||
'name': 'Test DingTalk Rule', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'name': 'Test DingTalk Rule', | |
'name': 'Test Wechat Rule', |
tests/alerters/wechat_test.py
Outdated
'name': 'Test DingTalk Rule', | ||
'type': 'any', | ||
'alert': [], | ||
'alert_subject': 'Test DingTalk' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'alert_subject': 'Test DingTalk' | |
'alert_subject': 'Test Wechat' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your advice.
Signed-off-by: daiwei <[email protected]>
Signed-off-by: daiwei233 <[email protected]>
Although it is a setting of schema.yaml, Wechat should be described between Twilio and Zabbix. ### Wechat
wechat_corp_id: {type: string}
wechat_secret: {type: string}
wechat_agent_id: {type: integer} |
Signed-off-by: daiwei <[email protected]>
ok. |
Bring the latest information on jertel: master into your repository before adding change logs. |
Signed-off-by: daiwei <[email protected]>
Done. |
|
||
``wechat_secret``: The wechat agent secret. | ||
|
||
``wechat_to_party`` & ``wechat_to_user`` & ``wechat_to_tag``: One of wechat_to_party, wechat_to_user, or wechat_to_tag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should change the &
to |
to avoid confusion since not all are required.
self.wechat_message_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={}' | ||
self.expires_in = datetime.datetime.now() - datetime.timedelta(seconds=3600) | ||
|
||
def get_token(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function could use some unit test coverage.
self.wechat_access_token = token_json['access_token'] | ||
self.expires_in = datetime.datetime.now() + datetime.timedelta(seconds=token_json['expires_in']) | ||
|
||
def format_body(self, body): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use a simple unit test.
@@ -551,6 +551,11 @@ properties: | |||
twilio_message_service_sid: {type: string} | |||
twilio_use_copilot: {type: boolean} | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be more schema definitions listed here since this alerter has a large number of input parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the new alerter! This is looking good. I added some code review feedback, primarily around the need for more unit test coverage, and also a couple minor updates. The team has been working hard to get to 100% test coverage so I'm hesitant to merge anything that moves us backwards on the test coverage.
It is recommended to define all in schema.yaml. When the rule is executed, jsonschema will perform validation check with the settings described in schema.yaml and generate an error. example ### Wechat
wechat_corp_id: {type: string}
wechat_secret: {type: string}
wechat_agent_id: {type: integer}
wechat_msgtype: {type: string, enum: ['text', 'textcard', 'markdown']}
wechat_to_party: {type: string}
wechat_to_user: {type: string}
wechat_to_tag: {type: string}
wechat_textcard_url: {type: string}
wechat_enable_duplicate_check: {type: integer}
wechat_duplicate_check_interval: {type: integer}
wechat_proxy: {type: string}
wechat_proxy_login: {type: string}
wechat_proxy_pass: {type: string} |
There is an error in flake8. Did you really run
|
The overall coverage is 67% because the pull request was made without merging the latest repository state,
Is it possible to add unimplemented test code? |
|
Do you need the following functions on lines 58 and 59? .. It doesn't seem to be used. wechat.py
|
example 84% 41, 47-48, 53, 59, 63, 72, 95->101, 105-106 wechat_test.py
|
Thank you guys, I will make it better! (That is my first pull request.😅) |
What is the string null_url in wechat_textcard_url? .. It's essential, so I thought it would be rough if I forced it.
|
When msg_type is text and markdown, I think the following implementation is fine, but when msg_type is textcard, there seems to be a limit of 128 for title and 512 for description. Is this overlooked?
|
Although it is described in the document of wechat_proxy, I thought that it is better to add |
It is described in the document of wechat_enable_duplicate_check, but are the values that can be set 0 and 1? .. If so, should I mention setting 1 to enable it? Wechat_duplicate_check_interval is described as within 4 hours (14400 in seconds?) According to the document, so it would be better to describe the maximum setting value in seconds. ..
|
Wechat_enable_duplicate_check and wechat_duplicate_check_interval have default values when they are not specified in the api specifications, so it should be implemented to be included in the request only when specified. current
Fix
|
What happened after that? .. Did you give up? |
Closing PR due to lack of interest by OP. |
Description
Wechat alerter support, see: #280
Checklist
make test-docker
with my changes.