diff --git a/network/fritzbox/mode/dns1.pm b/network/fritzbox/mode/dns1.pm deleted file mode 100644 index 1d4e3266c..000000000 --- a/network/fritzbox/mode/dns1.pm +++ /dev/null @@ -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 . -# -# 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 -# -#################################################################################### - -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 diff --git a/network/fritzbox/mode/dns2.pm b/network/fritzbox/mode/dns2.pm deleted file mode 100644 index 32c3a50b6..000000000 --- a/network/fritzbox/mode/dns2.pm +++ /dev/null @@ -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 . -# -# 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 -# -#################################################################################### - -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 diff --git a/network/fritzbox/mode/externalip.pm b/network/fritzbox/mode/externalip.pm deleted file mode 100644 index 6b274048b..000000000 --- a/network/fritzbox/mode/externalip.pm +++ /dev/null @@ -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 . -# -# 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 -# -#################################################################################### - -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 diff --git a/network/fritzbox/mode/libgetdata.pm b/network/fritzbox/mode/libgetdata.pm index 1b6a29fac..1fecf5165 100644 --- a/network/fritzbox/mode/libgetdata.pm +++ b/network/fritzbox/mode/libgetdata.pm @@ -39,44 +39,54 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::misc; +use SOAP::Lite; -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"); + } + + $self->{output}->display(); + $self->{output}->exit(); + } + ); +} - #Check SOAP Session Setup - if (! defined($soap)) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => 'NO DATA FOUND'); - $self->{output}->display(); - $self->{output}->exit(); - } +sub call { + my ($self, %options) = @_; + + my $method = $options{soap_method}; + $response = $soap->$method(); +} - # SOAP Call - $som = $soap->$space(); - - # 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(); - } - - $body = $som->body->{$space."Response"}; - return $body->{$section}; -}; +sub value { + my ($self, %options) = @_; + my $value = $response->valueof($options{path}); + + return $value; +} 1; \ No newline at end of file diff --git a/network/fritzbox/mode/traffic.pm b/network/fritzbox/mode/traffic.pm index ec89d6ec2..c4fd2e64c 100644 --- a/network/fritzbox/mode/traffic.pm +++ b/network/fritzbox/mode/traffic.pm @@ -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? @@ -131,10 +117,10 @@ sub run { # so if you want all in BYTE... # (8 BIT = 1 BYTE) # calc ($VAR / 8) - $NewLayer1UpstreamMaxBitRate = ($NewLayer1UpstreamMaxBitRate / 8); - $NewLayer1DownstreamMaxBitRate = ($NewLayer1DownstreamMaxBitRate / 8); - $new_datas->{in} = ($NewTotalBytesReceived); - $new_datas->{out} = ($NewTotalBytesSent); + $NewLayer1UpstreamMaxBitRate = ($NewLayer1UpstreamMaxBitRate); + $NewLayer1DownstreamMaxBitRate = ($NewLayer1DownstreamMaxBitRate); + $new_datas->{in} = ($NewTotalBytesReceived) * 8; + $new_datas->{out} = ($NewTotalBytesSent) * 8; $self->{statefile_value}->write(data => $new_datas); my $old_in = $self->{statefile_value}->get(name => 'in'); @@ -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); @@ -236,7 +226,7 @@ Threshold critical for 'out' traffic. =item B<--units> -Units of thresholds (Default: '%') ('%', 'B'). +Units of thresholds (Default: '%') ('%', 'b'). =item B<--hostname> diff --git a/network/fritzbox/mode/upstatus.pm b/network/fritzbox/mode/upstatus.pm index 1c600cd37..7241a8ff1 100644 --- a/network/fritzbox/mode/upstatus.pm +++ b/network/fritzbox/mode/upstatus.pm @@ -82,43 +82,24 @@ sub check_options { sub run { my ($self, %options) = @_; my $exit_code; - - $self->{pfad} = '/upnp/control/WANCommonIFC1'; - $self->{uri} = 'urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1'; - $self->{space} = 'GetCommonLinkProperties'; - $self->{section} = 'NewWANAccessType'; - my $WANAccessType = network::fritzbox::mode::libgetdata::getdata($self); - #print "Type: " . $WANAccessType . "\n"; + 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} = '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'; } diff --git a/network/fritzbox/plugin.pm b/network/fritzbox/plugin.pm index c9853b356..e2510c536 100644 --- a/network/fritzbox/plugin.pm +++ b/network/fritzbox/plugin.pm @@ -79,7 +79,6 @@ package network::fritzbox::plugin; use strict; use warnings; use base qw(centreon::plugins::script_simple); -use SOAP::Lite; sub new { my ($class, %options) = @_; @@ -89,11 +88,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; }