[collectd] exec-nagios and pseudo-hashes

Tom Throckmorton throck at gmail.com
Wed Feb 25 14:19:06 CET 2009


On Feb 24 12:24, Florian Forster wrote:
> Hi Tom,
> 
> `exec-nagios.px' uses the `Config::General' Perl module to parse the
> configuration. Since that module has no knowlege of the structure of the
> config file, the returned structure depends on the configuration. That
> sucks, but is common with script languages :/
> 
> On Mon, Feb 23, 2009 at 04:50:03PM -0500, Tom Throckmorton wrote:
> > In this case, the script returns an error:
> > 
> > | Pseudo-hashes are deprecated at ./exec-nagios.px line 126.
> > | No such pseudo-hash field "script" at ./exec-nagios.px line 126.
> 
> Could you please add the following lines _before_ line 126 to get some
> more useful output?
> 
>   require Data::Dumper;
>   print Data::Dumper->Dump ([$opts, $script], ['opts', 'script']);
> 
> > Before I get too deep, can anyone recommend a good way to
> > address/correct this?
> 
> My guess is that, when two identical blocks are found, they are returned
> as an array-reference rather than a hash-reference. If I'm right, the
> solution would be something like this:
> 
>   if (ref ($opts) eq 'ARRAY')
>   {
>     for (@$opts)
>     {
>       my $opt = $_;
>       do_something ($opt);
>     }
>   }
>   else
>   {
>     do_something ($opts);
>   }

Thanks Florian!

As you suspected, adding something similar in that subroutine worked - patch
attached.

FWIW, I'm using this script because it provides a few interesting features:

- the ability to use arbitrary nagios plugins, which I'd be using anyway.
- the ability to call this plugin with a different interval than the global setting
- and of course, it was already written and available ;)

The second feature is actually _very_ important - I have a few
network-intensive plugins that I want to call at a much longer interval, and as
I understand it, there is no way to do this natively - am I correct?

Thanks for all your help and effort!

-tt

-------------- next part --------------
diff -pur collectd/contrib/exec-nagios.px collectd.tt/contrib/exec-nagios.px
--- collectd/contrib/exec-nagios.px	2009-02-24 13:41:52.000000000 -0500
+++ collectd.tt/contrib/exec-nagios.px	2009-02-25 08:09:40.000000000 -0500
@@ -123,8 +123,20 @@ sub handle_config_script
     }
     else
     {
-      $opts->{'script'} = $script;
-      push (@$Scripts, $opts);
+      if (ref ($opts) eq 'ARRAY')
+        {
+          for (@$opts)
+            {
+              my $opt = $_;
+              $opt->{'script'} = $script;
+              push (@$Scripts, $opt);
+            }
+        }
+          else
+        {
+          $opts->{'script'} = $script;
+          push (@$Scripts, $opts);
+        }
     }
   } # for (keys %$scripts)
 } # handle_config_script


More information about the collectd mailing list