This file is indexed.

/usr/sbin/munin-node-configure is in munin-node 2.0.19-3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
#!/usr/bin/perl -w
# -*- cperl -*-
#
# Copyright (C) 2003-2006 Jimmy Olsen, Nicolai Langfeldt.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 dated June,
# 1991.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

use strict;
use warnings;

use Getopt::Long;

use Munin::Common::Defaults;
use Munin::Node::Configure::PluginList;
use Munin::Node::Configure::Debug;

use Munin::Node::Config;
my $config = Munin::Node::Config->instance();

my @all_families     = qw/auto manual contrib/;
my @default_families = qw/auto/;


sub main
{
	parse_args();

    my $plugins = $config->{plugins};
    $plugins->load();

    # Gather information
    if ($config->{snmp}) {
        $plugins->{library}->prepare_plugin_environment($plugins->names);
        fetch_plugin_snmpconf($plugins, $_) foreach ($plugins->list);

        $config->{snmp}->run_probes($plugins);
    }
    elsif ($config->{suggest}) {
        gather_suggestions($plugins);
    }
    else {
        print_status_list($plugins);
        exit 0;
    }

    # Display results.
    if ($config->{shell}) {
        manage_links($plugins);
    }
    else {
        show_suggestions($plugins);
    }

    # Report errors.
    # FIXME: surely exit 0 unless m-n-c itself has gone funny?
    if (my @errors = list_errors($plugins->list)) {
        print STDERR "# The following plugins caused errors:\n", @errors;
        exit 1;
    }
    exit 0;
}


sub parse_args
{
	my $conffile   = "$Munin::Common::Defaults::MUNIN_CONFDIR/munin-node.conf";
	my $servicedir = "$Munin::Common::Defaults::MUNIN_CONFDIR/plugins";
	my $sconfdir   = "$Munin::Common::Defaults::MUNIN_CONFDIR/plugin-conf.d";
	my $libdir     = "$Munin::Common::Defaults::MUNIN_LIBDIR/plugins";

	my $debug = 0;
	my $pidebug = 0;
	my ($suggest, $shell, $removes, $newer);
	my $exit_not_error = 1;
	my @families;
	my (@snmp_hosts, $snmpver, $snmpcomm, $snmpport);
    my ($snmp3username, $snmp3authpass, $snmp3authproto, $snmp3privpass, $snmp3privproto);

    print_usage_and_exit() unless GetOptions(
        'help'            => \&print_usage_and_exit,
        'version'         => \&print_version_and_exit,

        'suggest!'        => \$suggest,
        'exitnoterror!'   => \$exit_not_error,
        'newer=s'         => \$newer,

        'shell!'          => \$shell,
        'remove-also!'    => \$removes,

        'debug!'          => \$debug,
        'pidebug!'        => \$pidebug,

        # paths
        'config=s'        => \$conffile,
        'servicedir=s'    => \$servicedir,
        'sconfdir=s'      => \$sconfdir,
        'libdir=s'        => \$libdir,
        'families=s'      => \@families,

        # SNMP
        'snmp=s'          => \@snmp_hosts,
        'snmpversion=s'   => \$snmpver,
        'snmpport=i'      => \$snmpport,
        # SNMPv1/2c
        'snmpcommunity=s' => \$snmpcomm,
        # SNMPv3
        'snmpusername=s'  => \$snmp3username,
        'snmpauthpass=s'  => \$snmp3authpass,
        'snmpauthproto=s' => \$snmp3authproto,
        'snmpprivpass=s'  => \$snmp3privpass,
        'snmpprivproto=s' => \$snmp3privproto,
    );

	$config->parse_config_from_file($conffile);

    # --shell implies --suggest unless --snmp was also used
    $suggest = 1 if ($shell and not @snmp_hosts);

    @families = (@families)    ? map { split /,/ } @families :
                (@snmp_hosts)  ? ('snmpauto')                :
                ($suggest)     ? @default_families           :
                                 @all_families               ;

    # Allow the user to mix multiple invocations of --snmp with the
    # comma-delimited form
    @snmp_hosts = map { split /,/ } @snmp_hosts;

    my $snmp = init_snmp(
        hosts        => \@snmp_hosts,
        version      => $snmpver,
        port         => $snmpport,

        community    => $snmpcomm,

        username     => $snmp3username,
        authpassword => $snmp3authpass,
        authprotocol => $snmp3authproto,
        privpassword => $snmp3privpass,
        privprotocol => $snmp3privproto,
    ) if @snmp_hosts;

    my $plugins = Munin::Node::Configure::PluginList->new(
        libdir     => $libdir,
        servicedir => $servicedir,

        pidebug    => $pidebug,

        families   => \@families,
        newer      => $newer,
    );

    $config->reinitialize({
        %$config,

        exit_not_error => $exit_not_error,
        suggest        => $suggest,

        shell          => $shell,
        remove_also    => $removes,

        snmp => $snmp,

	plugins => $plugins,

        conffile   => $conffile,
        servicedir => $servicedir,  # needed for creating/removing links
        sconfdir   => $sconfdir,

        DEBUG   => $debug,
    });

    return;
}


