1# -*- cperl -*-
2# vim: ts=4 : sw=4 : et
3use warnings;
4use strict;
5
6use Test::More tests => 5;
7
8use_ok('Munin::Master::Config');
9
10use Munin::Master::Config;
11use Munin::Common::Defaults;
12
13my $config = Munin::Master::Config->instance();
14my $userconfig = $config->{config};
15
16$userconfig->parse_config(\*DATA);
17
18# Build the correct answer by hand.
19my $fasit = {
20    'root_instance' => 1,
21
22    oldconfig => {
23    	config_file => "$Munin::Common::Defaults::MUNIN_DBDIR/datafile"
24    },
25
26    config => {
27        config_file     => "$Munin::Common::Defaults::MUNIN_CONFDIR/munin.conf",
28        dbdir           => '/opt/munin/sandbox/var/opt/munin',
29        debug           => 0,
30        fork            => 1,
31        graph_data_size => 'normal',
32        graph_strategy  => 'cron',
33        groups          => {
34            marvin => {
35                hosts => {
36                    marvin => {
37                        use_node_name       => 1,
38                        address             => '127.0.0.1',
39                        port                => '4948',
40                        'load1.graph_title' => 'Loads side by side',
41                        'load1.graph_order' => 'fii=fii.foo.com:load.load fay=fay.foo.com:load.load',
42                        host_name           => 'marvin',
43                        update              => 1,
44                    },
45                },
46                group      => undef,
47                group_name => 'marvin',
48            },
49        },
50        htmldir                => '/opt/munin/sandbox/www',
51        local_address          => 0,
52        logdir                 => '/opt/munin/sandbox/var/log/munin',
53        max_processes          => 16,
54        rundir                 => '/opt/munin/sandbox/var/run/munin',
55        ssh_command            => "ssh",
56        ssh_options            => "-o ChallengeResponseAuthentication=no -o StrictHostKeyChecking=no",
57        timeout                => 180,
58        timeout_fetch_all_nodes     => 240,
59        timeout_fetch_one_node       => 180,
60        tls                    => 'disabled',
61        tls_ca_certificate     => '/opt/munin/common/t/tls/CA/ca_cert.pem',
62        tls_certificate        => '/opt/munin/common/t/tls/master_cert.pem',
63        tls_private_key        => '/opt/munin/common/t/tls/master_key.pem',
64        tls_verify_certificate => 1,
65        tls_verify_depth       => '5',
66        tmpldir                => '/opt/munin/sandbox/etc/opt/munin/templates',
67	staticdir              => '/opt/munin/sandbox/etc/opt/munin/static',
68	rrdcached_socket       => '/var/run/rrdcached.sock',
69	cgitmpdir              => '/opt/munin/sandbox/var/cache/munin-cgi',
70    },
71};
72
73$fasit->{config}{groups}{marvin}{hosts}{marvin}{group}
74    = $fasit->{config}{groups}{marvin};
75
76is_deeply($config, $fasit, 'Config hash contents');
77
78
79### _final_char_is
80ok(  Munin::Master::Config::_final_char_is('h', 'blah'), 'it was the last character');
81ok(! Munin::Master::Config::_final_char_is('a', 'blah'), 'it was not the last character');
82ok(! Munin::Master::Config::_final_char_is('z', 'blah'), 'it not in the string at all');
83
84
85__DATA__
86
87# Example configuration file for Munin, generated by 'make build'
88
89# The next three variables specifies where the location of the RRD
90# databases, the HTML output, and the logs, severally.  They all
91# must be writable by the user running munin-cron.
92dbdir	/opt/munin/sandbox/var/opt/munin
93htmldir	/opt/munin/sandbox/www
94logdir	/opt/munin/sandbox/var/log/munin
95rundir  /opt/munin/sandbox/var/run/munin
96
97# Where to look for the HTML templates
98tmpldir	/opt/munin/sandbox/etc/opt/munin/templates
99staticdir /opt/munin/sandbox/etc/opt/munin/static
100
101# Make graphs show values per minute instead of per second
102#graph_period minute
103
104# Graphics files are normally generated on-demand by a CGI process.
105# See http://munin-monitoring.org/wiki/CgiHowto2 for more
106# documentation.
107#
108#graph_strategy cgi
109cgitmpdir /opt/munin/sandbox/var/cache/munin-cgi
110
111# Drop somejuser@fnord.comm and anotheruser@blibb.comm an email everytime
112# something changes (OK -> WARNING, CRITICAL -> OK, etc)
113#contact.someuser.command mail -s "Munin notification" somejuser@fnord.comm
114#contact.anotheruser.command mail -s "Munin notification" anotheruser@blibb.comm
115#
116# For those with Nagios, the following might come in handy. In addition,
117# the services must be defined in the Nagios server as well.
118#contact.nagios.command /usr/bin/send_nsca nagios.host.comm -c /etc/nsca.conf
119
120tls disabled
121tls_private_key /opt/munin/common/t/tls/master_key.pem
122tls_certificate /opt/munin/common/t/tls/master_cert.pem
123tls_ca_certificate /opt/munin/common/t/tls/CA/ca_cert.pem
124tls_verify_certificate yes
125tls_verify_depth 5
126
127rrdcached_socket /var/run/rrdcached.sock
128
129# a simple host tree
130[marvin]
131    address 127.0.0.1
132    port 4948
133    use_node_name yes
134    load1.graph_title Loads side by side
135    load1.graph_order fii=fii.foo.com:load.load fay=fay.foo.com:load.load
136
137#
138# A more complex example of a host tree
139#
140## First our "normal" host.
141# [fii.foo.com]
142#       address foo
143#
144## Then our other host...
145# [fay.foo.com]
146#       address fay
147#
148## Then we want totals...
149# [foo.com;Totals] #Force it into the "foo.com"-domain...
150#       update no   # Turn off data-fetching for this "host".
151#
152#   # The graph "load1". We want to see the loads of both machines...
153#   # "fii=fii.foo.com:load.load" means "label=machine:graph.field"
154#       load1.graph_title Loads side by side
155#       load1.graph_order fii=fii.foo.com:load.load fay=fay.foo.com:load.load
156#
157#   # The graph "load2". Now we want them stacked on top of each other.
158#       load2.graph_title Loads on top of each other
159#       load2.dummy_field.stack fii=fii.foo.com:load.load fay=fay.foo.com:load.load
160#       load2.dummy_field.draw AREA # We want area instead the default LINE2.
161#       load2.dummy_field.label dummy # This is needed. Silly, really.
162#
163#   # The graph "load3". Now we want them summarised into one field
164#       load3.graph_title Loads summarised
165#       load3.combined_loads.sum fii.foo.com:load.load fay.foo.com:load.load
166#       load3.combined_loads.label Combined loads # Must be set, as this is
167#                                                 # not a dummy field!
168#
169## ...and on a side note, I want them listen in another order (default is
170## alphabetically)
171#
172# # Since [foo.com] would be interpreted as a host in the domain "com", we
173# # specify that this is a domain by adding a semicolon.
174# [foo.com;]
175#       node_order Totals fii.foo.com fay.foo.com
176#
177