~ubuntu-branches/ubuntu/gutsy/munin/gutsy

« back to all changes in this revision

Viewing changes to server/Munin.pm.in

  • Committer: Bazaar Package Importer
  • Author(s): Tore Anderson
  • Date: 2004-05-21 20:51:19 UTC
  • Revision ID: james.westby@ubuntu.com-20040521205119-oz8bllbjp9hs80ig
Tags: upstream-0+1.0.0pre5
ImportĀ upstreamĀ versionĀ 0+1.0.0pre5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package Munin;
 
2
#!@@PERL@@
 
3
#
 
4
# $Id: Munin.pm.in,v 1.3 2004/01/29 18:19:58 jimmyo Exp $
 
5
#
 
6
# $Log: Munin.pm.in,v $
 
7
# Revision 1.3  2004/01/29 18:19:58  jimmyo
 
8
# Made Munin compatible with perl 5.005_03 (patch by Lupe Christoph) (SF#884622)
 
9
#
 
10
# Revision 1.2  2004/01/15 15:20:01  jimmyo
 
11
# Making things workable after name change. Upping for test verwion.
 
12
#
 
13
# Revision 1.1  2004/01/02 18:50:01  jimmyo
 
14
# Renamed occurrances of lrrd -> munin
 
15
#
 
16
# Revision 1.1.1.1  2004/01/02 15:18:07  jimmyo
 
17
# Import of LRRD CVS tree after renaming to Munin
 
18
#
 
19
# Revision 1.29  2003/12/12 18:59:30  jimmyo
 
20
# Change \1 to  to make lrrd-update shut up.
 
21
#
 
22
# Revision 1.28  2003/12/10 11:59:39  jimmyo
 
23
# Enable/disable notifications at any level
 
24
#
 
25
# Revision 1.27  2003/12/06 20:19:55  jimmyo
 
26
# Typo fix
 
27
#
 
28
# Revision 1.26  2003/12/06 19:12:57  jimmyo
 
29
# Added max_processes config variable. Also, removed zombie-generation code. :-P
 
30
#
 
31
# Revision 1.25  2003/12/06 17:13:56  jimmyo
 
32
# Can now escape #. Can now use \ to join lines.
 
33
#
 
34
# Revision 1.24  2003/12/02 11:48:56  jimmyo
 
35
# Forgot small change
 
36
#
 
37
# Revision 1.23  2003/12/02 10:14:43  jimmyo
 
38
# Moved some functions to LRRD.pm, since other programs use them as well.
 
39
#
 
40
# Revision 1.22  2003/11/24 16:25:51  jimmyo
 
41
# Make sure LRRD doesn't write any illegal lines to the datafile
 
42
#
 
43
# Revision 1.21  2003/11/24 14:22:10  jimmyo
 
44
# 0.9.9 release 2. Fixes a couple of stupid (minor) bugs
 
45
#
 
46
# Revision 1.20  2003/11/24 12:58:01  jimmyo
 
47
# minor bugfix - no noise about "extinfo"
 
48
#
 
49
# Revision 1.19  2003/11/16 11:33:16  jimmyo
 
50
# Minor bugfixes
 
51
#
 
52
# Revision 1.18  2003/11/15 13:26:01  jimmyo
 
53
# Added warn to legal options
 
54
#
 
55
# Revision 1.17  2003/11/15 11:10:29  jimmyo
 
56
# Various fixes
 
57
#
 
58
# Revision 1.16  2003/11/10 16:09:00  jimmyo
 
59
# Be nice to Nagios - don't DOS it.
 
60
#
 
61
# Revision 1.15  2003/11/07 23:57:05  jimmyo
 
62
# Remove trailing whitespace from config file
 
63
#
 
64
# Revision 1.14  2003/11/07 22:58:09  jimmyo
 
65
# Documentation of new features/changes
 
66
#
 
67
# Revision 1.13  2003/11/07 20:46:12  jimmyo
 
68
# Only require Config::General if using old config format.
 
69
#
 
70
# Revision 1.12  2003/11/07 20:12:02  jimmyo
 