sub print_usage_and_exit
{
    require Pod::Usage;
    Pod::Usage::pod2usage(-verbose => 1);
}


sub print_version_and_exit
{
    require Pod::Usage;
    Pod::Usage::pod2usage(
        -verbose => 99,
        -sections => 'VERSION|COPYRIGHT',
    );
}


sub print_table_entry
{
	printf "%-26s | %-4s | %-39s\n", @_;
	return;
}


### Reporting current status ###################################################

# For each available plugin, prints a line detailing whether or not it's
# installed, and (if it's a wildcard plugin) what identities are currently
# in use
sub print_status_list
{
	my ($plugins) = @_;

	print_table_entry("Plugin", "Used", "Extra information");
	print_table_entry("------", "----", "-----------------");

	foreach my $plugin ($plugins->list) {
        print_table_entry(
            $plugin->{name},
            $plugin->is_installed,
            $plugin->installed_services_string
        );
	}

	return;
}


### Reporting and managing suggestions #########################################

# Asks each available autoconf plugin whether or not it should be installed,
# and (if it's a wildcard plugin) its suggested profiles.
sub gather_suggestions
{
	my ($plugins) = @_;

	# We're going to be running plugins
    $plugins->{library}->prepare_plugin_environment($plugins->names);

    foreach my $plugin ($plugins->list) {
        fetch_plugin_autoconf($plugins, $plugin);
        fetch_plugin_suggestions($plugins, $plugin);
    }

	return;
}


# Prints out the tabular representation of the suggestion
sub show_suggestions
{
	my ($plugins) = @_;

    print_table_entry("Plugin", "Used", "Suggestions");
    print_table_entry("------", "----", "-----------");

    foreach my $plugin ($plugins->list) {
        print_table_entry(
            $plugin->{name},
            $plugin->is_installed,
            $plugin->suggestion_string
        );
    }
	return;
}


# prints shell commands to get the system into the recommended
# state by adding or removing symlinks
sub manage_links
{
    my ($plugins) = @_;

    foreach my $plugin ($plugins->list) {
        link_add($plugin->{path}, $_) foreach $plugin->services_to_add;
        if ($config->{remove_also}) {
            link_remove($_) foreach $plugin->services_to_remove;
        }
    }
    return;
}


# Prints a shell-command to remove a given symlink from the servicedir
sub link_remove
{
    my ($service) = @_;
    return unless (-l "$config->{servicedir}/$service"); # Strange...
    print "rm -f '$config->{servicedir}/$service'\n";
	return;
}


# Prints a shell-command to add a symlink called $service pointing to
# the plugin.
sub link_add
{
	my ($plugin, $service) = @_;
    print "ln -s '$plugin' '$config->{servicedir}/$service'\n";
	return;
}


### SNMP probing ###############################################################

sub init_snmp
{
    unless (eval { require Munin::Node::SNMPConfig; }) {
        die "# ERROR: Cannot perform SNMP probing as Munin::Node::SNMPConfig module is not available.\n",
            $@;
    }
    return Munin::Node::SNMPConfig->new(@_);
}


### Running plugins and analysing responses ####################################

