This file is indexed.

/usr/share/perl5/Munin/Node/Configure/PluginList.pm is in munin-node 2.0.33-1.

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

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
package Munin::Node::Configure::PluginList;

# $Id$

use strict;
use warnings;

use File::Basename qw(fileparse);

use Munin::Node::Service;
use Munin::Node::Configure::Plugin;
use Munin::Node::Configure::History;
use Munin::Node::Configure::Debug;


sub new
{
    my ($class, %opts) = @_;

    my $libdir     = delete $opts{libdir}     or die "Must specify the directory\n";
    my $servicedir = delete $opts{servicedir} or die "Must specify the service directory\n";

    my $library  = Munin::Node::Service->new(servicedir => $libdir);
    my $services = Munin::Node::Service->new(servicedir => $servicedir);

    my $families = delete $opts{families} or die "Must provide a list of families to load\n";
    my $newer    = delete $opts{newer};

    my %plugin = (
        libdir     => $libdir,
        library    => $library,

        servicedir => $servicedir,
        services   => $services,

        families   => $families,
        newer      => $newer,

        %opts,
    );

    return bless \%plugin, $class;
}


### Plugin and service enumeration #############################################

sub load
{
    my ($self) = @_;
    $self->_load_available();
    $self->_load_installed();
    return;
}


sub _load_available
{
    my ($self) = @_;

    my @families = @{$self->{families}};
    my %found;
    my $plugin_count = 0;

    my $history = Munin::Node::Configure::History->new(
        history_file => "$self->{libdir}/plugins.history",
        newer        => $self->{newer},
    );
    $history->load;

    DEBUG("Searching '$self->{libdir}' for available plugins.");

    foreach my $item (_valid_files($self->{library})) {
        my $path = $item->{path};
        my $plug = $item->{name};

        DEBUG("Considering '$path'");

        my $plugin = Munin::Node::Configure::Plugin->new(name => $plug, path => $path);

        $plugin->read_magic_markers();

        unless ($plugin->in_family(@families)) {
            DEBUG("\tFamily '$plugin->{family}' is currently ignored.  Skipping.");
            next;
        }

        if ($history->too_old($plugin)) {
            DEBUG("\tPlugin is older than $self->{newer}.  Skipping.");
            next;
        }

        $found{$plug} = $plugin;
        $plugin_count++;
    }

    $self->{plugins} = \%found;
    DEBUG("$plugin_count plugins available.");

    return;
}


sub _load_installed
{
    my ($self) = @_;
    my $service_count = 0;  # the number of services currently installed.

    DEBUG("Searching '$self->{servicedir}' for installed services.");

    foreach my $item (_valid_files($self->{services})) {
        my $path    = $item->{path};
        my $service = $item->{name};

        my $realfile;
        # Ignore non-symlinks, and symlinks that point anywhere other
        # than the plugin library
        next unless -l $path;
        unless ($realfile = readlink($path)) {
            # FIXME: should be a given, since it's tested by is_a_runnable_service()
            DEBUG("Warning: symlink '$path' is broken.");
            next;
        }
        next unless ($realfile =~ /^$self->{libdir}\//);

        DEBUG("Found '$service'");

        $realfile = fileparse($realfile);
        unless ($self->{plugins}{$realfile}) {
            DEBUG("\tCorresponds to an ignored plugin ($realfile).  Skipping.");
            next;
        }

        $self->{plugins}{$realfile}->add_instance($service);
        $service_count++;
    }

    DEBUG("$service_count services currently installed.");
    return;
}


sub list
{
    my ($self) = @_;
    my @plugins;
    foreach my $plug (sort keys %{$self->{plugins}}) {
        push @plugins, $self->{plugins}{$plug};
    }
    return @plugins;
}


sub names { return keys %{(shift)->{plugins}} }


sub _valid_files
{
    my ($dir) = @_;
    return map { { path => "$dir->{servicedir}/$_", name => $_ } } $dir->list;
}


1;

__END__

=head1 NAME

Munin::Node::Configure::PluginList - Loading and listing a collection of plugins


=head1 SYNOPSIS

  my $plugins = Munin::Node::Configure::PluginList->new(
        libdir     => '/usr/share/munin/plugins/',
        servicedir => '/etc/munin/plugins/',
  );
  $plugins->load('auto');
  foreach my $plugin ($plugins->list) {
        # do something to each 'auto' plugin in turn
  }


=head1 SUBROUTINES

=over

=item B<new(%args)>

Constructor.

Required arguments are 'libdir' and 'servicedir', which are the plugin library
and service directory, respectively.


=item B<load(@families)>

Finds all the plugins in 'libdir' that are in any of @families, and any
instances of these plugins in 'servicedir'.


=item B<list()>

Returns a list of Munin::Node::Configure::Plugin objects currently loaded,
sorted alphabetically by name.


=item B<names()>

Returns the names of the currently-loaded plugins.

=back

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