Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / nagios / nagios_multi_ @ 8589c6df

Historique | Voir | Annoter | Télécharger (30,8 ko)

1
#!/usr/bin/perl
2
#
3
=head1 NAGIOS MULTIGRAPH
4

    
5
A Plugin to monitor Nagios Servers and their Performance (Multigraph)
6

    
7
=head1 MUNIN CONFIGURATION
8

    
9
[nagios_multi_*]
10
 user root
11
 env.binary /usr/local/nagios/bin/nagiostats *default*
12
 env.passive off *default*
13

    
14
=head2 MUNIN ENVIRONMENT CONFIGURATION EXPLANATION
15

    
16
 binary = location of your nagiostats binary including binary
17
 passive = tell the plugin to graph passive results 
18

    
19
=head1 NODE CONFIGURATION
20

    
21
 Make sure the nagiostats binary exists and is executable by root
22
 or by the user specified that the plugin will run as.
23

    
24
 Available root graphs and subgraphs contained in this Plugin.
25

    
26
 services => I<MULTIGRAPH> This graphs the current service problems.
27
    svcchkdetail => This graph shows current services warning,critical,unknown,checked,scheduled,flapping,down
28
    svcchkext => This graph shows the service check execution times
29
    svcchklat => This graph shows the service check latency times
30
    svcchksc => This graph shows the service check state change %
31

    
32
 hosts => I<MULTIGRAPH> This graphs the current host problems.
33
    hostchkdetail => This graph shows current hosts down,unreachable,checked,scheduled,flapping,down
34
    hostchkext => This graph shows the host check execution times
35
    hostchklat => This graph shows the host check latency times
36
    hostchksc => This graph shows the host check state change %
37

    
38
 checks => I<MULTIGRAPH> This graphs the current host problems.
39
    extcmdcount => This graph shows external command buffer availability / usage
40
    hostchkactcount => This graph shows the active host checks for the last 1,5,15,60M
41
    hostchkpsvcount => This graph shows the passive host checks for the last 1,5,15,60M
42
        * depends on passive flag, which defaults to off, and forces these graphs to not be drawn
43
    svcchkactcount => This graph shows the active service checks for the last 1,5,15,60M
44
    svcchkpsvcount => This graph shows the passive service checks for the last 1,5,15,60M
45
        * depends on passive flag, which defaults to off, and forces these graphs to not be drawn
46

    
47
=head1 MUNIN PLUGIN DOCUMENTATION
48

    
49
    This is just some helpful links for plugin troubleshooting.
50

    
51
        http://munin-monitoring.org/wiki/Documentation#Plugins
52
        http://munin-monitoring.org/wiki/protocol-config
53

    
54
=head1 AUTHOR
55

    
56
Matt West < https://github.com/mhwest13/Nagios-Munin-Plugin >
57

    
58
=head1 LICENSE
59

    
60
GPLv2
61

    
62
=head1 MAGIC MARKERS
63
  
64
#%# family=auto
65
#%# capabilities=autoconf suggest
66

    
67
=cut
68

    
69
use strict;
70
use warnings;
71
use Munin::Plugin;
72
use File::Basename;
73

    
74
if (basename($0) !~ /^nagios_multi_/) {
75
    print "This script needs to be named nagios_multi_ and have symlinks which start the same.\n";
76
    exit 1;
77
}
78

    
79
# tell munin about our multigraph capabilties
80
need_multigraph();
81

    
82
# import binary information or use default setting
83
my $binary = $ENV{binary} || '/usr/local/nagios/bin/nagiostats';
84
unless ((-e $binary) && (-x $binary)) {
85
    # err, I'm unable to run the binary specified
86
    print "no: Unable to execute $binary\n";
87
    exit 1;
88
}
89

    
90
# import passive flag or use default setting
91
my $passive = $ENV{passive} || 'off';
92

    
93
=head1 Graph Declarations
94

    
95
    This block of code builds up all of the graph info for all root / sub graphs.
96

    
97
    %graphs: is a container for all of the graph definition information. In here is where you'll
98
             find the configuration information for munin's graphing procedure.
99
    Format:
100

    
101
    $graph{graph_name} => {
102
        config => {
103
            You'll find the main graph config stored here
104
            { key => value },
105
            { ... },
106
        },
107
        keys => [ 'Name', 'Name', 'Name', ... ],
108
        datasrc => [
109
            Name: name given to data value
110
            Attr: Attribute and value, attribute must be valid plugin argument
111
            { name => 'Name', info => 'info about graph' },
112
            { ... },
113
        ],
114
        results => {
115
            You'll find the results info from a stats call stored here
116
            { key => value },
117
            { ... },
118
        },
119
    }
