mpounsett / nagiosplugin

A Python class library which helps with writing Nagios (Icinga) compatible plugins.
https://nagiosplugin.readthedocs.io/
Other
28 stars 14 forks source link

Support for extra-opts #32

Open rpv-tomsk opened 3 years ago

rpv-tomsk commented 3 years ago

It would be nice to provide common/standart solution for plugins to support "Extra-Opts" (https://nagios-plugins.org/doc/extra-opts.html).

That highly required to "hide" passwords for command line arguments. I think this project is a very good place to provide such a solution.

mpounsett commented 3 years ago

I'm not sure that's really in scope of nagiosplugin. It seems to me that your sample code above is very specific to your plugin, and doesn't generalize well to plugins that don't use the same set of options, or use options that you're not using.

If using a nagiosplugin method to import extra-opts requires 90% of the same code that just loading a config file yourself and matching up options does, then I'm not sure I see the point of it. If you have an idea for a more generalized implementation that measurably reduces the amount of code a programmer needs to write in order to add extra-opts to their plugin, then I'm willing to reconsider.

I'm not even going to insist on a PR (although that would be appreciated)... if you can suggest a method signature with a bit of documentation about how you see it working that would help me understand what you're aiming for.

rpv-tomsk commented 3 years ago

It seems to me that your sample code above is very specific to your plugin, and doesn't generalize well to plugins that don't use the same set of options, or use options that you're not using.

Yes, adding the code was a mistake. I understand what my patch (in deleted comment) confused you and sent your thoughts in the wrong direction.
That was a dirty hack to solve my task of hiding the password from the command line. Probably should have added a comment saying that without changing your library, the implementation looks exactly so complicated :-)

Let's review "support for extra-opts" issue again, without looking to my "sample code", and reopen it?

rpv-tomsk commented 3 years ago

I'm not sure that's really in scope of nagiosplugin.

Did you take a look on https://nagios-plugins.org/doc/extra-opts.html ?

My proposal is to add common/standart solution for such/similar task into your library, which already has 'ArgumentParser' part. That part should be smart to properly handle the --extra-opts option and support reading options from a given configuration file. Then any of Python plugins that use your library will be able to handle arguments defined in file without (or with minor) code changes.

I'm not a Python developer, so I can't suggest an implementation [without being ridiculed].

mpounsett commented 2 years ago

Yes, I've read that doc before, and I'm familiar with it. I'm not sure I see a way to implement this in a way that's easily portable between plugins. The only ways to implement it that come to mind are going to require a lot of custom code for each use of it, which to my mind defeats the purpose.

I'll leave the issue open for a bit in case you can suggest a way to implement this that's not going to require each plugin developer to write a ton of code to use.