71
# datafile now saved in new config format
 
72
#
 
73
# Revision 1.11  2003/11/07 17:43:16  jimmyo
 
74
# Cleanups and log entries
 
75
#
 
76
#
 
77
 
 
78
 
 
79
use Exporter;
 
80
@ISA = ('Exporter');
 
81
@EXPORT = ('munin_trend', 
 
82
           'munin_fetch', 
 
83
           'munin_nscasend', 
 
84
           'munin_createlock',
 
85
           'munin_removelock',
 
86
           'munin_runlock',
 
87
           'munin_getlock',
 
88
           'munin_readconfig',
 
89
           'munin_writeconfig',
 
90
           'munin_delete',
 
91
           'munin_overwrite',
 
92
           'munin_config',
 
93
           'munin_get_bool',
 
94
           'munin_get_bool_val',
 
95
           'munin_get_val',
 
96
           'munin_get_filename');
 
97
 
 
98
use strict;
 
99
use RRDs;
 
100
use Fcntl qw(:DEFAULT :flock);
 
101
use IO::Handle;
 
102
use Symbol 'gensym';
 
103
 
 
104
my $nsca = new IO::Handle;
 
105
my $config = undef;
 
106
 
 
107
my $DEBUG=0;
 
108
my $configfile="@@CONFDIR@@/munin.conf";
 
109
 
 
110
my @legal = ("tmpldir", "ncsa", "ncsa_server", "ncsa_config", "rundir",
 
111
        "dbdir", "logdir", "htmldir", "include", "domain_order", "node_order", 
 
112
        "graph_order", "fork", "graph_title", "create_args", "graph_args",
 
113
        "graph_vlabel", "graph_vtitle", "graph_total", "graph_scale", "graph",
 
114
        "update", "host_name", "label", "cdef", "draw", "graph", "max", "min",
 
115
        "negative", "skipdraw", "type", "warning", "critical", "special_stack",
 
116
        "special_sum", "stack", "sum", "address", "htaccess", "warn",
 
117
        "use_default_name", "use_node_name", "port", "graph_noscale",
 
118
        "nsca", "nsca_server", "nsca_config", "extinfo", "fetch_data",
 
119
        "filename", "max_processes", "nagios"
 
120
    );
 