120

    
121
=cut
122

    
123
my %graphs;
124

    
125
# main graph for service checks 
126
$graphs{services} = {
127
    config => {
128
        args => '--lower-limit 0',
129
        vlabel => 'Service Problems',
130
        category => 'nagios',
131
        title => 'Service Problems',
132
        info => 'Current Service Problems by Alert Status',
133
    },
134
    keys => [ 'NUMSVCOK', 'NUMSVCWARN', 'NUMSVCUNKN', 'NUMSVCCRIT' ],
135
    datasrc => [
136
        { name => 'NUMSVCOK', label => 'Up', min => '0', type => 'GAUGE', info => 'number of services which are Ok.', graph => 'no', draw => 'LINE2' },
137
        { name => 'NUMSVCWARN', label => 'Warning', min => '0', type => 'GAUGE', info => 'number of services which are Warning.', draw => 'LINE2' },
138
        { name => 'NUMSVCUNKN', label => 'Unknown', min => '0', type => 'GAUGE', info => 'number of services which are Unknown.', draw => 'LINE2' },
139
        { name => 'NUMSVCCRIT', label => 'Critical', min => '0', type => 'GAUGE', info => 'number of services which are Critical.', draw => 'LINE2' },
140
    ],
141
};
142
# multi-graph for service check detail information ( sub graph of service problems graph )
143
$graphs{svcchkdetail} = {
144
    config => {
145
        args => '--lower-limit 0',
146
        vlabel => 'Total Number of Service Checks',
147
        category => 'details',
148
        title => 'Detailed Service Info',
149
        info => 'Detailed Service Check Information',
150
    },
151
    keys => [ 'NUMSVCWARN', 'NUMSVCUNKN', 'NUMSVCCRIT', 'NUMSVCCHECKED', 'NUMSVCSCHEDULED', 'NUMSVCFLAPPING', 'NUMSVCDOWNTIME' ],
152
    datasrc => [
153
        { name => 'NUMSVCWARN', label => 'Warning', min => '0', type => 'GAUGE', info => 'number of services which are Warning.', draw => 'LINE2' },
154
        { name => 'NUMSVCUNKN', label => 'Unknown', min => '0', type => 'GAUGE', info => 'number of services which are Unknown.', draw => 'LINE2' },
155
        { name => 'NUMSVCCRIT', label => 'Critical', min => '0', type => 'GAUGE', info => 'number of services which are Critical.', draw => 'LINE2' },
156
        { name => 'NUMSVCCHECKED', label => 'Checked', min => '0', type => 'GAUGE', info => 'total number of services that have been checked since start.', draw => 'LINE2' },
157
        { name => 'NUMSVCSCHEDULED', label => 'Scheduled', min => '0', type => 'GAUGE', info => 'total number of services that are currently scheduled to be checked.', draw => 'LINE2' },
158
        { name => 'NUMSVCFLAPPING', label => 'Flapping', min => '0', type => 'GAUGE', info => 'total number of services that are currently flapping.', draw => 'LINE2' },
159
        { name => 'NUMSVCDOWNTIME', label => 'Scheduled Downtime', min => '0', type => 'GAUGE', info => 'total number of services that are currently in scheduled downtime.', draw => 'LINE2' },
160
    ],
161
};
162
# multi-graph for service check % state change ( sub graph of service problems graph )
163
$graphs{svcchksc} = {
164
    config => {
165
        args => '--lower-limit 0 --upper-limit 100',
166
        vlabel => '%',
167
        category => 'statechange',
168
        title => 'Service State Change',
169
        info => 'Total Percent of State Change between checks',
170
    },
171
    keys => [ 'MINSVCPSC', 'MAXSVCPSC', 'AVGSVCPSC' ],
172
    datasrc => [
173
        { name => 'MINSVCPSC', label => 'Min', min => '0', type => 'GAUGE', info => 'min service check % state change.', draw => 'AREA' },
174
        { name => 'MAXSVCPSC', label => 'Max', min => '0', type => 'GAUGE', info => 'max service check % state change.', draw => 'AREA' },
175
        { name => 'AVGSVCPSC', label => 'Average', min => '0', type => 'GAUGE', info => 'avg service check % state change.', draw => 'LINE2' },
176
    ],
177
};
178
# multi-graph for service check latency and execution times ( sub graph of service problems graph )
179
$graphs{svcchklat} = {
180
    config => {
181
        args => '--lower-limit 0',
182
        vlabel => 'time (ms)',
183
        category => 'latency',
184
        title => 'Service Check Latency Times',
185
        info => 'Service Check Latency Times',
186
    },
187
    keys => [ 'MINACTSVCLAT', 'MAXACTSVCLAT', 'AVGACTSVCLAT' ],
188
    datasrc => [
189
        { name => 'MINACTSVCLAT', label => 'Min Latency', min => '0', type => 'GAUGE', info => 'min active service check latency (ms).', draw => 'LINE2' },
190
        { name => 'MAXACTSVCLAT', label => 'Max Latency', min => '0', type => 'GAUGE', info => 'max active service check latency (ms).', draw => 'LINE2' },
191
        { name => 'AVGACTSVCLAT', label => 'Average Latency', min => '0', type => 'GAUGE', info => 'avg active service check latency (ms).', draw => 'LINE2' },
192
    ],
193
};
194
# multi-graph for service check execution time ( sub graph of service problems graph )
195
$graphs{svcchkext} = {
196
    config => {
197
        args => '--lower-limit 0',
198
        vlabel => 'time (ms)',
199
        category => 'execution',
200
        title => 'Service Check Execution Times',
201
        info => 'Service Check Execution Times',
202
    },
203
    keys => [ 'MINACTSVCEXT', 'MAXACTSVCEXT', 'AVGACTSVCEXT' ],
204
    datasrc => [
205
        { name => 'MINACTSVCEXT', label => 'Min Execution', min => '0', type => 'GAUGE', info => 'min active service check execution time (ms).', draw => 'LINE2' },
206
        { name => 'MAXACTSVCEXT', label => 'Max Execution', min => '0', type => 'GAUGE', info => 'max active service check execution time (ms).', draw => 'LINE2' },
207
        { name => 'AVGACTSVCEXT', label => 'Average Execution', min => '0', type => 'GAUGE', info => 'avg active service check execution time (ms).', draw => 'LINE2' },
208
    ],
209
};
210
# main graph for host problems 
211
$graphs{hosts} = {
212
    config => {
213
        args => '--lower-limit 0',
214
        vlabel => 'Host Problems',
215
        category => 'nagios',
216
        title => 'Host Problems',
217
        info => 'Current Host Problems by Alert Status',
218
    },
219
    keys => [ 'NUMHSTUP', 'NUMHSTDOWN', 'NUMHSTUNR' ],
220
    datasrc => [
221
        { name => 'NUMHSTUP', label => 'Up', min => '0', type => 'GAUGE', info => 'number of hosts up.', graph => 'no', draw => 'LINE2' },
222
        { name => 'NUMHSTDOWN', label => 'Down', min => '0', type => 'GAUGE', info => 'number of hosts which are down.', draw => 'LINE2' },
223
        { name => 'NUMHSTUNR', label => 'Unknown', min => '0', type => 'GAUGE', info => 'number of hosts which are Unreachable.', draw => 'LINE2' },
224
    ],
225
};
226
# multi-graph for host check detail information ( sub graph of host problems graph )
227
$graphs{hostchkdetail} = {
228
    config => {
229
        args => '--lower-limit 0',
230
        vlabel => 'Total Number of Host Checks',
231
        category => 'details',
232
        title => 'Detailed Host Info',
233
        info => 'Detailed Host Check Information',
234
    },
235
    keys => [ 'NUMHSTDOWN', 'NUMHSTUNR', 'NUMHSTCHECKED', 'NUMHSTSCHEDULED', 'NUMHSTFLAPPING', 'NUMHSTDOWNTIME' ],
236
    datasrc => [
237
        { name => 'NUMHSTDOWN', label => 'Down', min => '0', type => 'GAUGE', info => 'number of hosts which are down.', draw => 'LINE2' },
238
        { name => 'NUMHSTUNR', label => 'Unknown', min => '0', type => 'GAUGE', info => 'number of hosts which are Unreachable.', draw => 'LINE2' },
239
        { name => 'NUMHSTCHECKED', label => 'Checked', min => '0', type => 'GAUGE', info => 'total number of hosts that have been checked since start.', draw => 'LINE2' },
240
        { name => 'NUMHSTSCHEDULED', label => 'Scheduled', min => '0', type => 'GAUGE', info => 'total number of hosts that are currently scheduled to be checked.', draw => 'LINE2' },
241
        { name => 'NUMHSTFLAPPING', label => 'Flapping', min => '0', type => 'GAUGE', info => 'total number of hosts that are currently flapping.', draw => 'LINE2' },
242
        { name => 'NUMHSTDOWNTIME', label => 'Downtime', min => '0', type => 'GAUGE', info => 'total number of hosts that are currently in scheduled downtime.', draw => 'LINE2' },
243
    ],
244
};
245
# multi-graph for host check % state change ( sub graph of host problems graph )
246
$graphs{hostchksc} = {
247
    config => {
248
        args => '--lower-limit 0 --upper-limit 100',
249
        vlabel => '%',
250
        category => 'statechange',
251
        title => 'Host State Change',
252
        info => 'Total Percent of State Change between checks',
253
    },
254
    keys => [ 'MINHSTPSC', 'MAXHSTPSC', 'AVGHSTPSC' ],
255
    datasrc => [
256
        { name => 'MINHSTPSC', label => 'Min', min => '0', type => 'GAUGE', info => 'min host check % state change.', draw => 'AREA' },
257
        { name => 'MAXHSTPSC', label => 'Max', min => '0', type => 'GAUGE', info => 'max host check % state change.', draw => 'AREA' },
258
        { name => 'AVGHSTPSC', label => 'Average', min => '0', type => 'GAUGE', info => 'avg host check % state change.', draw => 'LINE2' },
259
    ],
260
};
261
# multi-graph for host check latency times ( sub graph of host problems graph )
262
$graphs{hostchklat} = {
263
    config => {
264
        args => '--lower-limit 0',
265
        vlabel => 'time (ms)',
266
        category => 'latency',
267
        title => 'Host Check Latency Times',
268
        info => 'Host Check Latency Times',
269
    },
270
    keys => [ 'MINACTHSTLAT', 'MAXACTHSTLAT', 'AVGACTHSTLAT' ],
271
    datasrc => [
272
        { name => 'MINACTHSTLAT', label => 'Min Latency', min => '0', type => 'GAUGE', info => 'min active host check latency (ms).', draw => 'LINE2' },
273
        { name => 'MAXACTHSTLAT', label => 'Max Latency', min => '0', type => 'GAUGE', info => 'max active host check latency (ms).', draw => 'LINE2' },
274
        { name => 'AVGACTHSTLAT', label => 'Average Latency', min => '0', type => 'GAUGE', info => 'avg active host check latency (ms).', draw => 'LINE2' },
275
    ],
276
};
277
# multi-graph for host check execution times ( sub graph of host problems graph )
278
$graphs{hostchkext} = {
279
    config => {
280
        args => '--lower-limit 0',
281
        vlabel => 'time (ms)',
282
        category => 'execution',
283
        title => 'Host Check Execution Times',
284
        info => 'Host Check Execution Times',
285
    },
286
    keys => [ 'MINACTHSTEXT', 'MAXACTHSTEXT', 'AVGACTHSTEXT' ],
287
    datasrc => [
288
        { name => 'MINACTHSTEXT', label => 'Min Execution', min => '0', type => 'GAUGE', info => 'min active host check execution time (ms).', draw => 'LINE2' },
289
        { name => 'MAXACTHSTEXT', label => 'Max Execution', min => '0', type => 'GAUGE', info => 'max active host check execution time (ms).', draw => 'LINE2' },
290
        { name => 'AVGACTHSTEXT', label => 'Average Execution', min => '0', type => 'GAUGE', info => 'avg active host check execution time (ms).', draw => 'LINE2' },
291
    ],
292
};
293
# main graph for host / service check counts 
294
$graphs{checks} = {
295
    config => {
296
        args => '--lower-limit 0',
297
        vlabel => 'Total Number of Checks',
298
        category => 'nagios',
299
        title => 'Totals',
300
        info => 'Total Number of Service and Host Checks',
301
    },
302
    keys => [ 'NUMSERVICES', 'NUMHOSTS' ],
303
    datasrc => [
304
        { name => 'NUMSERVICES', label => 'Number of Services', min => '0', type => 'GAUGE', info => 'total number of services.', draw => 'LINE2' },
305
        { name => 'NUMHOSTS', label => 'Number of Hosts', min => '0', type => 'GAUGE', info => 'total number of hosts.', draw => 'LINE2' },
306
    ],
307
};
308
# multi-graph for number of host checks in x mins ( sub graph of checks graph )
309
$graphs{hostchkactcount} = {
310
    config => {
311
        args => '--lower-limit 0',
312
        vlabel => 'Number Host Checks',
313
        category => 'active',
314
        title => 'Host Checks',
315
        info => 'Total Number of Active Host Checks',
316
        order => 'NUMHSTACTCHK60M NUMHSTACTCHK15M NUMHSTACTCHK5M NUMHSTACTCHK1M',
317
    },
318
    keys => [ 'NUMHSTACTCHK1M', 'NUMHSTACTCHK5M', 'NUMHSTACTCHK15M', 'NUMHSTACTCHK60M' ],
319
    datasrc => [
320
        { name => 'NUMHSTACTCHK1M', label => 'Active Checks 1m', min => '0', type => 'GAUGE', info => 'number of hosts actively checked in last 1 minutes.', draw => 'AREA' },
321
        { name => 'NUMHSTACTCHK5M', label => 'Active Checks 5m', min => '0', type => 'GAUGE', info => 'number of hosts actively checked in last 5 minutes.', draw => 'AREA' },
322
        { name => 'NUMHSTACTCHK15M', label => 'Active Checks 15m', min => '0', type => 'GAUGE', info => 'number of hosts actively checked in last 15 minutes.', draw => 'AREA' },
323
        { name => 'NUMHSTACTCHK60M', label => 'Active Checks 60m', min => '0', type => 'GAUGE', info => 'number of hosts actively checked in last 60 minutes.', draw => 'AREA' },
324
    ],
325
};
326
# multi-graph for number of host checks in x mins ( sub graph of checks graph )
327
$graphs{hostchkpsvcount} = {
328
    config => {
329
        args => '--lower-limit 0',
330
        vlabel => 'Number Host Checks',
331
        category => 'passive',
332
        title => 'Host Checks',
333
        info => 'Total Number of Passive Host Checks',
334
        order => 'NUMHSTPSVCHK60M NUMHSTPSVCHK15M NUMHSTPSVCHK5M NUMHSTPSVCHK1M',
335
    },
336
    keys => [ 'NUMHSTPSVCHK1M', 'NUMHSTPSVCHK5M', 'NUMHSTPSVCHK15M', 'NUMHSTPSVCHK60M' ],
337
    datasrc => [
338
        { name => 'NUMHSTPSVCHK1M', label => 'Passive Checks 1m', min => '0', type => 'GAUGE', info => 'number of hosts passively checked in last 1 minutes.', draw => 'AREA' },
339
        { name => 'NUMHSTPSVCHK5M', label => 'Passive Checks 5m', min => '0', type => 'GAUGE', info => 'number of hosts passively checked in last 5 minutes.', draw => 'AREA' },
340
        { name => 'NUMHSTPSVCHK15M', label => 'Passive Checks 15m', min => '0', type => 'GAUGE', info => 'number of hosts passively checked in last 15 minutes.', draw => 'AREA' },
341
        { name => 'NUMHSTPSVCHK60M', label => 'Passive Checks 60m', min => '0', type => 'GAUGE', info => 'number of hosts passively checked in last 60 minutes.', draw => 'AREA' },
342
    ],
343
};
344
# multi-graph for number of service checks in x mins ( sub graph of checks graph )
345
$graphs{svcchkactcount} = {
346
    config => {
347
        args => '--lower-limit 0',
348
        vlabel => 'Number of Service Checks',
349
        category => 'active',
350
        title => 'Service Checks',
351
        info => 'Total Number of Active Service Checks',
352
        order => 'NUMSVCACTCHK60M NUMSVCACTCHK15M NUMSVCACTCHK5M NUMSVCACTCHK1M',
353
    },
354
    keys => [ 'NUMSVCACTCHK1M', 'NUMSVCACTCHK5M', 'NUMSVCACTCHK15M', 'NUMSVCACTCHK60M' ],
355
    datasrc => [
356
        { name => 'NUMSVCACTCHK1M', label => 'Active Checks 1m', min => '0', type => 'GAUGE', info => 'number of services actively checked in last 1 minutes.', draw => 'AREA' },
357
        { name => 'NUMSVCACTCHK5M', label => 'Active Checks 5m', min => '0', type => 'GAUGE', info => 'number of services actively checked in last 5 minutes.', draw => 'AREA' },
358
        { name => 'NUMSVCACTCHK15M', label => 'Active Checks 15m', min => '0', type => 'GAUGE', info => 'number of services actively checked in last 15 minutes.', draw => 'AREA' },
359
        { name => 'NUMSVCACTCHK60M', label => 'Active Checks 60m', min => '0', type => 'GAUGE', info => 'number of services actively checked in last 60 minutes.', draw => 'AREA' },
360
    ],
361
};
362
# multi-graph for number of service checks in x mins ( sub graph of checks graph )
363
$graphs{svcchkpsvcount} = {
364
    config => {
365
        args => '--lower-limit 0',
366
        vlabel => 'Number of Service Checks',
367
        category => 'passive',
368
        title => 'Service Checks',
369
        info => 'Total Number of Passive Service Checks',
370
        order => 'NUMSVCPSVCHK60M NUMSVCPSVCHK15M NUMSVCPSVCHK5M NUMSVCPSVCHK1M',
371
    },
372
    keys => [ 'NUMSVCPSVCHK1M', 'NUMSVCPSVCHK5M', 'NUMSVCPSVCHK15M', 'NUMSVCPSVCHK60M' ],
373
    datasrc => [
374
        { name => 'NUMSVCPSVCHK1M', label => 'Passive Checks 1m', min => '0', type => 'GAUGE', info => 'number of services passively checked in last 1 minutes.', draw => 'AREA' },
375
        { name => 'NUMSVCPSVCHK5M', label => 'Passive Checks 5m', min => '0', type => 'GAUGE', info => 'number of services passively checked in last 5 minutes.', draw => 'AREA' },
376
        { name => 'NUMSVCPSVCHK15M', label => 'Passive Checks 15m', min => '0', type => 'GAUGE', info => 'number of services passively checked in last 15 minutes.', draw => 'AREA' },
377
        { name => 'NUMSVCPSVCHK60M', label => 'Passive Checks 60m', min => '0', type => 'GAUGE', info => 'number of services passively checked in last 60 minutes.', draw => 'AREA' },
378
    ],
379
};
380
# multi-graph for external command count ( sub graph of checks graph )
381
$graphs{extcmdcount} = {
382
    config => {
383
        args => '--lower-limit 0',
384
        vlabel => 'Number of Ext Command Slots',
385
        category => 'externalcmds',
386
        title => 'External Commands',
387
        info => 'External Command Buffer Slot Information',
388
    },
389
    keys => [ 'TOTCMDBUF', 'USEDCMDBUF', 'HIGHCMDBUF', 'NUMEXTCMDS1M', 'NUMEXTCMDS5M', 'NUMEXTCMDS15M' ],
390
    datasrc => [
391
        { name => 'TOTCMDBUF', label => 'Total', min => '0', type => 'GAUGE', info => 'total number of external command buffer slots available.', draw => 'AREA' },
392
        { name => 'USEDCMDBUF', label => 'Current Used', min => '0', type => 'GAUGE', info => 'number of external command buffer slots currently in use.', draw => 'LINE2' },
393
        { name => 'HIGHCMDBUF', label => 'Peak Used', min => '0', type => 'GAUGE', info => 'highest number of external command buffer slots ever in use.', draw => 'LINE2' },
394
        { name => 'NUMEXTCMDS1M', label => 'Used last 1m', min => '0', type => 'GAUGE', info => 'number of external commands processed in last 1 minutes.', draw => 'LINE2' },
395
        { name => 'NUMEXTCMDS5M', label => 'Used last 5m', min => '0', type => 'GAUGE', info => 'number of external commands processed in last 5 minutes.', draw => 'LINE2' },
396
        { name => 'NUMEXTCMDS15M', label => 'Used last 15m', min => '0', type => 'GAUGE', info => 'number of external commands processed in last 15 minutes.', draw => 'LINE2' },
397
    ],
398
};
399

    
400
=head1 Munin Checks
401

    
402
    These checks look for config / autoconf / suggest params