# Runs the plugin with argument $mode (eg. 'suggest', 'autoconf') and runs
# tests on the results.  Assuming no errors were detected, returns a list
# of the lines printed to STDOUT, with any debug output removed.
sub run_plugin
{
    my ($plugins, $plugin, $mode) = @_;
    my $name = $plugin->{name};

	DEBUG("Running '$mode' on $name" );
    my $res = $plugins->{library}->fork_service($name, $mode);

	# No if it timed out
	if ($res->{timed_out}) {
        $plugin->log_error("Timed out during $mode");
		return;
	}
	elsif ($res->{retval}) {
		# Non-zero exit is an immediate fail
		my $plugin_exit   = $res->{retval} >> 8;
		my $plugin_signal = $res->{retval} & 127;

		# Definitely a bad sign
		if ($plugin_signal) {
            $plugin->log_error("Died with signal $plugin_signal during $mode");
			return;
		}
		elsif ($plugin_exit) {
            $plugin->log_error("Non-zero exit during $mode ($plugin_exit)");

			# Verboten according to the specification, but lots of plugins
            # still exit(1) it during autoconf.  So making it a non-fatal error
			# for the time being
			return unless ($mode eq 'autoconf'
			           and $plugin_exit == 1
			           and $config->{exit_not_error});
		}
	}

	# No if there is anything on stderr that's not debug
	if (my @junk = grep !/^#/, @{ $res->{stderr} }) {
	       $plugin->log_error("Junk printed to stderr");
	       DEBUG("Junk printed to stderr: @junk");
	       return;
	}

    # Ignore debug output
	my @response = grep !/^#/, @{ $res->{stdout} };
    $plugin->log_error('Nothing printed to stdout') unless (scalar @response);

    return @response;
}


# Runs the given plugin, and records whether it thinks it should be installed.
# Sets the 'default' and 'defaultreason' fields
sub fetch_plugin_autoconf
{
    my ($plugins, $plugin) = @_;

    return unless ($plugin->{capabilities}{autoconf});

    my @response = run_plugin($plugins, $plugin, 'autoconf') or return;
	return $plugin->parse_autoconf_response(@response);
}


# Runs the given wildcard plugin and saves a list of suggested profiles
# in the 'suggestions' field
sub fetch_plugin_suggestions
{
    my ($plugins, $plugin) = @_;

	# Only run if the autoconf gave the go-ahead
	return unless ($plugin->{default} eq "yes");

    return unless ($plugin->{capabilities}{suggest});

    my @suggested = run_plugin($plugins, $plugin, 'suggest');
	return $plugin->parse_suggest_response(@suggested);
}


# Runs a given snmpconf-capable plugin, and notes the parameters it returns
sub fetch_plugin_snmpconf
{
    my ($plugins, $plugin) = @_;

    return unless ($plugin->{capabilities}{snmpconf});

    my @response = run_plugin($plugins, $plugin, 'snmpconf');
	return $plugin->parse_snmpconf_response(@response);
}


### Debugging and error reporting ##############################################

sub list_errors
{
    my @error_list;
    foreach my $plugin (@_) {
        if (my @errors = @{$plugin->{errors}}) {
            push @error_list, "# $plugin->{name}:\n";
            push @error_list, map { "# \t$_\n" } @errors;
        }
    }
    return @error_list;
}


exit main() unless caller;


1;

__END__

=head1 NAME

munin-node-configure - View and modify which plugins are enabled.

=head1 SYNOPSIS

  munin-node-configure [options]

=head1 DESCRIPTION

B<munin-node-configure> reports which plugins are enabled on the current node,
and suggest changes to this list.

By default this program shows which plugins are activated on the system.

