| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 81 | 0 | ▶ | $result = sprintf("%.2f", $result) if ($metric ne 'kB'); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 107 | |||||||||||||||
| 108 | 18 | ▶ | my $osType = ( exists $_[0]->{_getOptionsArgv}->{ostype} ) ? $_[0]->{_getOptionsArgv}->{ostype} : undef; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 109 | 18 | ▶ | $osType = ( defined $osType ? $osType : ( defined $^O ? $^O : 'Linux' ) ); | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 110 | |||||||||||||||
| 111 | 18 | ▶ | my $osVersion = ( exists $_[0]->{_getOptionsArgv}->{osversion} ) ? $_[0]->{_getOptionsArgv}->{osversion} : undef; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 112 | |||||||||||||||
| 113 | 18 | for ( $osType ) { | |||||||||||||
| 114 | 0 | ▶ | /aix/i && do { $osType = 'AIX'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 115 | 0 | ▶ | /cygwin/i && do { $osType = 'Cygwin'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 116 | 0 | ▶ | /freebsd/i && do { $osType = 'FreeBSD'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 117 | 18 | ▶ | /linux/i && do { $osType = 'Linux'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 118 | 0 | ▶ | /hp-ux/i && do { $osType = 'HP-UX'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 119 | 0 | ▶ | /irix/i && do { $osType = 'Irix'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 120 | 0 | ▶ | /macos/i && do { $osType = 'MacOS'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 121 | 0 | ▶ | /(?:FreeMiNt|MiNT)/i && do { $osType = 'MiNT'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 122 | 0 | ▶ | /netbsd/i && do { $osType = 'NetBSD'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 123 | 0 | ▶ | /netware/i && do { $osType = 'NetWare'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 124 | 0 | ▶ | /openbsd/i && do { $osType = 'OpenBSD'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 125 | 0 | ▶ | /os2/i && do { $osType = 'OS2'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 126 | 0 | ▶ | /sco/i && do { $osType = 'SCO'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 127 | 0 | ▶ | /solaris/i && do { $osType = 'Solaris'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 128 | 0 | ▶ | /stratus/i && do { $osType = 'Stratus'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 129 | 0 | ▶ | /unix/i && do { $osType = 'Unix'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 130 | 0 | ▶ | /vms/i && do { $osType = 'VMS'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 131 | 0 | ▶ | /mswin32/i && do { $osType = 'Win32'; last; }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 138 | 18 | ▶ | $_[0]->printUsage ('Invalid metric option: '. $metric) unless ($metric =~ /^k|M|G$/); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 139 | 18 | ▶ | $_[0]->{_getOptionsValues}->{metric} = ($metric eq 'M') ? 'MB' : ($metric eq 'G') ? 'GB' : 'kB'; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 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
| |||||||||||||||
| 152 | 0 | $_[0]->SUPER::DESTROY; | |||||||||||||
| 153 | } | ||||||||||||||
| 154 | |||||||||||||||
| 155 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||||||||||||||
| 156 | |||||||||||||||
| 157 | 35 | 1; | |||||||||||||
| 158 | |||||||||||||||
| 159 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||||||||||||||
| 160 | |||||||||||||||
| 161 | __END__ | ||||||||||||||