403

    
404
=head2 Config Check
405

    
406
    This block of code looks at the argument that is possibly supplied,
407
    should it be config, it then checks to make sure the plugin 
408
    specified exists, assuming it does, it will run the do_config 
409
    subroutine for the plugin specified, otherwise it dies complaining
410
    about an unknown plugin.
411

    
412
=cut
413

    
414
if (defined $ARGV[0] && $ARGV[0] eq 'config') {
415
    # Lets take the plugin from the execution name.
416
    $0 =~ /nagios_multi_(.+)*/;
417
    my $plugin = $1;
418
    # And lets make sure we have a plugin called that.
419
    die 'Unknown Plugin Specified: ' . ($plugin ? $plugin : '') unless $graphs{$plugin};
420
    # Now lets go ahead and print out our config.
421
	do_config($plugin);
422
	exit 0;
423
}
424

    
425
=head2 Autoconf Check
426

    
427
    This block of code looks at the argument that is possibly supplied,
428
    should it be autoconf, we are going to print yes at this point since
429
    we've already tested for our binary to exist and be executable, the
430
    process will then exit.
431

    
432
=cut
433

    
434
if (defined $ARGV[0] && $ARGV[0] eq 'autoconf') {
435
    # well we can execute the binary, so plugin should be good from here...
436
    print "yes\n";
437
    exit 0;
438
}
439

    
440
=head2 Suggest Check
441

    
442
    This block of code looks at the argument that is possibly supplied,
