-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Improve Zabbix returner #61314
Improve Zabbix returner #61314
Conversation
Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar. |
64791f2
to
fc5112a
Compare
else: | ||
return False | ||
if ZABBIX_SENDER is None or ZABBIX_CONFIG is None: | ||
message = "No zabbix_sender and no zabbix_agent(d|2).conf found." |
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.
Would be clearer as if return elif return else return
.
Consider also glob syntax for the message rather than regex syntax - i.e. {d,2}
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 feedback. I prefer the current approach. Is this a non-mandatory suggestion or a must? :)
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.
Well I got confused reading it.
None of my suggestions are mandatory, but I strongly feel that a simpler control flow is better.
salt/returners/zabbix_return.py
Outdated
|
||
|
||
def zabbix_send(key, output): | ||
if not (ZABBIX_SENDER and ZABBIX_CONFIG): | ||
raise AssertionError() |
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 isn't necessary, and should be an assert
.
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.
It's a cheap check where I usually opt for non-assert, but sure, can make it an assert.
cmd = ( | ||
zbx()["sender"] | ||
ZABBIX_SENDER |
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 may as well be an f-string now.
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.
True, but I wanted to keep the diff as minimal as possible.
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.
IIRC, an f-string wouldn't work here as the command needs to be an iterable of strings rather than a single string.
It is also possible to use the configuration file of Zabbix's Agent 2 for zabbix_sender, hence this file also also be considered as argument for zabbix_sender's --config command line paramter. Fixes saltstack#61313.
fc5112a
to
34ab329
Compare
Hi! I'm your friendly PR bot!You might be wondering what I'm doing commenting here on your PR. Yes, as a matter of fact, I am... I'm just here to help us improve the documentation. I can't respond to Okay... so what do you do? I detect modules that are missing docstrings or "CLI Example" on existing docstrings! So what does that have to do with my PR? I noticed that in this PR there are some files changed that have some of these Okay, what are they? Well, my favorite, is that since you were making changes here I'm hoping that If I can, then what? Well, you can either add them to this PR or add them to another PR. Either way is fine! Well... what if I can't, or don't want to? That's also fine! We appreciate all contributions to the Salt Project. If you Whatever approach you decide to take, just drop a comment here letting us know! Detected Issues (click me)Check Known Missing Docstrings...........................................Failed - hook id: invoke - exit code: 1 Thanks again! |
1 similar comment
Hi! I'm your friendly PR bot!You might be wondering what I'm doing commenting here on your PR. Yes, as a matter of fact, I am... I'm just here to help us improve the documentation. I can't respond to Okay... so what do you do? I detect modules that are missing docstrings or "CLI Example" on existing docstrings! So what does that have to do with my PR? I noticed that in this PR there are some files changed that have some of these Okay, what are they? Well, my favorite, is that since you were making changes here I'm hoping that If I can, then what? Well, you can either add them to this PR or add them to another PR. Either way is fine! Well... what if I can't, or don't want to? That's also fine! We appreciate all contributions to the Salt Project. If you Whatever approach you decide to take, just drop a comment here letting us know! Detected Issues (click me)Check Known Missing Docstrings...........................................Failed - hook id: invoke - exit code: 1 Thanks again! |
This is going to need tests. and pre-commit to be fixed. |
Mentioning @waynew here since he is working on a returners test overhaul at the moment. |
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.
@Flowdalic thanks for the PR - this does need some tests - if you're up for adding them, and
If you need help - attend one of the Test Clinics on Twitch.
If you're not interested or able to add the tests here, we can close the PR and I can incorporate this work when I get to the zabbix returner tests as part of #61757.
If I don't hear back in the next ~week, I'll consider this PR as abandoned and go ahead and close it - if you want to pick it back up, just ping one of the core team on IRC or Slack and we can re-open it though!
|
||
|
||
def zabbix_send(key, output): | ||
assert ZABBIX_SENDER and ZABBIX_CONFIG |
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.
suggestion assertions can be optimized away by Python. If it's essential then this should read:
if not (ZABBIX_SENDER or ZABBIX_CONFIG):
raise SomeSaltError(...)
But that shouldn't be required, because __virtual__
will only return True if both of those are set, and Salt will refuse to load the module (or make available the module anyway, to be precise) if __virtual__
returns False.
cmd = ( | ||
zbx()["sender"] | ||
ZABBIX_SENDER |
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.
IIRC, an f-string wouldn't work here as the command needs to be an iterable of strings rather than a single string.
Going ahead and closing this PR - @Flowdalic if you want to resume work on it, just reach out to a core team member in IRC or Slack (you can also try pinging on here, but GitHub notifications often just get lost in the noise 😓) As mentioned in a previous comment, if you don't get this updated then I should end out getting to it with my work on #61757 👍 Thanks again! |
Cleanup the Zabbix returner code and consider file Zabbix agent 2 configuration file also (see #61313).
Previously Zabbix returner would only consider
zabbix_agentd.conf
(Zabbix agent 1), now it also considerszabbix_agent2.conf
(Zabbix agent 2) configuration files.