From bcb95743d949e732684003402e8e85328baa8c13 Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Thu, 9 Apr 2020 08:28:21 +0000 Subject: [PATCH] remove Cache::File package --- blockchain/parity/ethpoller/mode/fork.pm | 23 +++++++----- blockchain/parity/ethpoller/mode/watchlist.pm | 22 ++++++----- blockchain/parity/restapi/mode/eth.pm | 37 ++++++++++--------- blockchain/parity/restapi/mode/net.pm | 27 ++++++++------ blockchain/parity/restapi/mode/parity.pm | 37 ++++++++++--------- 5 files changed, 80 insertions(+), 66 deletions(-) diff --git a/blockchain/parity/ethpoller/mode/fork.pm b/blockchain/parity/ethpoller/mode/fork.pm index 7fc4f5c0c..597dbd4a0 100644 --- a/blockchain/parity/ethpoller/mode/fork.pm +++ b/blockchain/parity/ethpoller/mode/fork.pm @@ -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} . diff --git a/blockchain/parity/ethpoller/mode/watchlist.pm b/blockchain/parity/ethpoller/mode/watchlist.pm index a6a7b28f8..69e2baef2 100644 --- a/blockchain/parity/ethpoller/mode/watchlist.pm +++ b/blockchain/parity/ethpoller/mode/watchlist.pm @@ -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}); + # } } diff --git a/blockchain/parity/restapi/mode/eth.pm b/blockchain/parity/restapi/mode/eth.pm index 00c479110..fd819842a 100644 --- a/blockchain/parity/restapi/mode/eth.pm +++ b/blockchain/parity/restapi/mode/eth.pm @@ -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 }; diff --git a/blockchain/parity/restapi/mode/net.pm b/blockchain/parity/restapi/mode/net.pm index 17ceaed4b..b3d9fdd5a 100644 --- a/blockchain/parity/restapi/mode/net.pm +++ b/blockchain/parity/restapi/mode/net.pm @@ -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}) }; diff --git a/blockchain/parity/restapi/mode/parity.pm b/blockchain/parity/restapi/mode/parity.pm index 8823d1673..f58e3234e 100644 --- a/blockchain/parity/restapi/mode/parity.pm +++ b/blockchain/parity/restapi/mode/parity.pm @@ -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);