443
    should it be suggest, we are going to print the possible plugins
444
    which can be specified. Note we only specify the root graphs for the
445
    multigraphs, since the rest of the subgraphs will appear "behind" the
446
    root graphs.
447

    
448
=cut
449

    
450
if (defined $ARGV[0] && $ARGV[0] eq 'suggest') {
451
    # well we can execute the binary, so print possible root multigraph plugin names
452
    my @rootplugins = ('services','hosts','checks');
453
    foreach my $plugin (@rootplugins) {
454
        print "$plugin\n";
455
    }
456
    exit 0;
457
}
458

    
459
=head1 Subroutines
460

    
461
    Begin Subroutine calls to output data / config information
462

    
463
=head2 fetch_output
464

    
465
    This subroutine is the main call for printing data for the plugin.
466
    No parameters are taken as this is the default call if no arguments
467
    are supplied from the command line.
468

    
469
=cut
470

    
471
fetch_output();
472

    
473
sub fetch_output {
474
    # Lets figure out what plugin they want to run, and check that it exists
475
    $0 =~ /nagios_multi_(.+)*/;
476
    my $plugin = $1;
477
    die 'Unknown Plugin Specified: ' . ($plugin ? $plugin : '') unless $graphs{$plugin};
478
    # Lets set up our subgraphs array with all of the graphs which are extensions
479
    # of the root graph / plugin
480
    my @subgraphs;
481
    if ($plugin eq 'services') {
482
        @subgraphs = ('svcchkdetail','svcchksc','svcchklat','svcchkext');
483
    } elsif ($plugin eq 'hosts') {
484
        @subgraphs = ('hostchkdetail','hostchksc','hostchklat','hostchkext');
485
    } elsif ($plugin eq 'checks') {
486
        @subgraphs = ('svcchkactcount','hostchkactcount','extcmdcount');
487
        if ($passive =~ /on/i) {
488
            push(@subgraphs,'svcchkpsvcount');
489
            push(@subgraphs,'hostchkpsvcount');
490
        }
491
    }
492
    # Lets just double check the plugin you specified is a root graph / plugin
493
    if (grep $_ eq $plugin, @subgraphs) {
494
        die "Error: $plugin is not a valid root graph, valid graphs are: @subgraphs\n";
495
    }
496
    # Lets print out the data for our sub graphs / plugins
497
    foreach my $subgraph (@subgraphs) {
498
        print_sub_output($plugin,$subgraph);
499
    }
500
    # Lets print out the data for our main graph / plugin
501
    print_root_output($plugin);
502
    return;
503
}
504

    
505
=head2 print_root_output
506

    
507
    This block of code prints out the return values for our root graphs. It takes
