This commit is contained in:
Quentin Garnier 2014-03-24 19:04:23 +01:00
parent 300189f260
commit 93bb206740
7 changed files with 68 additions and 436 deletions

View File

@ -1,115 +0,0 @@
###############################################################################
# Copyright 2005-2013 MERETHIS
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
# GPL Licence 2.0.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation ; either version 2 of the License.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, see <http://www.gnu.org/licenses>.
#
# Linking this program statically or dynamically with other modules is making a
# combined work based on this program. Thus, the terms and conditions of the GNU
# General Public License cover the whole combination.
#
# As a special exception, the copyright holders of this program give MERETHIS
# permission to link this program with independent modules to produce an timeelapsedutable,
# regardless of the license terms of these independent modules, and to copy and
# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that
# MERETHIS also meet, for each linked independent module, the terms and conditions
# of the license of that module. An independent module is a module which is not
# derived from this program. If you modify this program, you may extend this
# exception to your version of the program, but you are not obliged to do so. If you
# do not wish to do so, delete this exception statement from your version.
#
# For more information : contact@centreon.com
# Authors : Florian Asche <info@florian-asche.de>
#
####################################################################################
package network::fritzbox::mode::dns1;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use network::fritzbox::mode::libgetdata;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => 49000 },
"timeout:s" => { name => 'timeout', default => 30 },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (!defined($self->{option_results}->{hostname})) {
$self->{output}->add_option_msg(short_msg => "Need to specify an Hostname.");
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
my $exit_code;
$self->{pfad} = '/upnp/control/WANCommonIFC1';
$self->{uri} = 'urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1';
$self->{space} = 'GetAddonInfos';
$self->{section} = 'NewDNSServer1';
my $IP = network::fritzbox::mode::libgetdata::getdata($self);
#print $IP . "\n";
if ($IP =~ /^((([0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])[.]){3}([0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5]))$/) {
$exit_code = 'ok';
} else {
$exit_code = 'critical';
}
$self->{output}->output_add(severity => $exit_code,
short_msg => sprintf("Your current DNS-Server is " . $IP));
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
This Mode provides your current first DNS Address.
This Mode needs UPNP.
=over 8
=item B<--hostname>
Hostname to query.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=back
=cut

View File

@ -1,115 +0,0 @@
###############################################################################
# Copyright 2005-2013 MERETHIS
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
# GPL Licence 2.0.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation ; either version 2 of the License.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, see <http://www.gnu.org/licenses>.
#
# Linking this program statically or dynamically with other modules is making a
# combined work based on this program. Thus, the terms and conditions of the GNU
# General Public License cover the whole combination.
#
# As a special exception, the copyright holders of this program give MERETHIS
# permission to link this program with independent modules to produce an timeelapsedutable,
# regardless of the license terms of these independent modules, and to copy and
# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that
# MERETHIS also meet, for each linked independent module, the terms and conditions
# of the license of that module. An independent module is a module which is not
# derived from this program. If you modify this program, you may extend this
# exception to your version of the program, but you are not obliged to do so. If you
# do not wish to do so, delete this exception statement from your version.
#
# For more information : contact@centreon.com
# Authors : Florian Asche <info@florian-asche.de>
#
####################################################################################
package network::fritzbox::mode::dns2;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use network::fritzbox::mode::libgetdata;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => 49000 },
"timeout:s" => { name => 'timeout', default => 30 },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (!defined($self->{option_results}->{hostname})) {
$self->{output}->add_option_msg(short_msg => "Need to specify an Hostname.");
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
my $exit_code;
$self->{pfad} = '/upnp/control/WANCommonIFC1';
$self->{uri} = 'urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1';
$self->{space} = 'GetAddonInfos';
$self->{section} = 'NewDNSServer2';
my $IP = network::fritzbox::mode::libgetdata::getdata($self);
#print $IP . "\n";
if ($IP =~ /^((([0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])[.]){3}([0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5]))$/) {
$exit_code = 'ok';
} else {
$exit_code = 'critical';
}
$self->{output}->output_add(severity => $exit_code,
short_msg => sprintf("Your current DNS-Server is " . $IP));
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
This Mode provides your current second DNS Address.
This Mode needs UPNP.
=over 8
=item B<--hostname>
Hostname to query.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=back
=cut

View File

@ -1,115 +0,0 @@
###############################################################################
# Copyright 2005-2013 MERETHIS
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
# GPL Licence 2.0.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation ; either version 2 of the License.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, see <http://www.gnu.org/licenses>.
#
# Linking this program statically or dynamically with other modules is making a
# combined work based on this program. Thus, the terms and conditions of the GNU
# General Public License cover the whole combination.
#
# As a special exception, the copyright holders of this program give MERETHIS
# permission to link this program with independent modules to produce an timeelapsedutable,
# regardless of the license terms of these independent modules, and to copy and
# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that
# MERETHIS also meet, for each linked independent module, the terms and conditions
# of the license of that module. An independent module is a module which is not
# derived from this program. If you modify this program, you may extend this
# exception to your version of the program, but you are not obliged to do so. If you
# do not wish to do so, delete this exception statement from your version.
#
# For more information : contact@centreon.com
# Authors : Florian Asche <info@florian-asche.de>
#
####################################################################################
package network::fritzbox::mode::externalip;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use network::fritzbox::mode::libgetdata;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => 49000 },
"timeout:s" => { name => 'timeout', default => 30 },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (!defined($self->{option_results}->{hostname})) {
$self->{output}->add_option_msg(short_msg => "Need to specify an Hostname.");
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
my $exit_code;
$self->{pfad} = '/upnp/control/WANIPConn1';
$self->{uri} = 'urn:schemas-upnp-org:service:WANIPConnection:1';
$self->{space} = 'GetExternalIPAddress';
$self->{section} = 'NewExternalIPAddress';
my $IP = network::fritzbox::mode::libgetdata::getdata($self);
#print $IP . "\n";
if ($IP =~ /^((([0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])[.]){3}([0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5]))$/) {
$exit_code = 'ok';
} else {
$exit_code = 'critical';
}
$self->{output}->output_add(severity => $exit_code,
short_msg => sprintf("Your current IP-Address is " . $IP));
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
This Mode provides your current WAN IPv4 Address.
This Mode needs UPNP.
=over 8
=item B<--hostname>
Hostname to query.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=back
=cut

View File

@ -39,44 +39,53 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::misc;
sub getdata {
my $soap;
my $response;
sub init {
my ($self, %options) = @_;
my ($soap,$som,$body);
$self->{url} = 'http://' . $self->{option_results}->{hostname} . ':' . $self->{option_results}->{port} . $self->{pfad};
my $proxy = 'http://' . $self->{option_results}->{hostname} . ':' . $self->{option_results}->{port} . $options{pfad};
$soap = SOAP::Lite->new(
proxy => $self->{url},
uri => $self->{uri},
timeout => $self->{option_results}->{timeout}
proxy => $proxy,
uri => $options{uri},
timeout => $self->{option_results}->{timeout}
);
$soap->on_fault(
sub { # SOAP fault handler
my $soap = shift;
my $res = shift;
my $space = $self->{space};
my $section = $self->{section};
if(ref($res)) {
chomp( my $err = $res->faultstring );
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "SOAP Fault: $err");
} else {
chomp( my $err = $soap->transport->status );
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Transport error: $err");
}
#Check SOAP Session Setup
if (! defined($soap)) {
$self->{output}->output_add(severity => 'CRITICAL',
short_msg => 'NO DATA FOUND');
$self->{output}->display();
$self->{output}->exit();
}
$self->{output}->display();
$self->{output}->exit();
}
);
}
# SOAP Call
$som = $soap->$space();
sub call {
my ($self, %options) = @_;
# Check Response
if (! exists($som->body->{$space."Response"})) {
$self->{output}->output_add(severity => 'CRITICAL',
short_msg => 'NO DATA FOUND');
$self->{output}->display();
$self->{output}->exit();
}
my $method = $options{soap_method};
$response = $soap->$method();
}
$body = $som->body->{$space."Response"};
return $body->{$section};
};
sub value {
my ($self, %options) = @_;
my $value = $response->valueof($options{path});
return $value;
}
1;

