Icinga / icingaweb2-module-director

The Director aims to be your new favourite Icinga config deployment tool. Director is designed for those who want to automate their configuration deployment and those who want to grant their “point & click” users easy access to the configuration.
https://icinga.com/docs/director/latest
GNU General Public License v2.0
413 stars 201 forks source link

Property to indicate if Icinga2 Agent is installed #1435

Open offsides opened 6 years ago

offsides commented 6 years ago

I'd like to be able to set apply rules based on whether the Icinga2 Agent is installed on the host, and it doesn't appear that there's any way to do that at this time. Can setting the Icinga2 Agent setting to Yes automatically set host.vars.has_agent which could then be used for apply rules?

offsides commented 6 years ago

I've come up with partial code to make this happen, though it's not a complete fix. It requires adding a custom datafield ('has_agent', type Boolean) and then assigning it as an optional field to your host template, but it does work otherwise. It's probably not the best place to put it (it hijacks the autosubmit nature of the 'Icinga2 Agent' field in the 'Icinga Agent and zone settings' section), but it's what my limited understanding of the Director code came up with. I'm happy to generate a pull request, but I'll wait for some feedback before doing so in case there's either a better way of doing it or a suggestion for getting around the manual datafield setup (though that might not be a bad thing in case the var isn't wanted).

diff -urN icingaweb2-module-director-1.4.3/application/forms/IcingaHostForm.php.orig icingaweb2-module-director-1.4.3/application/forms/IcingaHostForm.php
--- icingaweb2-module-director-1.4.3/application/forms/IcingaHostForm.php.orig 2018-01-23 04:18:26.000000000 -0500
+++ icingaweb2-module-director-1.4.3/application/forms/IcingaHostForm.php      2018-03-20 09:44:32.800371446 -0400
@@ -92,6 +92,8 @@

             $this->addHidden('command_endpoint_id', null);
             $this->setSentValue('command_endpoint_id', null);
+            $this->addHidden('var_has_agent', 'y');
+            $this->setSentValue('var_has_agent', 'y');
         } else {
             if ($this->isTemplate()) {
                 $this->addElement('select', 'command_endpoint_id', [
@@ -106,7 +108,7 @@
                 ]);
             }

-            foreach (['master_should_connect', 'accept_config'] as $key) {
+            foreach (['master_should_connect', 'accept_config', 'var_has_agent'] as $key) {
                 $this->addHidden($key, null);
                 $this->setSentValue($key, null);
             }
Thomas-Gelf commented 6 years ago

While we're trying not to do too much hidden magic I like this idea... We would apply it in other places, probably at rendering time. For your scenario I'd suggest to not set "Use Agent" on single hosts but on a Template. Especially to benefit from goodies like the Self-Service-API and the PowerShell module for Windows this is something one should always do.

And then you can set such custom value on your template - and are all done. Or you wouldn't even need the variable, add your Services to that template - and they'll be rolled out as Apply Rules in a magic way.

offsides commented 6 years ago

IIRC, the issue is this (it's been a while and that project has been unfortunately sidelined for a while). I currently have a full infrastructure using NRPE on the Linux side and WMI on the Windows side. When Icinga2 gets rolled out, there's going to have to be a transition from one paradigm to the other. On top of that, I don't know yet what we're going to be using for client-side monitoring agents, but in any event I need to be able to indicate what servers are monitored by the agent vs. other methods. Thus I need a modifer on top of other groupings to indicate the method of monitoring, as opposed to what is being monitored. This has_agent flag would do that nicely. Yes, it's best applied via template rather than on individual hosts, but I don't want to have separate hostgroups for (e.g.) "Monitor disk space via Agent" vs. "Monitor disk space via other method". A single hostgroup for "Monitor disk space" with apply rules of which underlying service definition get applied. Ideally a host running the agent would be able to simply self-report, but I believe that becomes a bit of a chicken and egg problem when defining how to monitor the host in the first place...

Tqnsls commented 9 months ago

I think there is still no update on how to solve @offsides' problem. We would also appreciate such possibility to add servicesets based on the question if the agent is installed / configured. For when we migrate vom NRPE to icinga-agent because I would like to not have to modify the hosts itself (except installing and configuring agent). I figured out there is another var like host.command_endpoint but it is not usable for this i guess.

Any other idea to apply servicesets based on "is the agent installed?" like OP's initial topic @Thomas-Gelf ?