ASNMTAP
view release on metacpan or search on metacpan
lib/ASNMTAP/Asnmtap/Plugins/Nagios.pm view on Meta::CPAN
my ($metric, $value) = @_;
my $result = ( ($metric =~ /^[Gg]$/) ? ($value * (1024 * 1024)) : ( ($metric =~ /^[Mm]$/) ? ($value * 1024) : $value ) );
return ( $result )
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub convert_from_KB_to_metric {
my ($metric, $value) = @_;
my $result = ( ($metric eq 'GB') ? ($value / (1024 * 1024)) : ( ($metric eq 'MB') ? ($value / 1024) : $value ) );
$result = sprintf("%.2f", $result) if ($metric ne 'kB');
return ( $result )
}
# Constructor & initialisation - - - - - - - - - - - - - - - - - - - - -
sub _init {
$_[0]->SUPER::_init($_[1]);
carp ('ASNMTAP::Asnmtap::Plugins::Nagios: _init') if ( $_[0]->{_debug} );
$_[0]->{_programUsageSuffix} = ' [-o|--ostype <OSTYPE>] [-m|--metric <METRIC>] '. $_[0]->{_programUsageSuffix};
$_[0]->{_programHelpSuffix} = "
-o, --ostype=<OSTYPE>
-m, --metric=<k|M|G>,
k=kB (default), M=MB or G=GB
" . $_[0]->{_programHelpSuffix};
push (@{ $_[0]->{_programGetOptions} }, 'ostype|o:s', 'metric|m:s');
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub _getOptions {
$_[0]->SUPER::_getOptions();
carp ('ASNMTAP::Asnmtap::Plugins::Nagios: _getOptions') if ( $_[0]->{_debug} );
my $osType = ( exists $_[0]->{_getOptionsArgv}->{ostype} ) ? $_[0]->{_getOptionsArgv}->{ostype} : undef;
$osType = ( defined $osType ? $osType : ( defined $^O ? $^O : 'Linux' ) );
my $osVersion = ( exists $_[0]->{_getOptionsArgv}->{osversion} ) ? $_[0]->{_getOptionsArgv}->{osversion} : undef;
for ( $osType ) {
/aix/i && do { $osType = 'AIX'; last; };
/cygwin/i && do { $osType = 'Cygwin'; last; };
/freebsd/i && do { $osType = 'FreeBSD'; last; };
/linux/i && do { $osType = 'Linux'; last; };
/hp-ux/i && do { $osType = 'HP-UX'; last; };
/irix/i && do { $osType = 'Irix'; last; };
/macos/i && do { $osType = 'MacOS'; last; };
/(?:FreeMiNt|MiNT)/i && do { $osType = 'MiNT'; last; };
/netbsd/i && do { $osType = 'NetBSD'; last; };
/netware/i && do { $osType = 'NetWare'; last; };
/openbsd/i && do { $osType = 'OpenBSD'; last; };
/os2/i && do { $osType = 'OS2'; last; };
/sco/i && do { $osType = 'SCO'; last; };
/solaris/i && do { $osType = 'Solaris'; last; };
/stratus/i && do { $osType = 'Stratus'; last; };
/unix/i && do { $osType = 'Unix'; last; };
/vms/i && do { $osType = 'VMS'; last; };
/mswin32/i && do { $osType = 'Win32'; last; };
}
$_[0]->{_getOptionsValues}->{osType} = $osType;
$_[0]->{_getOptionsValues}->{osVersion} = $osVersion;
my $metric = (exists $_[0]->{_getOptionsArgv}->{metric}) ? $_[0]->{_getOptionsArgv}->{metric} : 'kB';
$_[0]->printUsage ('Invalid metric option: '. $metric) unless ($metric =~ /^k|M|G$/);
$_[0]->{_getOptionsValues}->{metric} = ($metric eq 'M') ? 'MB' : ($metric eq 'G') ? 'GB' : 'kB';
}
# Object accessor methods - - - - - - - - - - - - - - - - - - - - - - - -
# Class accessor methods - - - - - - - - - - - - - - - - - - - - - - - -
# Utility methods - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Destructor - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub DESTROY {
print (ref ($_[0]), "::DESTROY: ()\n") if ( $_[0]->{_debug} );
$_[0]->SUPER::DESTROY;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
__END__
=head1 NAME
ASNMTAP::Asnmtap::Plugins::Nagios provides a nice object oriented interface for building Nagios (http://www.nagios.org) compatible plugins.
=head1 Description
ASNMTAP::Asnmtap::Plugins::Nagios Subclass of ASNMTAP::Asnmtap::Plugins
=head1 SEE ALSO
ASNMTAP::Asnmtap, ASNMTAP::Asnmtap::Plugins
=head1 AUTHOR
Alex Peeters [alex.peeters@citap.be]
=head1 COPYRIGHT NOTICE
(c) Copyright 2000-2011 by Alex Peeters [alex.peeters@citap.be],
All Rights Reserved.
ASNMTAP is based on 'Process System daemons v1.60.17-01', Alex Peeters [alex.peeters@citap.be]
Purpose: CronTab (CT, sysdCT),
Disk Filesystem monitoring (DF, sysdDF),
Intrusion Detection for FW-1 (ID, sysdID)
Process System daemons (PS, sysdPS),
( run in 1.116 second using v1.01-cache-2.11-cpan-2398b32b56e )