aboutsummaryrefslogtreecommitdiffstats
path: root/sitesummary-nodes
blob: 8fd3478c02ae2cf26c20d008ec00c1535c06b80a (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
#!/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;
    # Should check debian/dpkg-l for 'ii *munin-node '
    1; # Assume all nodes are munin nodes for now
}

sub print_munin_list {
    for my $hostname (sort keys %hostnames) {
        return 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
    }
}