508
    one parameter $plugin. Returns when completed
509

    
510
        $plugin;    main(root) graph we are calling up to print data values for
511

    
512
    Example: print_root_output($plugin);
513

    
514
=cut
515

    
516
sub print_root_output {
517
    # Lets get our plugin, set our graph information, and print for Munin to process
518
    my ($plugin) = (@_);
519
    my $graph = $graphs{$plugin};
520
    print "multigraph nagios_$plugin\n";
521
    # Getting keys to pass to nagiostats for data retrieval
522
    # call up fetch_nagios_stats with the keys we just got.
523
    my @keys = @{$graph->{keys}};
524
    fetch_nagios_stats($plugin,@keys);
525
    # print the results for the keys with the name for Munin to process
526
    foreach my $dsrc (@{$graph->{datasrc}}) {
527
        my $output = 0;
528
        my %datasrc = %$dsrc;
529
        while ( my ($key, $value) = each(%datasrc)) {
530
            next if ($key ne 'name');
531
            print "$dsrc->{name}.value $graph->{results}->{$value}\n";
532
        }
533
    }
534
    return;
535
}
536

    
537
=head2 print_sub_output
538

    
539
    This block of code prints out the return values for our root graphs. It takes
540
    one parameter $plugin. Returns when completed
541

    
542
        $plugin;    main(root) being called, used for multigraph output
