| Nagios-Plugin-OverHTTP documentation | Contained in the Nagios-Plugin-OverHTTP distribution. |
Nagios::Plugin::OverHTTP::Formatter::Nagios::Auto - Detect installed Nagios version and format accordingly
This documentation refers to Nagios::Plugin::OverHTTP::Formatter::Nagios::Auto version 0.14
#TODO: Write this
This formatter for Nagios::Plugin::OverHTTP will attempt to detect the installed Nagios version and load the appropriate formatter for the version.
This is fully object-oriented, and as such before any method can be used, the constructor needs to be called to create an object to work with.
This will construct a new plugin object.
%attributes is a HASH where the keys are attributes (specified in the
ATTRIBUTES section).
$attributes is a HASHREF where the keys are attributes (specified in the
ATTRIBUTES section).
# Set an attribute $object->attribute_name($new_value); # Get an attribute my $value = $object->attribute_name;
Required. This is the Nagios::Plugin::OverHTTP::Response object to format.
This takes a HTTP::Response object and parses it and will return a Nagios::Plugin::OverHTTP::Response object.
Status header %s is in validThe status header that was provided did not contain any known status format.
This module is dependent on the following modules:
Douglas Christopher Wilson, <doug at somethingdoug.com>
Please report any bugs or feature requests to
bug-nagios-plugin-overhttp at rt.cpan.org, or through the web interface at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Nagios-Plugin-OverHTTP. I
will be notified, and then you'll automatically be notified of progress on your
bug as I make changes.
Copyright 2010 Douglas Christopher Wilson, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of either:
| Nagios-Plugin-OverHTTP documentation | Contained in the Nagios-Plugin-OverHTTP distribution. |
package Nagios::Plugin::OverHTTP::Formatter::Nagios::Auto; use 5.008001; use strict; use warnings 'all'; ########################################################################### # METADATA our $AUTHORITY = 'cpan:DOUGDUDE'; our $VERSION = '0.14'; ########################################################################### # MODULE IMPORTS use Carp qw(croak); use English qw(-no_match_vars); use Env::Path 0.04; use IPC::System::Simple 0.13; use Readonly 1.03; use Regexp::Common 2.119; use Try::Tiny; ########################################################################### # ALL IMPORTS BEFORE THIS WILL BE ERASED use namespace::clean 0.04 -except => [qw(meta)]; ########################################################################### # PRIVATE CONSTANTS Readonly my $NAGIOS_FORMATTER_PRE => 'Nagios::Plugin::OverHTTP::Formatter::Nagios'; Readonly my $DEFAULT_FORMATTER => join q{::}, $NAGIOS_FORMATTER_PRE, q{Version3}; Readonly my $NAGIOS_EXECUTABLE => 'nagios'; Readonly my $VERSION_RE => $RE{num}{int}{-sep => q{.}}{-group => q{1,3}}; ########################################################################### # CONSTRUCTOR sub new { my ($class, @args) = @_; # Find all Nagios executables my @nagios_executables = Env::Path->PATH->Whence($NAGIOS_EXECUTABLE); # Get a list of version numbers my @nagios_versions = grep { defined $_ } map { _get_nagios_version($_) } @nagios_executables; # The module to use my $formatter = $DEFAULT_FORMATTER; # Look for the formatter VERSION: foreach my $version (@nagios_versions) { # Split the version into the different dot parts my @parts = split m{\.}msx, $version; VERSION_PART: while (@parts) { # Construct version to check for my $check_for_version = join q{.}, @parts; my $module_name = join q{::Version}, $NAGIOS_FORMATTER_PRE, $check_for_version; if (eval "require $module_name; 1;") { # The module exists, so use this $formatter = $module_name; last VERSION; } # Remove last version part for next check pop @parts; } } # Make sure the formatter is loaded if (!eval "require $formatter; 1;") { # Module failed to load croak $EVAL_ERROR; } # Return a new formatter instance return $formatter->new(@args); } ########################################################################### # PRIVATE FUNCTIONS sub _get_nagios_version { my ($nagios_executable) = @_; # Get the output from using the -v switch my $version_info = try { # Capture output IPC::System::Simple::capturex($nagios_executable, q{-v}); } catch { # If error thrown, return empty string q{}; }; # Parse out the version number my ($version) = $version_info =~ m{^nagios \s+ (?:core \s+)? ($VERSION_RE)}imsx; # Return the version (or undef) return $version; } 1; __END__