/[nagios-plugins-perl]/trunk/plugins/check_guirlande.pl
ViewVC logotype

Contents of /trunk/plugins/check_guirlande.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 207 - (show annotations) (download)
Thu Mar 21 15:09:17 2019 UTC (20 months, 1 week ago) by racvision
File MIME type: text/plain
File size: 2156 byte(s)
1 #!/usr/bin/perl -w
2 #
3 # Copyright (c) 2018 St├ęphane URBANOVSKI - CRT Supervision
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #
19 #
20
21 use strict;
22 use warnings;
23
24
25 use POSIX qw(strftime setlocale);
26 use Locale::gettext;
27 use File::Basename;
28
29 use Nagios::Plugin ;
30
31 use Data::Dumper;
32 $Data::Dumper::Terse = 1;
33
34 my $VERSION = '1.0';
35 my $TIMEOUT = 20;
36
37 my $tookWarn = 0.2;
38 my $tookCrit = 1.5;
39
40 my $np = Nagios::Plugin->new(
41 version => $VERSION,
42 blurb => 'Demo plugin returning random states',
43 usage => "Usage: %s [ -v|--verbose ]",
44 timeout => $TIMEOUT+1
45 );
46
47
48 $np->add_arg (
49 spec => 'w=i',
50 help => _gt('Warning level (percent)'),
51 default => 60,
52 );
53
54 $np->add_arg (
55 spec => 'c=i',
56 help => _gt('Critical level (percent)'),
57 default => 80,
58 );
59 $np->getopts;
60
61 my $DEBUG = $np->opts->verbose;
62
63
64 my $warnLvl = $np->opts->get('w');
65 my $critLvl = $np->opts->get('c');
66
67 my $random = rand() * 100;
68
69
70 my $retStatus = $np->check_threshold(
71 'check' => $random,
72 'warning' => $warnLvl,
73 'critical' => $critLvl,
74 );
75
76 $np->add_perfdata(
77 'label' => 'rand',
78 'value' => $random,
79 'min' => 0,
80 'max' => 100,
81 'uom' => 'c',
82 'threshold' => $np->threshold()
83 );
84
85 if ( $retStatus == OK) {
86 $np->add_message(OK, sprintf(_gt('Tout va bien (%d%%)'),$random) );
87 } else {
88 $np->add_message($retStatus, sprintf(_gt('Random too high ! (%d%%)'),$random) );
89 }
90
91 my ($status, $message) = $np->check_messages('join' => ' ');
92
93
94 $np->nagios_exit($status, $message );
95
96
97 # Gettext wrapper
98 sub _gt {
99 return gettext($_[0]);
100 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.8