File: munin-update

package info (click to toggle)
munin 2.999.14-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 10,036 kB
  • sloc: perl: 31,052; sh: 12,473; java: 1,924; python: 852; makefile: 336; ruby: 232; awk: 169; xml: 45; sql: 11
file content (242 lines) | stat: -rwxr-xr-x 5,529 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/usr/bin/perl -T

use warnings;
use strict;


use English qw(-no_match_vars);
use Getopt::Long;
use Pod::Usage;
use Munin::Common::Logger;

use Munin::Master::Update;
use Munin::Master::Config;
use Munin::Master::Utils;


# TODO
#
# - Include data from Munin::Master::Config in config dump?
# - nested groups

Getopt::Long::Configure(qw(auto_help));

my $globconfig = Munin::Master::Config->instance();
my $config = $globconfig->{'config'};

sub main {
    exit_if_run_by_super_user();

    configure();

    my %log = (
        output => $config->{logoutput},
        logdir => $config->{logdir},
    );
    $log{output} = 'screen' if $config->{screen};
    $log{level}  = 'info'   if $config->{verbose};
    $log{level}  = 'debug'  if $config->{debug};

    Munin::Common::Logger::configure(%log);

    my $update = Munin::Master::Update->new();
    $update->run();

    return 0;
}


sub configure {
    my %args = parse_args();

    # Uses default file if config_file is not defined by arguments.
    $config->parse_config_from_file($args{config});

    if (defined $config->{'includedir'}) {
	my $dirname = $config->{'includedir'};

	my $DIR;
	opendir($DIR, $dirname) or
	    WARN "[Warning] Could not open includedir directory $dirname: $OS_ERROR\n";
	my @files = grep { ! /^\.|~$/ } readdir($DIR);
	closedir($DIR);

	## no critic qw(ControlStructures::ProhibitMutatingListFunctions)
	@files = map { $_ = $dirname.'/'.$_; } (sort @files);

	foreach my $f (@files) {
	    $config->parse_config_from_file($f);
	}
    }

    # Arguments overrides settings from config file.  Note that
    # this only handles settings that are on the base level, not
    # anything within groups or hosts.
    $config->set(\%args);
}


sub parse_args {
    my $do_usage = 0;
    my $do_version = 0;

    my %args = (
        "version" => \&print_version_and_exit,
    );

    GetOptions (
        \%args,
        "config|config_file=s",
        "debug",
        "verbose",
        "screen",
        "fork!",
        "host=s@",
        "service=s@",
        "timeout=s",
        "version!",
    ) or pod2usage(1);

    # We let the call shoot himself in the foot with cli args
    my $config_file = $args{config_file};
    if ($config_file) {
        $args{config_file} = $1 if $config_file =~ m/(.*)/;
    }

    delete $args{version};

    $args{limit_hosts} = { map { $_ => 1 } @{$args{host}} };
    delete $args{host};

    $args{limit_services} = { map { $_ => 1 } @{$args{service}} };;
    delete $args{service};

    return %args;
}


exit main() unless caller;


1;

__END__

=encoding utf8

=head1 NAME

munin-update - A program to gather data from machines running munin-node

=head1 SYNOPSIS

munin-update [options]

 Options:
     --config_file=<file>    Use <file> as configuration file.
     --debug                 Enable debug messages.
     --verbose               Be verbose.
     --screen                Send log messages the screen (STDERR).
     --[no]fork              Query hosts in parallel (--fork), or
                             sequentially (--nofork). [--fork]
     --host <host>	     Limit graphed hosts to <host>. Multiple --host
                             options may be supplied.
     --service <service>     Limit graphed services to <service>. Multiple
 			     --service options may be supplied.
     --timeout=<seconds>     TCP timeout when talking to clients. [$timeout]
     --help                  View this message.
     --version               View version information.


=head1 OPTIONS

=over 5

=item B<< --config_file=<file> >>

Use E<lt>fileE<gt> as the configuration file. [@@CONFDIR@@/munin.conf]

=item B<< --[no]debug >>

If set, log debug messages. [--nodebug]

=item B<< --[no]verbose >>

If set, be verbose. [--noverbose]

=item B<< --[no]fork >>

If set, will fork off one process for each host. [--fork]

=item B<< --host <host> >>

Limit fetched data to those from E<lt>host<gt>. Multiple --host
options may be supplied. [unset]

=item B<< --service <service> >>

Limit fetched data to those of E<lt>serviceE<gt>. Multiple --service
options may be supplied. [unset]

=item B<< --timeout <seconds> >>

Set the network timeout to <seconds>. [180]

=item B<< --help >>

Print the help message then exit.

=item B<< --version >>

Print version information then exit.

=back


=head1 DESCRIPTION


Munin-update is a part of the package Munin, which is used in
combination with Munin's node.  Munin is a group of programs to gather
data from Munin's nodes, graph them, create html-pages, and optionally
warn Nagios about any off-limit values.

Munin-update does the gathering. It is usually only used from within
munin-cron.

It contacts each host's munin-node in turn, gathers data from it, and
stores them in .rrd-files. If necessary, it will create the rrd-files
and the directories to store them in.


=head1 FILES

	@@CONFDIR@@/munin.conf
	@@DBDIR@@/*
	@@LOGDIR@@/munin-update
	@@STATEDIR@@/*


=head1 BUGS

For a list of bugs concerning munin-update, see FIX<point to right
ticket report>.

Please report bugs in the bug tracker at L<http://munin-monitoring.org/>.


=head1 AUTHOR

  Copyright (C) 2009 Nicolai Langfeldt
  Copyright (C) 2009 Kjell-Magne Øierud
  Copyright (C) Audun Ytterdal
  Copyright (C) Jimmy Olsen
  Copyright (C) Tore Andersson

=head1 LICENSE

This is free software; see the source for copying conditions. There is
NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

This program is released under the GNU General Public License.