File: testplugin

package info (click to toggle)
munin 2.0.76-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,064 kB
  • sloc: perl: 11,684; java: 1,924; sh: 1,632; makefile: 636; javascript: 365; python: 267
file content (147 lines) | stat: -rw-r--r-- 3,098 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/perl

# 21:59 < janll> 1. good config, no fetch
# 22:00 < janll> 2. no config, good fetch
# 22:00 < janll> 3. no config, no fetch
# 22:00 < janll> 4. broken config, good fetch
# 22:00 < janll> 5. good config, broken fetch
# 22:00 < janll> 6. broken everything
#
# 22:03 < janll> modes of breakage: mistyped keywords, missing keywords, missing
#                values, illegal values

# Plugin filename = testplugin
#
# env.config {good,bad}
# - good: working output
# - bad: non-working output
#
# env.fetch {good,bad}
# - good: working output
# - bad: non-working output
#
# env.aspect {minimal,normal,broken,weird}
# - minimal: barebone requirements
# - normal: a regular run
# - broken: regular identifiers, broken values
# - weird: broken identifiers, regular output
#
# env.other {sleep,die,disturb}
# - sleep: waits 30 seconds before giving any output
# - die: exits right away, weird exit code.
# - disturb: swaps config and regular run
#
# Plugin basename = testplugin_

# use strict;
use Data::Dumper;
use vars qw ($configure_mode %aspects %config %fetch);

my $config = ($ENV{'config'} || 'good');
my $fetch  = ($ENV{'fetch'}  || 'good');
my $aspect = ($ENV{'aspect'} || 'normal');
my $other  = ($ENV{'other'}  || '');

my $arg = $ARGV[0];
if ($arg eq "config") {
  $configure_mode = 1;
}

%config = (
    good => {
	minimal => {
	    'graph_title' => 'Test plugin',
	    'test.label' => 'Test',
	},
	normal => {
	    'graph_title' => 'Test plugin',
	    'graph_args' => '--base 1000 -l 0',
	    'graph_category' => 'Test',
	    'test.label' => 'Test',
	},
	broken => {
	    'graph_title' => 'Uærk*^~',
	    'graph_category' => 'Test',
	    'test.label' => '',
	},
	weird => {
	    'gräph_ärgs' => '--base 768',
	    'test.label' => 'gnørk',
	},
    },
    bad => {
	minimal => {
	    'graph_title' => '',
	    'test.label' => 'Test',
	},
	normal => {
	    'graph_title' => '',
	    'graph_args' => '--base 1000 -l 0',
	    'graph_category' => 'Test',
	    'test.label' => 'Test',
	},
	broken => {
	    'graph_categöry' => 'Uærk*^~',
	    'test.label' => '',
	},
	weird => {
	    'graph_args' => '--base -14',
	    'test.label' => 'gnørk',
	},
    },
    );
%fetch = (
    good => {
        minimal => {
            'test.value' => 42,
	},
	normal => {
	    'test.value' => 42,
	},
	broken => {
	    'test.value' => '42,34',
	},
	weird => {
	    'test.value' => 'ø',
	}
    },
    bad => {
        minimal => {
            'test.value' => '',
        },
	normal => {
	    'test.value' => '',
	},
	broken => {
	    'test.valüe' => '',
	},
        weird => {
            'test.value' => 'ø',
        },
    },
    );

my $line;

if ($other eq 'sleep') {
    sleep 30;
} elsif ($other eq 'die') {
    exit 17;
}

if ($other eq 'disturb') {
    $configure_mode -= 1;
}


if ($configure_mode) {
    foreach $line (keys %{$config{$config}->{$aspect}}) {
        print $line, " ", $config{$config}->{$aspect}->{$line}, "\n";
    }
} else {
    foreach $line (keys %{$fetch{$fetch}->{$aspect}}) {
        print $line, " ", $fetch{$fetch}->{$aspect}->{$line}, "\n";
    }
}