diff --git a/hardware/routers/fritzbox/mode/dns1.pm b/network/fritzbox/mode/dns1.pm similarity index 90% rename from hardware/routers/fritzbox/mode/dns1.pm rename to network/fritzbox/mode/dns1.pm index 3df4f7056..1d4e3266c 100644 --- a/hardware/routers/fritzbox/mode/dns1.pm +++ b/network/fritzbox/mode/dns1.pm @@ -33,13 +33,13 @@ # #################################################################################### -package hardware::routers::fritzbox::mode::dns1; +package network::fritzbox::mode::dns1; use base qw(centreon::plugins::mode); use strict; use warnings; -use hardware::routers::fritzbox::mode::libgetdata; +use network::fritzbox::mode::libgetdata; sub new { my ($class, %options) = @_; @@ -50,10 +50,8 @@ sub new { $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '49000' }, + "port:s" => { name => 'port', default => 49000 }, "timeout:s" => { name => 'timeout', default => 30 }, - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, }); return $self; } @@ -77,15 +75,14 @@ sub run { $self->{uri} = 'urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1'; $self->{space} = 'GetAddonInfos'; $self->{section} = 'NewDNSServer1'; - my $IP = hardware::routers::fritzbox::mode::libgetdata::getdata($self); + 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)); diff --git a/hardware/routers/fritzbox/mode/dns2.pm b/network/fritzbox/mode/dns2.pm similarity index 90% rename from hardware/routers/fritzbox/mode/dns2.pm rename to network/fritzbox/mode/dns2.pm index bc0e47029..32c3a50b6 100644 --- a/hardware/routers/fritzbox/mode/dns2.pm +++ b/network/fritzbox/mode/dns2.pm @@ -33,13 +33,13 @@ # #################################################################################### -package hardware::routers::fritzbox::mode::dns2; +package network::fritzbox::mode::dns2; use base qw(centreon::plugins::mode); use strict; use warnings; -use hardware::routers::fritzbox::mode::libgetdata; +use network::fritzbox::mode::libgetdata; sub new { my ($class, %options) = @_; @@ -50,10 +50,8 @@ sub new { $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '49000' }, + "port:s" => { name => 'port', default => 49000 }, "timeout:s" => { name => 'timeout', default => 30 }, - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, }); return $self; } @@ -77,15 +75,14 @@ sub run { $self->{uri} = 'urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1'; $self->{space} = 'GetAddonInfos'; $self->{section} = 'NewDNSServer2'; - my $IP = hardware::routers::fritzbox::mode::libgetdata::getdata($self); + 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)); diff --git a/hardware/routers/fritzbox/mode/externalip.pm b/network/fritzbox/mode/externalip.pm similarity index 90% rename from hardware/routers/fritzbox/mode/externalip.pm rename to network/fritzbox/mode/externalip.pm index bee0d3ef0..6b274048b 100644 --- a/hardware/routers/fritzbox/mode/externalip.pm +++ b/network/fritzbox/mode/externalip.pm @@ -33,13 +33,13 @@ # #################################################################################### -package hardware::routers::fritzbox::mode::externalip; +package network::fritzbox::mode::externalip; use base qw(centreon::plugins::mode); use strict; use warnings; -use hardware::routers::fritzbox::mode::libgetdata; +use network::fritzbox::mode::libgetdata; sub new { my ($class, %options) = @_; @@ -50,10 +50,8 @@ sub new { $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '49000' }, + "port:s" => { name => 'port', default => 49000 }, "timeout:s" => { name => 'timeout', default => 30 }, - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, }); return $self; } @@ -77,15 +75,14 @@ sub run { $self->{uri} = 'urn:schemas-upnp-org:service:WANIPConnection:1'; $self->{space} = 'GetExternalIPAddress'; $self->{section} = 'NewExternalIPAddress'; - my $IP = hardware::routers::fritzbox::mode::libgetdata::getdata($self); + 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)); diff --git a/hardware/routers/fritzbox/mode/libgetdata.pm b/network/fritzbox/mode/libgetdata.pm similarity index 98% rename from hardware/routers/fritzbox/mode/libgetdata.pm rename to network/fritzbox/mode/libgetdata.pm index 38a8f6527..1b6a29fac 100644 --- a/hardware/routers/fritzbox/mode/libgetdata.pm +++ b/network/fritzbox/mode/libgetdata.pm @@ -33,7 +33,7 @@ # #################################################################################### -package hardware::routers::fritzbox::mode::libgetdata; +package network::fritzbox::mode::libgetdata; use base qw(centreon::plugins::mode); diff --git a/hardware/routers/fritzbox/mode/traffic.pm b/network/fritzbox/mode/traffic.pm similarity index 86% rename from hardware/routers/fritzbox/mode/traffic.pm rename to network/fritzbox/mode/traffic.pm index 5056a2799..bf9ea9b6f 100644 --- a/hardware/routers/fritzbox/mode/traffic.pm +++ b/network/fritzbox/mode/traffic.pm @@ -33,15 +33,14 @@ # #################################################################################### -package hardware::routers::fritzbox::mode::traffic; +package network::fritzbox::mode::traffic; use base qw(centreon::plugins::mode); use strict; use warnings; use centreon::plugins::misc; use centreon::plugins::statefile; -use Digest::MD5 qw(md5_hex); -use hardware::routers::fritzbox::mode::libgetdata; +use network::fritzbox::mode::libgetdata; sub new { my ($class, %options) = @_; @@ -54,12 +53,12 @@ sub new { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '49000' }, "timeout:s" => { name => 'timeout', default => 30 }, - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, + "warning-in:s" => { name => 'warning_in', }, + "critical-in:s" => { name => 'critical_in', }, + "warning-out:s" => { name => 'warning_out', }, + "critical-out:s" => { name => 'critical_out', }, "units:s" => { name => 'units', default => 'B' }, }); - $self->{result} = {}; - $self->{hostname} = undef; $self->{statefile_value} = centreon::plugins::statefile->new(%options); return $self; } @@ -91,16 +90,13 @@ sub check_options { $self->{statefile_value}->check_options(%options); $self->{hostname} = $self->{option_results}->{hostname}; - if (!defined($self->{hostname})) { - $self->{hostname} = 'me'; - } } sub run { my ($self, %options) = @_; my $new_datas = {}; - $self->{statefile_value}->read(statefile => "cache_linux_local_" . $self->{hostname} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all'))); + $self->{statefile_value}->read(statefile => "cache_fritzbox_" . $self->{hostname} . '_' . $self->{mode}); $new_datas->{last_timestamp} = time(); my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp'); @@ -110,22 +106,22 @@ sub run { $self->{space} = 'GetAddonInfos'; $self->{section} = 'NewTotalBytesSent'; - my $NewTotalBytesSent = hardware::routers::fritzbox::mode::libgetdata::getdata($self); + my $NewTotalBytesSent = network::fritzbox::mode::libgetdata::getdata($self); #print $NewTotalBytesSent . "\n"; $self->{space} = 'GetAddonInfos'; $self->{section} = 'NewTotalBytesReceived'; - my $NewTotalBytesReceived = hardware::routers::fritzbox::mode::libgetdata::getdata($self); + my $NewTotalBytesReceived = network::fritzbox::mode::libgetdata::getdata($self); #print $NewTotalBytesReceived . "\n"; $self->{space} = 'GetCommonLinkProperties'; $self->{section} = 'NewLayer1UpstreamMaxBitRate'; - my $NewLayer1UpstreamMaxBitRate = hardware::routers::fritzbox::mode::libgetdata::getdata($self); + my $NewLayer1UpstreamMaxBitRate = network::fritzbox::mode::libgetdata::getdata($self); #print $NewLayer1UpstreamMaxBitRate . "\n"; $self->{space} = 'GetCommonLinkProperties'; $self->{section} = 'NewLayer1DownstreamMaxBitRate'; - my $NewLayer1DownstreamMaxBitRate = hardware::routers::fritzbox::mode::libgetdata::getdata($self); + my $NewLayer1DownstreamMaxBitRate = network::fritzbox::mode::libgetdata::getdata($self); #print $NewLayer1DownstreamMaxBitRate . "\n"; ### GET DATA END @@ -137,20 +133,24 @@ sub run { # calc ($VAR / 8) $NewLayer1UpstreamMaxBitRate = ($NewLayer1UpstreamMaxBitRate / 8); $NewLayer1DownstreamMaxBitRate = ($NewLayer1DownstreamMaxBitRate / 8); - $new_datas->{'in'} = ($NewTotalBytesReceived); - $new_datas->{'out'} = ($NewTotalBytesSent); - + $new_datas->{in} = ($NewTotalBytesReceived); + $new_datas->{out} = ($NewTotalBytesSent); + $self->{statefile_value}->write(data => $new_datas); + my $old_in = $self->{statefile_value}->get(name => 'in'); my $old_out = $self->{statefile_value}->get(name => 'out'); if (!defined($old_timestamp) || !defined($old_in) || !defined($old_out)) { - #next; - print "ERROR"; + $self->{output}->output_add(severity => 'OK', + short_msg => "Buffer creation..."); + $self->{output}->display(); + $self->{output}->exit(); } - if ($new_datas->{'in'} < $old_in) { + + if ($new_datas->{in} < $old_in) { # We set 0. Has reboot. $old_in = 0; } - if ($new_datas->{'out'} < $old_out) { + if ($new_datas->{out} < $old_out) { # We set 0. Has reboot. $old_out = 0; } @@ -160,8 +160,8 @@ sub run { # At least one second. two fast calls ;) $time_delta = 1; } - my $in_absolute_per_sec = ($new_datas->{'in'} - $old_in) / $time_delta; - my $out_absolute_per_sec = ($new_datas->{'out'} - $old_out) / $time_delta; + my $in_absolute_per_sec = ($new_datas->{in} - $old_in) / $time_delta; + my $out_absolute_per_sec = ($new_datas->{out} - $old_out) / $time_delta; my ($exit, $in_prct, $out_prct); @@ -175,8 +175,6 @@ sub run { $in_prct = sprintf("%.2f", $in_prct); $out_prct = sprintf("%.2f", $out_prct); - - ### Manage Output my ($in_value, $in_unit) = $self->{perfdata}->change_bytes(value => $in_absolute_per_sec, network => 1); my ($out_value, $out_unit) = $self->{perfdata}->change_bytes(value => $out_absolute_per_sec, network => 1); @@ -203,11 +201,7 @@ sub run { critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-out', total => $NewLayer1UpstreamMaxBitRate), min => 0, max => $NewLayer1UpstreamMaxBitRate); - $self->{statefile_value}->write(data => $new_datas); - if (!defined($old_timestamp)) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Buffer creation..."); - } + $self->{output}->display(); $self->{output}->exit(); diff --git a/hardware/routers/fritzbox/mode/upstatus.pm b/network/fritzbox/mode/upstatus.pm similarity index 90% rename from hardware/routers/fritzbox/mode/upstatus.pm rename to network/fritzbox/mode/upstatus.pm index c48136210..1c600cd37 100644 --- a/hardware/routers/fritzbox/mode/upstatus.pm +++ b/network/fritzbox/mode/upstatus.pm @@ -33,13 +33,13 @@ # #################################################################################### -package hardware::routers::fritzbox::mode::upstatus; +package network::fritzbox::mode::upstatus; use base qw(centreon::plugins::mode); use strict; use warnings; -use hardware::routers::fritzbox::mode::libgetdata; +use network::fritzbox::mode::libgetdata; use POSIX; sub new { @@ -53,9 +53,9 @@ sub new { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '49000' }, "timeout:s" => { name => 'timeout', default => 30 }, - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, - "seconds" => { name => 'seconds', }, + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, + "seconds" => { name => 'seconds', }, }); return $self; } @@ -88,12 +88,12 @@ sub run { $self->{space} = 'GetCommonLinkProperties'; $self->{section} = 'NewWANAccessType'; - my $WANAccessType = hardware::routers::fritzbox::mode::libgetdata::getdata($self); + my $WANAccessType = network::fritzbox::mode::libgetdata::getdata($self); #print "Type: " . $WANAccessType . "\n"; $self->{space} = 'GetCommonLinkProperties'; $self->{section} = 'NewPhysicalLinkStatus'; - my $LinkStatus = hardware::routers::fritzbox::mode::libgetdata::getdata($self); + my $LinkStatus = network::fritzbox::mode::libgetdata::getdata($self); #print "Physical Link is: " . $LinkStatus . "\n"; $self->{pfad} = '/upnp/control/WANIPConn1'; @@ -101,26 +101,26 @@ sub run { $self->{space} = 'GetStatusInfo'; $self->{section} = 'NewUptime'; - my $uptime = hardware::routers::fritzbox::mode::libgetdata::getdata($self); + 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 = hardware::routers::fritzbox::mode::libgetdata::getdata($self); + my $ConnectionStatus = network::fritzbox::mode::libgetdata::getdata($self); #print "Internet is: " . $ConnectionStatus . "\n"; $exit_code = $self->{perfdata}->threshold_check(value => floor($uptime), - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); if ($LinkStatus !~ /^up$/i) { $exit_code = 'critical'; - }; + } if ($ConnectionStatus !~ /^connected$/i) { $exit_code = 'critical'; - }; + } $self->{output}->perfdata_add(label => 'uptime', value => floor($uptime), diff --git a/hardware/routers/fritzbox/plugin.pm b/network/fritzbox/plugin.pm similarity index 88% rename from hardware/routers/fritzbox/plugin.pm rename to network/fritzbox/plugin.pm index 4c04fa3d0..c9853b356 100644 --- a/hardware/routers/fritzbox/plugin.pm +++ b/network/fritzbox/plugin.pm @@ -74,7 +74,7 @@ #NewExternalIPAddress : 133.71.33.7 #################################################################################### -package hardware::routers::fritzbox::plugin; +package network::fritzbox::plugin; use strict; use warnings; @@ -89,11 +89,11 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'upstatus' => 'hardware::routers::fritzbox::mode::upstatus', - 'traffic' => 'hardware::routers::fritzbox::mode::traffic', - 'externalip' => 'hardware::routers::fritzbox::mode::externalip', - 'dns1' => 'hardware::routers::fritzbox::mode::dns1', - 'dns2' => 'hardware::routers::fritzbox::mode::dns2', + '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', ); return $self; }