remove Cache::File package

This commit is contained in:
Lotfi zaouche 2020-04-09 08:28:21 +00:00
parent 2b08bbb6aa
commit bcb95743d9
5 changed files with 80 additions and 66 deletions

View File

@ -24,12 +24,12 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Cache::File;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
@ -43,6 +43,9 @@ sub new {
sub manage_selection {
my ($self, %options) = @_;
$self->{cache_name} = "parity_ethpoller_" . $self->{mode} . '_' . (defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'me') . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
my $result = $options{custom}->request_api(url_path => '/fork');
# use Data::Dumper;
@ -52,15 +55,15 @@ sub manage_selection {
my $res_timestamp = localtime(hex($result->{last_update}->{timestamp}));
# Alerts management
my $cache = Cache::File->new( cache_root => './parity-eth-poller-cache' );
# my $cache = Cache::File->new( cache_root => './parity-eth-poller-cache' );
if (my $cached_timestamp = $cache->get('fork_timestamp')) {
if ($cached_timestamp ne $res_timestamp) {
#alert
}
} else {
$cache->set('fork_timestamp', $res_timestamp);
}
# if (my $cached_timestamp = $cache->get('fork_timestamp')) {
# if ($cached_timestamp ne $res_timestamp) {
# #alert
# }
# } else {
# $cache->set('fork_timestamp', $res_timestamp);
# }
$self->{output}->output_add(severity => 'OK', long_msg => '[Fork]: fork_timestamp: ' . $res_timestamp .
' | fork_occurence: ' . $result->{occurence} . ' | fork_blockNumber: ' . $result->{last_update}->{blockNumber} .

View File

@ -24,12 +24,11 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Cache::File;
use Digest::MD5 qw(md5_hex);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
@ -42,13 +41,16 @@ sub new {
sub manage_selection {
my ($self, %options) = @_;
$self->{cache_name} = "parity_ethpoller_" . $self->{mode} . '_' . (defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'me') . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
my $results = $options{custom}->request_api(url_path => '/watchlist');
# use Data::Dumper;
# print Dumper($results);
# Alerts management
my $cache = Cache::File->new( cache_root => './parity-eth-poller-cache' );
# my $cache = Cache::File->new( cache_root => './parity-eth-poller-cache' );
foreach my $account (@{$results->{Accounts}}) {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
@ -84,13 +86,13 @@ sub manage_selection {
' | timestamp: ' . localtime(hex($contract->{last_update}->{timestamp})) . ' | blockNumber: ' . $contract->{last_update}->{blockNumber} .
' | sender: ' . $contract->{last_update}->{sender} . ' | value: ' . $contract->{last_update}->{value} );
if (my $cached_balance = $cache->get('contract_balance_' . $contract->{id})) {
if ($cached_balance != $contract->{balance}) {
#alert
}
} else {
$cache->set('contract_balance_' . $contract->{id}, $contract->{balance});
}
# if (my $cached_balance = $cache->get('contract_balance_' . $contract->{id})) {
# if ($cached_balance != $contract->{balance}) {
# #alert
# }
# } else {
# $cache->set('contract_balance_' . $contract->{id}, $contract->{balance});
# }
}

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Cache::File;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output {
@ -101,7 +101,7 @@ sub set_counters {
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
@ -128,6 +128,9 @@ sub prefix_module_output {
sub manage_selection {
my ($self, %options) = @_;
$self->{cache_name} = "parity_restapi_" . $self->{mode} . '_' . (defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'me') . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
my $query_form_post = [ { method => 'eth_mining', params => [], id => "1", jsonrpc => "2.0" },
{ method => 'eth_coinbase', params => [], id => "2", jsonrpc => "2.0" },
{ method => 'eth_gasPrice', params => [], id => "3", jsonrpc => "2.0" } ,
@ -151,23 +154,23 @@ sub manage_selection {
my $res_highestBlock = $res_sync != 100 ? hex(@{$result}[6]->{result}->{highestBlock}) : 'none';
# Alerts management
my $cache = Cache::File->new( cache_root => './parity-restapi-cache' );
# my $cache = Cache::File->new( cache_root => './parity-restapi-cache' );
if (my $cached_sync = $cache->get('node_sync')) {
if ($cached_sync == 100 && $res_sync < 100) {
#alert
}
} else {
$cache->set('node_sync', $res_sync);
}
# if (my $cached_sync = $cache->get('node_sync')) {
# if ($cached_sync == 100 && $res_sync < 100) {
# #alert
# }
# } else {
# $cache->set('node_sync', $res_sync);
# }
if (my $cached_price = $cache->get('gas_price')) {
if ($cached_price != $gas_price) {
#alert
}
} else {
$cache->set('gas_price', $gas_price);
}
# if (my $cached_price = $cache->get('gas_price')) {
# if ($cached_price != $gas_price) {
# #alert
# }
# } else {
# $cache->set('gas_price', $gas_price);
# }
$self->{global} = { gas_price => $gas_price };

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Cache::File;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output {
@ -57,7 +57,7 @@ sub set_counters {
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
@ -84,6 +84,9 @@ sub prefix_module_output {
sub manage_selection {
my ($self, %options) = @_;
$self->{cache_name} = "parity_restapi_" . $self->{mode} . '_' . (defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'me') . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
my $query_form_post = [ { method => 'net_listening', params => [], id => "1", jsonrpc => "2.0" },
{ method => 'net_peerCount', params => [], id => "2", jsonrpc => "2.0" } ];
@ -92,17 +95,17 @@ sub manage_selection {
my $peer_count = hex(@{$result}[1]->{result});
# Alerts management
my $cache = Cache::File->new( cache_root => './parity-restapi-cache' );
# my $cache = Cache::File->new( cache_root => './parity-restapi-cache' );
if (my $cached_count = $cache->get('peers_count')) {
if ($peer_count < $cached_count) {
#alert
} elsif ($peer_count > $cached_count) {
#alert
}
} else {
$cache->set('peers_count', $peer_count);
}
# if (my $cached_count = $cache->get('peers_count')) {
# if ($peer_count < $cached_count) {
# #alert
# } elsif ($peer_count > $cached_count) {
# #alert
# }
# } else {
# $cache->set('peers_count', $peer_count);
# }
$self->{network} = { peers => hex(@{$result}[1]->{result}) };

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Cache::File;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub set_counters {
@ -49,7 +49,7 @@ sub set_counters {
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
@ -76,6 +76,9 @@ sub prefix_module_output {
sub manage_selection {
my ($self, %options) = @_;
$self->{cache_name} = "parity_restapi_" . $self->{mode} . '_' . (defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'me') . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
my $query_form_post = [ { method => 'parity_versionInfo', params => [], id => "1", jsonrpc => "2.0" },
{ method => 'parity_chain', params => [], id => "2", jsonrpc => "2.0" },
{ method => 'parity_pendingTransactions', params => [], id => "3", jsonrpc => "2.0" } ,
@ -93,23 +96,23 @@ sub manage_selection {
my $res_parity_version = @{$result}[0]->{result}->{version}->{major} . '.' . @{$result}[0]->{result}->{version}->{minor} . '.' . @{$result}[0]->{result}->{version}->{patch};
# Alerts management
my $cache = Cache::File->new( cache_root => './parity-restapi-cache' );
# my $cache = Cache::File->new( cache_root => './parity-restapi-cache' );
if (my $cached_version = $cache->get('parity_version')) {
if ($res_parity_version ne $cached_version) {
#alert
}
} else {
$cache->set('parity_version', $res_parity_version);
}
# if (my $cached_version = $cache->get('parity_version')) {
# if ($res_parity_version ne $cached_version) {
# #alert
# }
# } else {
# $cache->set('parity_version', $res_parity_version);
# }
if (my $cached_name = $cache->get('chain_name')) {
if ($cached_name ne @{$result}[1]->{result}) {
#alert
}
} else {
$cache->set('chain_name', @{$result}[1]->{result});
}
# if (my $cached_name = $cache->get('chain_name')) {
# if ($cached_name ne @{$result}[1]->{result}) {
# #alert
# }
# } else {
# $cache->set('chain_name', @{$result}[1]->{result});
# }
# use Data::Dumper;
# print Dumper($result);