View File

@ -38,7 +38,6 @@ package network::fritzbox::mode::traffic;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::misc;
use centreon::plugins::statefile;
use network::fritzbox::mode::libgetdata;
@ -57,7 +56,7 @@ sub new {
"critical-in:s" => { name => 'critical_in', },
"warning-out:s" => { name => 'warning_out', },
"critical-out:s" => { name => 'critical_out', },
"units:s" => { name => 'units', default => 'B' },
"units:s" => { name => 'units', default => '%' },
});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
@ -101,28 +100,15 @@ sub run {
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
### GET DATA START
$self->{pfad} = '/upnp/control/WANCommonIFC1';
$self->{uri} = 'urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1';
network::fritzbox::mode::libgetdata::init($self, pfad => '/upnp/control/WANCommonIFC1',
uri => 'urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1');
network::fritzbox::mode::libgetdata::call($self, soap_method => 'GetAddonInfos');
my $NewTotalBytesSent = network::fritzbox::mode::libgetdata::value($self, path => '/GetAddonInfosResponse/NewTotalBytesSent');
my $NewTotalBytesReceived = network::fritzbox::mode::libgetdata::value($self, path => '/GetAddonInfosResponse/NewTotalBytesReceived');
$self->{space} = 'GetAddonInfos';
$self->{section} = 'NewTotalBytesSent';
my $NewTotalBytesSent = network::fritzbox::mode::libgetdata::getdata($self);
#print $NewTotalBytesSent . "\n";
$self->{space} = 'GetAddonInfos';
$self->{section} = 'NewTotalBytesReceived';
my $NewTotalBytesReceived = network::fritzbox::mode::libgetdata::getdata($self);
#print $NewTotalBytesReceived . "\n";
$self->{space} = 'GetCommonLinkProperties';
$self->{section} = 'NewLayer1UpstreamMaxBitRate';
my $NewLayer1UpstreamMaxBitRate = network::fritzbox::mode::libgetdata::getdata($self);
#print $NewLayer1UpstreamMaxBitRate . "\n";
$self->{space} = 'GetCommonLinkProperties';
$self->{section} = 'NewLayer1DownstreamMaxBitRate';
my $NewLayer1DownstreamMaxBitRate = network::fritzbox::mode::libgetdata::getdata($self);
#print $NewLayer1DownstreamMaxBitRate . "\n";
network::fritzbox::mode::libgetdata::call($self, soap_method => 'GetCommonLinkProperties');
my $NewLayer1UpstreamMaxBitRate = network::fritzbox::mode::libgetdata::value($self, path => '/GetCommonLinkPropertiesResponse/NewLayer1UpstreamMaxBitRate');
my $NewLayer1DownstreamMaxBitRate = network::fritzbox::mode::libgetdata::value($self, path => '/GetCommonLinkPropertiesResponse/NewLayer1DownstreamMaxBitRate');
### GET DATA END
# DID U KNOW?
@ -171,6 +157,10 @@ sub run {
my $exit1 = $self->{perfdata}->threshold_check(value => $in_prct, threshold => [ { label => 'critical-in', 'exit_litteral' => 'critical' }, { label => 'warning-in', exit_litteral => 'warning' } ]);
my $exit2 = $self->{perfdata}->threshold_check(value => $out_prct, threshold => [ { label => 'critical-out', 'exit_litteral' => 'critical' }, { label => 'warning-out', exit_litteral => 'warning' } ]);
$exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
} else {
my $exit1 = $self->{perfdata}->threshold_check(value => $in_absolute_per_sec, threshold => [ { label => 'critical-in', 'exit_litteral' => 'critical' }, { label => 'warning-in', exit_litteral => 'warning' } ]);
my $exit2 = $self->{perfdata}->threshold_check(value => $out_absolute_per_sec, threshold => [ { label => 'critical-out', 'exit_litteral' => 'critical' }, { label => 'warning-out', exit_litteral => 'warning' } ]);
$exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
}
$in_prct = sprintf("%.2f", $in_prct);
$out_prct = sprintf("%.2f", $out_prct);
@ -189,13 +179,13 @@ sub run {
}
$self->{output}->perfdata_add(label => 'traffic_in',
unit => 'b/s',
unit => 'B/s',
value => sprintf("%.2f", $in_absolute_per_sec),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-in', total => $NewLayer1DownstreamMaxBitRate),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-in', total => $NewLayer1DownstreamMaxBitRate),
min => 0, max => $NewLayer1DownstreamMaxBitRate);
$self->{output}->perfdata_add(label => 'traffic_out',
unit => 'b/s',
unit => 'B/s',
value => sprintf("%.2f", $out_absolute_per_sec),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-out', total => $NewLayer1UpstreamMaxBitRate),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-out', total => $NewLayer1UpstreamMaxBitRate),