543
        $subgraph;  graph we are actually trying to print data values for
544

    
545
    Example: print_sub_output($plugin,$subgraph);
546

    
547
=cut
548

    
549
sub print_sub_output {
550
    # Lets get our plugin, set our graph information, and print for Munin to process
551
    my ($plugin,$subgraph) = (@_);
552
    my $graph = $graphs{$subgraph};
553
    print "multigraph nagios_$plugin\.$subgraph\n";
554
    # Getting keys to pass to nagiostats for data retrieval
555
    # call up fetch_nagios_stats with the keys we just got.
556
    my @keys = @{$graph->{keys}};
557
    fetch_nagios_stats($subgraph,@keys);
558
    # print the results for the keys with the name for Munin to process
559
    foreach my $dsrc (@{$graph->{datasrc}}) {
560
        my $output = 0;
561
        my %datasrc = %$dsrc;
562
        while ( my ($key, $value) = each(%datasrc)) {
563
            next if ($key ne 'name');
564
            print "$dsrc->{name}.value $graph->{results}->{$value}\n";
565
        }
566
    }
567
    return;
568
}
569

    
570
=head2 do_config
571

    
572
    This is the main call issued assuming we call up config and plugin specified exists
573
    The subroutine takes one parameter $plugin, and returns when completed.