If you specify C<--suggest>, it will present a table of plugins that will
probably work (according to the plugins' autoconf command).

If you specify C<--snmp>, followed by a list of hosts, it will present a table
of SNMP plugins that they support.

If you additionally specify C<--shell>, shell commands to install those same
plugins will be printed. These can be reviewed or piped directly into a shell
to install the plugins.


=head1 GENERAL OPTIONS

=over 4

=item B<< --help >>

Show this help page.

=item B<< --version >>

Show version information.

=item B<< --debug >>

Print debug information on the operations of C<munin-node-configure>.  This can
be very verbose.

All debugging output is printed to STDOUT, and each line is prefixed with '#'.
Only errors are printed to STDERR.

=item B<< --pidebug >>

Plugin debug.  Sets the environment variable MUNIN_DEBUG to 1 so that plugins
may enable debugging.

=item B<< --config <file> >>

Override configuration file [/etc/munin/munin-node.conf]

=item B<< --servicedir <dir> >>

Override plugin directory [/etc/munin/plugins/]

=item B<< --sconfdir <dir> >>

Override plugin configuration directory [/etc/munin/plugin-conf.d/]

=item B<< --libdir <dir> >>

Override plugin library [/usr/share/munin/plugins/]

=item B<< --exitnoterror >>

Do not consider plugins that exit non-zero exit-value as error.

=item B<< --suggest >>

Suggest plugins that might be added or removed, instead of those that are
currently enabled.

=back


=head2 OUTPUT OPTIONS

By default, C<munin-node-configure> will print out a table summarising the
results.

=over 4

=item B<< --shell >>

Instead of a table, print shell commands to install the new plugin suggestions.

This implies C<--suggest>, unless C<--snmp> was also enabled.  By default, it
will not attempt to remove any plugins.

=item B<< --remove-also >>

When C<--shell> is enabled, also provide commands to remove plugins that are no
longer applicable from the service directory.

=back


=head2 PLUGIN SELECTION OPTIONS

=over 4

=item B<< --families <family,...> >>

Override the list of families that will be used (auto, manual, contrib,
snmpauto).  Multiple families can be specified as a comma-separated list, by
repeating the C<--families> option, or as a combination of the two.

When listing installed plugins, the default families are 'auto', 'manual' and
'contrib'.  Only 'auto' plugins are checked for suggestions.  SNMP probing is only
performed on 'snmpauto' plugins.

=item B<< --newer <version> >>

Only consider plugins added to the Munin core since <version>.  This option is
useful when upgrading, since it can prevent plugins that have been manually
removed from being reinstalled.  This only applies to plugins in the 'auto'
family.

=back

=head2 SNMP Options

=over 4

=item B<< --snmp <host|cidr,...> >>

Probe the SNMP agents on the host or CIDR network (e.g. "192.168.1.0/24"), to
see what plugins they support. This may take some time, especially if the many
hosts are specified.

This option can be specified multiple times, or as a comma-separated list, to
include more than one host/CIDR.

=item B<< --snmpversion <ver> >>

The SNMP version (1, 2c or 3) to use. ['2c']

=item B<< --snmpport <port> >>

The SNMP port to use [161]

=item B<SNMP 1/2c authentication>

SNMP versions 1 and 2c use a "community string" for authentication.  This is
a shared password, sent in plaintext over the network.

=item B<< --snmpcommunity <string> >>

The community string for version 1 and 2c agents.  ['public'] (If this works
your device is probably very insecure and needs a security checkup).

=item B<SNMP 3 authentication>

SNMP v3 has three security levels. Lowest is C<noAuthNoPriv>, which provides
neither authentication nor encryption.  If a username and C<authpassword> are
given it goes up to C<authNoPriv>, and the connection is authenticated.  If
C<privpassword> is also given the security level becomes C<authPriv>, and the
connection is authenticated and encrypted.

B<Note>: Encryption can slow down slow or heavily loaded network devices.  For
most uses C<authNoPriv> will be secure enough -- the password is sent over the
network encrypted in any case.

ContextEngineIDs are not (yet) supported.

For further reading on SNMP v3 security models please consult RFC3414 and the
documentation for L<Net::SNMP>.

=item B<< --snmpusername <name> >>

Username.  There is no default.

=item B<< --snmpauthpassword <password> >>

Authentication password.  Optional when encryption is also enabled, in which
case defaults to the privacy password (C<--snmpprivpassword>).

=item B<< --snmpauthprotocol <protocol> >>

Authentication protocol.  One of 'md5' or 'sha' (HMAC-MD5-96, RFC1321 and
SHA-1/HMAC-SHA-96, NIST FIPS PIB 180, RFC2264).  ['md5']

=item B<< --snmpprivpassword <password> >>

Privacy password to enable encryption.  There is no default.  An empty ('')
password is considered as no password and will not enable encryption.

Privacy requires a privprotocol as well as an authprotocol and a authpassword,
but all of these are defaulted (to 'des', 'md5', and the privpassword value,
respectively) and may therefore be left unspecified.

=item B<< --snmpprivprotocol <protocol> >>

If the privpassword is set this setting controls what kind of encryption is
used to achieve privacy in the session.  Only the very weak 'des' encryption
method is supported officially.  ['des']

munin-node-configure also supports '3des' (CBC-3DES-EDE, aka Triple-DES, NIST
FIPS 46-3) as specified in IETF draft-reeder-snmpv3-usm-3desede.  Whether or
not this works with any particular device, we do not know.

=back

=head1 FILES

    /etc/munin/munin-node.conf
    /etc/munin/plugin-conf.d/*
    /etc/munin/plugins/*
    /usr/share/munin/plugins/plugins.history
    /usr/share/munin/plugins/*

=head1 VERSION

This is munin-node-configure (munin-node) v2.0.19-3.

$Id$

=head1 AUTHORS

Jimmy Olsen, Nicolai Langfeldt, Matthew Boyle

=head1 BUGS

Please see L<http://munin-monitoring.org/report/1>.

=head1 COPYRIGHT

Copyright (C) 2003-2006 Jimmy Olsen, Nicolai Langfeldt.

Copyright (C) 2009-2010 Matthew Boyle

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

=cut

# vim: sw=4 : ts=4 : expandtab