From 0b6423f9c99d9edf8c96fefd0f6c453859395aa1 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Mon, 30 Sep 2013 00:03:24 +0200 Subject: Import Nagios Plugins site Import the Nagios Plugins web site, Cronjobs, infrastructure scripts, and configuration files. --- web/attachments/40409-utils.pm.in.diff | 86 ++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 web/attachments/40409-utils.pm.in.diff (limited to 'web/attachments/40409-utils.pm.in.diff') diff --git a/web/attachments/40409-utils.pm.in.diff b/web/attachments/40409-utils.pm.in.diff new file mode 100644 index 0000000..cb2ea12 --- /dev/null +++ b/web/attachments/40409-utils.pm.in.diff @@ -0,0 +1,86 @@ +*** utils.pm.in.orig Wed Jan 22 15:39:22 2003 +--- utils.pm.in Wed Jan 22 16:39:06 2003 +*************** +*** 19,25 **** + + require Exporter; + @ISA = qw(Exporter); +! @EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage); + + #use strict; + #use vars($TIMEOUT %ERRORS); +--- 19,25 ---- + + require Exporter; + @ISA = qw(Exporter); +! @EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage &config_value &config_values); + + #use strict; + #use vars($TIMEOUT %ERRORS); +*************** +*** 27,34 **** +--- 27,38 ---- + sub usage; + sub support(); + sub is_hostname; ++ sub config_value ($); ++ sub config_values ($); + + ## updated by autoconf ++ $prefix = "@prefix@"; ++ $sysconfdir = "@sysconfdir@"; + $PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ; + $PATH_TO_NTPDATE = "@PATH_TO_NTPDATE@" ; + $PATH_TO_NTPDC = "@PATH_TO_NTPDC@" ; +*************** +*** 72,75 **** +--- 76,124 ---- + } + } + ++ ## subroutines to read nagios.cfg and return values of config items. ++ $parsedConfig = 0; ++ %configItems = {}; ++ ++ sub read_config { ++ my $configFile = "$sysconfdir/nagios.cfg"; ++ ++ return 1 if $parsedConfig; ++ ++ if (! open CONFIG, "<$configFile") { ++ print "$configFile: $!\n"; ++ return 0; ++ } ++ ++ while () { ++ next unless /^\s*([^=\s]+)=(.*)$/; ++ ++ if (defined(@{$configItems{$1}})) { ++ $configItems{$1} = [@{$configItems{$1}}, $2]; ++ } else { ++ $configItems{$1} = [$2]; ++ } ++ } ++ close CONFIG; ++ ++ $parsedConfig = 1; ++ return 1; ++ } ++ ++ ## Returns the value/values of a config item. If called in array context, ++ ## a list of values is returned, otherwise the first value of the item ++ ## is returned. (Most Nagios config items have only one value, but some ++ ## such as cfg_file can be specified more than once.) ++ ## ++ ## ex: @cfg_files = &config_value('cfg_file'); ++ ## ex: $resource_file = &config_value('resource_file'); ++ sub config_value ($) { ++ my $key = shift; ++ return undef unless &read_config; ++ if (wantarray) { ++ return @{$configItems{$key}}; ++ } ++ return $configItems{$key}->[0]; ++ } ++ + 1; -- cgit v1.2.3-74-g34f1