blib/lib/ASNMTAP/Asnmtap/Plugins/Nagios.pm

filter: Statementstmt 47.7% 52 / 109 Branchbran 20.5% 14 / 68 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 76.9% 10 / 13 Podpod 100% 2 / 2 totaltotal 40.6% 78 / 192 CC 36 SCAR 54.5
CC
36
Cov
37%
_getOptions
380.8
convert_from_KB_to_metric
20.0
convert_to_KB
12.0
CRAP 233.0
« blib/lib/ASNMTAP/Asnmtap/Plugins/SOAP.pm ↑ Summary blib/lib/ASNMTAP/Asnmtap/Plugins/NPTest.pm »
1 # ----------------------------------------------------------------------------------------------------------
2 # © Copyright 2000-2011 by Alex Peeters [alex.peeters@citap.be]
3 # ----------------------------------------------------------------------------------------------------------
4 # 2011/mm/dd, v3.002.003, package ASNMTAP::Asnmtap::Plugins::Nagios Object-Oriented Perl
5 # ----------------------------------------------------------------------------------------------------------
6  
7 # Class name - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 package ASNMTAP::Asnmtap::Plugins::Nagios;
9  
10 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
11  
12 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 35 ▶use warnings; # Must be used in test mode only. This reduces a little process speed
Subroutine BEGIN: called CC=1 SCAR=0.0
14 #use diagnostics; # Must be used in test mode only. This reduces a lot of process speed
15  
16 35 ▶no warnings 'deprecated';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
19  
20 35 ▶use Carp qw(carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 35 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
24  
25 35 ▶use ASNMTAP::Asnmtap::Plugins qw(:PLUGINS :COMMANDS :_HIDDEN);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
28  
29 35 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
30 35 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 35 @ASNMTAP::Asnmtap::Plugins::Nagios::ISA = qw(Exporter ASNMTAP::Asnmtap::Plugins);
33  
34 35 %ASNMTAP::Asnmtap::Plugins::Nagios::EXPORT_TAGS = (ALL => [ qw($APPLICATION $BUSINESS $DEPARTMENT $COPYRIGHT $SENDEMAILTO
35 $CAPTUREOUTPUT
36 $PREFIXPATH $PLUGINPATH $LOGPATH $PIDPATH $PERL5LIB $MANPATH $LD_LIBRARY_PATH
37 %ERRORS %STATE %TYPE
38  
39 $CHATCOMMAND $DIFFCOMMAND $KILLALLCOMMAND $PERLCOMMAND $PPPDCOMMAND $ROUTECOMMAND $RSYNCCOMMAND $SCPCOMMAND $SSHCOMMAND
40  
41 &convert_to_KB &convert_from_KB_to_metric ) ],
42  
43 NAGIOS => [ qw($APPLICATION $BUSINESS $DEPARTMENT $COPYRIGHT $SENDEMAILTO
44 $CAPTUREOUTPUT
45 $PREFIXPATH $PLUGINPATH $LOGPATH $PIDPATH $PERL5LIB $MANPATH $LD_LIBRARY_PATH
46 %ERRORS %STATE %TYPE
47  
48 &convert_to_KB &convert_from_KB_to_metric ) ],
49  
50 COMMANDS => [ qw($CHATCOMMAND $DIFFCOMMAND $KILLALLCOMMAND $PERLCOMMAND $PPPDCOMMAND $ROUTECOMMAND $RSYNCCOMMAND $SCPCOMMAND $SSHCOMMAND) ] );
51  
52 35 @ASNMTAP::Asnmtap::Plugins::Nagios::EXPORT_OK = ( @{ $ASNMTAP::Asnmtap::Plugins::Nagios::EXPORT_TAGS{ALL} } );
53  
54 35 $ASNMTAP::Asnmtap::Plugins::Nagios::VERSION = do { my @r = (q$Revision: 3.002.003$ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r };
55 }
56  
57 # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
58 # Public subs = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
59 # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
60  
61 sub convert_to_KB;
62 sub convert_from_KB_to_metric;
63  
64 # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
65 # Public subs without TAGS = = = = = = = = = = = = = = = = = = = = = = =
66 # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
67  
68 0 ▶sub convert_to_KB {
Subroutine convert_to_KB: not called CC=3 SCAR=24.8
Pod documented
69 0 my ($metric, $value) = @_;
70  
71 0 ▶ my $result = ( ($metric =~ /^[Gg]$/) ? ($value * (1024 * 1024)) : ( ($metric =~ /^[Mm]$/) ? ($value * 1024) : $value ) );
Branch: 2 branches
BranchTrueFalseTotal
$metric =~ /^[Gg]$/ ? : 0 0 0
$metric =~ /^[Mm]$/ ? : 0 0 0
72 0 return ( $result )
73 }
74  
75 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
76  
77 0 ▶sub convert_from_KB_to_metric {
Subroutine convert_from_KB_to_metric: not called CC=4 SCAR=30.0
Pod documented
78 0 my ($metric, $value) = @_;
79  
80 0 ▶ my $result = ( ($metric eq 'GB') ? ($value / (1024 * 1024)) : ( ($metric eq 'MB') ? ($value / 1024) : $value ) );
Branch: 2 branches
BranchTrueFalseTotal
$metric eq 'GB' ? : 0 0 0
$metric eq 'MB' ? : 0 0 0
81 0 ▶ $result = sprintf("%.2f", $result) if ($metric ne 'kB');
Branch: 1 branch
BranchTrueFalseTotal
if $metric ne "kB" 0 0 0
82 0 return ( $result )
83 }
84  
85 # Constructor & initialisation - - - - - - - - - - - - - - - - - - - - -
86  
87 35 ▶sub _init {
Subroutine _init: called CC=2 SCAR=7.0
88 35 $_[0]->SUPER::_init($_[1]);
89 35 ▶ carp ('ASNMTAP::Asnmtap::Plugins::Nagios: _init') if ( $_[0]->{_debug} );
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"_debug"} 0 35 35
90  
91 35 $_[0]->{_programUsageSuffix} = ' [-o|--ostype <OSTYPE>] [-m|--metric <METRIC>] '. $_[0]->{_programUsageSuffix};
92  
93 $_[0]->{_programHelpSuffix} = "
94 -o, --ostype=<OSTYPE>
95 -m, --metric=<k|M|G>,
96 k=kB (default), M=MB or G=GB
97 35 " . $_[0]->{_programHelpSuffix};
98  
99 35 push (@{ $_[0]->{_programGetOptions} }, 'ostype|o:s', 'metric|m:s');
100 }
101  
102 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
103  
104 39 ▶sub _getOptions {
Subroutine _getOptions: called CC=29 SCAR=59.4
105 39 $_[0]->SUPER::_getOptions();
106 18 ▶ carp ('ASNMTAP::Asnmtap::Plugins::Nagios: _getOptions') if ( $_[0]->{_debug} );
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"_debug"} 0 18 18
107  
108 18 ▶ my $osType = ( exists $_[0]->{_getOptionsArgv}->{ostype} ) ? $_[0]->{_getOptionsArgv}->{ostype} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]{'_getOptionsArgv'}{'ostype'} ? : 0 18 18
109 18 ▶ $osType = ( defined $osType ? $osType : ( defined $^O ? $^O : 'Linux' ) );
Branch: 2 branches
BranchTrueFalseTotal
defined $osType ? : 0 18 18
defined $^O ? : 18 0 18
110  
111 18 ▶ my $osVersion = ( exists $_[0]->{_getOptionsArgv}->{osversion} ) ? $_[0]->{_getOptionsArgv}->{osversion} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]{'_getOptionsArgv'}{'osversion'} ? : 0 18 18
112  
113 18 for ( $osType ) {
114 0 ▶ /aix/i && do { $osType = 'AIX'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/aix/i and do { $osType = "AIX"; last } 0 18 18
115 0 ▶ /cygwin/i && do { $osType = 'Cygwin'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/cygwin/i and do { $osType = "Cygwin"; last } 0 18 18
116 0 ▶ /freebsd/i && do { $osType = 'FreeBSD'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/freebsd/i and do { $osType = "FreeBSD"; last } 0 18 18
117 18 ▶ /linux/i && do { $osType = 'Linux'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/linux/i and do { $osType = "Linux"; last } 18 0 18
118 0 ▶ /hp-ux/i && do { $osType = 'HP-UX'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/hp-ux/i and do { $osType = "HP-UX"; last } 0 0 0
119 0 ▶ /irix/i && do { $osType = 'Irix'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/irix/i and do { $osType = "Irix"; last } 0 0 0
120 0 ▶ /macos/i && do { $osType = 'MacOS'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/macos/i and do { $osType = "MacOS"; last } 0 0 0
121 0 ▶ /(?:FreeMiNt|MiNT)/i && do { $osType = 'MiNT'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/(?:FreeMiNt|MiNT)/i and do { $osType = "MiNT"; last } 0 0 0
122 0 ▶ /netbsd/i && do { $osType = 'NetBSD'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/netbsd/i and do { $osType = "NetBSD"; last } 0 0 0
123 0 ▶ /netware/i && do { $osType = 'NetWare'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/netware/i and do { $osType = "NetWare"; last } 0 0 0
124 0 ▶ /openbsd/i && do { $osType = 'OpenBSD'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/openbsd/i and do { $osType = "OpenBSD"; last } 0 0 0
125 0 ▶ /os2/i && do { $osType = 'OS2'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/os2/i and do { $osType = "OS2"; last } 0 0 0
126 0 ▶ /sco/i && do { $osType = 'SCO'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/sco/i and do { $osType = "SCO"; last } 0 0 0
127 0 ▶ /solaris/i && do { $osType = 'Solaris'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/solaris/i and do { $osType = "Solaris"; last } 0 0 0
128 0 ▶ /stratus/i && do { $osType = 'Stratus'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/stratus/i and do { $osType = "Stratus"; last } 0 0 0
129 0 ▶ /unix/i && do { $osType = 'Unix'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/unix/i and do { $osType = "Unix"; last } 0 0 0
130 0 ▶ /vms/i && do { $osType = 'VMS'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/vms/i and do { $osType = "VMS"; last } 0 0 0
131 0 ▶ /mswin32/i && do { $osType = 'Win32'; last; };
Branch: 1 branch
BranchTrueFalseTotal
/mswin32/i and do { $osType = "Win32"; last } 0 0 0
132 }
133  
134 18 $_[0]->{_getOptionsValues}->{osType} = $osType;
135 18 $_[0]->{_getOptionsValues}->{osVersion} = $osVersion;
136  
137 18 ▶ my $metric = (exists $_[0]->{_getOptionsArgv}->{metric}) ? $_[0]->{_getOptionsArgv}->{metric} : 'kB';
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]{'_getOptionsArgv'}{'metric'} ? : 0 18 18
138 18 ▶ $_[0]->printUsage ('Invalid metric option: '. $metric) unless ($metric =~ /^k|M|G$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $metric =~ /^k|M|G$/ 0 18 18
139 18 ▶ $_[0]->{_getOptionsValues}->{metric} = ($metric eq 'M') ? 'MB' : ($metric eq 'G') ? 'GB' : 'kB';
Branch: 2 branches
BranchTrueFalseTotal
$metric eq 'M' ? : 0 18 18
$metric eq 'G' ? : 0 18 18
140 }
141  
142 # Object accessor methods - - - - - - - - - - - - - - - - - - - - - - - -
143  
144 # Class accessor methods - - - - - - - - - - - - - - - - - - - - - - - -
145  
146 # Utility methods - - - - - - - - - - - - - - - - - - - - - - - - - - - -
147  
148 # Destructor - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
149  
150 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=2 SCAR=17.9
151 0 ▶ print (ref ($_[0]), "::DESTROY: ()\n") if ( $_[0]->{_debug} );
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"_debug"} 0 0 0
152 0 $_[0]->SUPER::DESTROY;
153 }
154  
155 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
156  
157 35 1;
158  
159 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
160  
161 __END__
« blib/lib/ASNMTAP/Asnmtap/Plugins/SOAP.pm ↑ Summary blib/lib/ASNMTAP/Asnmtap/Plugins/NPTest.pm »