574

    
575
        $plugin; main(root) graph being called
576

    
577
    Example: do_config($plugin);
578

    
579
=cut
580

    
581
sub do_config {
582
    # Lets get our plugin and set subgraphs to undef
583
    my ($plugin) = (@_);
584
    my @subgraphs;
585
    if ($plugin eq 'services') {
586
        # update subgraphs since our plugin is services
587
        @subgraphs = ('svcchkdetail','svcchksc','svcchklat','svcchkext');
588
    } elsif ($plugin eq 'hosts') {
589
        # update subgraphs since our plugin is hosts
590
        @subgraphs = ('hostchkdetail','hostchksc','hostchklat','hostchkext');
591
    } elsif ($plugin eq 'checks') {
592
        # update subgraphs since our plugin is checks
593
        @subgraphs = ('svcchkactcount','hostchkactcount','extcmdcount');
594
        if ($passive =~ /on/i) {
595
            push(@subgraphs,'svcchkpsvcount');
596
            push(@subgraphs,'hostchkpsvcount');
597
        }
598
    }
599
    # Now that we know what graphs to reference, lets print out their config info
600
    foreach my $subgraph (@subgraphs) {
601
        print_sub_config($plugin,$subgraph);
602
    }
603
    # Now lets print out the config information for our root graph
604
    print_root_config($plugin);
605
    return;
606
}
607

    
608
=head2 print_sub_config
609

    
610
    This subroutine prints out the config information for all of the subgraphs.
