thias / puppet-nagios

Puppet Nagios module
Other
23 stars 72 forks source link

How do I pass arguments to check_nginx? #96

Open egrist opened 8 years ago

egrist commented 8 years ago

Using v1.0.10 How do I add arguments to check_nginx?

I've tried in yaml: nagios::check::nginx::args: 'argument' and: nagios_check_nginx_args: 'argument'

If I add a block of nagios::check::nginx and using args parameter, it works, though the "default (which contains no arguments)" check is still there.

pelacables commented 7 years ago

Hi, I'm running the version "1.0.7" of this puppet module and hiera 1.3.4. hiera data binding for defines is not supported (I guess it isn't in any hiera version, but I'm not 100% sure).

I came to the same problem when trying to pass arguments to check_http ("-u /something" in my case) and the only way I found to do that was to patch the nagios::check::httpd define call in defaultchecks.pp (so the data binding takes places when calling the define and not later).

diff --git a/modules/nagios/manifests/defaultchecks.pp b/modules/nagios/manifests/defaultchecks.pp
index 8b6e7e1..6cc3cd4 100644
--- a/modules/nagios/manifests/defaultchecks.pp
+++ b/modules/nagios/manifests/defaultchecks.pp
@@ -15,7 +15,9 @@ class nagios::defaultchecks {
   # Conditional checks, enabled based on custom facts
   if $::nagios_check_httpd_disable != 'true' and
      $::nagios_httpd {
-    nagios::check::httpd { $nagios::client::host_name: }
+    nagios::check::httpd { $nagios::client::host_name:
+      args => hiera('nagios_check_httpd_args',''),
+    }
   } else {
     nagios::check::httpd { $nagios::client::host_name: ensure => absent }
   }

So I guess you should do the same for the nginx check (with some extra modification in the check::nginx define itself:

diff --git a/modules/nagios/manifests/defaultchecks.pp b/modules/nagios/manifests/defaultchecks.pp
index 6cc3cd4..1c012f7 100644
--- a/modules/nagios/manifests/defaultchecks.pp
+++ b/modules/nagios/manifests/defaultchecks.pp
@@ -35,7 +35,9 @@ class nagios::defaultchecks {
   }
   if $::nagios_check_nginx_disable != 'true' and
      $::nagios_httpd_nginx {
-    nagios::check::nginx { $nagios::client::host_name: }
+    nagios::check::nginx { $nagios::client::host_name:
+      args => hiera('nagios_check_nginx_args',''),
+    }
   } else {
     nagios::check::nginx { $nagios::client::host_name: ensure => absent }
   }

then change the nginx check define to:

define nagios::check::nginx (
  $ensure = undef,
  $args   = $::nagios_check_nginx_args,
) {

and set nagios_check_nginx_args in your hiera file:

nagios_check_nginx_args: '-u /s'

HTH

egrist commented 7 years ago

Nice, thanks a lot for this, will you make a PR?

pelacables commented 7 years ago

I don't know... I see 9 PR in queue and @thias not very active lately...

egrist commented 7 years ago

Well, you could fork or branch it, and we can use that in the mean time until it maybe gets merged since we are using r10k.

pelacables commented 7 years ago

I've not tested the nginx part so I cannot ensure that it will work. Also, I'm running and old version of the module (1.0.7), so I don't think it's a good idea to create a PR. This is a 4 lines "patch", I prefer to leave the solution here and wait until I move to the latest version of the module where I'll implement the patch for both nginx and http.