diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-09-30 00:03:24 +0200 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-09-30 00:03:24 +0200 |
commit | 0b6423f9c99d9edf8c96fefd0f6c453859395aa1 (patch) | |
tree | 1c2b6b21704a294940f87c7892676998d8371707 /web/attachments/40409-utils.pm.in.diff | |
download | site-0b6423f9c99d9edf8c96fefd0f6c453859395aa1.tar.gz |
Import Nagios Plugins site
Import the Nagios Plugins web site, Cronjobs, infrastructure scripts,
and configuration files.
Diffstat (limited to 'web/attachments/40409-utils.pm.in.diff')
-rw-r--r-- | web/attachments/40409-utils.pm.in.diff | 86 |
1 files changed, 86 insertions, 0 deletions
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 @@ | |||
1 | *** utils.pm.in.orig Wed Jan 22 15:39:22 2003 | ||
2 | --- utils.pm.in Wed Jan 22 16:39:06 2003 | ||
3 | *************** | ||
4 | *** 19,25 **** | ||
5 | |||
6 | require Exporter; | ||
7 | @ISA = qw(Exporter); | ||
8 | ! @EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage); | ||
9 | |||
10 | #use strict; | ||
11 | #use vars($TIMEOUT %ERRORS); | ||
12 | --- 19,25 ---- | ||
13 | |||
14 | require Exporter; | ||
15 | @ISA = qw(Exporter); | ||
16 | ! @EXPORT_OK = qw($TIMEOUT %ERRORS &print_revision &support &usage &config_value &config_values); | ||
17 | |||
18 | #use strict; | ||
19 | #use vars($TIMEOUT %ERRORS); | ||
20 | *************** | ||
21 | *** 27,34 **** | ||
22 | --- 27,38 ---- | ||
23 | sub usage; | ||
24 | sub support(); | ||
25 | sub is_hostname; | ||
26 | + sub config_value ($); | ||
27 | + sub config_values ($); | ||
28 | |||
29 | ## updated by autoconf | ||
30 | + $prefix = "@prefix@"; | ||
31 | + $sysconfdir = "@sysconfdir@"; | ||
32 | $PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ; | ||
33 | $PATH_TO_NTPDATE = "@PATH_TO_NTPDATE@" ; | ||
34 | $PATH_TO_NTPDC = "@PATH_TO_NTPDC@" ; | ||
35 | *************** | ||
36 | *** 72,75 **** | ||
37 | --- 76,124 ---- | ||
38 | } | ||
39 | } | ||
40 | |||
41 | + ## subroutines to read nagios.cfg and return values of config items. | ||
42 | + $parsedConfig = 0; | ||
43 | + %configItems = {}; | ||
44 | + | ||
45 | + sub read_config { | ||
46 | + my $configFile = "$sysconfdir/nagios.cfg"; | ||
47 | + | ||
48 | + return 1 if $parsedConfig; | ||
49 | + | ||
50 | + if (! open CONFIG, "<$configFile") { | ||
51 | + print "$configFile: $!\n"; | ||
52 | + return 0; | ||
53 | + } | ||
54 | + | ||
55 | + while (<CONFIG>) { | ||
56 | + next unless /^\s*([^=\s]+)=(.*)$/; | ||
57 | + | ||
58 | + if (defined(@{$configItems{$1}})) { | ||
59 | + $configItems{$1} = [@{$configItems{$1}}, $2]; | ||
60 | + } else { | ||
61 | + $configItems{$1} = [$2]; | ||
62 | + } | ||
63 | + } | ||
64 | + close CONFIG; | ||
65 | + | ||
66 | + $parsedConfig = 1; | ||
67 | + return 1; | ||
68 | + } | ||
69 | + | ||
70 | + ## Returns the value/values of a config item. If called in array context, | ||
71 | + ## a list of values is returned, otherwise the first value of the item | ||
72 | + ## is returned. (Most Nagios config items have only one value, but some | ||
73 | + ## such as cfg_file can be specified more than once.) | ||
74 | + ## | ||
75 | + ## ex: @cfg_files = &config_value('cfg_file'); | ||
76 | + ## ex: $resource_file = &config_value('resource_file'); | ||
77 | + sub config_value ($) { | ||
78 | + my $key = shift; | ||
79 | + return undef unless &read_config; | ||
80 | + if (wantarray) { | ||
81 | + return @{$configItems{$key}}; | ||
82 | + } | ||
83 | + return $configItems{$key}->[0]; | ||
84 | + } | ||
85 | + | ||
86 | 1; | ||