611
    It takes two parameters, $plugin and $subgraph
612

    
613
        $plugin;    main(root) graph used for multigraph call
614
        $subgraph;  subgraph being called up.
615

    
616
    Example:  print_sub_config($plugin,$subgraph);
617

    
618
=cut
619

    
620
sub print_sub_config {
621
    # Lets get our plugin and subgraph, after that print for Munin to process it. 
622
    my ($plugin,$subgraph) = (@_);
623
    my $graph = $graphs{$subgraph};
624
    print "multigraph nagios_$plugin.$subgraph\n";
625
    # Lets print our subgraph's main config info.
626
    my %graphconf = %{$graph->{config}};
627
    while ( my ($key, $value) = each(%graphconf)) {
628
        print "graph_$key $value\n";
629
    }
630
    # Lets print our subgraph's per graph config info.
631
    foreach my $dsrc (@{$graph->{datasrc}}) {
632
        my %datasrc = %$dsrc;
633
        while ( my ($key, $value) = each(%datasrc)) {
634
            next if ($key eq 'name');
635
            print "$dsrc->{name}.$key $value\n";
636
        }
637
    }
638
    return;
639
}
640

    
641
=head2 print_root_config
642

    
643
    This subroutine prints out the config information for all of the main(root) graphs.
644
    It takes one parameters, $plugin
645

    
646
        $plugin;    main(root) graph used for multigraph call
647

    
648
    Example:  print_root_config($plugin);
649

    
650
=cut
651

    
652
sub print_root_config {
653
    # Lets get our plugin and graph, after that print for Munin to process it.
654
    my ($plugin) = (@_);
655
    my $graph = $graphs{$plugin};
656
    print "multigraph nagios_$plugin\n";
657
    # Lets print out graph's main config info.
658
    my %graphconf = %{$graph->{config}};
659
    while ( my ($key, $value) = each(%graphconf)) {
660
        print "graph_$key $value\n";
661
    }
662
    # Lets print our graphs per graph config info.
663
    foreach my $dsrc (@{$graph->{datasrc}}) {
664
        my %datasrc = %$dsrc;
665
        while ( my ($key, $value) = each(%datasrc)) {
666
            next if ($key eq 'name');
667
            print "$dsrc->{name}.$key $value\n";
668
        }
669
    }
670
    return;
671
}
672

    
673
=head2 fetch_nagios_stats
674

    
675
    This subroutine actually runs the nagiostats binary with the keys specified in an array
676
    Two parameters are passed, $plugin and @keys, and it will return when complete.
677

    
678
        $plugin;    graph we are calling up, we use this to store the results in the hash
679
                    for easy recall later.
680
        @keys;      keys we want the values for from nagiostats binary.
681

    
682
    Example: fetch_nagios_stats($plugin,@keys);
683

    
684
=cut
685

    
686
sub fetch_nagios_stats {
687
    # Lets get our current plugin and list of keys we want info for, as well as reference our graph
688
    my ($plugin,@keys) = (@_);
689
    my $graph = $graphs{$plugin};
690
    # Lets set our command to include our binary plus options, as well as join our array with ,'s
691
    my $command = $binary . " -m -d " . join(",",@keys);
692
    # Lets open the command and pipe it out for easy reading by line
693
    open(CMD, "$command |") or die "Unable to execute command: $command\n";
694
    # While a return exists from the command, store the value in the key specified
695
    while (my $line = <CMD>) {
696
        chomp($line);
697
        my $key = shift(@keys);
698
        $graph->{results}->{$key} = $line;
699
    }
700
    return;
701
}