1#!@@PERL@@
2# -*- cperl -*-
3
4use warnings;
5use strict;
6
7use English qw(-no_match_vars);
8use Getopt::Long;
9use Pod::Usage;
10use Log::Log4perl qw(:easy);
11
12use Munin::Master::Update;
13use Munin::Master::Logger;
14use Munin::Master::Config;
15use Munin::Master::Utils;
16
17
18# TODO
19#
20# - Include data from Munin::Master::Config in config dump?
21# - nested groups
22
23Getopt::Long::Configure(qw(auto_help));
24
25my $globconfig = Munin::Master::Config->instance();
26my $config = $globconfig->{'config'};
27
28sub main {
29    exit_if_run_by_super_user();
30
31    configure();
32
33    logger_open($config->{'logdir'});
34    logger_debug() if $config->{debug};
35
36    my $update = Munin::Master::Update->new();
37    $update->run();
38
39    return 0;
40}
41
42
43sub configure {
44    my %args = parse_args();
45
46    # Uses default file if config_file is not defined by arguments.
47    $config->parse_config_from_file($args{config_file});
48
49    if (defined $config->{'includedir'}) {
50	my $dirname = $config->{'includedir'};
51
52	my $DIR;
53	opendir($DIR, $dirname) or
54	    WARN "[Warning] Could not open includedir directory $dirname: $OS_ERROR\n";
55	my @files = grep { ! /^\.|~$/ } readdir($DIR);
56	closedir($DIR);
57
58	@files = map { $_ = $dirname.'/'.$_; } (sort @files);
59
60	foreach my $f (@files) {
61	    $config->parse_config_from_file($f);
62	}
63    }
64
65    # Arguments overrides settings from config file.  Note that
66    # this only handles settings that are on the base level, not
67    # anything within groups or hosts.
68    $config->set(\%args);
69}
70
71
72sub parse_args {
73    my $do_usage = 0;
74    my $do_version = 0;
75
76    my %args = (
77        "version" => \&print_version_and_exit,
78    );
79
80    GetOptions (
81        \%args,
82        "config_file=s",
83        "debug!",
84        "fork!",
85        "host=s@",
86        "service=s@",
87        "timeout=s",
88        "version!",
89    ) or pod2usage(1);
90
91    delete $args{version};
92
93    $args{limit_hosts} = { map { $_ => 1 } @{$args{host}} };
94    delete $args{host};
95
96    $args{limit_services} = { map { $_ => 1 } @{$args{service}} };;
97    delete $args{service};
98
99    return %args;
100}
101
102
103exit main() unless caller;
104
105
1061;
107
108__END__
109
110=encoding utf8
111
112=head1 NAME
113
114munin-update - A program to gather data from machines running munin-node
115
116=head1 SYNOPSIS
117
118munin-update [options]
119
120 Options:
121     --config_file=<file>    Use <file> as configuration file.
122     --[no]debug             Enable [or disable] debug messages. [--nodebug]
123     --[no]fork              Query hosts in parallel (--fork), or
124                             sequentially (--nofork). [--fork]
125     --host <host>	     Limit graphed hosts to <host>. Multiple --host
126                             options may be supplied.
127     --service <service>     Limit graphed services to <service>. Multiple
128 			     --service options may be supplied.
129     --timeout=<seconds>     TCP timeout when talking to clients. [$timeout]
130     --help                  View this message.
131     --version               View version information.
132
133
134=head1 OPTIONS
135
136=over 5
137
138=item B<< --config_file=<file> >>
139
140Use E<lt>fileE<gt> as the configuration file. [@@CONFDIR@@/munin.conf]
141
142=item B<< --[no]debug >>
143
144If set, log debug messages. [--nodebug]
145
146=item B<< --[no]fork >>
147
148If set, will fork off one process for each host. [--fork]
149
150=item B<< --host <host> >>
151
152Limit fetched data to those from E<lt>host<gt>. Multiple --host
153options may be supplied. [unset]
154
155=item B<< --service <service> >>
156
157Limit fetched data to those of E<lt>serviceE<gt>. Multiple --service
158options may be supplied. [unset]
159
160=item B<< --timeout <seconds> >>
161
162Set the network timeout to <seconds>. [180]
163
164=item B<< --help >>
165
166Print the help message then exit.
167
168=item B<< --version >>
169
170Print version information then exit.
171
172=back
173
174
175=head1 DESCRIPTION
176
177
178Munin-update is a part of the package Munin, which is used in
179combination with Munin's node.  Munin is a group of programs to gather
180data from Munin's nodes, graph them, create html-pages, and optionally
181warn Nagios about any off-limit values.
182
183Munin-update does the gathering. It is usually only used from within
184munin-cron.
185
186It contacts each host's munin-node in turn, gathers data from it, and
187stores them in .rrd-files. If necessary, it will create the rrd-files
188and the directories to store them in.
189
190
191=head1 FILES
192
193	@@CONFDIR@@/munin.conf
194	@@DBDIR@@/*
195	@@LOGDIR@@/munin-update
196	@@STATEDIR@@/*
197
198
199=head1 BUGS
200
201For a list of bugs concerning munin-update, see FIX<point to right
202ticket report>.
203
204Please report bugs in the bug tracker at L<http://munin-monitoring.org/>.
205
206
207=head1 AUTHORS
208
209The Munin Team. FIX
210
211
212=head1 COPYRIGHT
213
214Copyright © 2002-2009 Jimmy Olsen, Audun Ytterdal, Tore Andersson, Kjell-Magne Øierud, Linpro AS, Redpill Linpro AS
215
216This is free software; see the source for copying conditions. There is
217NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
218PURPOSE.
219
220This program is released under the GNU General Public License.
221