From 5bc57d7a4054e49ac2c30dba2c1ab167dfd08769 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Mon, 23 Mar 2020 13:38:28 +0100 Subject: [PATCH 01/26] (wip)sample net mode for parity --- .../blockchain/parity/restapi/custom/api.pm | 187 ++++++++++++++++++ .../blockchain/parity/restapi/mode/net.pm | 133 +++++++++++++ .../blockchain/parity/restapi/plugin.pm | 48 +++++ 3 files changed, 368 insertions(+) create mode 100644 centreon-plugins/blockchain/parity/restapi/custom/api.pm create mode 100644 centreon-plugins/blockchain/parity/restapi/mode/net.pm create mode 100644 centreon-plugins/blockchain/parity/restapi/plugin.pm diff --git a/centreon-plugins/blockchain/parity/restapi/custom/api.pm b/centreon-plugins/blockchain/parity/restapi/custom/api.pm new file mode 100644 index 000000000..d792c57d8 --- /dev/null +++ b/centreon-plugins/blockchain/parity/restapi/custom/api.pm @@ -0,0 +1,187 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package blockchain::parity::restapi::custom::api; + +use strict; +use warnings; +use centreon::plugins::http; +use JSON; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + "hostname:s" => { name => 'hostname' }, + "timeout:s" => { name => 'timeout' }, + "api-path:s" => { name => 'api_path' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : undef; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; + $self->{api_path} = (defined($self->{option_results}->{api_path})) ? $self->{option_results}->{api_path} : '/'; + + if (!defined($self->{hostname})) { + $self->{output}->add_option_msg(short_msg => "Need to specify hostname option."); + $self->{output}->option_exit(); + } + return 0; +} + +sub get_connection_infos { + my ($self, %options) = @_; + + return $self->{hostname} . '_' . $self->{http}->get_port(); +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{port} = 8545; + $self->{option_results}->{proto} = 'http'; +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->add_header(key => 'Accept', value => 'application/json'); + $self->{http}->add_header(key => 'Content-Type', value => 'application/json'); + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub request_api { + my ($self, %options) = @_; + + + $self->settings(); + + my $encoded; + eval { + $encoded = encode_json($options{query_form_post}); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot encode json request"); + $self->{output}->option_exit(); + } + + my $content = $self->{http}->request(method => $options{method}, url_path => '/', query_form_post => $encoded, + critical_status => '', warning_status => '', unknown_status => ''); + + my $decoded; + eval { + $decoded = decode_json($content); + }; + if ($@) { + $self->{output}->output_add(long_msg => $content, debug => 1); + $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); + $self->{output}->option_exit(); + } + if ($self->{http}->get_code() != 200) { + $self->{output}->add_option_msg(short_msg => "Connection issue: " . $decoded->{msg}); + $self->{output}->option_exit(); + } + + return $decoded; +} + +1; + +__END__ + +=head1 NAME + +Parity node JSON WEBRPC + +=head1 SYNOPSIS + +Parity node JSON RPC API custom mode + +=head1 REST API OPTIONS + +=over 8 + +=item B<--hostname> + +Parity node hostname or IP + +=item B<--timeout> + +Set HTTP timeout in seconds (Default: '10'). + +=item B<--api-path> + +API base url path (Default: '/'). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/blockchain/parity/restapi/mode/net.pm b/centreon-plugins/blockchain/parity/restapi/mode/net.pm new file mode 100644 index 000000000..a1f94ffc3 --- /dev/null +++ b/centreon-plugins/blockchain/parity/restapi/mode/net.pm @@ -0,0 +1,133 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package blockchain::parity::restapi::mode::net; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'Listening status: %s ', + $self->{result_values}->{listening}, + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'network', cb_prefix_output => 'prefix_module_output', type => 0 }, + ]; + + $self->{maps_counters}->{network} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'listening' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } + }, + { label => 'peers', nlabel => 'parity.network.peers.count', set => { + key_values => [ { name => 'peers' } ], + output_template => "connected peers: %s ", + perfdatas => [ + { label => 'peer_count', value => 'peers_absolute', template => '%d', min => 0 } + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{listening} !~ /true/' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +sub prefix_module_output { + my ($self, %options) = @_; + + return "Parity network module: "; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $query_form_post_listening = { method => 'net_listening', params => [], id => "1", jsonrpc => "2.0" }; + my $result_listening = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post_listening); + + my $query_form_post_peer = { method => 'net_peerCount', params => [], id => "1", jsonrpc => "2.0" }; + my $result_peer = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post_peer); + + $self->{network} = { listening => $result_listening->{result}, + peers => hex($result_peer->{result}) } + +} + +1; + +__END__ + +=head1 MODE + +Check network module metrics parity (net_isListening, net_peerCount) + +=over 8 + +=item B<--unknown-status> + +Set unknown threshold for listening status (Default: ''). + +=item B<--warning-status> + +Set warning threshold for listening status (Default: ''). + +=item B<--critical-status> + +Set critical threshold for listening status (Default: '%{listening} !~ /true/'). + +=item B<--warning-peers> B<--critical-peers> + +Warning and Critical threhsold on the number of peer + +=back + +=cut diff --git a/centreon-plugins/blockchain/parity/restapi/plugin.pm b/centreon-plugins/blockchain/parity/restapi/plugin.pm new file mode 100644 index 000000000..cda22b0ac --- /dev/null +++ b/centreon-plugins/blockchain/parity/restapi/plugin.pm @@ -0,0 +1,48 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package blockchain::parity::restapi::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'net' => 'blockchain::parity::restapi::mode::net', + ); + $self->{custom_modes}{api} = 'blockchain::parity::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Parity blockchain with JSON RPC + +=cut From 3af3b4ff513fea704507aff73837a22cf9075e08 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Mon, 23 Mar 2020 15:21:56 +0100 Subject: [PATCH 02/26] (wip) sample multiple method post on RPC --- .../blockchain/parity/restapi/mode/net.pm | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/centreon-plugins/blockchain/parity/restapi/mode/net.pm b/centreon-plugins/blockchain/parity/restapi/mode/net.pm index a1f94ffc3..d5e8f88cf 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/net.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/net.pm @@ -91,15 +91,14 @@ sub prefix_module_output { sub manage_selection { my ($self, %options) = @_; - my $query_form_post_listening = { method => 'net_listening', params => [], id => "1", jsonrpc => "2.0" }; - my $result_listening = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post_listening); - - my $query_form_post_peer = { method => 'net_peerCount', params => [], id => "1", jsonrpc => "2.0" }; - my $result_peer = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post_peer); + my $query_form_post = [ { method => 'net_listening', params => [], id => "1", jsonrpc => "2.0" }, + { method => 'net_peerCount', params => [], id => "2", jsonrpc => "2.0" } ]; + + my $result = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post); + + $self->{network} = { listening => @{$result}[0]->{result}, + peers => hex(@{$result}[1]->{result}) }; - $self->{network} = { listening => $result_listening->{result}, - peers => hex($result_peer->{result}) } - } 1; From 4fb88add7e3b96227fe61978c52ddc110f711739 Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Wed, 25 Mar 2020 16:38:57 +0000 Subject: [PATCH 03/26] adding eth module --- .../blockchain/parity/restapi/mode/eth.pm | 223 ++++++++++++++++++ .../blockchain/parity/restapi/plugin.pm | 1 + 2 files changed, 224 insertions(+) create mode 100644 centreon-plugins/blockchain/parity/restapi/mode/eth.pm diff --git a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm new file mode 100644 index 000000000..6beec926d --- /dev/null +++ b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm @@ -0,0 +1,223 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package blockchain::parity::restapi::mode::eth; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'Listening status: %s ', + $self->{result_values}->{listening}, + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'eth', cb_prefix_output => 'prefix_module_output', type => 0 }, + ]; + + $self->{maps_counters}->{eth} = [ + { label => 'is_minning', nlabel => 'parity.eth.peers.minning.status', set => { + key_values => [ { name => 'is_minning' } ], + output_template => "Client is minning: %s ", + perfdatas => [ + { label => 'is_minning', value => 'is_minning_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'coinbase', nlabel => 'parity.eth.client.coinbase', set => { + key_values => [ { name => 'coinbase' } ], + output_template => "Client coinbase is: %s ", + perfdatas => [ + { label => 'client_coinbase', value => 'coinbase_absolute', template => '%s', min => 0 } + ], + } + }, + { label => 'gas_price', nlabel => 'parity.eth.gas.price', set => { + key_values => [ { name => 'gas_price' } ], + output_template => "The gas price is: %d wei ", + perfdatas => [ + { label => 'gas_price', value => 'gas_price_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'hashrate', nlabel => 'parity.eth.node.hashrate', set => { + key_values => [ { name => 'hashrate' } ], + output_template => "Node hashrate is: %d/s ", + perfdatas => [ + { label => 'node_hashrate', value => 'hashrate_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'block_number', nlabel => 'parity.eth.block.number', set => { + key_values => [ { name => 'block_number' } ], + output_template => "Most recent block number is: %d ", + perfdatas => [ + { label => 'block_number', value => 'block_number_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'block_time', nlabel => 'parity.eth.block.time', set => { + key_values => [ { name => 'block_time' } ], + output_template => "Block time is: %s ", + perfdatas => [ + { label => 'block_time', value => 'block_time_absolute', template => '%s', min => 0 } + ], + } + }, + { label => 'sync_start', nlabel => 'parity.eth.sync.start.block', set => { + key_values => [ { name => 'sync_start' } ], + output_template => "Sync start block number is: %d ", + perfdatas => [ + { label => 'sync_start', value => 'sync_start_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'sync_current', nlabel => 'parity.eth.sync.current.block', set => { + key_values => [ { name => 'sync_current' } ], + output_template => "Sync current block number is: %d ", + perfdatas => [ + { label => 'sync_current', value => 'sync_current_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'sync_highest', nlabel => 'parity.eth.sync.highest.block', set => { + key_values => [ { name => 'sync_highest' } ], + output_template => "Sync highest block number is: %d ", + perfdatas => [ + { label => 'sync_highest', value => 'sync_highest_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'sync', nlabel => 'parity.eth.sync.ratio', set => { + key_values => [ { name => 'sync' } ], + output_template => "Sync ratio is: %d% ", + perfdatas => [ + { label => 'sync', value => 'sync_absolute', template => '%d', min => 0 } + ], + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{listening} !~ /true/' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +sub prefix_module_output { + my ($self, %options) = @_; + + return "Parity Eth module: "; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $query_form_post = [ { method => 'eth_mining', params => [], id => "1", jsonrpc => "2.0" }, + { method => 'eth_coinbase', params => [], id => "1", jsonrpc => "2.0" }, + { method => 'eth_gasPrice', params => [], id => "1", jsonrpc => "2.0" } , + { method => 'eth_hashrate', params => [], id => "1", jsonrpc => "2.0" } , + { method => 'eth_blockNumber', params => [], id => "1", jsonrpc => "2.0" }, + { method => 'eth_getBlockByNumber', params => ["latest","false"], id => "1", jsonrpc => "2.0" }, + { method => 'eth_syncing', params => [], id => "1", jsonrpc => "2.0" }, + { method => 'eth_coinbase', params => [], id => "1", jsonrpc => "2.0" }, + { method => 'eth_coinbase', params => [], id => "1", jsonrpc => "2.0" }, + { method => 'eth_coinbase', params => [], id => "1", jsonrpc => "2.0" }, + { method => 'eth_coinbase', params => [], id => "1", jsonrpc => "2.0" }, + { method => 'eth_coinbase', params => [], id => "1", jsonrpc => "2.0" } ]; + + my $result = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post); + + # conditional formating: + my $res_sync = @{$result}[6]->{result} ? (@{$result}[6]->{result}->{currentBlock} / @{$result}[6]->{result}->{highestBlock}) * 100 : 100; + my $res_startingBlock = $res_sync != 100 ? @{$result}[6]->{result}->{startingBlock} : undef; + my $res_currentBlock = $res_sync != 100 ? @{$result}[6]->{result}->{currentBlock} : undef; + my $res_highestBlock = $res_sync != 100 ? @{$result}[6]->{result}->{highestBlock} : undef; + + # Unix time conversion + my $res_timestamp = localtime((@{$result}[5]->{result}->{timestamp})); + + $self->{eth} = { is_minning => @{$result}[0]->{result}, + coinbase => @{$result}[1]->{result}, + gas_price => @{$result}[2]->{result}, + hashrate => hex(@{$result}[3]->{result}), + block_number => @{$result}[4]->{result}, + block_time => $res_timestamp, + sync_start => $res_startingBlock, + sync_current => $res_currentBlock, + sync_highest => $res_highestBlock, + sync => $res_sync }; + +} + +1; + +__END__ + +=head1 MODE + +Check eth module metrics parity (eth_mining, eth_coinbase, eth_gasPrice, eth_hashrate, eth_blockNumber, eth_getBlockByNumber::timestamp) + +=over 8 + +=item B<--unknown-status> + +Set unknown threshold for listening status (Default: ''). + +=item B<--warning-status> + +Set warning threshold for listening status (Default: ''). + +=item B<--critical-status> + +Set critical threshold for listening status (Default: '%{listening} !~ /true/'). + +=item B<--warning-peers> B<--critical-peers> + +Warning and Critical threhsold on the number of peer + +=back + +=cut diff --git a/centreon-plugins/blockchain/parity/restapi/plugin.pm b/centreon-plugins/blockchain/parity/restapi/plugin.pm index cda22b0ac..64e9f0a9b 100644 --- a/centreon-plugins/blockchain/parity/restapi/plugin.pm +++ b/centreon-plugins/blockchain/parity/restapi/plugin.pm @@ -32,6 +32,7 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( 'net' => 'blockchain::parity::restapi::mode::net', + 'eth' => 'blockchain::parity::restapi::mode::eth', ); $self->{custom_modes}{api} = 'blockchain::parity::restapi::custom::api'; return $self; From 193007ef20fbc82ea7e039a6e42b13bbe6fe8644 Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Thu, 26 Mar 2020 08:40:14 +0000 Subject: [PATCH 04/26] adding parity mode --- .../blockchain/parity/restapi/mode/parity.pm | 204 ++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 centreon-plugins/blockchain/parity/restapi/mode/parity.pm diff --git a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm new file mode 100644 index 000000000..122fd090b --- /dev/null +++ b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm @@ -0,0 +1,204 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package blockchain::parity::restapi::mode::parity; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'parity', cb_prefix_output => 'prefix_module_output', type => 0 }, + ]; + + $self->{maps_counters}->{parity} = [ + { label => 'parity_version', nlabel => 'parity.version', set => { + key_values => [ { name => 'parity_version' } ], + output_template => "Parity version is: %s ", + perfdatas => [ + { label => 'parity_version', value => 'parity_version_absolute', template => '%s', min => 0 } + ], + } + }, + { label => 'parity_version_hash', nlabel => 'parity.version.hash', set => { + key_values => [ { name => 'parity_version_hash' } ], + output_template => "Parity version hash is: %s ", + perfdatas => [ + { label => 'parity_version_hash', value => 'parity_version_hash_absolute', template => '%s', min => 0 } + ], + } + }, + { label => 'chain_name', nlabel => 'parity.chain.name', set => { + key_values => [ { name => 'chain_name' } ], + output_template => "Chain name is: %s ", + perfdatas => [ + { label => 'chain_name', value => 'chain_name_absolute', template => '%s', min => 0 } + ], + } + }, + { label => 'pending_transactions', nlabel => 'parity.pending.transactions', set => { + key_values => [ { name => 'pending_transactions' } ], + output_template => "Pending transactions: %d ", + perfdatas => [ + { label => 'pending_transactions', value => 'pending_transactions_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'mempool', nlabel => 'parity.mempol.capacity', set => { + key_values => [ { name => 'mempool' } ], + output_template => "Mempool: %d % ", + perfdatas => [ + { label => 'mempool', value => 'mempool_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'peers_connected', nlabel => 'parity.peers.connected', set => { + key_values => [ { name => 'peers_connected' } ], + output_template => "Number of connected peers: %d ", + perfdatas => [ + { label => 'peers_connected', value => 'peers_connected_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'peers_max', nlabel => 'parity.peers.max.connected', set => { + key_values => [ { name => 'peers_max' } ], + output_template => "Maximum number of connected peers: %d ", + perfdatas => [ + { label => 'peers_max', value => 'peers_max_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'peers', nlabel => 'parity.peers', set => { + key_values => [ { name => 'peers' } ], + output_template => "Peers: %d ", + perfdatas => [ + { label => 'peers', value => 'peers_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'enode', nlabel => 'parity.node.enode.uri', set => { + key_values => [ { name => 'enode' } ], + output_template => "Node enode URI: %s ", + perfdatas => [ + { label => 'enode', value => 'enode_absolute', template => '%s', min => 0 } + ], + } + }, + { label => 'node_name', nlabel => 'parity.node.name', set => { + key_values => [ { name => 'node_name' } ], + output_template => "Node name: %s ", + perfdatas => [ + { label => 'node_name', value => 'node_name_absolute', template => '%s', min => 0 } + ], + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{listening} !~ /true/' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +sub prefix_module_output { + my ($self, %options) = @_; + + return "Parity module: "; +} + +sub manage_selection { + my ($self, %options) = @_; + + 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" } , + { method => 'parity_netPeers', params => [], id => "4", jsonrpc => "2.0" }, + { method => 'parity_enode', params => [], id => "5", jsonrpc => "2.0" }, + { method => 'parity_nodeName', params => [], id => "6", jsonrpc => "2.0" }, + { method => 'parity_transactionsLimit', params => [], id => "7", jsonrpc => "2.0" } # could be done once, at the beginning of the process + ]; + + my $result = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post); + + # Parity version construction + my $res_parity_version = @{$result}[0]->{result}->{version}->{major} . @{$result}[0]->{result}->{version}->{minor} . @{$result}[0]->{result}->{version}->{patch}; + + $self->{eth} = { parity_version => $res_parity_version, + parity_version_hash => @{$result}[0]->{result}->{hash}, + chain_name => @{$result}[1]->{result}, + pending_transactions => scalar @{$result}[2]->{result}, + mempool => @{$result}[2]->{result} / @{$result}[6]->{result} * 100, + peers_connected => @{$result}[3]->{result}->{connected}, + peers_max => @{$result}[3]->{result}->{max}, + peers => scalar @{$result}[3]->{result}->{peers}, + enode => @{$result}[4]->{result}, + node_name => @{$result}[5]->{result} }; + +} + +1; + +__END__ + +=head1 MODE + +Check parity module metrics parity (parity_versionInfo, ) + +=over 8 + +=item B<--unknown-status> + +Set unknown threshold for listening status (Default: ''). + +=item B<--warning-status> + +Set warning threshold for listening status (Default: ''). + +=item B<--critical-status> + +Set critical threshold for listening status (Default: '%{listening} !~ /true/'). + +=item B<--warning-peers> B<--critical-peers> + +Warning and Critical threhsold on the number of peer + +=back + +=cut From 56072bec0a4931c841eef214226758ac781d57b2 Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Thu, 26 Mar 2020 08:45:23 +0000 Subject: [PATCH 05/26] adding parity mode --- centreon-plugins/blockchain/parity/restapi/plugin.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/centreon-plugins/blockchain/parity/restapi/plugin.pm b/centreon-plugins/blockchain/parity/restapi/plugin.pm index 64e9f0a9b..7cffb8686 100644 --- a/centreon-plugins/blockchain/parity/restapi/plugin.pm +++ b/centreon-plugins/blockchain/parity/restapi/plugin.pm @@ -31,8 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'net' => 'blockchain::parity::restapi::mode::net', - 'eth' => 'blockchain::parity::restapi::mode::eth', + 'net' => 'blockchain::parity::restapi::mode::net', + 'eth' => 'blockchain::parity::restapi::mode::eth', + 'parity' => 'blockchain::parity::restapi::mode::parity' ); $self->{custom_modes}{api} = 'blockchain::parity::restapi::custom::api'; return $self; From b6fe4df42ff277d1a5c8bf2495b17b22a652baf6 Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Thu, 26 Mar 2020 09:21:33 +0000 Subject: [PATCH 06/26] code cleanning --- .../blockchain/parity/restapi/mode/eth.pm | 64 ++++++++++--------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm index 6beec926d..5dcd4d71e 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm @@ -26,12 +26,12 @@ use strict; use warnings; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); -sub custom_status_output { +sub custom_mining_status_output { my ($self, %options) = @_; return sprintf( - 'Listening status: %s ', - $self->{result_values}->{listening}, + 'Client mininig status: %s ', + $self->{result_values}->{is_mining}, ); } @@ -43,14 +43,23 @@ sub set_counters { ]; $self->{maps_counters}->{eth} = [ - { label => 'is_minning', nlabel => 'parity.eth.peers.minning.status', set => { - key_values => [ { name => 'is_minning' } ], - output_template => "Client is minning: %s ", + { label => 'is_mining', nlabel => 'parity.eth.peers.mining.status', set => { + key_values => [ { name => 'is_mining' } ], + output_template => "Client is mining: " . $self->can('custom_mining_status_output'), perfdatas => [ - { label => 'is_minning', value => 'is_minning_absolute', template => '%d', min => 0 } + { label => 'is_mining', value => 'is_mining_absolute', template => '%s', min => 0 } ], } }, + # { label => 'is_mining', nlabel => 'parity.eth.peers.mining.status', threshold => 0, set => { + # key_values => [ { name => 'is_mining' } ], + # output_template => "Client is mining: %s ", + # closure_custom_calc => \&catalog_status_calc, + # closure_custom_output => $self->can('custom_mining_status_output'), + # closure_custom_perfdata => sub { return 0; }, + # closure_custom_threshold_check => \&catalog_status_threshold + # } + # }, { label => 'coinbase', nlabel => 'parity.eth.client.coinbase', set => { key_values => [ { name => 'coinbase' } ], output_template => "Client coinbase is: %s ", @@ -156,39 +165,34 @@ sub manage_selection { my ($self, %options) = @_; my $query_form_post = [ { method => 'eth_mining', params => [], id => "1", jsonrpc => "2.0" }, - { method => 'eth_coinbase', params => [], id => "1", jsonrpc => "2.0" }, - { method => 'eth_gasPrice', params => [], id => "1", jsonrpc => "2.0" } , - { method => 'eth_hashrate', params => [], id => "1", jsonrpc => "2.0" } , - { method => 'eth_blockNumber', params => [], id => "1", jsonrpc => "2.0" }, - { method => 'eth_getBlockByNumber', params => ["latest","false"], id => "1", jsonrpc => "2.0" }, - { method => 'eth_syncing', params => [], id => "1", jsonrpc => "2.0" }, - { method => 'eth_coinbase', params => [], id => "1", jsonrpc => "2.0" }, - { method => 'eth_coinbase', params => [], id => "1", jsonrpc => "2.0" }, - { method => 'eth_coinbase', params => [], id => "1", jsonrpc => "2.0" }, - { method => 'eth_coinbase', params => [], id => "1", jsonrpc => "2.0" }, - { method => 'eth_coinbase', params => [], id => "1", jsonrpc => "2.0" } ]; + { method => 'eth_coinbase', params => [], id => "2", jsonrpc => "2.0" }, + { method => 'eth_gasPrice', params => [], id => "3", jsonrpc => "2.0" } , + { method => 'eth_hashrate', params => [], id => "4", jsonrpc => "2.0" } , + { method => 'eth_blockNumber', params => [], id => "5", jsonrpc => "2.0" }, + { method => 'eth_getBlockByNumber', params => ["latest","false"], id => "6", jsonrpc => "2.0" }, + { method => 'eth_syncing', params => [], id => "7", jsonrpc => "2.0" } ]; my $result = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post); # conditional formating: - my $res_sync = @{$result}[6]->{result} ? (@{$result}[6]->{result}->{currentBlock} / @{$result}[6]->{result}->{highestBlock}) * 100 : 100; + my $res_sync = @{$result}[6]->{result} ? hex((@{$result}[6]->{result}->{currentBlock} / @{$result}[6]->{result}->{highestBlock})) * 100 : 100; my $res_startingBlock = $res_sync != 100 ? @{$result}[6]->{result}->{startingBlock} : undef; my $res_currentBlock = $res_sync != 100 ? @{$result}[6]->{result}->{currentBlock} : undef; my $res_highestBlock = $res_sync != 100 ? @{$result}[6]->{result}->{highestBlock} : undef; # Unix time conversion - my $res_timestamp = localtime((@{$result}[5]->{result}->{timestamp})); + my $res_timestamp = localtime(hex(@{$result}[5]->{result}->{timestamp})); - $self->{eth} = { is_minning => @{$result}[0]->{result}, - coinbase => @{$result}[1]->{result}, - gas_price => @{$result}[2]->{result}, - hashrate => hex(@{$result}[3]->{result}), - block_number => @{$result}[4]->{result}, - block_time => $res_timestamp, - sync_start => $res_startingBlock, - sync_current => $res_currentBlock, - sync_highest => $res_highestBlock, - sync => $res_sync }; + $self->{eth} = { is_mining => @{$result}[0]->{result}, + coinbase => @{$result}[1]->{result}, + gas_price => hex(@{$result}[2]->{result}), + hashrate => hex(@{$result}[3]->{result}), + block_number => hex(@{$result}[4]->{result}), + block_time => $res_timestamp, + sync_start => hex($res_startingBlock), + sync_current => hex($res_currentBlock), + sync_highest => hex($res_highestBlock), + sync => $res_sync }; } From 7856ad2d05460e5911fcea8418ee0855e131ee37 Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Thu, 26 Mar 2020 17:10:09 +0000 Subject: [PATCH 07/26] counters split --- .../blockchain/parity/restapi/mode/eth.pm | 118 ++++++++------- .../blockchain/parity/restapi/mode/parity.pm | 134 +++++++++++------- 2 files changed, 150 insertions(+), 102 deletions(-) diff --git a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm index 5dcd4d71e..21aa5498b 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm @@ -26,7 +26,7 @@ use strict; use warnings; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); -sub custom_mining_status_output { +sub custom_status_output { my ($self, %options) = @_; return sprintf( @@ -39,30 +39,17 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'eth', cb_prefix_output => 'prefix_module_output', type => 0 }, + { name => 'global', cb_prefix_output => 'prefix_module_output', type => 0 }, + { name => 'peer', cb_prefix_output => 'prefix_module_output', type => 0 }, + { name => 'block', cb_prefix_output => 'prefix_module_output', type => 0 }, + { name => 'sync', cb_prefix_output => 'prefix_module_output', type => 0 } ]; - $self->{maps_counters}->{eth} = [ - { label => 'is_mining', nlabel => 'parity.eth.peers.mining.status', set => { - key_values => [ { name => 'is_mining' } ], - output_template => "Client is mining: " . $self->can('custom_mining_status_output'), - perfdatas => [ - { label => 'is_mining', value => 'is_mining_absolute', template => '%s', min => 0 } - ], - } - }, - # { label => 'is_mining', nlabel => 'parity.eth.peers.mining.status', threshold => 0, set => { - # key_values => [ { name => 'is_mining' } ], - # output_template => "Client is mining: %s ", - # closure_custom_calc => \&catalog_status_calc, - # closure_custom_output => $self->can('custom_mining_status_output'), - # closure_custom_perfdata => sub { return 0; }, - # closure_custom_threshold_check => \&catalog_status_threshold - # } - # }, + $self->{maps_counters}->{global} = [ { label => 'coinbase', nlabel => 'parity.eth.client.coinbase', set => { key_values => [ { name => 'coinbase' } ], output_template => "Client coinbase is: %s ", + # closure_custom_perfdata => sub { return 0; } perfdatas => [ { label => 'client_coinbase', value => 'coinbase_absolute', template => '%s', min => 0 } ], @@ -75,6 +62,25 @@ sub set_counters { { label => 'gas_price', value => 'gas_price_absolute', template => '%d', min => 0 } ], } + } + ]; + + $self->{maps_counters}->{peer} = [ + # { label => 'status', nlabel => 'parity.eth.peers.mining.status', set => { + # key_values => [ { name => 'is_mining' } ], + # output_template => "Client is mining: " . $self->can('custom_mining_status_output'), + # perfdatas => [ + # { label => 'is_mining', value => 'is_mining_absolute', template => '%s', min => 0 } + # ], + # } + # }, + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'is_mining' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold + } }, { label => 'hashrate', nlabel => 'parity.eth.node.hashrate', set => { key_values => [ { name => 'hashrate' } ], @@ -84,41 +90,52 @@ sub set_counters { ], } }, + ]; + + $self->{maps_counters}->{block} = [ { label => 'block_number', nlabel => 'parity.eth.block.number', set => { key_values => [ { name => 'block_number' } ], output_template => "Most recent block number is: %d ", - perfdatas => [ - { label => 'block_number', value => 'block_number_absolute', template => '%d', min => 0 } - ], + closure_custom_perfdata => sub { return 0; } + # perfdatas => [ + # { label => 'block_number', value => 'block_number_absolute', template => '%d', min => 0 } + # ], } }, { label => 'block_time', nlabel => 'parity.eth.block.time', set => { key_values => [ { name => 'block_time' } ], output_template => "Block time is: %s ", - perfdatas => [ - { label => 'block_time', value => 'block_time_absolute', template => '%s', min => 0 } - ], + closure_custom_perfdata => sub { return 0; } + # perfdatas => [ + # { label => 'block_time', value => 'block_time_absolute', template => '%s', min => 0 } + # ], } }, + ]; + + $self->{maps_counters}->{sync} = [ { label => 'sync_start', nlabel => 'parity.eth.sync.start.block', set => { key_values => [ { name => 'sync_start' } ], output_template => "Sync start block number is: %d ", - perfdatas => [ - { label => 'sync_start', value => 'sync_start_absolute', template => '%d', min => 0 } - ], + closure_custom_perfdata => sub { return 0; } + # perfdatas => [ + # { label => 'sync_start', value => 'sync_start_absolute', template => '%d', min => 0 } + # ], } }, { label => 'sync_current', nlabel => 'parity.eth.sync.current.block', set => { key_values => [ { name => 'sync_current' } ], output_template => "Sync current block number is: %d ", - perfdatas => [ - { label => 'sync_current', value => 'sync_current_absolute', template => '%d', min => 0 } - ], + closure_custom_perfdata => sub { return 0; } + # perfdatas => [ + # { label => 'sync_current', value => 'sync_current_absolute', template => '%d', min => 0 } + # ], } }, { label => 'sync_highest', nlabel => 'parity.eth.sync.highest.block', set => { key_values => [ { name => 'sync_highest' } ], output_template => "Sync highest block number is: %d ", + # closure_custom_perfdata => sub { return 0; } perfdatas => [ { label => 'sync_highest', value => 'sync_highest_absolute', template => '%d', min => 0 } ], @@ -131,7 +148,7 @@ sub set_counters { { label => 'sync', value => 'sync_absolute', template => '%d', min => 0 } ], } - } + } ]; } @@ -169,31 +186,36 @@ sub manage_selection { { method => 'eth_gasPrice', params => [], id => "3", jsonrpc => "2.0" } , { method => 'eth_hashrate', params => [], id => "4", jsonrpc => "2.0" } , { method => 'eth_blockNumber', params => [], id => "5", jsonrpc => "2.0" }, - { method => 'eth_getBlockByNumber', params => ["latest","false"], id => "6", jsonrpc => "2.0" }, + { method => 'eth_getBlockByNumber', params => ["latest",\0], id => "6", jsonrpc => "2.0" }, { method => 'eth_syncing', params => [], id => "7", jsonrpc => "2.0" } ]; my $result = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post); - + + # use Data::Dumper; + # print Dumper($result); + # conditional formating: my $res_sync = @{$result}[6]->{result} ? hex((@{$result}[6]->{result}->{currentBlock} / @{$result}[6]->{result}->{highestBlock})) * 100 : 100; - my $res_startingBlock = $res_sync != 100 ? @{$result}[6]->{result}->{startingBlock} : undef; - my $res_currentBlock = $res_sync != 100 ? @{$result}[6]->{result}->{currentBlock} : undef; - my $res_highestBlock = $res_sync != 100 ? @{$result}[6]->{result}->{highestBlock} : undef; + my $res_startingBlock = $res_sync != 100 ? hex(@{$result}[6]->{result}->{startingBlock}) : undef; + my $res_currentBlock = $res_sync != 100 ? hex(@{$result}[6]->{result}->{currentBlock}) : undef; + my $res_highestBlock = $res_sync != 100 ? hex(@{$result}[6]->{result}->{highestBlock}) : undef; # Unix time conversion my $res_timestamp = localtime(hex(@{$result}[5]->{result}->{timestamp})); - $self->{eth} = { is_mining => @{$result}[0]->{result}, - coinbase => @{$result}[1]->{result}, - gas_price => hex(@{$result}[2]->{result}), - hashrate => hex(@{$result}[3]->{result}), - block_number => hex(@{$result}[4]->{result}), - block_time => $res_timestamp, - sync_start => hex($res_startingBlock), - sync_current => hex($res_currentBlock), - sync_highest => hex($res_highestBlock), + $self->{global} = { coinbase => @{$result}[1]->{result}, + gas_price => hex(@{$result}[2]->{result}) }; + + $self->{block} = { block_number => defined @{$result}[4]->{result} ? hex(@{$result}[4]->{result}) : 0, + block_time => $res_timestamp }; + + $self->{sync} = { sync_start => $res_startingBlock, + sync_current => $res_currentBlock, + sync_highest => $res_highestBlock, sync => $res_sync }; + $self->{peer} = { is_mining => @{$result}[0]->{result}, + hashrate => hex(@{$result}[3]->{result}) }; } 1; @@ -216,7 +238,7 @@ Set warning threshold for listening status (Default: ''). =item B<--critical-status> -Set critical threshold for listening status (Default: '%{listening} !~ /true/'). +Set critical threshold for listening status (Default: '%{is_mining} !~ /true/'). =item B<--warning-peers> B<--critical-peers> diff --git a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm index 122fd090b..099216314 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm @@ -30,50 +30,64 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'parity', cb_prefix_output => 'prefix_module_output', type => 0 }, + { name => 'global', cb_prefix_output => 'prefix_module_output', type => 0 }, + { name => 'node', cb_prefix_output => 'prefix_module_output', type => 0 }, + { name => 'mempool', cb_prefix_output => 'prefix_module_output', type => 0 }, + { name => 'network', cb_prefix_output => 'prefix_module_output', type => 0 } ]; - $self->{maps_counters}->{parity} = [ + $self->{maps_counters}->{global} = [ { label => 'parity_version', nlabel => 'parity.version', set => { key_values => [ { name => 'parity_version' } ], output_template => "Parity version is: %s ", - perfdatas => [ - { label => 'parity_version', value => 'parity_version_absolute', template => '%s', min => 0 } - ], + closure_custom_perfdata => sub { return 0; } + # perfdatas => [ + # { label => 'parity_version', value => 'parity_version_absolute', template => '%s', min => 0 } + # ], } }, { label => 'parity_version_hash', nlabel => 'parity.version.hash', set => { key_values => [ { name => 'parity_version_hash' } ], output_template => "Parity version hash is: %s ", - perfdatas => [ - { label => 'parity_version_hash', value => 'parity_version_hash_absolute', template => '%s', min => 0 } - ], + closure_custom_perfdata => sub { return 0; } + # perfdatas => [ + # { label => 'parity_version_hash', value => 'parity_version_hash_absolute', template => '%s', min => 0 } + # ], } }, { label => 'chain_name', nlabel => 'parity.chain.name', set => { key_values => [ { name => 'chain_name' } ], output_template => "Chain name is: %s ", - perfdatas => [ - { label => 'chain_name', value => 'chain_name_absolute', template => '%s', min => 0 } - ], + closure_custom_perfdata => sub { return 0; } + # perfdatas => [ + # { label => 'chain_name', value => 'chain_name_absolute', template => '%s', min => 0 } + # ], } }, - { label => 'pending_transactions', nlabel => 'parity.pending.transactions', set => { - key_values => [ { name => 'pending_transactions' } ], - output_template => "Pending transactions: %d ", - perfdatas => [ - { label => 'pending_transactions', value => 'pending_transactions_absolute', template => '%d', min => 0 } - ], + ]; + + $self->{maps_counters}->{node} = [ + { label => 'enode', nlabel => 'parity.node.enode.uri', set => { + key_values => [ { name => 'enode' } ], + output_template => "Node enode URI: %s ", + closure_custom_perfdata => sub { return 0; } + # perfdatas => [ + # { label => 'enode', value => 'enode_absolute', template => '%s', min => 0 } + # ], } }, - { label => 'mempool', nlabel => 'parity.mempol.capacity', set => { - key_values => [ { name => 'mempool' } ], - output_template => "Mempool: %d % ", - perfdatas => [ - { label => 'mempool', value => 'mempool_absolute', template => '%d', min => 0 } - ], + { label => 'node_name', nlabel => 'parity.node.name', set => { + key_values => [ { name => 'node_name' } ], + output_template => "Node name: %s ", + closure_custom_perfdata => sub { return 0; } + # perfdatas => [ + # { label => 'node_name', value => 'node_name_absolute', template => '%s', min => 0 } + # ], } - }, + } + ]; + + $self->{maps_counters}->{network} = [ { label => 'peers_connected', nlabel => 'parity.peers.connected', set => { key_values => [ { name => 'peers_connected' } ], output_template => "Number of connected peers: %d ", @@ -97,24 +111,28 @@ sub set_counters { { label => 'peers', value => 'peers_absolute', template => '%d', min => 0 } ], } - }, - { label => 'enode', nlabel => 'parity.node.enode.uri', set => { - key_values => [ { name => 'enode' } ], - output_template => "Node enode URI: %s ", - perfdatas => [ - { label => 'enode', value => 'enode_absolute', template => '%s', min => 0 } - ], - } - }, - { label => 'node_name', nlabel => 'parity.node.name', set => { - key_values => [ { name => 'node_name' } ], - output_template => "Node name: %s ", - perfdatas => [ - { label => 'node_name', value => 'node_name_absolute', template => '%s', min => 0 } - ], - } } ]; + + $self->{maps_counters}->{mempool} = [ + { label => 'pending_transactions', nlabel => 'parity.pending.transactions', set => { + key_values => [ { name => 'pending_transactions' } ], + output_template => "Pending transactions: %d ", + perfdatas => [ + { label => 'pending_transactions', value => 'pending_transactions_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'mempool', nlabel => 'parity.mempol.capacity', set => { + key_values => [ { name => 'mempool' } ], + output_template => "Mempool: %d % ", + perfdatas => [ + { label => 'mempool', value => 'mempool_absolute', template => '%d', min => 0 } + ], + } + }, + ]; + } sub new { @@ -152,24 +170,32 @@ sub manage_selection { { method => 'parity_netPeers', params => [], id => "4", jsonrpc => "2.0" }, { method => 'parity_enode', params => [], id => "5", jsonrpc => "2.0" }, { method => 'parity_nodeName', params => [], id => "6", jsonrpc => "2.0" }, - { method => 'parity_transactionsLimit', params => [], id => "7", jsonrpc => "2.0" } # could be done once, at the beginning of the process - ]; + { method => 'parity_transactionsLimit', params => [], id => "7", jsonrpc => "2.0" } ]; # parity_transactionsLimit could be done once, at the beginning of the process + my $result = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post); # Parity version construction - my $res_parity_version = @{$result}[0]->{result}->{version}->{major} . @{$result}[0]->{result}->{version}->{minor} . @{$result}[0]->{result}->{version}->{patch}; + my $res_parity_version = @{$result}[0]->{result}->{version}->{major} . '.' . @{$result}[0]->{result}->{version}->{minor} . '.' . @{$result}[0]->{result}->{version}->{patch}; - $self->{eth} = { parity_version => $res_parity_version, - parity_version_hash => @{$result}[0]->{result}->{hash}, - chain_name => @{$result}[1]->{result}, - pending_transactions => scalar @{$result}[2]->{result}, - mempool => @{$result}[2]->{result} / @{$result}[6]->{result} * 100, - peers_connected => @{$result}[3]->{result}->{connected}, - peers_max => @{$result}[3]->{result}->{max}, - peers => scalar @{$result}[3]->{result}->{peers}, - enode => @{$result}[4]->{result}, - node_name => @{$result}[5]->{result} }; + + # use Data::Dumper; + # print Dumper($res_parity_version); + + + $self->{global} = { parity_version => $res_parity_version, + parity_version_hash => @{$result}[0]->{result}->{hash}, + chain_name => @{$result}[1]->{result} }; + + $self->{node} = { enode => @{$result}[4]->{result}, + node_name => @{$result}[5]->{result} }; + + $self->{network} = { peers_connected => @{$result}[3]->{result}->{connected}, + peers_max => @{$result}[3]->{result}->{max}, + peers => length(@{$result}[3]->{result}->{peers}) }; + + $self->{mempool} = { pending_transactions => length(@{$result}[2]->{result}), + mempool => @{$result}[2]->{result} / @{$result}[6]->{result} * 100 }; } @@ -179,7 +205,7 @@ __END__ =head1 MODE -Check parity module metrics parity (parity_versionInfo, ) +Check parity module metrics parity (parity_versionInfo, parity_chain, parity_pendingTransactions, parity_netPeers, parity_enode, parity_nodeName, parity_transactionsLimit) =over 8 From 70106edfe0fb1592ece0527ecc0f03b546233a23 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Fri, 27 Mar 2020 16:12:08 +0100 Subject: [PATCH 08/26] dirty code update as an example --- .../blockchain/parity/restapi/mode/parity.pm | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm index 099216314..0050e1ce9 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm @@ -30,17 +30,18 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', cb_prefix_output => 'prefix_module_output', type => 0 }, +# { name => 'global', cb_prefix_output => 'prefix_module_output', type => 0 }, { name => 'node', cb_prefix_output => 'prefix_module_output', type => 0 }, { name => 'mempool', cb_prefix_output => 'prefix_module_output', type => 0 }, { name => 'network', cb_prefix_output => 'prefix_module_output', type => 0 } ]; $self->{maps_counters}->{global} = [ - { label => 'parity_version', nlabel => 'parity.version', set => { + { label => 'parity_version', nlabel => 'parity.version', threshold => 0, set => { key_values => [ { name => 'parity_version' } ], output_template => "Parity version is: %s ", - closure_custom_perfdata => sub { return 0; } + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => sub { return 0; } # perfdatas => [ # { label => 'parity_version', value => 'parity_version_absolute', template => '%s', min => 0 } # ], @@ -67,10 +68,11 @@ sub set_counters { ]; $self->{maps_counters}->{node} = [ - { label => 'enode', nlabel => 'parity.node.enode.uri', set => { + { label => 'enode', nlabel => 'parity.node.enode.uri', threshold => 0, set => { key_values => [ { name => 'enode' } ], output_template => "Node enode URI: %s ", - closure_custom_perfdata => sub { return 0; } + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => sub { return 0; } # perfdatas => [ # { label => 'enode', value => 'enode_absolute', template => '%s', min => 0 } # ], @@ -125,7 +127,7 @@ sub set_counters { }, { label => 'mempool', nlabel => 'parity.mempol.capacity', set => { key_values => [ { name => 'mempool' } ], - output_template => "Mempool: %d % ", + output_template => "Mempool: %d %% ", perfdatas => [ { label => 'mempool', value => 'mempool_absolute', template => '%d', min => 0 } ], @@ -182,13 +184,15 @@ sub manage_selection { # use Data::Dumper; # print Dumper($res_parity_version); + $self->{output}->output_add(long_msg => "[config] chain name: " . @{$result}[1]->{result} . " parity version: " . $res_parity_version . " version_hash: " . @{$result}[0]->{result}->{hash}, + severity => 'OK'); - $self->{global} = { parity_version => $res_parity_version, - parity_version_hash => @{$result}[0]->{result}->{hash}, - chain_name => @{$result}[1]->{result} }; +# $self->{global} = { parity_version => $res_parity_version, +# parity_version_hash => @{$result}[0]->{result}->{hash}, +# chain_name => @{$result}[1]->{result} }; - $self->{node} = { enode => @{$result}[4]->{result}, - node_name => @{$result}[5]->{result} }; +# $self->{node} = { enode => @{$result}[4]->{result}, +# node_name => @{$result}[5]->{result} }; $self->{network} = { peers_connected => @{$result}[3]->{result}->{connected}, peers_max => @{$result}[3]->{result}->{max}, From da441ccc19dc4dc8edd9db53eef4d61fe9698d07 Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Fri, 27 Mar 2020 15:51:49 +0000 Subject: [PATCH 09/26] formating fix --- centreon-plugins/blockchain/parity/restapi/mode/eth.pm | 2 +- centreon-plugins/blockchain/parity/restapi/mode/parity.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm index 21aa5498b..de8eb872f 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm @@ -143,7 +143,7 @@ sub set_counters { }, { label => 'sync', nlabel => 'parity.eth.sync.ratio', set => { key_values => [ { name => 'sync' } ], - output_template => "Sync ratio is: %d% ", + output_template => "Sync ratio is: %d%% ", perfdatas => [ { label => 'sync', value => 'sync_absolute', template => '%d', min => 0 } ], diff --git a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm index 099216314..cbc70e312 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm @@ -125,7 +125,7 @@ sub set_counters { }, { label => 'mempool', nlabel => 'parity.mempol.capacity', set => { key_values => [ { name => 'mempool' } ], - output_template => "Mempool: %d % ", + output_template => "Mempool: %d %% ", perfdatas => [ { label => 'mempool', value => 'mempool_absolute', template => '%d', min => 0 } ], From 91129fdb2c6773500c7d77a497985482394d70b4 Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Wed, 8 Apr 2020 16:34:15 +0000 Subject: [PATCH 10/26] eth-poller plugin and restapi plugin update --- .../blockchain/parity/ethpoller/custom/api.pm | 204 ++++++++++++++++++ .../blockchain/parity/ethpoller/mode/fork.pm | 98 +++++++++ .../blockchain/parity/ethpoller/mode/stats.pm | 114 ++++++++++ .../parity/ethpoller/mode/watchlist.pm | 130 +++++++++++ .../blockchain/parity/ethpoller/plugin.pm | 50 +++++ .../blockchain/parity/restapi/mode/eth.pm | 175 +++++++-------- .../blockchain/parity/restapi/mode/net.pm | 29 ++- .../blockchain/parity/restapi/mode/parity.pm | 147 +++---------- 8 files changed, 720 insertions(+), 227 deletions(-) create mode 100644 centreon-plugins/blockchain/parity/ethpoller/custom/api.pm create mode 100644 centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm create mode 100644 centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm create mode 100644 centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm create mode 100644 centreon-plugins/blockchain/parity/ethpoller/plugin.pm diff --git a/centreon-plugins/blockchain/parity/ethpoller/custom/api.pm b/centreon-plugins/blockchain/parity/ethpoller/custom/api.pm new file mode 100644 index 000000000..b6462c32f --- /dev/null +++ b/centreon-plugins/blockchain/parity/ethpoller/custom/api.pm @@ -0,0 +1,204 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package blockchain::parity::ethpoller::custom::api; + +use strict; +use warnings; +use centreon::plugins::http; +use DateTime; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port' }, + "proto:s" => { name => 'proto' }, + "url-path:s" => { name => 'url_path' }, + "timeout:s" => { name => 'timeout' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : undef; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 8000; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'http'; + $self->{url_path} = (defined($self->{option_results}->{url_path})) ? $self->{option_results}->{url_path} : ''; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; + + if (!defined($self->{hostname}) || $self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); + $self->{output}->option_exit(); + } + + return 0; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{url_path} = $self->{url_path}; + $self->{option_results}->{warning_status} = ''; + $self->{option_results}->{critical_status} = ''; +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->add_header(key => 'Accept', value => 'application/json'); + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub get_connection_info { + my ($self, %options) = @_; + + return $self->{hostname} . ":" . $self->{port}; +} + +sub get_hostname { + my ($self, %options) = @_; + + return $self->{hostname}; +} + +sub get_port { + my ($self, %options) = @_; + + return $self->{port}; +} + +sub request_api { + my ($self, %options) = @_; + + $self->settings; + + $self->{output}->output_add(long_msg => "Query URL: '" . $self->{proto} . "://" . $self->{hostname} . + $self->{url_path} . $options{url_path} . "'", debug => 1); + + my $content = $self->{http}->request(url_path => $self->{url_path} . $options{url_path}); + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($content); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@"); + $self->{output}->option_exit(); + } + + return $decoded; +} + +1; + +__END__ + +=head1 NAME + +Parity eth-poller Rest API + +=head1 SYNOPSIS + +Parity eth-poller Rest API custom mode + +=head1 REST API OPTIONS + +Parity eth-poller Rest API + +=over 8 + +=item B<--hostname> + +Parity eth-poller API hostname. + +=item B<--port> + +API port (Default: 8000) + +=item B<--proto> + +Specify https if needed (Default: 'http') + +=item B<--url-path> + +API URL path (Default: '') + +=item B<--timeout> + +Set HTTP timeout + +=back + +=head1 DESCRIPTION + +B. + +=cut \ No newline at end of file diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm new file mode 100644 index 000000000..226fdbc4a --- /dev/null +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm @@ -0,0 +1,98 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package blockchain::parity::ethpoller::mode::fork; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +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); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{listening} !~ /true/' }, + }); + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->request_api(url_path => '/fork'); + + # use Data::Dumper; + # print Dumper($result); + + # Unix time conversion + my $res_timestamp = localtime(hex($result->{last_update}->{timestamp})); + + # Alerts management + 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); + } + + $self->{output}->output_add(severity => 'OK', long_msg => '[Fork]: fork_timestamp: ' . $res_timestamp . + ' | fork_occurence: ' . $result->{occurence} . ' | fork_blockNumber: ' . $result->{last_update}->{blockNumber} . + ' | fork_in: ' . $result->{last_update}->{in} . ' | fork_out: ' . $result->{last_update}->{out} ); + +} + +1; + +__END__ + +=head1 MODE + +Check Parity eth-poller for forks details + +=over 8 + +=item B<--unknown-status> + +Set unknown threshold for listening status (Default: ''). + +=item B<--warning-status> + +Set warning threshold for listening status (Default: ''). + +=item B<--critical-status> + +Set critical threshold for listening status (Default: '%{is_mining} !~ /true/'). + +=item B<--warning-peers> B<--critical-peers> + +Warning and Critical threhsold on the number of peer + +=back + +=cut diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm new file mode 100644 index 000000000..4844e9d6f --- /dev/null +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm @@ -0,0 +1,114 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package blockchain::parity::ethpoller::mode::stats; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', cb_prefix_output => 'prefix_module_output', type => 0 }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'stats_blockInterval', nlabel => 'parity.network.peers.count', set => { + key_values => [ { name => 'stats_blockInterval' } ], + output_template => "Block interval: %d ", + perfdatas => [ + { label => 'stats_blockInterval', value => 'stats_blockInterval_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'stats_contracts', nlabel => 'eth.poller.stats.contracts.number', set => { + key_values => [ { name => 'stats_contracts' } ], + output_template => "Cumulative contracts: %d ", + perfdatas => [ + { label => 'stats_contracts', value => 'stats_contracts_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'stats_blocks', nlabel => 'eth.poller.stats.blocks.number', set => { + key_values => [ { name => 'stats_blocks' } ], + output_template => "Cumulative blocks: %d ", + perfdatas => [ + { label => 'stats_blocks', value => 'stats_blocks_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'stats_transactions', nlabel => 'eth.poller.stats.transactions.number', set => { + key_values => [ { name => 'stats_transactions' } ], + output_template => "Cumulative transactions: %d ", + perfdatas => [ + { label => 'stats_transactions', value => 'stats_transactions_absolute', template => '%d', min => 0 } + ], + } + }, + ]; + +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Stats '"; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->request_api(url_path => '/stats'); + + # use Data::Dumper; + # print Dumper($result); + + $self->{global} = { stats_blockInterval => $result->{blockInterval}, + stats_contracts => $result->{cumulative}->{contracts}, + stats_blocks => $result->{cumulative}->{blocks}, + stats_transactions => $result->{cumulative}->{transactions} + }; +} + +1; + +__END__ + +=head1 MODE + +Check Parity eth-poller for accounts tracking + +=cut diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm new file mode 100644 index 000000000..8a6e734f2 --- /dev/null +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm @@ -0,0 +1,130 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package blockchain::parity::ethpoller::mode::watchlist; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + 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' ); + + if (my $cached_balance = $cache->get('contract_balance')) { + if ($cached_balance != $contract->{balance}) { + #alert + } + } else { + $cache->set('contract_balance', $contract->{balance}); + } + + foreach my $account (@{$results->{Accounts}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $account->{id} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $account->{id} . "': no matching filter name.", debug => 1); + next; + } + + $self->{output}->output_add(severity => 'OK', long_msg => '[Account ' . $account->{id} . ']: label: ' . $account->{label} . ' | nonce: ' . $account->{nonce} . + ' | timestamp: ' . localtime(hex($account->{last_update}->{timestamp})) . ' | blockNumber: ' . $account->{last_update}->{blockNumber} . + ' | receiver: ' . $account->{last_update}->{receiver} . ' | value: ' . $account->{last_update}->{value} ); + } + + foreach my $minner (@{$results->{Miners}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $minner->{id} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $minner->{id} . "': no matching filter name.", debug => 1); + next; + } + + $self->{output}->output_add(severity => 'OK', long_msg => '[Minner ' . $minner->{id} . ']: label: ' . $minner->{label} . ' | blocks: ' . $minner->{blocks} . + ' | timestamp: ' . localtime(hex($minner->{last_update}->{timestamp})) . ' | blockNumber: ' . $minner->{last_update}->{blockNumber} ); + } + + foreach my $contract (@{$results->{Constracts}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $contract->{id} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $contract->{id} . "': no matching filter name.", debug => 1); + next; + } + + $self->{output}->output_add(severity => 'OK', long_msg => '[Contract ' . $contract->{id} . ']: label: ' . $contract->{label} . ' | balance: ' . $contract->{balance} . + ' | timestamp: ' . localtime(hex($contract->{last_update}->{timestamp})) . ' | blockNumber: ' . $contract->{last_update}->{blockNumber} . + ' | sender: ' . $contract->{last_update}->{sender} . ' | value: ' . $contract->{last_update}->{value} ); + } + + foreach my $function (@{$results->{Functions}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $function->{id} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $function->{id} . "': no matching filter name.", debug => 1); + next; + } + + $self->{output}->output_add(severity => 'OK', long_msg => '[Function ' . $function->{id} . ']: label: ' . $function->{label} . ' | calls: ' . $function->{calls} . + ' | timestamp: ' . localtime(hex($function->{last_update}->{timestamp})) . ' | blockNumber: ' . $function->{last_update}->{blockNumber} . + ' | sender: ' . $function->{last_update}->{sender} . ' | receiver: ' . $function->{last_update}->{receiver} . + ' | value: ' . $function->{last_update}->{value} ); + } + + foreach my $event (@{$results->{Events}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $event->{id} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $event->{id} . "': no matching filter name.", debug => 1); + next; + } + + $self->{output}->output_add(severity => 'OK', long_msg => '[Event ' . $event->{id} . ']: label: ' . $event->{label} . ' | calls: ' . $event->{calls} . + ' | timestamp: ' . localtime(hex($event->{last_update}->{timestamp})) . ' | blockNumber: ' . $event->{last_update}->{blockNumber} . + ' | sender: ' . $event->{last_update}->{sender} . ' | receiver: ' . $event->{last_update}->{receiver}); + } + +} + +1; + +__END__ + +=head1 MODE + +Check Parity eth-poller for accounts tracking + +=cut diff --git a/centreon-plugins/blockchain/parity/ethpoller/plugin.pm b/centreon-plugins/blockchain/parity/ethpoller/plugin.pm new file mode 100644 index 000000000..77989acd3 --- /dev/null +++ b/centreon-plugins/blockchain/parity/ethpoller/plugin.pm @@ -0,0 +1,50 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package blockchain::parity::ethpoller::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'watchlist' => 'blockchain::parity::ethpoller::mode::watchlist', + 'fork' => 'blockchain::parity::ethpoller::mode::fork', + 'stats' => 'blockchain::parity::ethpoller::mode::stats' + ); + $self->{custom_modes}{api} = 'blockchain::parity::ethpoller::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Parity blockchain accounts, contracts and forks from eth-poller with HTTP GET + +=cut diff --git a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm index de8eb872f..ca604f753 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm @@ -40,21 +40,10 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'global', cb_prefix_output => 'prefix_module_output', type => 0 }, - { name => 'peer', cb_prefix_output => 'prefix_module_output', type => 0 }, { name => 'block', cb_prefix_output => 'prefix_module_output', type => 0 }, - { name => 'sync', cb_prefix_output => 'prefix_module_output', type => 0 } ]; $self->{maps_counters}->{global} = [ - { label => 'coinbase', nlabel => 'parity.eth.client.coinbase', set => { - key_values => [ { name => 'coinbase' } ], - output_template => "Client coinbase is: %s ", - # closure_custom_perfdata => sub { return 0; } - perfdatas => [ - { label => 'client_coinbase', value => 'coinbase_absolute', template => '%s', min => 0 } - ], - } - }, { label => 'gas_price', nlabel => 'parity.eth.gas.price', set => { key_values => [ { name => 'gas_price' } ], output_template => "The gas price is: %d wei ", @@ -65,90 +54,47 @@ sub set_counters { } ]; - $self->{maps_counters}->{peer} = [ - # { label => 'status', nlabel => 'parity.eth.peers.mining.status', set => { - # key_values => [ { name => 'is_mining' } ], - # output_template => "Client is mining: " . $self->can('custom_mining_status_output'), - # perfdatas => [ - # { label => 'is_mining', value => 'is_mining_absolute', template => '%s', min => 0 } - # ], - # } - # }, - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'is_mining' } ], - closure_custom_calc => \&catalog_status_calc, - closure_custom_output => $self->can('custom_status_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold - } - }, - { label => 'hashrate', nlabel => 'parity.eth.node.hashrate', set => { - key_values => [ { name => 'hashrate' } ], - output_template => "Node hashrate is: %d/s ", - perfdatas => [ - { label => 'node_hashrate', value => 'hashrate_absolute', template => '%d', min => 0 } - ], - } - }, - ]; - $self->{maps_counters}->{block} = [ - { label => 'block_number', nlabel => 'parity.eth.block.number', set => { - key_values => [ { name => 'block_number' } ], - output_template => "Most recent block number is: %d ", - closure_custom_perfdata => sub { return 0; } - # perfdatas => [ - # { label => 'block_number', value => 'block_number_absolute', template => '%d', min => 0 } - # ], - } - }, - { label => 'block_time', nlabel => 'parity.eth.block.time', set => { - key_values => [ { name => 'block_time' } ], - output_template => "Block time is: %s ", - closure_custom_perfdata => sub { return 0; } - # perfdatas => [ - # { label => 'block_time', value => 'block_time_absolute', template => '%s', min => 0 } - # ], - } - }, - ]; - - $self->{maps_counters}->{sync} = [ - { label => 'sync_start', nlabel => 'parity.eth.sync.start.block', set => { - key_values => [ { name => 'sync_start' } ], - output_template => "Sync start block number is: %d ", - closure_custom_perfdata => sub { return 0; } - # perfdatas => [ - # { label => 'sync_start', value => 'sync_start_absolute', template => '%d', min => 0 } - # ], - } - }, - { label => 'sync_current', nlabel => 'parity.eth.sync.current.block', set => { - key_values => [ { name => 'sync_current' } ], - output_template => "Sync current block number is: %d ", - closure_custom_perfdata => sub { return 0; } - # perfdatas => [ - # { label => 'sync_current', value => 'sync_current_absolute', template => '%d', min => 0 } - # ], - } - }, - { label => 'sync_highest', nlabel => 'parity.eth.sync.highest.block', set => { - key_values => [ { name => 'sync_highest' } ], - output_template => "Sync highest block number is: %d ", - # closure_custom_perfdata => sub { return 0; } + { label => 'block_size', nlabel => 'parity.eth.block.size', set => { + key_values => [ { name => 'block_size' } ], + output_template => "Most recent block size: %d ", perfdatas => [ - { label => 'sync_highest', value => 'sync_highest_absolute', template => '%d', min => 0 } + { label => 'block_size', value => 'block_size_absolute', template => '%d', min => 0 } ], } }, - { label => 'sync', nlabel => 'parity.eth.sync.ratio', set => { - key_values => [ { name => 'sync' } ], - output_template => "Sync ratio is: %d%% ", + { label => 'block_transactions', nlabel => 'parity.eth.block.transactions.number', set => { + key_values => [ { name => 'block_transactions' } ], + output_template => "Block transactions number: %d ", perfdatas => [ - { label => 'sync', value => 'sync_absolute', template => '%d', min => 0 } + { label => 'block_transactions', value => 'block_transactions_absolute', template => '%d', min => 0 } ], } - } + }, + { label => 'block_gas', nlabel => 'parity.eth.block.gas', set => { + key_values => [ { name => 'block_gas' } ], + output_template => "Block gas: %d ", + perfdatas => [ + { label => 'block_gas', value => 'block_gas_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'block_difficulty', nlabel => 'parity.eth.block.difficulty', set => { + key_values => [ { name => 'block_difficulty' } ], + output_template => "Block difficulty: %f ", + perfdatas => [ + { label => 'block_difficulty', value => 'block_difficulty_absolute', template => '%f', min => 0 } + ], + } + }, + { label => 'block_uncles', nlabel => 'parity.eth.block.difficulty', set => { + key_values => [ { name => 'block_uncles' } ], + output_template => "Block uncles: %d ", + perfdatas => [ + { label => 'block_uncles', value => 'block_uncles_absolute', template => '%d', min => 0 } + ], + } + }, ]; } @@ -190,32 +136,55 @@ sub manage_selection { { method => 'eth_syncing', params => [], id => "7", jsonrpc => "2.0" } ]; my $result = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post); + + my $gas_price = hex(@{$result}[2]->{result}); # use Data::Dumper; - # print Dumper($result); + # my $length = scalar(@{$$result[5]->{result}->{transactions}}); + # print Dumper($result) ; # conditional formating: my $res_sync = @{$result}[6]->{result} ? hex((@{$result}[6]->{result}->{currentBlock} / @{$result}[6]->{result}->{highestBlock})) * 100 : 100; - my $res_startingBlock = $res_sync != 100 ? hex(@{$result}[6]->{result}->{startingBlock}) : undef; - my $res_currentBlock = $res_sync != 100 ? hex(@{$result}[6]->{result}->{currentBlock}) : undef; - my $res_highestBlock = $res_sync != 100 ? hex(@{$result}[6]->{result}->{highestBlock}) : undef; + my $res_startingBlock = $res_sync != 100 ? hex(@{$result}[6]->{result}->{startingBlock}) : 'none'; + my $res_currentBlock = $res_sync != 100 ? hex(@{$result}[6]->{result}->{currentBlock}) : 'none'; + my $res_highestBlock = $res_sync != 100 ? hex(@{$result}[6]->{result}->{highestBlock}) : 'none'; - # Unix time conversion - my $res_timestamp = localtime(hex(@{$result}[5]->{result}->{timestamp})); + # Alerts management + my $cache = Cache::File->new( cache_root => './parity-restapi-cache' ); - $self->{global} = { coinbase => @{$result}[1]->{result}, - gas_price => hex(@{$result}[2]->{result}) }; + if (my $cached_sync = $cache->get('node_sync')) { + if ($cached_sync == 100 && $res_sync < 100) { + #alert + } + } else { + $cache->set('node_sync', $res_sync); + } - $self->{block} = { block_number => defined @{$result}[4]->{result} ? hex(@{$result}[4]->{result}) : 0, - block_time => $res_timestamp }; + if (my $cached_price = $cache->get('gas_price')) { + if ($cached_price != $gas_price) { + #alert + } + } else { + $cache->set('gas_price', $gas_price); + } - $self->{sync} = { sync_start => $res_startingBlock, - sync_current => $res_currentBlock, - sync_highest => $res_highestBlock, - sync => $res_sync }; + $self->{global} = { gas_price => $gas_price }; - $self->{peer} = { is_mining => @{$result}[0]->{result}, - hashrate => hex(@{$result}[3]->{result}) }; + $self->{block} = { block_size => hex(@{$result}[5]->{result}->{size}), + block_gas => hex(@{$result}[5]->{result}->{gasUsed}), + block_difficulty => hex(@{$result}[5]->{result}->{totalDifficulty}), + block_uncles => scalar(@{$$result[5]->{result}->{uncles}}), + block_transactions => scalar(@{$$result[5]->{result}->{transactions}})}; + + $self->{output}->output_add(severity => 'OK', long_msg => '[Node status] is_mining: ' . @{$result}[0]->{result} . ' | sync_start: ' . $res_startingBlock . + ' | sync_current: ' . $res_currentBlock . ' | sync_highest: ' . $res_highestBlock . ' | sync: ' . $res_sync . '%%'); + $self->{output}->output_add(severity => 'OK', long_msg => '[Client] coinbase: ' . @{$result}[1]->{result}); + $self->{output}->output_add(severity => 'OK', long_msg => '[Global] hashrate: ' . hex(@{$result}[3]->{result}) . + ' | block_number: ' . (defined @{$result}[4]->{result} ? hex(@{$result}[4]->{result}) : 0)); + $self->{output}->output_add(severity => 'OK', long_msg => '[Last block] block_time: ' . localtime(hex(@{$result}[5]->{result}->{timestamp})) . ' | block_gas_limit: ' . hex(@{$result}[5]->{result}->{gasLimit}) . + ' | block_miner: ' . @{$result}[5]->{result}->{miner} . ' | block_hash: ' . @{$result}[5]->{result}->{hash} . + ' | last_block_number: ' . hex(@{$result}[5]->{result}->{number})); + } 1; diff --git a/centreon-plugins/blockchain/parity/restapi/mode/net.pm b/centreon-plugins/blockchain/parity/restapi/mode/net.pm index d5e8f88cf..02ba31028 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/net.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/net.pm @@ -43,15 +43,7 @@ sub set_counters { ]; $self->{maps_counters}->{network} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'listening' } ], - closure_custom_calc => \&catalog_status_calc, - closure_custom_output => $self->can('custom_status_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold - } - }, - { label => 'peers', nlabel => 'parity.network.peers.count', set => { + { label => 'peers', nlabel => 'parity.network.peers.count', set => { key_values => [ { name => 'peers' } ], output_template => "connected peers: %s ", perfdatas => [ @@ -96,9 +88,24 @@ sub manage_selection { my $result = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post); - $self->{network} = { listening => @{$result}[0]->{result}, - peers => hex(@{$result}[1]->{result}) }; + my $peer_count = hex(@{$result}[1]->{result}); + # Alerts management + 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); + } + + $self->{network} = { peers => hex(@{$result}[1]->{result}) }; + + $self->{output}->output_add(long_msg => "[Node] is_listening: " . $peer_count, severity => 'OK'); } 1; diff --git a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm index 0050e1ce9..8823d1673 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm @@ -24,108 +24,18 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use Cache::File; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ -# { name => 'global', cb_prefix_output => 'prefix_module_output', type => 0 }, - { name => 'node', cb_prefix_output => 'prefix_module_output', type => 0 }, - { name => 'mempool', cb_prefix_output => 'prefix_module_output', type => 0 }, - { name => 'network', cb_prefix_output => 'prefix_module_output', type => 0 } - ]; - - $self->{maps_counters}->{global} = [ - { label => 'parity_version', nlabel => 'parity.version', threshold => 0, set => { - key_values => [ { name => 'parity_version' } ], - output_template => "Parity version is: %s ", - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => sub { return 0; } - # perfdatas => [ - # { label => 'parity_version', value => 'parity_version_absolute', template => '%s', min => 0 } - # ], - } - }, - { label => 'parity_version_hash', nlabel => 'parity.version.hash', set => { - key_values => [ { name => 'parity_version_hash' } ], - output_template => "Parity version hash is: %s ", - closure_custom_perfdata => sub { return 0; } - # perfdatas => [ - # { label => 'parity_version_hash', value => 'parity_version_hash_absolute', template => '%s', min => 0 } - # ], - } - }, - { label => 'chain_name', nlabel => 'parity.chain.name', set => { - key_values => [ { name => 'chain_name' } ], - output_template => "Chain name is: %s ", - closure_custom_perfdata => sub { return 0; } - # perfdatas => [ - # { label => 'chain_name', value => 'chain_name_absolute', template => '%s', min => 0 } - # ], - } - }, - ]; - - $self->{maps_counters}->{node} = [ - { label => 'enode', nlabel => 'parity.node.enode.uri', threshold => 0, set => { - key_values => [ { name => 'enode' } ], - output_template => "Node enode URI: %s ", - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => sub { return 0; } - # perfdatas => [ - # { label => 'enode', value => 'enode_absolute', template => '%s', min => 0 } - # ], - } - }, - { label => 'node_name', nlabel => 'parity.node.name', set => { - key_values => [ { name => 'node_name' } ], - output_template => "Node name: %s ", - closure_custom_perfdata => sub { return 0; } - # perfdatas => [ - # { label => 'node_name', value => 'node_name_absolute', template => '%s', min => 0 } - # ], - } - } - ]; - - $self->{maps_counters}->{network} = [ - { label => 'peers_connected', nlabel => 'parity.peers.connected', set => { - key_values => [ { name => 'peers_connected' } ], - output_template => "Number of connected peers: %d ", - perfdatas => [ - { label => 'peers_connected', value => 'peers_connected_absolute', template => '%d', min => 0 } - ], - } - }, - { label => 'peers_max', nlabel => 'parity.peers.max.connected', set => { - key_values => [ { name => 'peers_max' } ], - output_template => "Maximum number of connected peers: %d ", - perfdatas => [ - { label => 'peers_max', value => 'peers_max_absolute', template => '%d', min => 0 } - ], - } - }, - { label => 'peers', nlabel => 'parity.peers', set => { - key_values => [ { name => 'peers' } ], - output_template => "Peers: %d ", - perfdatas => [ - { label => 'peers', value => 'peers_absolute', template => '%d', min => 0 } - ], - } - } - ]; + { name => 'mempool', cb_prefix_output => 'prefix_module_output', type => 0 } + ]; $self->{maps_counters}->{mempool} = [ - { label => 'pending_transactions', nlabel => 'parity.pending.transactions', set => { - key_values => [ { name => 'pending_transactions' } ], - output_template => "Pending transactions: %d ", - perfdatas => [ - { label => 'pending_transactions', value => 'pending_transactions_absolute', template => '%d', min => 0 } - ], - } - }, - { label => 'mempool', nlabel => 'parity.mempol.capacity', set => { + { label => 'mempool', nlabel => 'parity.mempol.usage', set => { key_values => [ { name => 'mempool' } ], output_template => "Mempool: %d %% ", perfdatas => [ @@ -172,35 +82,46 @@ sub manage_selection { { method => 'parity_netPeers', params => [], id => "4", jsonrpc => "2.0" }, { method => 'parity_enode', params => [], id => "5", jsonrpc => "2.0" }, { method => 'parity_nodeName', params => [], id => "6", jsonrpc => "2.0" }, - { method => 'parity_transactionsLimit', params => [], id => "7", jsonrpc => "2.0" } ]; # parity_transactionsLimit could be done once, at the beginning of the process + { method => 'parity_transactionsLimit', params => [], id => "7", jsonrpc => "2.0" } ]; #TO CHECK parity_transactionsLimit could be done once, at the beginning of the process - my $result = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post); + use Data::Dumper; + # print Dumper($result); + # Parity version construction 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' ); + + 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}); + } # use Data::Dumper; - # print Dumper($res_parity_version); + # print Dumper($result); - $self->{output}->output_add(long_msg => "[config] chain name: " . @{$result}[1]->{result} . " parity version: " . $res_parity_version . " version_hash: " . @{$result}[0]->{result}->{hash}, - severity => 'OK'); - -# $self->{global} = { parity_version => $res_parity_version, -# parity_version_hash => @{$result}[0]->{result}->{hash}, -# chain_name => @{$result}[1]->{result} }; - -# $self->{node} = { enode => @{$result}[4]->{result}, -# node_name => @{$result}[5]->{result} }; - - $self->{network} = { peers_connected => @{$result}[3]->{result}->{connected}, - peers_max => @{$result}[3]->{result}->{max}, - peers => length(@{$result}[3]->{result}->{peers}) }; - - $self->{mempool} = { pending_transactions => length(@{$result}[2]->{result}), - mempool => @{$result}[2]->{result} / @{$result}[6]->{result} * 100 }; + $self->{output}->output_add(long_msg => "[config] chain name: " . @{$result}[1]->{result} . " | parity version: " . $res_parity_version . " | version_hash: " + . @{$result}[0]->{result}->{hash}, severity => 'OK'); + $self->{output}->output_add(long_msg => "[Network] peers_connected: " . @{$result}[3]->{result}->{connected} . " | peers_max: " . @{$result}[3]->{result}->{max} . " | peers: " + . scalar(@{$$result[3]->{result}->{peers}}), severity => 'OK'); + $self->{output}->output_add(long_msg => "[Node] node_name: " . @{$result}[5]->{result} . " | enode: " . @{$result}[4]->{result} , severity => 'OK'); + $self->{output}->output_add(long_msg => "[Node] pending_transactions: " . scalar(@{$$result[2]->{result}}), severity => 'OK'); + $self->{mempool} = { mempool => scalar(@{$$result[2]->{result}}) / @{$result}[6]->{result} * 100 }; #TO CHECK division entière } 1; From 8dfa3be8304bc8cc5059dca41faa32e91aafd8a5 Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Thu, 9 Apr 2020 08:00:11 +0000 Subject: [PATCH 11/26] add missing package --- .../blockchain/parity/ethpoller/mode/fork.pm | 1 + .../parity/ethpoller/mode/watchlist.pm | 18 ++++++++++-------- .../blockchain/parity/restapi/mode/eth.pm | 1 + .../blockchain/parity/restapi/mode/net.pm | 1 + 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm index 226fdbc4a..7fc4f5c0c 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use Cache::File; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); sub new { diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm index 8a6e734f2..a6a7b28f8 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use Cache::File; use Digest::MD5 qw(md5_hex); sub new { @@ -49,14 +50,6 @@ sub manage_selection { # Alerts management my $cache = Cache::File->new( cache_root => './parity-eth-poller-cache' ); - if (my $cached_balance = $cache->get('contract_balance')) { - if ($cached_balance != $contract->{balance}) { - #alert - } - } else { - $cache->set('contract_balance', $contract->{balance}); - } - foreach my $account (@{$results->{Accounts}}) { if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $account->{id} !~ /$self->{option_results}->{filter_name}/) { @@ -90,6 +83,15 @@ sub manage_selection { $self->{output}->output_add(severity => 'OK', long_msg => '[Contract ' . $contract->{id} . ']: label: ' . $contract->{label} . ' | balance: ' . $contract->{balance} . ' | 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}); + } + } foreach my $function (@{$results->{Functions}}) { diff --git a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm index ca604f753..00c479110 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use Cache::File; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); sub custom_status_output { diff --git a/centreon-plugins/blockchain/parity/restapi/mode/net.pm b/centreon-plugins/blockchain/parity/restapi/mode/net.pm index 02ba31028..17ceaed4b 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/net.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/net.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use Cache::File; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); sub custom_status_output { From 7244e5813e532ee72308144edc4aed0bf772c736 Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Thu, 9 Apr 2020 08:28:21 +0000 Subject: [PATCH 12/26] remove Cache::File package --- .../blockchain/parity/ethpoller/mode/fork.pm | 23 +++++++----- .../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/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm index 7fc4f5c0c..597dbd4a0 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm +++ b/centreon-plugins/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/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm index a6a7b28f8..69e2baef2 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm +++ b/centreon-plugins/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/centreon-plugins/blockchain/parity/restapi/mode/eth.pm b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm index 00c479110..fd819842a 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm +++ b/centreon-plugins/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/centreon-plugins/blockchain/parity/restapi/mode/net.pm b/centreon-plugins/blockchain/parity/restapi/mode/net.pm index 17ceaed4b..b3d9fdd5a 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/net.pm +++ b/centreon-plugins/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/centreon-plugins/blockchain/parity/restapi/mode/parity.pm b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm index 8823d1673..f58e3234e 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm +++ b/centreon-plugins/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); From d4eeebddb7b05dd36a961a0176804677d449f5f1 Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Thu, 9 Apr 2020 09:50:29 +0000 Subject: [PATCH 13/26] change long_msg output format --- .../blockchain/parity/ethpoller/mode/fork.pm | 6 ++-- .../parity/ethpoller/mode/watchlist.pm | 30 +++++++++---------- .../blockchain/parity/restapi/mode/eth.pm | 16 +++++----- .../blockchain/parity/restapi/mode/net.pm | 2 +- .../blockchain/parity/restapi/mode/parity.pm | 12 ++++---- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm index 597dbd4a0..84b1d194f 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm @@ -65,9 +65,9 @@ sub manage_selection { # $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} . - ' | fork_in: ' . $result->{last_update}->{in} . ' | fork_out: ' . $result->{last_update}->{out} ); + $self->{output}->output_add(severity => 'OK', long_msg => 'Fork: [fork_timestamp: ' . $res_timestamp . + '] [fork_occurence: ' . $result->{occurence} . '] [fork_blockNumber: ' . $result->{last_update}->{blockNumber} . + '] [fork_in: ' . $result->{last_update}->{in} . '] [fork_out: ' . $result->{last_update}->{out} . ']'); } diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm index 69e2baef2..9ffb7fd85 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm @@ -59,9 +59,9 @@ sub manage_selection { next; } - $self->{output}->output_add(severity => 'OK', long_msg => '[Account ' . $account->{id} . ']: label: ' . $account->{label} . ' | nonce: ' . $account->{nonce} . - ' | timestamp: ' . localtime(hex($account->{last_update}->{timestamp})) . ' | blockNumber: ' . $account->{last_update}->{blockNumber} . - ' | receiver: ' . $account->{last_update}->{receiver} . ' | value: ' . $account->{last_update}->{value} ); + $self->{output}->output_add(severity => 'OK', long_msg => 'Account ' . $account->{id} . ': [label: ' . $account->{label} . '] [nonce: ' . $account->{nonce} . + '] [timestamp: ' . localtime(hex($account->{last_update}->{timestamp})) . '] [blockNumber: ' . $account->{last_update}->{blockNumber} . + '] [receiver: ' . $account->{last_update}->{receiver} . '] [value: ' . $account->{last_update}->{value} . ']' ); } foreach my $minner (@{$results->{Miners}}) { @@ -71,8 +71,8 @@ sub manage_selection { next; } - $self->{output}->output_add(severity => 'OK', long_msg => '[Minner ' . $minner->{id} . ']: label: ' . $minner->{label} . ' | blocks: ' . $minner->{blocks} . - ' | timestamp: ' . localtime(hex($minner->{last_update}->{timestamp})) . ' | blockNumber: ' . $minner->{last_update}->{blockNumber} ); + $self->{output}->output_add(severity => 'OK', long_msg => 'Minner ' . $minner->{id} . ': [label: ' . $minner->{label} . '] [blocks: ' . $minner->{blocks} . + '] [timestamp: ' . localtime(hex($minner->{last_update}->{timestamp})) . '] [blockNumber: ' . $minner->{last_update}->{blockNumber} . ']'); } foreach my $contract (@{$results->{Constracts}}) { @@ -82,9 +82,9 @@ sub manage_selection { next; } - $self->{output}->output_add(severity => 'OK', long_msg => '[Contract ' . $contract->{id} . ']: label: ' . $contract->{label} . ' | balance: ' . $contract->{balance} . - ' | timestamp: ' . localtime(hex($contract->{last_update}->{timestamp})) . ' | blockNumber: ' . $contract->{last_update}->{blockNumber} . - ' | sender: ' . $contract->{last_update}->{sender} . ' | value: ' . $contract->{last_update}->{value} ); + $self->{output}->output_add(severity => 'OK', long_msg => 'Contract ' . $contract->{id} . ': [label: ' . $contract->{label} . '] [balance: ' . $contract->{balance} . + '] [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}) { @@ -103,10 +103,10 @@ sub manage_selection { next; } - $self->{output}->output_add(severity => 'OK', long_msg => '[Function ' . $function->{id} . ']: label: ' . $function->{label} . ' | calls: ' . $function->{calls} . - ' | timestamp: ' . localtime(hex($function->{last_update}->{timestamp})) . ' | blockNumber: ' . $function->{last_update}->{blockNumber} . - ' | sender: ' . $function->{last_update}->{sender} . ' | receiver: ' . $function->{last_update}->{receiver} . - ' | value: ' . $function->{last_update}->{value} ); + $self->{output}->output_add(severity => 'OK', long_msg => '[Function ' . $function->{id} . ']: label: ' . $function->{label} . '] [calls: ' . $function->{calls} . + '] [timestamp: ' . localtime(hex($function->{last_update}->{timestamp})) . '] [blockNumber: ' . $function->{last_update}->{blockNumber} . + '] [sender: ' . $function->{last_update}->{sender} . '] [receiver: ' . $function->{last_update}->{receiver} . + '] [value: ' . $function->{last_update}->{value} . ']'); } foreach my $event (@{$results->{Events}}) { @@ -116,9 +116,9 @@ sub manage_selection { next; } - $self->{output}->output_add(severity => 'OK', long_msg => '[Event ' . $event->{id} . ']: label: ' . $event->{label} . ' | calls: ' . $event->{calls} . - ' | timestamp: ' . localtime(hex($event->{last_update}->{timestamp})) . ' | blockNumber: ' . $event->{last_update}->{blockNumber} . - ' | sender: ' . $event->{last_update}->{sender} . ' | receiver: ' . $event->{last_update}->{receiver}); + $self->{output}->output_add(severity => 'OK', long_msg => '[Event ' . $event->{id} . ']: label: ' . $event->{label} . '] [calls: ' . $event->{calls} . + '] [timestamp: ' . localtime(hex($event->{last_update}->{timestamp})) . '] [blockNumber: ' . $event->{last_update}->{blockNumber} . + '] [sender: ' . $event->{last_update}->{sender} . '] [receiver: ' . $event->{last_update}->{receiver} . ']'); } } diff --git a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm index fd819842a..63f7f435b 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm @@ -180,14 +180,14 @@ sub manage_selection { block_uncles => scalar(@{$$result[5]->{result}->{uncles}}), block_transactions => scalar(@{$$result[5]->{result}->{transactions}})}; - $self->{output}->output_add(severity => 'OK', long_msg => '[Node status] is_mining: ' . @{$result}[0]->{result} . ' | sync_start: ' . $res_startingBlock . - ' | sync_current: ' . $res_currentBlock . ' | sync_highest: ' . $res_highestBlock . ' | sync: ' . $res_sync . '%%'); - $self->{output}->output_add(severity => 'OK', long_msg => '[Client] coinbase: ' . @{$result}[1]->{result}); - $self->{output}->output_add(severity => 'OK', long_msg => '[Global] hashrate: ' . hex(@{$result}[3]->{result}) . - ' | block_number: ' . (defined @{$result}[4]->{result} ? hex(@{$result}[4]->{result}) : 0)); - $self->{output}->output_add(severity => 'OK', long_msg => '[Last block] block_time: ' . localtime(hex(@{$result}[5]->{result}->{timestamp})) . ' | block_gas_limit: ' . hex(@{$result}[5]->{result}->{gasLimit}) . - ' | block_miner: ' . @{$result}[5]->{result}->{miner} . ' | block_hash: ' . @{$result}[5]->{result}->{hash} . - ' | last_block_number: ' . hex(@{$result}[5]->{result}->{number})); + $self->{output}->output_add(severity => 'OK', long_msg => 'Node status: [is_mining: ' . @{$result}[0]->{result} . '] [sync_start: ' . $res_startingBlock . + '] [sync_current: ' . $res_currentBlock . '] [sync_highest: ' . $res_highestBlock . '] [sync: ' . $res_sync . '%%]'); + $self->{output}->output_add(severity => 'OK', long_msg => 'Client: [coinbase: ' . @{$result}[1]->{result} . ']'); + $self->{output}->output_add(severity => 'OK', long_msg => 'Global: [hashrate: ' . hex(@{$result}[3]->{result}) . + '] [block_number: ' . (defined @{$result}[4]->{result} ? hex(@{$result}[4]->{result}) : 0) . ']'); + $self->{output}->output_add(severity => 'OK', long_msg => 'Last block: [block_time: ' . localtime(hex(@{$result}[5]->{result}->{timestamp})) . '] [block_gas_limit: ' . hex(@{$result}[5]->{result}->{gasLimit}) . + '] [block_miner: ' . @{$result}[5]->{result}->{miner} . '] [block_hash: ' . @{$result}[5]->{result}->{hash} . + '] [last_block_number: ' . hex(@{$result}[5]->{result}->{number}) . ']'); } diff --git a/centreon-plugins/blockchain/parity/restapi/mode/net.pm b/centreon-plugins/blockchain/parity/restapi/mode/net.pm index b3d9fdd5a..2ad2ca153 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/net.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/net.pm @@ -109,7 +109,7 @@ sub manage_selection { $self->{network} = { peers => hex(@{$result}[1]->{result}) }; - $self->{output}->output_add(long_msg => "[Node] is_listening: " . $peer_count, severity => 'OK'); + $self->{output}->output_add(long_msg => "Node status: [is_listening: " . $peer_count . ']', severity => 'OK'); } 1; diff --git a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm index f58e3234e..d3aad2c31 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm @@ -117,12 +117,12 @@ sub manage_selection { # use Data::Dumper; # print Dumper($result); - $self->{output}->output_add(long_msg => "[config] chain name: " . @{$result}[1]->{result} . " | parity version: " . $res_parity_version . " | version_hash: " - . @{$result}[0]->{result}->{hash}, severity => 'OK'); - $self->{output}->output_add(long_msg => "[Network] peers_connected: " . @{$result}[3]->{result}->{connected} . " | peers_max: " . @{$result}[3]->{result}->{max} . " | peers: " - . scalar(@{$$result[3]->{result}->{peers}}), severity => 'OK'); - $self->{output}->output_add(long_msg => "[Node] node_name: " . @{$result}[5]->{result} . " | enode: " . @{$result}[4]->{result} , severity => 'OK'); - $self->{output}->output_add(long_msg => "[Node] pending_transactions: " . scalar(@{$$result[2]->{result}}), severity => 'OK'); + $self->{output}->output_add(long_msg => "Config: [chain name: " . @{$result}[1]->{result} . "] [parity version: " . $res_parity_version . "] [version_hash: " + . @{$result}[0]->{result}->{hash} . "]", severity => 'OK'); + $self->{output}->output_add(long_msg => "Network: [peers_connected: " . @{$result}[3]->{result}->{connected} . "] [peers_max: " . @{$result}[3]->{result}->{max} . "] [peers: " + . scalar(@{$$result[3]->{result}->{peers}}) . "]", severity => 'OK'); + $self->{output}->output_add(long_msg => "Node: [node_name: " . @{$result}[5]->{result} . "] [enode: " . @{$result}[4]->{result} . "]", severity => 'OK'); + $self->{output}->output_add(long_msg => "Mempool: [pending_transactions: " . scalar(@{$$result[2]->{result}}) . "]", severity => 'OK'); $self->{mempool} = { mempool => scalar(@{$$result[2]->{result}}) / @{$result}[6]->{result} * 100 }; #TO CHECK division entière } From 052bd440ec8f729fff7f83ff9e523fd7bb77c449 Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Thu, 9 Apr 2020 10:14:28 +0000 Subject: [PATCH 14/26] add package bigint --- centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm | 1 + centreon-plugins/blockchain/parity/restapi/mode/eth.pm | 1 + 2 files changed, 2 insertions(+) diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm index 9ffb7fd85..78b577fee 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm @@ -24,6 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use bigint; use Digest::MD5 qw(md5_hex); sub new { diff --git a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm index 63f7f435b..6d7fbe78c 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm @@ -25,6 +25,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); +use bigint; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); sub custom_status_output { From 7d8e8f6a9ce71872417f00320621b8bc7475c1a0 Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Mon, 13 Apr 2020 12:32:07 +0000 Subject: [PATCH 15/26] timestamp formating --- .../blockchain/parity/ethpoller/mode/fork.pm | 3 +- .../blockchain/parity/ethpoller/mode/stats.pm | 2 +- .../parity/ethpoller/mode/watchlist.pm | 22 ++++++++++--- .../blockchain/parity/restapi/mode/eth.pm | 33 ++++++++++--------- .../blockchain/parity/restapi/mode/parity.pm | 2 +- 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm index 84b1d194f..5d53b223f 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/fork.pm @@ -52,7 +52,8 @@ sub manage_selection { # print Dumper($result); # Unix time conversion - my $res_timestamp = localtime(hex($result->{last_update}->{timestamp})); + my $res_timestamp = $result->{last_update}->{timestamp} == 0 ? '': localtime($result->{last_update}->{timestamp}); + # Alerts management # my $cache = Cache::File->new( cache_root => './parity-eth-poller-cache' ); diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm index 4844e9d6f..e6cbe1451 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm @@ -34,7 +34,7 @@ sub set_counters { ]; $self->{maps_counters}->{global} = [ - { label => 'stats_blockInterval', nlabel => 'parity.network.peers.count', set => { + { label => 'stats_blockInterval', nlabel => 'parity.stats.block.interval', set => { key_values => [ { name => 'stats_blockInterval' } ], output_template => "Block interval: %d ", perfdatas => [ diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm index 78b577fee..2c4ed8304 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/watchlist.pm @@ -53,6 +53,8 @@ sub manage_selection { # Alerts management # my $cache = Cache::File->new( cache_root => './parity-eth-poller-cache' ); + my $res_timestamp = 0; + foreach my $account (@{$results->{Accounts}}) { if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $account->{id} !~ /$self->{option_results}->{filter_name}/) { @@ -60,8 +62,10 @@ sub manage_selection { next; } + $res_timestamp = $account->{last_update}->{timestamp} == 0 ? '': localtime($account->{last_update}->{timestamp}); + $self->{output}->output_add(severity => 'OK', long_msg => 'Account ' . $account->{id} . ': [label: ' . $account->{label} . '] [nonce: ' . $account->{nonce} . - '] [timestamp: ' . localtime(hex($account->{last_update}->{timestamp})) . '] [blockNumber: ' . $account->{last_update}->{blockNumber} . + '] [timestamp: ' . $res_timestamp . '] [blockNumber: ' . $account->{last_update}->{blockNumber} . '] [receiver: ' . $account->{last_update}->{receiver} . '] [value: ' . $account->{last_update}->{value} . ']' ); } @@ -72,8 +76,10 @@ sub manage_selection { next; } + $res_timestamp = $minner->{last_update}->{timestamp} == 0 ? '': localtime($minner->{last_update}->{timestamp}); + $self->{output}->output_add(severity => 'OK', long_msg => 'Minner ' . $minner->{id} . ': [label: ' . $minner->{label} . '] [blocks: ' . $minner->{blocks} . - '] [timestamp: ' . localtime(hex($minner->{last_update}->{timestamp})) . '] [blockNumber: ' . $minner->{last_update}->{blockNumber} . ']'); + '] [timestamp: ' . $res_timestamp . '] [blockNumber: ' . $minner->{last_update}->{blockNumber} . ']'); } foreach my $contract (@{$results->{Constracts}}) { @@ -83,8 +89,10 @@ sub manage_selection { next; } + $res_timestamp = $contract->{last_update}->{timestamp} == 0 ? '': localtime($contract->{last_update}->{timestamp}); + $self->{output}->output_add(severity => 'OK', long_msg => 'Contract ' . $contract->{id} . ': [label: ' . $contract->{label} . '] [balance: ' . $contract->{balance} . - '] [timestamp: ' . localtime(hex($contract->{last_update}->{timestamp})) . '] [blockNumber: ' . $contract->{last_update}->{blockNumber} . + '] [timestamp: ' . $res_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})) { @@ -104,8 +112,10 @@ sub manage_selection { next; } + $res_timestamp = $function->{last_update}->{timestamp} == 0 ? '': localtime($function->{last_update}->{timestamp}); + $self->{output}->output_add(severity => 'OK', long_msg => '[Function ' . $function->{id} . ']: label: ' . $function->{label} . '] [calls: ' . $function->{calls} . - '] [timestamp: ' . localtime(hex($function->{last_update}->{timestamp})) . '] [blockNumber: ' . $function->{last_update}->{blockNumber} . + '] [timestamp: ' . $res_timestamp . '] [blockNumber: ' . $function->{last_update}->{blockNumber} . '] [sender: ' . $function->{last_update}->{sender} . '] [receiver: ' . $function->{last_update}->{receiver} . '] [value: ' . $function->{last_update}->{value} . ']'); } @@ -117,8 +127,10 @@ sub manage_selection { next; } + $res_timestamp = $event->{last_update}->{timestamp} == 0 ? '': localtime($event->{last_update}->{timestamp}); + $self->{output}->output_add(severity => 'OK', long_msg => '[Event ' . $event->{id} . ']: label: ' . $event->{label} . '] [calls: ' . $event->{calls} . - '] [timestamp: ' . localtime(hex($event->{last_update}->{timestamp})) . '] [blockNumber: ' . $event->{last_update}->{blockNumber} . + '] [timestamp: ' . $res_timestamp . '] [blockNumber: ' . $event->{last_update}->{blockNumber} . '] [sender: ' . $event->{last_update}->{sender} . '] [receiver: ' . $event->{last_update}->{receiver} . ']'); } diff --git a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm index 6d7fbe78c..90f5a0ae8 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm @@ -81,15 +81,15 @@ sub set_counters { ], } }, - { label => 'block_difficulty', nlabel => 'parity.eth.block.difficulty', set => { - key_values => [ { name => 'block_difficulty' } ], - output_template => "Block difficulty: %f ", - perfdatas => [ - { label => 'block_difficulty', value => 'block_difficulty_absolute', template => '%f', min => 0 } - ], - } - }, - { label => 'block_uncles', nlabel => 'parity.eth.block.difficulty', set => { + # { label => 'block_difficulty', nlabel => 'parity.eth.block.difficulty', set => { + # key_values => [ { name => 'block_difficulty' } ], + # output_template => "Block difficulty: %f ", + # perfdatas => [ + # { label => 'block_difficulty', value => 'block_difficulty_absolute', template => '%f', min => 0 } + # ], + # } + # }, + { label => 'block_uncles', nlabel => 'parity.eth.block.uncles', set => { key_values => [ { name => 'block_uncles' } ], output_template => "Block uncles: %d ", perfdatas => [ @@ -143,10 +143,11 @@ sub manage_selection { my $result = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post); my $gas_price = hex(@{$result}[2]->{result}); - - # use Data::Dumper; - # my $length = scalar(@{$$result[5]->{result}->{transactions}}); - # print Dumper($result) ; + my $res_block_time = @{$result}[5]->{result}->{timestamp} == 0 ? '': localtime(hex(@{$result}[5]->{result}->{timestamp})); + + use Data::Dumper; + print Dumper($res_block_time) ; + print Dumper(@{$result}[5]->{result}->{timestamp}); # conditional formating: my $res_sync = @{$result}[6]->{result} ? hex((@{$result}[6]->{result}->{currentBlock} / @{$result}[6]->{result}->{highestBlock})) * 100 : 100; @@ -177,16 +178,16 @@ sub manage_selection { $self->{block} = { block_size => hex(@{$result}[5]->{result}->{size}), block_gas => hex(@{$result}[5]->{result}->{gasUsed}), - block_difficulty => hex(@{$result}[5]->{result}->{totalDifficulty}), + # block_difficulty => hex(@{$result}[5]->{result}->{totalDifficulty}), block_uncles => scalar(@{$$result[5]->{result}->{uncles}}), block_transactions => scalar(@{$$result[5]->{result}->{transactions}})}; $self->{output}->output_add(severity => 'OK', long_msg => 'Node status: [is_mining: ' . @{$result}[0]->{result} . '] [sync_start: ' . $res_startingBlock . - '] [sync_current: ' . $res_currentBlock . '] [sync_highest: ' . $res_highestBlock . '] [sync: ' . $res_sync . '%%]'); + '] [sync_current: ' . $res_currentBlock . '] [sync_highest: ' . $res_highestBlock . '] [sync: ' . $res_sync . '%]'); $self->{output}->output_add(severity => 'OK', long_msg => 'Client: [coinbase: ' . @{$result}[1]->{result} . ']'); $self->{output}->output_add(severity => 'OK', long_msg => 'Global: [hashrate: ' . hex(@{$result}[3]->{result}) . '] [block_number: ' . (defined @{$result}[4]->{result} ? hex(@{$result}[4]->{result}) : 0) . ']'); - $self->{output}->output_add(severity => 'OK', long_msg => 'Last block: [block_time: ' . localtime(hex(@{$result}[5]->{result}->{timestamp})) . '] [block_gas_limit: ' . hex(@{$result}[5]->{result}->{gasLimit}) . + $self->{output}->output_add(severity => 'OK', long_msg => 'Last block: [block_time: ' . $res_block_time . '] [block_gas_limit: ' . hex(@{$result}[5]->{result}->{gasLimit}) . '] [block_miner: ' . @{$result}[5]->{result}->{miner} . '] [block_hash: ' . @{$result}[5]->{result}->{hash} . '] [last_block_number: ' . hex(@{$result}[5]->{result}->{number}) . ']'); diff --git a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm index d3aad2c31..aad3fb67c 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm @@ -122,7 +122,7 @@ sub manage_selection { $self->{output}->output_add(long_msg => "Network: [peers_connected: " . @{$result}[3]->{result}->{connected} . "] [peers_max: " . @{$result}[3]->{result}->{max} . "] [peers: " . scalar(@{$$result[3]->{result}->{peers}}) . "]", severity => 'OK'); $self->{output}->output_add(long_msg => "Node: [node_name: " . @{$result}[5]->{result} . "] [enode: " . @{$result}[4]->{result} . "]", severity => 'OK'); - $self->{output}->output_add(long_msg => "Mempool: [pending_transactions: " . scalar(@{$$result[2]->{result}}) . "]", severity => 'OK'); + $self->{output}->output_add(long_msg => "Mempool: [pending_transactions: " . scalar(@{$$result[2]->{result}}) . "] [transactions_limit: " . @{$result}[6]->{result} . "]", severity => 'OK'); $self->{mempool} = { mempool => scalar(@{$$result[2]->{result}}) / @{$result}[6]->{result} * 100 }; #TO CHECK division entière } From 5d98ea5521631f828656bd76395c4b9e498404df Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Mon, 13 Apr 2020 15:41:39 +0000 Subject: [PATCH 16/26] default and configurable port support --- centreon-plugins/blockchain/parity/restapi/custom/api.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/centreon-plugins/blockchain/parity/restapi/custom/api.pm b/centreon-plugins/blockchain/parity/restapi/custom/api.pm index d792c57d8..a9e1866a5 100644 --- a/centreon-plugins/blockchain/parity/restapi/custom/api.pm +++ b/centreon-plugins/blockchain/parity/restapi/custom/api.pm @@ -41,7 +41,8 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port' }, "timeout:s" => { name => 'timeout' }, "api-path:s" => { name => 'api_path' }, }); @@ -81,6 +82,7 @@ sub check_options { my ($self, %options) = @_; $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : undef; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 8545; $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; $self->{api_path} = (defined($self->{option_results}->{api_path})) ? $self->{option_results}->{api_path} : '/'; @@ -102,7 +104,7 @@ sub build_options_for_httplib { $self->{option_results}->{hostname} = $self->{hostname}; $self->{option_results}->{timeout} = $self->{timeout}; - $self->{option_results}->{port} = 8545; + $self->{option_results}->{port} = $self->{port}; $self->{option_results}->{proto} = 'http'; } From 03766535ea9ab1a8dc4677a778d535be76935ec2 Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Tue, 14 Apr 2020 10:41:34 +0000 Subject: [PATCH 17/26] delete unnecessary print --- centreon-plugins/blockchain/parity/restapi/mode/eth.pm | 6 +++--- centreon-plugins/blockchain/parity/restapi/mode/parity.pm | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm index 90f5a0ae8..ac872603e 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm @@ -145,9 +145,9 @@ sub manage_selection { my $gas_price = hex(@{$result}[2]->{result}); my $res_block_time = @{$result}[5]->{result}->{timestamp} == 0 ? '': localtime(hex(@{$result}[5]->{result}->{timestamp})); - use Data::Dumper; - print Dumper($res_block_time) ; - print Dumper(@{$result}[5]->{result}->{timestamp}); + # use Data::Dumper; + # print Dumper($res_block_time) ; + # print Dumper(@{$result}[5]->{result}->{timestamp}); # conditional formating: my $res_sync = @{$result}[6]->{result} ? hex((@{$result}[6]->{result}->{currentBlock} / @{$result}[6]->{result}->{highestBlock})) * 100 : 100; diff --git a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm index aad3fb67c..9da861cb1 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm @@ -89,7 +89,7 @@ sub manage_selection { my $result = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post); - use Data::Dumper; + # use Data::Dumper; # print Dumper($result); # Parity version construction From e23d0dec2150dd342a3d64a149dc73b137c8d4bf Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Mon, 11 May 2020 15:50:37 +0000 Subject: [PATCH 18/26] Code to be completed --- .../blockchain/parity/ethpoller/mode/disk.pm | 135 +++++++++++ .../blockchain/parity/ethpoller/mode/stats.pm | 120 ++++++---- .../parity/ethpoller/mode/tracking.pm | 221 ++++++++++++++++++ .../blockchain/parity/ethpoller/plugin.pm | 8 +- .../blockchain/parity/restapi/mode/eth.pm | 48 +++- .../blockchain/parity/restapi/mode/infos.pm | 121 ++++++++++ .../blockchain/parity/restapi/mode/net.pm | 2 +- .../blockchain/parity/restapi/mode/parity.pm | 65 +++++- .../blockchain/parity/restapi/plugin.pm | 3 +- 9 files changed, 666 insertions(+), 57 deletions(-) create mode 100644 centreon-plugins/blockchain/parity/ethpoller/mode/disk.pm create mode 100644 centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm create mode 100644 centreon-plugins/blockchain/parity/restapi/mode/infos.pm diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/disk.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/disk.pm new file mode 100644 index 000000000..bd5158c28 --- /dev/null +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/disk.pm @@ -0,0 +1,135 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package blockchain::parity::ethpoller::mode::disk; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use bigint; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', cb_prefix_output => 'prefix_module_output', type => 0 }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'disk_free', nlabel => 'eth.poller.disk.free', set => { + key_values => [ { name => 'disk_free' } ], + output_template => "Disk free: %d ", + perfdatas => [ + { label => 'disk_free', value => 'disk_free_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'disk_available', nlabel => 'eth.poller.disk.free', set => { + key_values => [ { name => 'disk_available' } ], + output_template => "Disk available: %d ", + perfdatas => [ + { label => 'disk_available', value => 'disk_available_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'disk_size', nlabel => 'eth.poller.disk.size', set => { + key_values => [ { name => 'disk_size' } ], + output_template => "Disk size: %d ", + perfdatas => [ + { label => 'disk_size', value => 'disk_size_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'disk_used', nlabel => 'eth.poller.disk.used', set => { + key_values => [ { name => 'disk_used' } ], + output_template => "Disk used: %d ", + perfdatas => [ + { label => 'disk_used', value => 'disk_used_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'disk_usage', nlabel => 'eth.poller.disk.usage', set => { + key_values => [ { name => 'disk_usage' } ], + output_template => "Disk usage: %d %", + perfdatas => [ + { label => 'disk_usage', value => 'disk_usage_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'blockchain_dir', nlabel => 'eth.poller.blockchain.directory', set => { + key_values => [ { name => 'blockchain_dir' } ], + output_template => "Blockchain directory: %d", + perfdatas => [ + { label => 'blockchain_dir', value => 'blockchain_dir_absolute', template => '%d', min => 0 } + ], + } + } + ]; + +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Disk '"; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->request_api(url_path => '/disk'); + + # use Data::Dumper; + # print Dumper($result); + + $self->{global} = { disk_free => $result->{free}, + disk_available => $result->{available}, + disk_size => $result->{size}, + disk_used => $result->{used}, + disk_usage => $result->{usage}, + blockchain_dir => $result->{dir} + }; + + $self->{output}->output_add(severity => 'OK', long_msg => 'Ledger: ' . $result->{dir} . ' (' . $result->{usage} . '%)'); +} + +1; + +__END__ + +=head1 MODE + +Check Parity eth-poller for disk monitoring + +=cut diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm index e6cbe1451..10acb6bef 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm @@ -24,61 +24,61 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use bigint; use Digest::MD5 qw(md5_hex); sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', cb_prefix_output => 'prefix_module_output', type => 0 }, + { name => 'block', cb_prefix_output => 'prefix_output_block', type => 0 }, + { name => 'transaction', cb_prefix_output => 'prefix_output_transaction', type => 0 } ]; - $self->{maps_counters}->{global} = [ - { label => 'stats_blockInterval', nlabel => 'parity.stats.block.interval', set => { - key_values => [ { name => 'stats_blockInterval' } ], - output_template => "Block interval: %d ", + $self->{maps_counters}->{block} = [ + { label => 'block_freq', nlabel => 'parity.stats.block.frequency', set => { + key_values => [ { name => 'block_freq' } ], + output_template => "Block frequency: %d (block/min)", perfdatas => [ - { label => 'stats_blockInterval', value => 'stats_blockInterval_absolute', template => '%d', min => 0 } + { label => 'block_freq', value => 'block_freq_absolute', template => '%d', min => 0 } ], } - }, - { label => 'stats_contracts', nlabel => 'eth.poller.stats.contracts.number', set => { - key_values => [ { name => 'stats_contracts' } ], - output_template => "Cumulative contracts: %d ", - perfdatas => [ - { label => 'stats_contracts', value => 'stats_contracts_absolute', template => '%d', min => 0 } - ], - } - }, - { label => 'stats_blocks', nlabel => 'eth.poller.stats.blocks.number', set => { - key_values => [ { name => 'stats_blocks' } ], - output_template => "Cumulative blocks: %d ", - perfdatas => [ - { label => 'stats_blocks', value => 'stats_blocks_absolute', template => '%d', min => 0 } - ], - } - }, - { label => 'stats_transactions', nlabel => 'eth.poller.stats.transactions.number', set => { - key_values => [ { name => 'stats_transactions' } ], - output_template => "Cumulative transactions: %d ", - perfdatas => [ - { label => 'stats_transactions', value => 'stats_transactions_absolute', template => '%d', min => 0 } - ], - } - }, + } ]; + $self->{maps_counters}->{transaction} = [ + { label => 'transaction_freq', nlabel => 'parity.stats.transaction.frequency', set => { + key_values => [ { name => 'transaction_freq' } ], + output_template => "Transaction frequency: %d (tx/min)", + perfdatas => [ + { label => 'transaction_freq', value => 'transaction_freq_absolute', template => '%d', min => 0 } + ], + } + } + ]; } -sub prefix_output { +sub prefix_output_block { my ($self, %options) = @_; - return "Stats '"; + return "Block stats '"; +} + +sub prefix_output_fork { + my ($self, %options) = @_; + + return "Fork stats '"; +} + +sub prefix_output_transaction { + my ($self, %options) = @_; + + return "Transaction stats '"; } 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 => { @@ -91,16 +91,52 @@ 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 => '/stats'); - # use Data::Dumper; - # print Dumper($result); + my $old_block_timestamp = $self->{statefile_cache}->get(name => 'last_block_timestamp'); + my $old_block_count = $self->{statefile_cache}->get(name => 'last_block_count'); - $self->{global} = { stats_blockInterval => $result->{blockInterval}, - stats_contracts => $result->{cumulative}->{contracts}, - stats_blocks => $result->{cumulative}->{blocks}, - stats_transactions => $result->{cumulative}->{transactions} - }; + my $old_tx_timestamp = $self->{statefile_cache}->get(name => 'last_tx_timestamp'); + my $old_tx_count = $self->{statefile_cache}->get(name => 'last_tx_count'); + + my $datas = {}; + $datas->{last_block_timestamp} = time(); + $datas->{last_block_count} = $result->{block}->{count}; + + $datas->{last_tx_timestamp} = time(); + $datas->{last_tx_count} = $result->{block}->{count}; + + use Data::Dumper; + print Dumper($old_timestamp); + + my $res_timestamp = 0; + + if ($old_block_count && $old_block_timestamp) { + $res_timestamp = $result->{block}->{timestamp}) == 0 ? '' : $result->{block}->{timestamp})); + my $calculated_block_freq = ($result->{block}->{count} - $old_block_count) / (time() - $old_block_timestamp); + $self->{block} = { block_freq => $calculated_block_freq }; + $self->{output}->output_add(severity => 'OK', long_msg => 'Last block (#' . $result->{block}->{count} . ') was at ' . $res_timestamp); + } else { + $self->{output}->output_add(severity => 'OK', long_msg => 'Last block (#' . $result->{block}->{block} . ') was at ' . $res_timestamp . '. Block frequency is being calculated...'); + } + + if ($old_tx_count && $old_tx_timestamp) { + $res_timestamp = $result->{transaction}->{timestamp}) == 0 ? '' : $result->{transaction}->{timestamp})); + my $calculated_tx_freq = ($result->{transaction}->{count} - $old_tx_count) / (time() - $old_tx_timestamp); + $self->{transaction} = { transaction_freq => $calculated_tx_freq }; + $self->{output}->output_add(severity => 'OK', long_msg => 'Last transaction (#' . $result->{transaction}->{count} . ') was at ' . $res_timestamp); + } else { + $self->{output}->output_add(severity => 'OK', long_msg => 'Last transaction (#' . $result->{transaction}->{count} . ') was at ' . $res_timestamp . '. Transaction frequency is being calculated...'); + } + + if ($result->{fork}->{count} > 0) { + $self->{output}->output_add(severity => 'OK', long_msg => 'Last fork (#' . $result->{fork}->{count} . ') was at ' . $res_timestamp); + } else { + $self->{output}->output_add(severity => 'OK', long_msg => 'No fork occurence'); + } } 1; @@ -109,6 +145,6 @@ __END__ =head1 MODE -Check Parity eth-poller for accounts tracking +Check Parity eth-poller for stats =cut diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm new file mode 100644 index 000000000..3fbb113dc --- /dev/null +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm @@ -0,0 +1,221 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package blockchain::parity::ethpoller::mode::tracking; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use bigint; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'events', cb_prefix_output => 'prefix_module_events', type => 1, message_multiple => 'All event metrics are ok' }, + { name => 'miners', cb_prefix_output => 'prefix_module_miners', type => 1, message_multiple => 'All miner metrics are ok' }, + { name => 'balances', cb_prefix_output => 'prefix_module_balances', type => 1, message_multiple => 'All balance metrics are ok' }, + ]; + + $self->{maps_counters}->{events} = [ + { label => 'event_frequency', nlabel => 'parity.tracking.event.frequency', set => { + key_values => [ { name => 'event_frequency' } ], + output_template => "Event's frequency: %d (evt/min)", + perfdatas => [ + { label => 'event_frequency', value => 'event_frequency_absolute', template => '%d', min => 0 } + ], + } + } + ]; + + $self->{maps_counters}->{miners} = [ + { label => 'mining_frequency', nlabel => 'parity.tracking.mining.frequency', set => { + key_values => [ { name => 'mining_frequency' } ], + output_template => "Mining frequency: %d (block/min)", + perfdatas => [ + { label => 'mining_frequency', value => 'mining_frequency_absolute', template => '%d', min => 0 } + ], + } + } + ]; + + $self->{maps_counters}->{balances} = [ + { label => 'balance_fluctuation', nlabel => 'parity.tracking.balances.fluctuation', set => { + key_values => [ { name => 'balance_fluctuation' } ], + output_template => "Balance fluctuation: %d (diff/min)", + perfdatas => [ + { label => 'balance_fluctuation', value => 'balance_fluctuation_absolute', template => '%d', min => 0 } + ], + } + } + ]; + +} + +sub prefix_output_events { + my ($self, %options) = @_; + + return "Event stats '"; +} + +sub prefix_output_miners { + my ($self, %options) = @_; + + return "Miner stats '"; +} + +sub prefix_output_balances { + my ($self, %options) = @_; + + return "Balance stats '"; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +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 => '/tracking'); + + # use Data::Dumper; + # print Dumper($results); + + my $res_timestamp = 0; + my $calculated_frequency = 0; + + $self->{events} = {}; + $self->{miners} = {}; + $self->{balances} = {}; + + my $datas = {}; + + foreach my $event (@{$results->{events}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $event->{id} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $event->{id} . "': no matching filter name.", debug => 1); + next; + } + + my $old_event_timestamp = $self->{statefile_cache}->get(name => 'last_event_timestamp'); #get the id last_event_timestamp + my $old_event_count = $self->{statefile_cache}->get(name => 'last_event_count'); #get the id last_event_count + + $datas->{$event->{id}}->{last_event_timestamp} = time(); + $datas->{$event->{id}}->{last_event_count} = $result->{block}->{count}; + + if ($old_event_count && $old_event_timestamp) { + $calculated_frequency = ($event->{count} - $old_event_count) / (time() - $old_event_timestamp); + + $self->{events}->{$event->{id}}->{display} = $event->{label}; + $self->{events}->{$event->{id}}->{event_frequency} = $calculated_frequency; + + $res_timestamp = $event->{timestamp} == 0 ? '': localtime($event->{timestamp}); + + if ($event->{count} > 0) { + $self->{output}->output_add(severity => 'OK', long_msg => 'Event ' . $event->{id} . ': Last Tx from "' . $event->{label} . '" (#' . $event->{count} . + ') was at ' . $res_timestamp . ' (block #' . $event->{block} . ')' ); + } else { + $self->{output}->output_add(severity => 'OK', long_msg => 'Event ' . $event->{id} . ': No Tx from "' . $event->{label} . '"'); + } + } else { + $self->{output}->output_add(severity => 'OK', long_msg => 'Event ' . $event->{id} . ': Building perfdata for "' . $event->{label} . '"...'); + } + } + + foreach my $miner (@{$results->{miners}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $miner->{id} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $miner->{id} . "': no matching filter name.", debug => 1); + next; + } + + my $old_miner_timestamp = $self->{statefile_cache}->get(name => 'last_miner_timestamp'); #get the id last_miner_timestamp + my $old_miner_count = $self->{statefile_cache}->get(name => 'last_miner_count'); #get the id last_miner_count + + $datas->{$miner->{id}}->{last_miner_timestamp} = time(); + $datas->{$miner->{id}}->{last_miner_count} = $result->{block}->{count}; + + if ($old_miner_timestamp && $old_miner_timestamp) { + $calculated_frequency = ($miner->{count} - $old_miner_count) / (time() - $old_miner_timestamp); + + $self->{miners}->{$miner->{id}}->{display} = $miner->{label}; + $self->{miners}->{$miner->{id}}->{mining_frequency} = $calculated_frequency; + + $res_timestamp = $miner->{timestamp} == 0 ? '': localtime($miner->{timestamp}); + if ($miner->{count} > 0) { + $self->{output}->output_add(severity => 'OK', long_msg => 'Miner ' . $miner->{id} . ': Last block from label "' . $miner->{label} . '" (#' . $miner->{count} . + ') was at ' . $res_timestamp . ' (block #' . $miner->{block} . ')' ); + } else { + $self->{output}->output_add(severity => 'OK', long_msg => 'Miner ' . $miner->{id} . ': No validation from "' . $miner->{label} . '"'); + } + } else { + $self->{output}->output_add(severity => 'OK', long_msg => 'Miner ' . $miner->{id} . ': Building perfdata for "' . $miner->{label} . '"...'); + } + } + + foreach my $balance (@{$results->{balances}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $balance->{id} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $balance->{id} . "': no matching filter name.", debug => 1); + next; + } + + my $old_balance = $self->{statefile_cache}->get(name => 'last_balance'); #get the id last_balance + + $datas->{$balance->{id}}->{last_balance} = $balance->{balance}; + + if ($old_balance) { + $calculated_diff = ($balance->{balance} - $old_balance) / ($old_balance); + + $self->{balances}->{$balance->{id}}->{display} = $balance->{label}; + $self->{balances}->{$balance->{id}}->{balance} = $calculated_diff; + + $self->{output}->output_add(severity => 'OK', long_msg => 'Balance ' . $balance->{id} . ': Balance of "' . $balance->{label} . '" is ' . $balance->{balance} . ' ether' ); + } else { + $self->{output}->output_add(severity => 'OK', long_msg => 'Balance ' . $balance->{id} . ': Balance fluctuation of "' . $balance->{label} . '" is being calculated...'); + } + } + + +} + +1; + +__END__ + +=head1 MODE + +Check Parity eth-poller for events, miners and balances tracking + +=cut diff --git a/centreon-plugins/blockchain/parity/ethpoller/plugin.pm b/centreon-plugins/blockchain/parity/ethpoller/plugin.pm index 77989acd3..48e08df5c 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/plugin.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/plugin.pm @@ -31,9 +31,11 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'watchlist' => 'blockchain::parity::ethpoller::mode::watchlist', - 'fork' => 'blockchain::parity::ethpoller::mode::fork', - 'stats' => 'blockchain::parity::ethpoller::mode::stats' + # 'watchlist' => 'blockchain::parity::ethpoller::mode::watchlist', + # 'fork' => 'blockchain::parity::ethpoller::mode::fork', + 'stats' => 'blockchain::parity::ethpoller::mode::stats', + 'disk' => 'blockchain::parity::ethpoller::mode::disk', + 'tracking' => 'blockchain::parity::ethpoller::mode::tracking' ); $self->{custom_modes}{api} = 'blockchain::parity::ethpoller::custom::api'; return $self; diff --git a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm index ac872603e..08c7a8461 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm @@ -41,11 +41,23 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', cb_prefix_output => 'prefix_module_output', type => 0 }, + { name => 'gas', cb_prefix_output => 'prefix_module_output', type => 0 }, { name => 'block', cb_prefix_output => 'prefix_module_output', type => 0 }, + { name => 'sync', cb_prefix_output => 'prefix_module_output', type => 0 }, ]; - $self->{maps_counters}->{global} = [ + $self->{maps_counters}->{gas} = [ + { label => 'sync_status', nlabel => 'parity.eth.sync.status', set => { + key_values => [ { name => 'sync_status' } ], + output_template => "The gas price is: %d %% ", + perfdatas => [ + { label => 'sync_status', value => 'sync_status_absolute', template => '%d', min => 0 } + ], + } + } + ]; + + $self->{maps_counters}->{gas} = [ { label => 'gas_price', nlabel => 'parity.eth.gas.price', set => { key_values => [ { name => 'gas_price' } ], output_template => "The gas price is: %d wei ", @@ -53,6 +65,22 @@ sub set_counters { { label => 'gas_price', value => 'gas_price_absolute', template => '%d', min => 0 } ], } + }, + { label => 'gas_used', nlabel => 'parity.eth.gas.used', set => { + key_values => [ { name => 'gas_used' } ], + output_template => "The gas used is: %d", + perfdatas => [ + { label => 'gas_used', value => 'gas_used_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'gas_limit', nlabel => 'parity.eth.gas.limit', set => { + key_values => [ { name => 'gas_limit' } ], + output_template => "The gas limit is: %d", + perfdatas => [ + { label => 'gas_limit', value => 'gas_limit_absolute', template => '%d', min => 0 } + ], + } } ]; @@ -65,6 +93,14 @@ sub set_counters { ], } }, + { label => 'block_usage', nlabel => 'parity.eth.block.usage', set => { + key_values => [ { name => 'block_usage' } ], + output_template => "Block usage: %d %%", + perfdatas => [ + { label => 'block_usage', value => 'block_usage_absolute', template => '%d', min => 0 } + ], + } + }, { label => 'block_transactions', nlabel => 'parity.eth.block.transactions.number', set => { key_values => [ { name => 'block_transactions' } ], output_template => "Block transactions number: %d ", @@ -174,10 +210,16 @@ sub manage_selection { # $cache->set('gas_price', $gas_price); # } - $self->{global} = { gas_price => $gas_price }; + $self->{sync} = { sync_status => $res_sync }; + $self->{gas} = { gas_price => $gas_price, + gas_used => hex(@{$result}[5]->{result}->{gasLimit}), + gas_limit => hex(@{$result}[5]->{result}->{gasUsed}) }; + + my $calculated_block_usage = hex(@{$result}[5]->{result}->{gasUsed}) / hex(@{$result}[5]->{result}->{gasLimit}); $self->{block} = { block_size => hex(@{$result}[5]->{result}->{size}), block_gas => hex(@{$result}[5]->{result}->{gasUsed}), + block_usage => $calculated_block_usage, # block_difficulty => hex(@{$result}[5]->{result}->{totalDifficulty}), block_uncles => scalar(@{$$result[5]->{result}->{uncles}}), block_transactions => scalar(@{$$result[5]->{result}->{transactions}})}; diff --git a/centreon-plugins/blockchain/parity/restapi/mode/infos.pm b/centreon-plugins/blockchain/parity/restapi/mode/infos.pm new file mode 100644 index 000000000..c93eee5ab --- /dev/null +++ b/centreon-plugins/blockchain/parity/restapi/mode/infos.pm @@ -0,0 +1,121 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package blockchain::parity::restapi::mode::infos; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +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, statefile => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{listening} !~ /true/' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); +} + +sub prefix_module_output { + my ($self, %options) = @_; + + return "Parity network module: "; +} + +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 => 'eth_mining', params => [], id => "3", jsonrpc => "2.0" }, + { method => 'parity_nodeName', params => [], id => "4", jsonrpc => "2.0" }, ]; + + my $result = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post); + + # use Data::Dumper; + # print Dumper($result); + + # Parity version construction + 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' ); + + # 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->{output}->output_add(long_msg => "Parity version: '" . $res_parity_version . "'. Chain name: '" . @{$result}[1]->{result} . + "'. Node name: '" . @{$result}[3]->{result} . "'. is_validator: '" . @{$result}[2]->{result} . "'.", severity => 'OK'); +} + +1; + +__END__ + +=head1 MODE + +Check parity network cross module metrics (parity_versionInfo, parity_chain, eth_mining, parity_nodeName) + +=over 8 + +=item B<--unknown-status> + +Set unknown threshold for listening status (Default: ''). + +=item B<--warning-status> + +Set warning threshold for listening status (Default: ''). + +=item B<--critical-status> + +Set critical threshold for listening status (Default: '%{listening} !~ /true/'). + +=item B<--warning-peers> B<--critical-peers> + +Warning and Critical threhsold on the number of peer + +=back + +=cut diff --git a/centreon-plugins/blockchain/parity/restapi/mode/net.pm b/centreon-plugins/blockchain/parity/restapi/mode/net.pm index 2ad2ca153..7bc65d3a8 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/net.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/net.pm @@ -109,7 +109,7 @@ sub manage_selection { $self->{network} = { peers => hex(@{$result}[1]->{result}) }; - $self->{output}->output_add(long_msg => "Node status: [is_listening: " . $peer_count . ']', severity => 'OK'); + $self->{output}->output_add(long_msg => "Node status: [is_listening: " . @{$result}[0]->{result} . ']', severity => 'OK'); } 1; diff --git a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm index 9da861cb1..7e62fda50 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/parity.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/parity.pm @@ -31,15 +31,59 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'mempool', cb_prefix_output => 'prefix_module_output', type => 0 } + { name => 'mempool', cb_prefix_output => 'prefix_module_output', type => 0 }, + { name => 'peers', cb_prefix_output => 'prefix_module_output', type => 0 } ]; $self->{maps_counters}->{mempool} = [ - { label => 'mempool', nlabel => 'parity.mempol.usage', set => { - key_values => [ { name => 'mempool' } ], - output_template => "Mempool: %d %% ", + { label => 'tx_pending', nlabel => 'parity.pending.transactions', set => { + key_values => [ { name => 'tx_pending' } ], + output_template => "Pending transactions: %d", perfdatas => [ - { label => 'mempool', value => 'mempool_absolute', template => '%d', min => 0 } + { label => 'tx_pending', value => 'tx_pending_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'mempool_size', nlabel => 'parity.mempol.size', set => { + key_values => [ { name => 'mempool_size' } ], + output_template => "Mempool size: %d", + perfdatas => [ + { label => 'mempool_size', value => 'mempool_size_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'mempool_usage', nlabel => 'parity.mempol.usage', set => { + key_values => [ { name => 'mempool_usage' } ], + output_template => "Mempool usage: %d %% ", + perfdatas => [ + { label => 'mempool_usage', value => 'mempool_usage_absolute', template => '%d', min => 0 } + ], + } + }, + ]; + + $self->{maps_counters}->{peers} = [ + { label => 'peers_connected', nlabel => 'parity.peers.connected', set => { + key_values => [ { name => 'peers_connected' } ], + output_template => "Peers connected: %d", + perfdatas => [ + { label => 'peers_connected', value => 'peers_connected_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'peers_max', nlabel => 'parity.peers.max', set => { + key_values => [ { name => 'peers_max' } ], + output_template => "Peers max: %d", + perfdatas => [ + { label => 'peers_max', value => 'peers_max_absolute', template => '%d', min => 0 } + ], + } + }, + { label => 'peers_usage', nlabel => 'parity.peers.usage', set => { + key_values => [ { name => 'peers_usage' } ], + output_template => "Mempool usage: %d %% ", + perfdatas => [ + { label => 'peers_usage', value => 'peers_usage_absolute', template => '%d', min => 0 } ], } }, @@ -85,7 +129,8 @@ sub manage_selection { { method => 'parity_netPeers', params => [], id => "4", jsonrpc => "2.0" }, { method => 'parity_enode', params => [], id => "5", jsonrpc => "2.0" }, { method => 'parity_nodeName', params => [], id => "6", jsonrpc => "2.0" }, - { method => 'parity_transactionsLimit', params => [], id => "7", jsonrpc => "2.0" } ]; #TO CHECK parity_transactionsLimit could be done once, at the beginning of the process + { method => 'parity_transactionsLimit', params => [], id => "7", jsonrpc => "2.0" }, #TO CHECK parity_transactionsLimit could be done once, at the beginning of the process + { method => 'net_peerCount', params => [], id => "8", jsonrpc => "2.0" } ]; my $result = $options{custom}->request_api(method => 'POST', query_form_post => $query_form_post); @@ -124,7 +169,13 @@ sub manage_selection { $self->{output}->output_add(long_msg => "Node: [node_name: " . @{$result}[5]->{result} . "] [enode: " . @{$result}[4]->{result} . "]", severity => 'OK'); $self->{output}->output_add(long_msg => "Mempool: [pending_transactions: " . scalar(@{$$result[2]->{result}}) . "] [transactions_limit: " . @{$result}[6]->{result} . "]", severity => 'OK'); - $self->{mempool} = { mempool => scalar(@{$$result[2]->{result}}) / @{$result}[6]->{result} * 100 }; #TO CHECK division entière + $self->{mempool} = { mempool_usage => scalar(@{$$result[2]->{result}}) / @{$result}[6]->{result} * 100, #TO CHECK division entière + mempool_size => @{$result}[6]->{result}, + tx_pending => scalar(@{$$result[2]->{result}}) }; + + $self->{peers} = { peers_usage => @{$result}[3]->{result}->{connected} / @{$result}[3]->{result}->{max} * 100, #TO CHECK division entière + peers_max => @{$result}[3]->{result}->{max}, + peers_connected => @{$result}[3]->{result}->{connected} }; } 1; diff --git a/centreon-plugins/blockchain/parity/restapi/plugin.pm b/centreon-plugins/blockchain/parity/restapi/plugin.pm index 7cffb8686..b470c1666 100644 --- a/centreon-plugins/blockchain/parity/restapi/plugin.pm +++ b/centreon-plugins/blockchain/parity/restapi/plugin.pm @@ -33,7 +33,8 @@ sub new { %{$self->{modes}} = ( 'net' => 'blockchain::parity::restapi::mode::net', 'eth' => 'blockchain::parity::restapi::mode::eth', - 'parity' => 'blockchain::parity::restapi::mode::parity' + 'parity' => 'blockchain::parity::restapi::mode::parity', + 'infos' => 'blockchain::parity::restapi::mode::infos' ); $self->{custom_modes}{api} = 'blockchain::parity::restapi::custom::api'; return $self; From 36bfab3a4f180837dfdddf1b2feedc0135484d2c Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Mon, 11 May 2020 18:32:33 +0000 Subject: [PATCH 19/26] code to be completed 2/2 --- centreon-plugins/blockchain/parity/ethpoller/mode/disk.pm | 2 +- centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm | 6 +++--- .../blockchain/parity/ethpoller/mode/tracking.pm | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/disk.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/disk.pm index bd5158c28..586d41da9 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/disk.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/disk.pm @@ -69,7 +69,7 @@ sub set_counters { }, { label => 'disk_usage', nlabel => 'eth.poller.disk.usage', set => { key_values => [ { name => 'disk_usage' } ], - output_template => "Disk usage: %d %", + output_template => "Disk usage: %d %%", perfdatas => [ { label => 'disk_usage', value => 'disk_usage_absolute', template => '%d', min => 0 } ], diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm index 10acb6bef..e0cf28b7b 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm @@ -110,12 +110,12 @@ sub manage_selection { $datas->{last_tx_count} = $result->{block}->{count}; use Data::Dumper; - print Dumper($old_timestamp); + print Dumper($old_tx_timestamp); my $res_timestamp = 0; if ($old_block_count && $old_block_timestamp) { - $res_timestamp = $result->{block}->{timestamp}) == 0 ? '' : $result->{block}->{timestamp})); + $res_timestamp = $result->{block}->{timestamp} == 0 ? '' : $result->{block}->{timestamp}; my $calculated_block_freq = ($result->{block}->{count} - $old_block_count) / (time() - $old_block_timestamp); $self->{block} = { block_freq => $calculated_block_freq }; $self->{output}->output_add(severity => 'OK', long_msg => 'Last block (#' . $result->{block}->{count} . ') was at ' . $res_timestamp); @@ -124,7 +124,7 @@ sub manage_selection { } if ($old_tx_count && $old_tx_timestamp) { - $res_timestamp = $result->{transaction}->{timestamp}) == 0 ? '' : $result->{transaction}->{timestamp})); + $res_timestamp = $result->{transaction}->{timestamp} == 0 ? '' : $result->{transaction}->{timestamp}; my $calculated_tx_freq = ($result->{transaction}->{count} - $old_tx_count) / (time() - $old_tx_timestamp); $self->{transaction} = { transaction_freq => $calculated_tx_freq }; $self->{output}->output_add(severity => 'OK', long_msg => 'Last transaction (#' . $result->{transaction}->{count} . ') was at ' . $res_timestamp); diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm index 3fbb113dc..49a927894 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm @@ -132,7 +132,7 @@ sub manage_selection { my $old_event_count = $self->{statefile_cache}->get(name => 'last_event_count'); #get the id last_event_count $datas->{$event->{id}}->{last_event_timestamp} = time(); - $datas->{$event->{id}}->{last_event_count} = $result->{block}->{count}; + $datas->{$event->{id}}->{last_event_count} = $event->{count}; if ($old_event_count && $old_event_timestamp) { $calculated_frequency = ($event->{count} - $old_event_count) / (time() - $old_event_timestamp); @@ -164,7 +164,7 @@ sub manage_selection { my $old_miner_count = $self->{statefile_cache}->get(name => 'last_miner_count'); #get the id last_miner_count $datas->{$miner->{id}}->{last_miner_timestamp} = time(); - $datas->{$miner->{id}}->{last_miner_count} = $result->{block}->{count}; + $datas->{$miner->{id}}->{last_miner_count} = $miner->{count}; if ($old_miner_timestamp && $old_miner_timestamp) { $calculated_frequency = ($miner->{count} - $old_miner_count) / (time() - $old_miner_timestamp); @@ -196,7 +196,7 @@ sub manage_selection { $datas->{$balance->{id}}->{last_balance} = $balance->{balance}; if ($old_balance) { - $calculated_diff = ($balance->{balance} - $old_balance) / ($old_balance); + my $calculated_diff = ($balance->{balance} - $old_balance) / ($old_balance); $self->{balances}->{$balance->{id}}->{display} = $balance->{label}; $self->{balances}->{$balance->{id}}->{balance} = $calculated_diff; From f3f1d9b713d86e2cf907fe6ccdf4afa010ecfc71 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Mon, 11 May 2020 22:32:12 +0200 Subject: [PATCH 20/26] enh(plugin)correct-cache-file-mgmt --- .../parity/ethpoller/mode/tracking.pm | 122 +++++------------- 1 file changed, 31 insertions(+), 91 deletions(-) diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm index 49a927894..250383c55 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm @@ -31,40 +31,42 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'events', cb_prefix_output => 'prefix_module_events', type => 1, message_multiple => 'All event metrics are ok' }, - { name => 'miners', cb_prefix_output => 'prefix_module_miners', type => 1, message_multiple => 'All miner metrics are ok' }, - { name => 'balances', cb_prefix_output => 'prefix_module_balances', type => 1, message_multiple => 'All balance metrics are ok' }, + { name => 'events', cb_prefix_output => 'prefix_output_events', type => 1, message_multiple => 'Events metrics are ok' }, + { name => 'miners', cb_prefix_output => 'prefix_output_miners', type => 1, message_multiple => 'Miners metrics are ok' }, + { name => 'balances', cb_prefix_output => 'prefix_output_balances', type => 1, message_multiple => 'Balances metrics are ok' } ]; $self->{maps_counters}->{events} = [ - { label => 'event_frequency', nlabel => 'parity.tracking.event.frequency', set => { - key_values => [ { name => 'event_frequency' } ], - output_template => "Event's frequency: %d (evt/min)", - perfdatas => [ - { label => 'event_frequency', value => 'event_frequency_absolute', template => '%d', min => 0 } - ], + { label => 'event_frequency', nlabel => 'parity.tracking.event.persecond', set => { + key_values => [ { name => 'event_count', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => " %.2f (events/s)", + perfdatas => [ + { label => 'events', template => '%.2f', value => 'event_count_per_second', + label_extra_instance => 1, instance_use => 'display_absolute' } + ], } } ]; $self->{maps_counters}->{miners} = [ - { label => 'mining_frequency', nlabel => 'parity.tracking.mining.frequency', set => { + { label => 'mining_frequency', nlabel => 'parity.tracking.mined.block.persecond', set => { key_values => [ { name => 'mining_frequency' } ], - output_template => "Mining frequency: %d (block/min)", - perfdatas => [ - { label => 'mining_frequency', value => 'mining_frequency_absolute', template => '%d', min => 0 } - ], + output_template => " %.2f (blocks/s)", + perfdatas => [ instance_use => 'display_absolute', label_extra_instance => 1 ], } } ]; $self->{maps_counters}->{balances} = [ - { label => 'balance_fluctuation', nlabel => 'parity.tracking.balances.fluctuation', set => { - key_values => [ { name => 'balance_fluctuation' } ], - output_template => "Balance fluctuation: %d (diff/min)", + { label => 'balance_fluctuation', nlabel => 'parity.tracking.balances.variation.persecond', set => { + key_values => [ { name => 'balance', diff => 1 } ], + per_second => 1, + output_template => " variation: %.2f (diff/sec)", perfdatas => [ - { label => 'balance_fluctuation', value => 'balance_fluctuation_absolute', template => '%d', min => 0 } - ], + { label => 'balances', template => '%.2f', value => 'balance_per_second', + label_extra_instance => 1, instance_use => 'display_absolute' } + ], } } ]; @@ -74,24 +76,24 @@ sub set_counters { sub prefix_output_events { my ($self, %options) = @_; - return "Event stats '"; + return "Event '" . $options{instance_value}->{display} . "' "; } sub prefix_output_miners { my ($self, %options) = @_; - return "Miner stats '"; + return "Miner '" . $options{instance_value}->{display} . "' ";; } sub prefix_output_balances { my ($self, %options) = @_; - return "Balance stats '"; + return "Balance '" . $options{instance_value}->{display} . "' "; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { @@ -109,48 +111,20 @@ sub manage_selection { my $results = $options{custom}->request_api(url_path => '/tracking'); - # use Data::Dumper; - # print Dumper($results); - - my $res_timestamp = 0; - my $calculated_frequency = 0; - $self->{events} = {}; $self->{miners} = {}; $self->{balances} = {}; - - my $datas = {}; foreach my $event (@{$results->{events}}) { if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $event->{id} !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "skipping '" . $event->{id} . "': no matching filter name.", debug => 1); + $self->{output}->output_add(long_msg => "skipping '" . $event->{label} . "': no matching filter name.", debug => 1); next; } - my $old_event_timestamp = $self->{statefile_cache}->get(name => 'last_event_timestamp'); #get the id last_event_timestamp - my $old_event_count = $self->{statefile_cache}->get(name => 'last_event_count'); #get the id last_event_count + $self->{events}->{lc($event->{label})} = { display => lc($event->{label}), + event_count => $event->{count} }; - $datas->{$event->{id}}->{last_event_timestamp} = time(); - $datas->{$event->{id}}->{last_event_count} = $event->{count}; - - if ($old_event_count && $old_event_timestamp) { - $calculated_frequency = ($event->{count} - $old_event_count) / (time() - $old_event_timestamp); - - $self->{events}->{$event->{id}}->{display} = $event->{label}; - $self->{events}->{$event->{id}}->{event_frequency} = $calculated_frequency; - - $res_timestamp = $event->{timestamp} == 0 ? '': localtime($event->{timestamp}); - - if ($event->{count} > 0) { - $self->{output}->output_add(severity => 'OK', long_msg => 'Event ' . $event->{id} . ': Last Tx from "' . $event->{label} . '" (#' . $event->{count} . - ') was at ' . $res_timestamp . ' (block #' . $event->{block} . ')' ); - } else { - $self->{output}->output_add(severity => 'OK', long_msg => 'Event ' . $event->{id} . ': No Tx from "' . $event->{label} . '"'); - } - } else { - $self->{output}->output_add(severity => 'OK', long_msg => 'Event ' . $event->{id} . ': Building perfdata for "' . $event->{label} . '"...'); - } } foreach my $miner (@{$results->{miners}}) { @@ -160,51 +134,17 @@ sub manage_selection { next; } - my $old_miner_timestamp = $self->{statefile_cache}->get(name => 'last_miner_timestamp'); #get the id last_miner_timestamp - my $old_miner_count = $self->{statefile_cache}->get(name => 'last_miner_count'); #get the id last_miner_count - - $datas->{$miner->{id}}->{last_miner_timestamp} = time(); - $datas->{$miner->{id}}->{last_miner_count} = $miner->{count}; - - if ($old_miner_timestamp && $old_miner_timestamp) { - $calculated_frequency = ($miner->{count} - $old_miner_count) / (time() - $old_miner_timestamp); - - $self->{miners}->{$miner->{id}}->{display} = $miner->{label}; - $self->{miners}->{$miner->{id}}->{mining_frequency} = $calculated_frequency; - - $res_timestamp = $miner->{timestamp} == 0 ? '': localtime($miner->{timestamp}); - if ($miner->{count} > 0) { - $self->{output}->output_add(severity => 'OK', long_msg => 'Miner ' . $miner->{id} . ': Last block from label "' . $miner->{label} . '" (#' . $miner->{count} . - ') was at ' . $res_timestamp . ' (block #' . $miner->{block} . ')' ); - } else { - $self->{output}->output_add(severity => 'OK', long_msg => 'Miner ' . $miner->{id} . ': No validation from "' . $miner->{label} . '"'); - } - } else { - $self->{output}->output_add(severity => 'OK', long_msg => 'Miner ' . $miner->{id} . ': Building perfdata for "' . $miner->{label} . '"...'); - } } foreach my $balance (@{$results->{balances}}) { if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $balance->{id} !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "skipping '" . $balance->{id} . "': no matching filter name.", debug => 1); + $self->{output}->output_add(long_msg => "skipping '" . $balance->{label} . "': no matching filter name.", debug => 1); next; } - my $old_balance = $self->{statefile_cache}->get(name => 'last_balance'); #get the id last_balance - - $datas->{$balance->{id}}->{last_balance} = $balance->{balance}; - - if ($old_balance) { - my $calculated_diff = ($balance->{balance} - $old_balance) / ($old_balance); - - $self->{balances}->{$balance->{id}}->{display} = $balance->{label}; - $self->{balances}->{$balance->{id}}->{balance} = $calculated_diff; - - $self->{output}->output_add(severity => 'OK', long_msg => 'Balance ' . $balance->{id} . ': Balance of "' . $balance->{label} . '" is ' . $balance->{balance} . ' ether' ); - } else { - $self->{output}->output_add(severity => 'OK', long_msg => 'Balance ' . $balance->{id} . ': Balance fluctuation of "' . $balance->{label} . '" is being calculated...'); - } + $self->{balances}->{lc($balance->{label})} = { display => lc($balance->{label}), + balance => $balance->{balance} }; } From 4f20e75b8bf453cc9d63b0c1c3b67449dfd6046c Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Tue, 12 May 2020 20:26:06 +0000 Subject: [PATCH 21/26] update frequency counters --- .../blockchain/parity/ethpoller/mode/stats.pm | 67 +++++++------------ .../parity/ethpoller/mode/tracking.pm | 11 ++- 2 files changed, 33 insertions(+), 45 deletions(-) diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm index e0cf28b7b..a0c7f9687 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm @@ -36,22 +36,26 @@ sub set_counters { ]; $self->{maps_counters}->{block} = [ - { label => 'block_freq', nlabel => 'parity.stats.block.frequency', set => { - key_values => [ { name => 'block_freq' } ], - output_template => "Block frequency: %d (block/min)", + { label => 'block_frequency', nlabel => 'parity.stats.block.persecond', set => { + key_values => [ { name => 'block_count', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => "Block frequency: %.2f (block/s)", perfdatas => [ - { label => 'block_freq', value => 'block_freq_absolute', template => '%d', min => 0 } + { label => 'block', value => 'block_count_per_second', template => ' %.2f', + label_extra_instance => 1, instance_use => 'display_absolute' } ], } } ]; $self->{maps_counters}->{transaction} = [ - { label => 'transaction_freq', nlabel => 'parity.stats.transaction.frequency', set => { - key_values => [ { name => 'transaction_freq' } ], - output_template => "Transaction frequency: %d (tx/min)", + { label => 'transaction_frequency', nlabel => 'parity.stats.transaction.persecond', set => { + key_values => [ { name => 'transaction_count', diff => 1 } ], + per_second => 1, + output_template => "Transaction frequency: %.2f (tx/s)", perfdatas => [ - { label => 'transaction_freq', value => 'transaction_freq_absolute', template => '%d', min => 0 } + { label => 'transaction', value => 'transaction_count_per_second', template => '%.2f', + label_extra_instance => 1, instance_use => 'display_absolute' } ], } } @@ -96,46 +100,25 @@ sub manage_selection { my $result = $options{custom}->request_api(url_path => '/stats'); - my $old_block_timestamp = $self->{statefile_cache}->get(name => 'last_block_timestamp'); - my $old_block_count = $self->{statefile_cache}->get(name => 'last_block_count'); + $self->{block} = { block_count => $result->{block}->{count} }; - my $old_tx_timestamp = $self->{statefile_cache}->get(name => 'last_tx_timestamp'); - my $old_tx_count = $self->{statefile_cache}->get(name => 'last_tx_count'); + $self->{transaction} = { transaction_count => $result->{transaction}->{count} }; - my $datas = {}; - $datas->{last_block_timestamp} = time(); - $datas->{last_block_count} = $result->{block}->{count}; + my $block_timestamp = $result->{block}->{timestamp} == 0 ? '' : localtime($result->{block}->{timestamp}); + $self->{output}->output_add(severity => 'OK', long_msg => 'Last block (#' . $result->{block}->{count} . ') was at ' . $block_timestamp); - $datas->{last_tx_timestamp} = time(); - $datas->{last_tx_count} = $result->{block}->{count}; - - use Data::Dumper; - print Dumper($old_tx_timestamp); - - my $res_timestamp = 0; - - if ($old_block_count && $old_block_timestamp) { - $res_timestamp = $result->{block}->{timestamp} == 0 ? '' : $result->{block}->{timestamp}; - my $calculated_block_freq = ($result->{block}->{count} - $old_block_count) / (time() - $old_block_timestamp); - $self->{block} = { block_freq => $calculated_block_freq }; - $self->{output}->output_add(severity => 'OK', long_msg => 'Last block (#' . $result->{block}->{count} . ') was at ' . $res_timestamp); + if ($result->{transaction}->{count} > 0) { + my $tx_timestamp = $result->{transaction}->{timestamp} == 0 ? '' : localtime($result->{transaction}->{timestamp}); + $self->{output}->output_add(severity => 'OK', long_msg => 'Last transaction (#' . $result->{transaction}->{count} . ') was at ' . $tx_timestamp); } else { - $self->{output}->output_add(severity => 'OK', long_msg => 'Last block (#' . $result->{block}->{block} . ') was at ' . $res_timestamp . '. Block frequency is being calculated...'); + $self->{output}->output_add(severity => 'OK', long_msg => 'No transaction...'); } - - if ($old_tx_count && $old_tx_timestamp) { - $res_timestamp = $result->{transaction}->{timestamp} == 0 ? '' : $result->{transaction}->{timestamp}; - my $calculated_tx_freq = ($result->{transaction}->{count} - $old_tx_count) / (time() - $old_tx_timestamp); - $self->{transaction} = { transaction_freq => $calculated_tx_freq }; - $self->{output}->output_add(severity => 'OK', long_msg => 'Last transaction (#' . $result->{transaction}->{count} . ') was at ' . $res_timestamp); + + if ($result->{transaction}->{count} > 0) { + my $fork_timestamp = $result->{fork}->{timestamp} == 0 ? '' : localtime($result->{fork}->{timestamp}); + $self->{output}->output_add(severity => 'OK', long_msg => 'Last fork (#' . $result->{fork}->{count} . ') was at ' . $fork_timestamp); } else { - $self->{output}->output_add(severity => 'OK', long_msg => 'Last transaction (#' . $result->{transaction}->{count} . ') was at ' . $res_timestamp . '. Transaction frequency is being calculated...'); - } - - if ($result->{fork}->{count} > 0) { - $self->{output}->output_add(severity => 'OK', long_msg => 'Last fork (#' . $result->{fork}->{count} . ') was at ' . $res_timestamp); - } else { - $self->{output}->output_add(severity => 'OK', long_msg => 'No fork occurence'); + $self->{output}->output_add(severity => 'OK', long_msg => 'No fork occurence...'); } } diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm index 250383c55..e41d6d726 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm @@ -51,9 +51,11 @@ sub set_counters { $self->{maps_counters}->{miners} = [ { label => 'mining_frequency', nlabel => 'parity.tracking.mined.block.persecond', set => { - key_values => [ { name => 'mining_frequency' } ], + key_values => [ { name => 'mining_count', diff => 1 }, { name => 'display' } ], + per_second => 1, output_template => " %.2f (blocks/s)", - perfdatas => [ instance_use => 'display_absolute', label_extra_instance => 1 ], + perfdatas => [ { label => 'miners', template => '%.2f', value => 'mining_count_per_second', + label_extra_instance => 1, instance_use => 'display_absolute' } ], } } ]; @@ -130,10 +132,13 @@ sub manage_selection { foreach my $miner (@{$results->{miners}}) { if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $miner->{id} !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "skipping '" . $miner->{id} . "': no matching filter name.", debug => 1); + $self->{output}->output_add(long_msg => "skipping '" . $miner->{label} . "': no matching filter name.", debug => 1); next; } + $self->{miners}->{lc($miner->{label})} = { display => lc($miner->{label}), + mining_count => $miner->{count} }; + } foreach my $balance (@{$results->{balances}}) { From a9ba41c75af3fd085cc2d41a092fe0b31b8a97fc Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Wed, 13 May 2020 11:13:46 +0000 Subject: [PATCH 22/26] POC prct --- .../blockchain/parity/ethpoller/mode/prct.pm | 129 ++++++++++++++++++ .../blockchain/parity/ethpoller/plugin.pm | 3 +- 2 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 centreon-plugins/blockchain/parity/ethpoller/mode/prct.pm diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/prct.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/prct.pm new file mode 100644 index 000000000..633c13b35 --- /dev/null +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/prct.pm @@ -0,0 +1,129 @@ +# +# Copyright 2020 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package blockchain::parity::ethpoller::mode::prct; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use bigint; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'balances', cb_prefix_output => 'prefix_output_balances', type => 1, message_multiple => 'Balances metrics are ok' } + ]; + + $self->{maps_counters}->{balances} = [ + { label => 'balance-fluctuation-prct', nlabel => 'parity.tracking.balances.variation.persecond', display_ok => 0, set => { + key_values => [], + manual_keys => 1, + closure_custom_calc => $self->can('custom_loss_calc'), + closure_custom_output => $self->can('custom_loss_output'), + threshold_use => 'balance_fluctuation', + perfdatas => [ + { value => 'balance_fluctuation', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display' }, + ], + } + } + ]; + +} + +sub custom_loss_output { + my ($self, %options) = @_; + + # use Data::Dumper; + # print Dumper('$total_balance'); + return sprintf( + "balance variation: %.2f%% ", + $self->{result_values}->{balance_fluctuation} + ); +} + +sub custom_loss_calc { + my ($self, %options) = @_; + + my $new_balance = $options{new_datas}->{$_}; + my $old_balance = $options{old_datas}->{$_}; + + # use Data::Dumper; + # print Dumper($total_balance); + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{balance_fluctuation} = 0; + if ($old_balance > 0) { + $self->{result_values}->{balance_fluctuation} = ($new_balance - $old_balance) / $old_balance; + } + + +} + +sub prefix_output_balances { + my ($self, %options) = @_; + + return "Balance '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +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 => '/tracking'); + use Data::Dumper; + # print Dumper($result); + + foreach my $balance (@{$result->{balances}}) { + # print Dumper($balance); + $self->{balances}->{$balance->{label}} = { display => $balance->{label} }; + $self->{balances}->{$balance->{label}}->{'balance_fluctuation'} = $balance->{balance}; + } + +} + + + +1; + +__END__ + +=head1 MODE + +Check Parity eth-poller for events, miners and balances tracking + +=cut diff --git a/centreon-plugins/blockchain/parity/ethpoller/plugin.pm b/centreon-plugins/blockchain/parity/ethpoller/plugin.pm index 48e08df5c..d28ab211d 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/plugin.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/plugin.pm @@ -35,7 +35,8 @@ sub new { # 'fork' => 'blockchain::parity::ethpoller::mode::fork', 'stats' => 'blockchain::parity::ethpoller::mode::stats', 'disk' => 'blockchain::parity::ethpoller::mode::disk', - 'tracking' => 'blockchain::parity::ethpoller::mode::tracking' + 'tracking' => 'blockchain::parity::ethpoller::mode::tracking', + 'prct' => 'blockchain::parity::ethpoller::mode::prct' ); $self->{custom_modes}{api} = 'blockchain::parity::ethpoller::custom::api'; return $self; From b227f04505b575e1c7a0d19524a3712b3d33f47b Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Thu, 14 May 2020 05:40:48 +0000 Subject: [PATCH 23/26] prct improvments --- .../blockchain/parity/ethpoller/mode/prct.pm | 48 +++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/prct.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/prct.pm index 633c13b35..205feff6a 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/prct.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/prct.pm @@ -35,42 +35,62 @@ sub set_counters { ]; $self->{maps_counters}->{balances} = [ - { label => 'balance-fluctuation-prct', nlabel => 'parity.tracking.balances.variation.persecond', display_ok => 0, set => { + { label => 'balance-fluctuation-prct', nlabel => 'parity.tracking.balances.fluctuation', display_ok => 0, set => { key_values => [], manual_keys => 1, - closure_custom_calc => $self->can('custom_loss_calc'), - closure_custom_output => $self->can('custom_loss_output'), + closure_custom_calc => $self->can('custom_prct_calc'), + closure_custom_output => $self->can('custom_prct_output'), threshold_use => 'balance_fluctuation', perfdatas => [ - { value => 'balance_fluctuation', template => '%d', + { value => 'balance_fluctuation', template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' }, ], } + }, + { label => 'balance', nlabel => 'parity.tracking.balance', set => { + key_values => [ { name => 'balance' } ], + output_template => "%d (wei)", + perfdatas => [ + { label => 'balance', template => '%d', value => 'balance_absolute' } + ], + } } ]; } -sub custom_loss_output { +sub custom_prct_output { my ($self, %options) = @_; # use Data::Dumper; # print Dumper('$total_balance'); return sprintf( - "balance variation: %.2f%% ", + "balance variation: %.2f ", $self->{result_values}->{balance_fluctuation} ); } -sub custom_loss_calc { +sub custom_prct_calc { + use Data::Dumper; + my ($self, %options) = @_; - my $new_balance = $options{new_datas}->{$_}; - my $old_balance = $options{old_datas}->{$_}; + my ($old_balance, $new_balance) = (0, 0); + foreach (keys %{$options{new_datas}}) { + # print Dumper($self->{instance}); + # print Dumper($options{new_datas}); + # print Dumper($options{new_datas}->{$_}); + if (/\Q$self->{instance}\E_.*_balance/) { + # print Dumper($self->{instance}); + $new_balance = $options{new_datas}->{$_}; + $old_balance = $options{old_datas}->{$_}; + # print Dumper($old_balance); + # print Dumper($new_balance); + } + } + + - # use Data::Dumper; - # print Dumper($total_balance); - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; $self->{result_values}->{balance_fluctuation} = 0; if ($old_balance > 0) { @@ -83,7 +103,7 @@ sub custom_loss_calc { sub prefix_output_balances { my ($self, %options) = @_; - return "Balance '" . $options{instance_value}->{display} . "' "; + return "Balance '" . $options{instance_value}->{display} . "': "; } sub new { @@ -111,7 +131,7 @@ sub manage_selection { foreach my $balance (@{$result->{balances}}) { # print Dumper($balance); $self->{balances}->{$balance->{label}} = { display => $balance->{label} }; - $self->{balances}->{$balance->{label}}->{'balance_fluctuation'} = $balance->{balance}; + $self->{balances}->{$balance->{label}}->{'balance'} = $balance->{balance}; } } From 8880a9b7f35397a7613bf3a4333f899d9b513e91 Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Thu, 14 May 2020 14:06:40 +0000 Subject: [PATCH 24/26] typos in eth correction --- centreon-plugins/blockchain/parity/restapi/mode/eth.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm index 08c7a8461..edb5e571b 100644 --- a/centreon-plugins/blockchain/parity/restapi/mode/eth.pm +++ b/centreon-plugins/blockchain/parity/restapi/mode/eth.pm @@ -46,10 +46,10 @@ sub set_counters { { name => 'sync', cb_prefix_output => 'prefix_module_output', type => 0 }, ]; - $self->{maps_counters}->{gas} = [ + $self->{maps_counters}->{sync} = [ { label => 'sync_status', nlabel => 'parity.eth.sync.status', set => { key_values => [ { name => 'sync_status' } ], - output_template => "The gas price is: %d %% ", + output_template => "Syncing: %d %% ", perfdatas => [ { label => 'sync_status', value => 'sync_status_absolute', template => '%d', min => 0 } ], @@ -213,8 +213,8 @@ sub manage_selection { $self->{sync} = { sync_status => $res_sync }; $self->{gas} = { gas_price => $gas_price, - gas_used => hex(@{$result}[5]->{result}->{gasLimit}), - gas_limit => hex(@{$result}[5]->{result}->{gasUsed}) }; + gas_used => hex(@{$result}[5]->{result}->{gasUsed}), + gas_limit => hex(@{$result}[5]->{result}->{gasLimit}) }; my $calculated_block_usage = hex(@{$result}[5]->{result}->{gasUsed}) / hex(@{$result}[5]->{result}->{gasLimit}); $self->{block} = { block_size => hex(@{$result}[5]->{result}->{size}), From 21d6f2af953f4c09a681c4cce357b6b5c2457a1f Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Thu, 14 May 2020 16:06:15 +0000 Subject: [PATCH 25/26] stats typos correction --- centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm index a0c7f9687..3431c9839 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm @@ -37,7 +37,7 @@ sub set_counters { $self->{maps_counters}->{block} = [ { label => 'block_frequency', nlabel => 'parity.stats.block.persecond', set => { - key_values => [ { name => 'block_count', diff => 1 }, { name => 'display' } ], + key_values => [ { name => 'block_count', diff => 1 } ], per_second => 1, output_template => "Block frequency: %.2f (block/s)", perfdatas => [ From b204aa4c7f66e092ba5510afdb721748bcff6301 Mon Sep 17 00:00:00 2001 From: Lotfi zaouche Date: Mon, 18 May 2020 21:25:03 +0000 Subject: [PATCH 26/26] typos correction --- .../blockchain/parity/ethpoller/mode/disk.pm | 2 +- .../blockchain/parity/ethpoller/mode/stats.pm | 6 ++-- .../parity/ethpoller/mode/tracking.pm | 32 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/disk.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/disk.pm index 586d41da9..cd06b13ba 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/disk.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/disk.pm @@ -43,7 +43,7 @@ sub set_counters { ], } }, - { label => 'disk_available', nlabel => 'eth.poller.disk.free', set => { + { label => 'disk_available', nlabel => 'eth.poller.disk.available', set => { key_values => [ { name => 'disk_available' } ], output_template => "Disk available: %d ", perfdatas => [ diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm index 3431c9839..72fe40df8 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm @@ -105,18 +105,18 @@ sub manage_selection { $self->{transaction} = { transaction_count => $result->{transaction}->{count} }; my $block_timestamp = $result->{block}->{timestamp} == 0 ? '' : localtime($result->{block}->{timestamp}); - $self->{output}->output_add(severity => 'OK', long_msg => 'Last block (#' . $result->{block}->{count} . ') was at ' . $block_timestamp); + $self->{output}->output_add(severity => 'OK', long_msg => 'Last block (#' . $result->{block}->{count} . ') was on ' . $block_timestamp); if ($result->{transaction}->{count} > 0) { my $tx_timestamp = $result->{transaction}->{timestamp} == 0 ? '' : localtime($result->{transaction}->{timestamp}); - $self->{output}->output_add(severity => 'OK', long_msg => 'Last transaction (#' . $result->{transaction}->{count} . ') was at ' . $tx_timestamp); + $self->{output}->output_add(severity => 'OK', long_msg => 'Last transaction (#' . $result->{transaction}->{count} . ') was on ' . $tx_timestamp); } else { $self->{output}->output_add(severity => 'OK', long_msg => 'No transaction...'); } if ($result->{transaction}->{count} > 0) { my $fork_timestamp = $result->{fork}->{timestamp} == 0 ? '' : localtime($result->{fork}->{timestamp}); - $self->{output}->output_add(severity => 'OK', long_msg => 'Last fork (#' . $result->{fork}->{count} . ') was at ' . $fork_timestamp); + $self->{output}->output_add(severity => 'OK', long_msg => 'Last fork (#' . $result->{fork}->{count} . ') was on ' . $fork_timestamp); } else { $self->{output}->output_add(severity => 'OK', long_msg => 'No fork occurence...'); } diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm index e41d6d726..4badb37de 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm @@ -32,36 +32,36 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'events', cb_prefix_output => 'prefix_output_events', type => 1, message_multiple => 'Events metrics are ok' }, - { name => 'miners', cb_prefix_output => 'prefix_output_miners', type => 1, message_multiple => 'Miners metrics are ok' }, - { name => 'balances', cb_prefix_output => 'prefix_output_balances', type => 1, message_multiple => 'Balances metrics are ok' } + { name => 'mining', cb_prefix_output => 'prefix_output_mining', type => 1, message_multiple => 'Mining metrics are ok' }, + { name => 'balance', cb_prefix_output => 'prefix_output_balance', type => 1, message_multiple => 'Balances metrics are ok' } ]; $self->{maps_counters}->{events} = [ - { label => 'event_frequency', nlabel => 'parity.tracking.event.persecond', set => { - key_values => [ { name => 'event_count', diff => 1 }, { name => 'display' } ], + { label => 'events_frequency', nlabel => 'parity.tracking.events.persecond', set => { + key_values => [ { name => 'events_count', diff => 1 }, { name => 'display' } ], per_second => 1, output_template => " %.2f (events/s)", perfdatas => [ - { label => 'events', template => '%.2f', value => 'event_count_per_second', + { label => 'events', template => '%.2f', value => 'events_count_per_second', label_extra_instance => 1, instance_use => 'display_absolute' } ], } } ]; - $self->{maps_counters}->{miners} = [ + $self->{maps_counters}->{mining} = [ { label => 'mining_frequency', nlabel => 'parity.tracking.mined.block.persecond', set => { key_values => [ { name => 'mining_count', diff => 1 }, { name => 'display' } ], per_second => 1, output_template => " %.2f (blocks/s)", - perfdatas => [ { label => 'miners', template => '%.2f', value => 'mining_count_per_second', + perfdatas => [ { label => 'mining', template => '%.2f', value => 'mining_count_per_second', label_extra_instance => 1, instance_use => 'display_absolute' } ], } } ]; - $self->{maps_counters}->{balances} = [ - { label => 'balance_fluctuation', nlabel => 'parity.tracking.balances.variation.persecond', set => { + $self->{maps_counters}->{balance} = [ + { label => 'balance_fluctuation', nlabel => 'parity.tracking.balance.variation.persecond', set => { key_values => [ { name => 'balance', diff => 1 } ], per_second => 1, output_template => " variation: %.2f (diff/sec)", @@ -81,13 +81,13 @@ sub prefix_output_events { return "Event '" . $options{instance_value}->{display} . "' "; } -sub prefix_output_miners { +sub prefix_output_mining { my ($self, %options) = @_; return "Miner '" . $options{instance_value}->{display} . "' ";; } -sub prefix_output_balances { +sub prefix_output_balance { my ($self, %options) = @_; return "Balance '" . $options{instance_value}->{display} . "' "; @@ -114,8 +114,8 @@ sub manage_selection { my $results = $options{custom}->request_api(url_path => '/tracking'); $self->{events} = {}; - $self->{miners} = {}; - $self->{balances} = {}; + $self->{mining} = {}; + $self->{balance} = {}; foreach my $event (@{$results->{events}}) { if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && @@ -125,7 +125,7 @@ sub manage_selection { } $self->{events}->{lc($event->{label})} = { display => lc($event->{label}), - event_count => $event->{count} }; + events_count => $event->{count} }; } @@ -136,7 +136,7 @@ sub manage_selection { next; } - $self->{miners}->{lc($miner->{label})} = { display => lc($miner->{label}), + $self->{mining}->{lc($miner->{label})} = { display => lc($miner->{label}), mining_count => $miner->{count} }; } @@ -148,7 +148,7 @@ sub manage_selection { next; } - $self->{balances}->{lc($balance->{label})} = { display => lc($balance->{label}), + $self->{balance}->{lc($balance->{label})} = { display => lc($balance->{label}), balance => $balance->{balance} }; }