View File

@ -83,42 +83,23 @@ sub run {
my ($self, %options) = @_;
my $exit_code;
$self->{pfad} = '/upnp/control/WANCommonIFC1';
$self->{uri} = 'urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1';
network::fritzbox::mode::libgetdata::init($self, pfad => '/upnp/control/WANCommonIFC1',
uri => 'urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1');
network::fritzbox::mode::libgetdata::call($self, soap_method => 'GetCommonLinkProperties');
my $WANAccessType = network::fritzbox::mode::libgetdata::value($self, path => '/GetCommonLinkPropertiesResponse/NewWANAccessType');
my $LinkStatus = network::fritzbox::mode::libgetdata::value($self, path => '/GetCommonLinkPropertiesResponse/NewPhysicalLinkStatus');
$self->{space} = 'GetCommonLinkProperties';
$self->{section} = 'NewWANAccessType';
my $WANAccessType = network::fritzbox::mode::libgetdata::getdata($self);
#print "Type: " . $WANAccessType . "\n";
$self->{space} = 'GetCommonLinkProperties';
$self->{section} = 'NewPhysicalLinkStatus';
my $LinkStatus = network::fritzbox::mode::libgetdata::getdata($self);
#print "Physical Link is: " . $LinkStatus . "\n";
$self->{pfad} = '/upnp/control/WANIPConn1';
$self->{uri} = 'urn:schemas-upnp-org:service:WANIPConnection:1';
$self->{space} = 'GetStatusInfo';
$self->{section} = 'NewUptime';
my $uptime = network::fritzbox::mode::libgetdata::getdata($self);
#print "Internet is Connected since: " . $uptime . " seconds\n";
#print "Internet is Connected since: " . floor($uptime / 60 / 60 / 24) . " days\n";
$self->{space} = 'GetStatusInfo';
$self->{section} = 'NewConnectionStatus';
my $ConnectionStatus = network::fritzbox::mode::libgetdata::getdata($self);
#print "Internet is: " . $ConnectionStatus . "\n";
network::fritzbox::mode::libgetdata::init($self, pfad => '/upnp/control/WANIPConn1',
uri => 'urn:schemas-upnp-org:service:WANIPConnection:1');
network::fritzbox::mode::libgetdata::call($self, soap_method => 'GetStatusInfo');
my $uptime = network::fritzbox::mode::libgetdata::value($self, path => '/GetStatusInfoResponse/NewUptime');
my $ConnectionStatus = network::fritzbox::mode::libgetdata::value($self, path => '/GetStatusInfoResponse/NewConnectionStatus');
$exit_code = $self->{perfdata}->threshold_check(value => floor($uptime),
threshold => [ { label => 'critical', exit_litteral => 'critical' },
{ label => 'warning', exit_litteral => 'warning' } ]);
if ($LinkStatus !~ /^up$/i) {
$exit_code = 'critical';
}
if ($ConnectionStatus !~ /^connected$/i) {
if ($LinkStatus !~ /^up$/i || $ConnectionStatus !~ /^connected$/i) {
$exit_code = 'critical';
}

View File

@ -89,11 +89,8 @@ sub new {
$self->{version} = '0.1';
%{$self->{modes}} = (
'upstatus' => 'network::fritzbox::mode::upstatus',
'traffic' => 'network::fritzbox::mode::traffic',
'externalip' => 'network::fritzbox::mode::externalip',
'dns1' => 'network::fritzbox::mode::dns1',
'dns2' => 'network::fritzbox::mode::dns2',
'upstatus' => 'network::fritzbox::mode::upstatus',
'traffic' => 'network::fritzbox::mode::traffic',
);
return $self;
}