blob: 1ac8fa17601e317f47ffa8e2dabea5b88273641a (
plain)
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
|
#!/usr/bin/perl
#
# Generate list of nodes to load from /etc/munin/munin.conf to check
# all the machines reporting to sitesummary.
use strict;
use warnings;
use SiteSummary;
use Getopt::Std;
my %opts;
getopts("m", \%opts);
my %hostnames;
for_all_hosts(\&handle_host);
if ($opts{'m'}) {
print_munin_list();
} else {
print_list();
}
sub handle_host {
my $hostid = shift;
my $hostname = get_hostname($hostid);
$hostnames{$hostname} = $hostid;
}
sub print_list {
for my $hostname (sort keys %hostnames) {
print "$hostname\n";
}
}
sub is_munin_client {
my $hostid = shift;
# Check debian/dpkg-l for 'ii *munin-node '
my $path = get_filepath_current($hostid, "/debian/dpkg-l");
if (open (my $fh, $path)) {
while(<$fh>) {
if (m/^ii *munin-node /) {
close($fh);
return 1
}
}
close($fh);
}
return undef;
}
sub print_munin_list {
for my $hostname (sort keys %hostnames) {
next unless (is_munin_client($hostnames{$hostname}));
# Using hostname as address, to avoid hardcoding IP addresses in
# the file. Might be an idea to fetch the IP address from
# system/ifconfig-a
print <<EOF;
[$hostname]
address $hostname
use_node_name yes
EOF
}
}
|