121
 
 
122
 
 
123
sub munin_trend {
 
124
    my (@array) = @_;
 
125
    return ($array[$#array] - $array[0]);
 
126
}
 
127
 
 
128
sub munin_fetch {
 
129
    my ($file,$last,$type) = @_;
 
130
    my ($start,$step,$names,$data) = RRDs::fetch $file,$type || "AVERAGE";
 
131
    my @array = map { @$_[0] } splice(@$data, $#$data - ($last || 1));
 
132
    return $array[0] if (!$last);
 
133
    return @array;
 
134
}
 
135
 
 
136
sub munin_nscasend {
 
137
    my ($name,$service,$label,$level,$comment) = @_;
 
138
 
 
139
    if (!$nsca->opened)
 
140
    {
 
141
        open ($nsca ,"|$config->{nsca} $config->{nsca_server} -c $config->{nsca_config} -to 60");
 
142
    }
 
143
    if ($label)
 
144
    {
 
145
        print $nsca  "$name\t$service: $label\t$level\t$comment\n";
 
146
        print ("$name;$service: $label;$level;$comment\n") if $DEBUG;
 
147
    }
 
148
    else
 
149
    {
 
150
        print $nsca  "$name\t$service\t$level\t$comment\n";
 
151
        print ("$name;$service;$level;$comment\n") if $DEBUG;
 
152
    }
 
153
}
 
154
 
 
155
sub munin_createlock {
 
156
  my ($lockname) = @_;
 
157
  if (-e $lockname && (! -w $lockname || ! -f $lockname)) {
 
158
      die "Error writing to $lockname, wrong permissions";
 
159
  }
 
160
  if (sysopen (LOCK,$lockname,O_WRONLY | O_CREAT | O_EXCL)) {
 
161
    print "Creating lock : $lockname succeded\n" if $DEBUG;
 
162
    print LOCK $$; # we want the pid inside for later use
 
163
    close LOCK;
 
164
    return 1;
 
165
  } else {
 
166
    print "Creating lock : $lockname failed, skipping\n" if $DEBUG;
 
167
    return 0;
 
168
  }
 
169
}
 
170
 
 
171
sub munin_removelock {
 
172
  my ($lockname) = @_;
 
173
  if (-e $lockname && ! -w $lockname) {
 
174
      die "Error deleting $lockname, wrong permissions";
 
175
  }
 
176
  if (-e $lockname) {
 
177
    unlink $lockname;
 
178
    print "Deleting lock : $lockname\n" if $DEBUG;
 
179
  } else {
 
180
    print "Deleting lock : $lockname not found, skipping\n" if $DEBUG;
 
181
  }
 
182
}
 
183
 
 
184
sub munin_runlock {
 
185
    my ($lockname) = @_;
 
186
    unless (&munin_getlock($lockname)) {
 
187
        print "Lock already exists: $lockname. Dying.\n";
 
188
        exit 0;
 
189
    }
 
190
    return 1;
 
191
}
 
192
 
 
193
sub munin_getlock {
 
194
  my ($lockname) = @_;
 
195
    unless (&munin_createlock($lockname)) {
 
196
      # Is the lockpid alive?
 
197
      open LOCK,$lockname;
 
198
      my $pid = <LOCK>;
 
199
      if ($pid =~ /^\d+$/ and kill(0,$pid)) {
 
200
          return 0;
 
201
      }
 
202
      &munin_removelock ($lockname);
 
203
      &munin_createlock($lockname);
 
204
    }
 
205
    return 1;
 
206
}
 
207
 
 
208
 
 
209
sub munin_delete {
 
210
    my ($config,$data) = @_;
 
211
    for my $domain (keys %{$data->{domain}}) {
 
212
        unless ($config->{domain}->{$domain}) {
 
213
            ::logger("Removing domain: $domain");
 
214
            delete ($data->{domain}->{$domain});
 
215
            next;
 
216
        }
 
217
        for my $node (keys %{$data->{domain}->{$domain}->{node}}) {
 
218
            unless ($config->{domain}->{$domain}->{node}->{$node}) {
 
219
                ::logger("Removing node from $domain: $node");
 
220
                delete ($data->{domain}->{$domain}->{node}->{$node});
 
221
            }
 
222
        }
 
223
    }
 
224
    return ($data);
 
225
}
 
226
sub munin_overwrite {
 
227
    my ($configfile,$overwrite) = @_;
 
228
    for my $key (keys %$overwrite) {
 
229
        if (ref $overwrite->{$key}) {
 
230
            &munin_overwrite($overwrite->{$key},$configfile->{$key});
 
231
        }
 
232
        $configfile->{$key} = $overwrite->{$key};
 
233
    }
 
234
    return ($configfile);
 
235
}
 
236
 
 
237
sub munin_readconfig {
 
238
    my ($conf, $missingok, $corruptok) = @_;
 
239
    my $config   = undef;
 
240
    my @contents = undef;
 
241
 
 
242
    $conf ||= $configfile;
 
243
    if (! -r $conf and ! $missingok) {
 
244
                ::logger ("munin_readconfig: cannot open '$conf'\n");
 
245
                return undef;
 
246
    }
 
247
    if (open (CFG, $conf))
 
248
    {
 
249
        @contents = <CFG>;
 
250
        close (CFG);
 
251
    }
 
252
 
 
253
    $config = &munin_parse_config (\@contents);
 
254
 
 
255
    # Some important defaults before we return...
 
256
    $config->{'rundir'} ||= "/tmp/";
 
257
    $config->{'dbdir'}  ||= "/var/lib/munin/";
 
258
    $config->{'logdir'} ||= "/var/log/";
 
259
    $config->{'tmpldir'}||= "/etc/munin/templates/";
 
260
    $config->{'htmldir'}||= "@@HTMLDIR@@/";
 
261
    return ($config);
 
262
}
 
263
 
 
264
sub munin_parse_config
 
265
{
 
266
    my $lines    = shift;
 
267
    my $hash     = undef;
 
268
    my $prefix   = "";
 
269
    my $prevline = "";
 
270
 
 
271
    foreach my $line (@{$lines})
 
272
    {
 
273
        chomp $line;
 
274
        $line =~ s/(^|[^\\])#.*/$1/g;  # Skip comments...
 
275
        next unless ($line =~ /\S/);  # And empty lines...
 
276
        if (length $prevline)
 
277
        {
 
278
            $line = $prevline . $line;
 
279
            $prevline = "";
 
280
        }
 
281
        if ($line =~ /\\$/)
 
282
        {
 
283
            ($prevline = $line) =~ s/\\$//;
 
284
            next;
 
285
        }
 
286
        $line =~ s/\s+$//g;           # And trailing whitespace...
 
287
        $line =~ s/^\s+//g;           # And heading whitespace...
 
288
 
 
289
        if ($line =~ /^\s*\.(\S+)\s+(.+)\s*$/)
 
290
        {
 
291
            my ($var, $val) = ($1, $2);
 
292
            $hash = &munin_set_var_path ($hash, $var, $val);
 
293
        }
 
294
        elsif ($line =~ /^\s*\[([^\]]*)]\s*$/)
 
295
        {
 
296
            $prefix = $1;
 
297
            if ($prefix =~ /^([^:;]+);([^:;]+)$/)
 
298
            {
 
299
                $prefix .= ":";
 
300
            }
 
301
            elsif ($prefix =~ /^([^:;]+);$/)
 
302
            {
 
303
                $prefix .= "";
 
304
            }
 
305
            elsif ($prefix =~ /^([^:;]+);([^:;]+):(.*)$/)
 
306
            {
 
307
                $prefix .= ".";
 
308
            }
 
309
            elsif ($prefix =~ /^([^:;]+)$/)
 
310
            {
 
311
                (my $domain = $prefix) =~ s/^[^\.]+\.//;
 
312
                $prefix = "$domain;$prefix:";
 
313
            }
 
314
            elsif ($prefix =~ /^([^:;]+):(.*)$/)
 
315
            {
 
316
                (my $domain = $prefix) =~ s/^[^\.]+\.//;
 
317
                $prefix = "$domain;$prefix.";
 
318
            }
 
319
        }
 
320
        elsif ($line =~ /^\s*(\S+)\s+(.+)\s*$/)
 
321
        {
 
322
            my ($var, $val) = ($1, $2);
 
323
            $hash = &munin_set_var_path ($hash, "$prefix$var", $val);
 
324
        }
 
325
        else
 
326
        {
 
327
            warn "Malformed configuration line \"$line\".";
 
328
        }
 
329
    }
 
330
 
 
331
    return $hash;
 
332
}
 
333
 
 
334
sub munin_get_var_path
 
335
{
 
336
    my $hash = shift;
 
337
    my $var  = shift;
 
338
    my $val  = shift;
 
339
 
 
340
    print "DEBUG: Getting var \"$var\" = \"$val\"\n" if $DEBUG;
 
341
    if ($var =~ /^\s*([^;:]+);([^;:]+):(\S+)\s*$/)
 
342
    {
 
343
        my ($dom, $host, $rest) = ($1, $2, $3);
 
344
        my @sp = split (/\s*\.\s*/, $rest);
 
345
 
 
346
        if (@sp == 3)
 
347
        {
 
348
            return $hash->{domain}->{$dom}->{node}->{$host}->{client}->{$sp[0]}->{"$sp[1].$sp[2]"};
 
349
        }
 
350
        elsif (@sp == 2)
 
351
        {
 
352
            return $hash->{domain}->{$dom}->{node}->{$host}->{client}->{$sp[0]}->{$sp[1]};
 
353
        }
 
354
        elsif (@sp == 1)
 
355
        {
 
356
            return $hash->{domain}->{$dom}->{node}->{$host}->{$sp[0]};
 
357
        }
 
358
        else
 
359
        {
 
360
            warn "munin_set_var: Malformatted variable path \"$var\".";
 
361
        }
 
362
    }
 
363
    elsif ($var =~ /^\s*([^;:]+);([^;:]+)\s*$/)
 
364
    {
 
365
        my ($dom, $rest) = ($1, $2);
 
366
        my @sp = split (/\s*\.\s*/, $rest);
 
367
 
 
368
        if (@sp == 1)
 
369
        {
 
370
            return $hash->{domain}->{$dom}->{$sp[0]};
 
371
        }
 
372
        else
 
373
        {
 
374
            warn "munin_set_var: Malformatted variable path \"$var\".";
 
375
        }
 
376
    }
 
377
    elsif ($var =~ /^\s*([^;:\.]+)\s*$/)
 
378
    {
 
379
        return $hash->{$1};
 
380
    }
 
381
    else
 
382
    {
 
383
        warn "munin_set_var: Malformatted variable path \"$var\".";
 
384
    }
 
385
 
 
386
    return undef;
 
387
}
 
388
 
 
389
sub munin_set_var_path
 
390
{
 
391
    my $hash = shift;
 
392
    my $var  = shift;
 
393
    my $val  = shift;
 
394
 
 
395
    print "DEBUG: Setting var \"$var\" = \"$val\"\n" if $DEBUG;
 
396
    if ($var =~ /^\s*([^;:]+);([^;:]+):(\S+)\s*$/)
 
397
    {
 
398
        my ($dom, $host, $rest) = ($1, $2, $3);
 
399
        my @sp = split (/\s*\.\s*/, $rest);
 
400
 
 
401
        if (@sp == 3)
 
402
        {
 
403
            print STDERR ("Warning: Unknown option \"$sp[2]\" in \"$dom;$host:$sp[0].$sp[1].$sp[2]\".\n")
 
404
                unless grep /^$sp[2]$/, @legal;
 
405
            $hash->{domain}->{$dom}->{node}->{$host}->{client}->{$sp[0]}->{"$sp[1].$sp[2]"} = $val;
 
406
        }
 
407
        elsif (@sp == 2)
 
408
        {
 
409
            print STDERR ("Warning: Unknown option \"$sp[1]\" in \"$dom;$host:$sp[0].$sp[1]\".\n")
 
410
                unless grep /^$sp[1]$/, @legal;
 
411
            $hash->{domain}->{$dom}->{node}->{$host}->{client}->{$sp[0]}->{$sp[1]} = $val;
 
412
        }
 
413
        elsif (@sp == 1)
 
414
        {
 
415
            print STDERR ("Warning: Unknown option \"$sp[0]\" in \"$dom;$host:$sp[0]\".\n")
 
416
                unless grep /^$sp[0]$/, @legal;
 
417
            $hash->{domain}->{$dom}->{node}->{$host}->{$sp[0]} = $val;
 
418
        }
 
419
        else
 
420
        {
 
421
            warn "munin_set_var: Malformatted variable path \"$var\".";
 
422
        }
 
423
    }
 
424
    elsif ($var =~ /^\s*([^;:]+);([^;:]+)\s*$/)
 
425
    {
 
426
        my ($dom, $rest) = ($1, $2);
 
427
        my @sp = split (/\s*\.\s*/, $rest);
 
428
 
 
429
        if (@sp == 1)
 
430
        {
 
431
            print STDERR ("Warning: Unknown option \"$sp[0]\" in \"$dom;$sp[0]\".\n")
 
432
                unless grep /^$sp[0]$/, @legal;
 
433
            $hash->{domain}->{$dom}->{$sp[0]} = $val;
 
434
        }
 
435
        else
 
436
        {
 
437
            warn "munin_set_var: Malformatted variable path \"$var\".";
 
438
        }
 
439
    }
 
440
    elsif ($var =~ /^\s*([^;:\.]+)\s*$/)
 
441
    {
 
442
        print STDERR ("Warning: Unknown option \"$1\" in \"$1\".\n")
 
443
            unless grep /^$1$/, @legal;
 
444
        $hash->{$1} = $val;
 
445
    }
 
446
    else
 
447
    {
 
448
        warn "munin_set_var: Malformatted variable path \"$var\".";
 
449
    }
 
450
 
 
451
    return $hash;
 
452
}
 
453
 
 
454
sub munin_writeconfig_loop {
 
455
    my ($data,$fh,$pre) = @_;
 
456
    $pre |= "";
 
457
 
 
458
    # Write datafile in new format
 
459
    foreach my $a (keys %{$data})
 
460
    {
 
461
        if (ref ($data->{$a}) eq "HASH")
 
462
        {
 
463
            if ($a eq "domain" or $a eq "node" or $a eq "client")
 
464
            {
 
465
                &munin_writeconfig_loop ($data->{$a}, $fh, "$pre");
 
466
            }
 
467
            else
 
468
            {
 
469
                my $lpre = $pre;
 
470
                if ($lpre eq "")
 
471
                {
 
472
                    $lpre = $a.";";
 
473
                }
 
474
                elsif ($lpre =~ /;$/)
 
475
                {
 
476
                    $lpre .= $a.":";
 
477
                }
 
478
                else
 
479
                {
 
480
                    $lpre .= $a.".";
 
481
                }
 
482
                &munin_writeconfig_loop ($data->{$a}, $fh, "$lpre");
 
483
            }
 
484
        }
 
485
        elsif (defined $data->{$a} and length $data->{$a})
 
486
        {
 
487
            print "Writing: $pre$a $data->{$a}\n" if $DEBUG;
 
488
            print $fh "$pre$a $data->{$a}\n";
 
489
        }
 
490
    }
 
491
}
 
492
sub munin_writeconfig {
 
493
    my ($datafilename,$data,$fh) = @_;
 
494
#   my $datafile = new Config::General();
 
495
#   $datafile->save_file($datafilename,$data);
 
496
 
 
497
    if (!defined $fh)
 
498
    {
 
499
        $fh = gensym();
 
500
        unless (open ($fh, ">$datafilename"))
 
501
        {
 
502
            die "Fatal error: Could not open \"$datafilename\" for writing: $!";
 
503
        }
 
504
    }
 
505
 
 
506
    # Write datafile in new format
 
507
    &munin_writeconfig_loop ($data, $fh, "");
 
508
    
 
509
    if (defined $fh)
 
510
    {
 
511
        print "DEBUG: Closing filehandle \"$datafilename\"...\n" if $DEBUG;
 
512
        close ($fh);
 
513
    }
 
514
}
 
515
    
 
516
sub munin_config {
 
517
    my $conffile = shift;
 
518
    $conffile ||= $configfile;
 
519
    $config = &munin_readconfig ($conffile);
 
520
    my $data = &munin_readconfig("$config->{dbdir}/datafile", 1, 1);
 
521
    
 
522
    $data = &munin_overwrite($data,$config);
 
523
    return ($data);
 
524
}
 
525
 
 
526
sub munin_get_filename {
 
527
        my ($domain,$node,$service,$field) = @_;
 
528
 
 
529
        return ($config->{'dbdir'} . "/$domain/$node-$service-$field-" . lc substr (($config->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{$field.".type"}||"GAUGE"), 0,1). ".rrd");
 
530
 
 
531
}
 
532
 
 
533
sub munin_get_bool
 
534
{
 
535
    my $conf     = shift;
 
536
    my $field    = shift;
 
537
    my $default  = shift;
 
538
    my $domain   = shift;
 
539
    my $node     = shift;
 
540
    my $service  = shift;
 
541
    my $plot     = shift;
 
542
 
 
543
    return undef unless defined $field;
 
544
 
 
545
    my $ans = &munin_get_val ($conf, $field, $default, $domain, $node, $service, $plot);
 
546
    return undef if not defined $ans;
 
547
 
 
548
    if ($ans =~ /^yes$/i or
 
549
        $ans =~ /^true$/i or
 
550
        $ans =~ /^on$/i or
 
551
        $ans =~ /^enable$/i or
 
552
        $ans =~ /^enabled$/i
 
553
       )
 
554
    {
 
555
    return 1;
 
556
    }
 
557
    elsif ($ans =~ /^no$/i or
 
558
        $ans =~ /^false$/i or
 
559
        $ans =~ /^off$/i or
 
560
        $ans =~ /^disable$/i or
 
561
        $ans =~ /^disabled$/i
 
562
      )
 
563
    {
 
564
    return 0;
 
565
    }
 
566
    elsif ($ans !~ /\D/)
 
567
    {
 
568
    return $ans;
 
569
    }
 
570
    else
 
571
    {
 
572
    return undef;
 
573
    }
 
574
}
 
575
 
 
576
sub munin_get_bool_val
 
577
{
 
578
    my $field    = shift;
 
579
    my $default  = shift;
 
580
 
 
581
    if (!defined $field)
 
582
    {
 
583
    if (!defined $default)
 
584
    {
 
585
        return 0;
 
586
    }
 
587
    else
 
588
    {
 
589
        return $default;
 
590
    }
 
591
    }
 
592
 
 
593
    if ($field =~ /^yes$/i or
 
594
        $field =~ /^true$/i or
 
595
        $field =~ /^on$/i or
 
596
        $field =~ /^enable$/i or
 
597
        $field =~ /^enabled$/i
 
598
       )
 
599
    {
 
600
    return 1;
 
601
    }
 
602
    elsif ($field =~ /^no$/i or
 
603
        $field =~ /^false$/i or
 
604
        $field =~ /^off$/i or
 
605
        $field =~ /^disable$/i or
 
606
        $field =~ /^disabled$/i
 
607
      )
 
608
    {
 
609
    return 0;
 
610
    }
 
611
    elsif ($field !~ /\D/)
 
612
    {
 
613
    return $field;
 
614
    }
 
615
    else
 
616
    {
 
617
    return undef;
 
618
    }
 
619
}
 
620
 
 
621
sub munin_get_val
 
622
{
 
623
    my $conf     = shift;
 
624
    my $field    = shift;
 
625
    my $default  = shift;
 
626
    my $domain   = shift;
 
627
    my $node     = shift;
 
628
    my $service  = shift;
 
629
    my $plot     = shift;
 
630
 
 
631
    if (defined $field)
 
632
    {
 
633
        return $conf->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{"$plot.$field"}
 
634
                if (defined $domain and defined $node and defined $service and defined $plot and 
 
635
                        defined $conf->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{"$plot.$field"});
 
636
 
 
637
        
 
638
 
 
639
        return $conf->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{$field}
 
640
                if (defined $domain and defined $node and defined $service and 
 
641
                        defined $conf->{domain}->{$domain}->{node}->{$node}->{client}->{$service}->{$field});
 
642
        return $conf->{domain}->{$domain}->{node}->{$node}->{$field}
 
643
                if (defined $domain and defined $node and 
 
644
                        defined $conf->{domain}->{$domain}->{node}->{$node}->{$field});
 
645
        return $conf->{domain}->{$domain}->{$field}
 
646
                if (defined $domain and defined $conf->{domain}->{$domain}->{$field});
 
647
        return $conf->{$field}
 
648
                if (defined $conf->{$field});
 
649
        return $default;
 
650
    }
 
651
    else
 
652
    {
 
653
        return $conf->{domain}->{$domain}->{node}->{$node}->{client}->{$service}
 
654
                if (defined $domain and defined $node and defined $service and 
 
655
                        defined $conf->{domain}->{$domain}->{node}->{$node}->{client}->{$service});
 
656
        return $conf->{domain}->{$domain}->{node}->{$node}
 
657
                if (defined $domain and defined $node and 
 
658
                        defined $conf->{domain}->{$domain}->{node}->{$node});
 
659
        return $conf->{domain}->{$domain}
 
660
                if (defined $domain and defined $conf->{domain}->{$domain});
 
661
        return $conf
 
662
                if (defined $conf);
 
663
        return $default;
 
664
    }
 
665
}
 
666
 
 
667
 
 
668
1;