From: Guilherme Maciel Ferreira Date: Fri, 25 Mar 2011 13:53:30 +0000 (+0100) Subject: Placed limit qualifier in the end of variables names (i.e. xxx_limit instead of limit... X-Git-Tag: v1.0~112 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=a341119ac6c13b13b1ab3d1d62e8205ff460c977;p=pingcheck Placed limit qualifier in the end of variables names (i.e. xxx_limit instead of limit_xxx) - this keeps a pleasing symmetry with other qualifiers, for example xxx_count, xxx_limit, xxx_index --- diff --git a/Readme b/Readme index 34f33a8..595dfd7 100644 --- a/Readme +++ b/Readme @@ -167,10 +167,10 @@ configuration block. 4.1. General --------------------------------------- This configurations are shared among and affect all the hosts. -- limit-hosts-down: an absolute number, which ranges from 0 to the number of +- hosts-down-limit: an absolute number, which ranges from 0 to the number of hosts available. This value represents the minimum number of hosts that have to fail (i.e. do not reply to the ping) in order to alert any external system. -- limit-ping-fail: percentage of pings to a host that can fail. If the +- ping-fail-limit: percentage of pings to a host that can fail. If the percentage of failed pings to a host exceed this number, then the host is considered down. - status-notifier-cmd: the command line that is called when a host is down, or diff --git a/conf/pingcheck.conf b/conf/pingcheck.conf index c97f5fa..7e3a5ad 100644 --- a/conf/pingcheck.conf +++ b/conf/pingcheck.conf @@ -1,5 +1,5 @@ -limit-hosts-down=4 -limit-ping-fail=40 +hosts-down-limit=4 +ping-fail-limit=40 status-notifier-cmd=./system_status_alert.sh ${status} [host] diff --git a/src/config/configuration.cpp b/src/config/configuration.cpp index 006ab51..5256b31 100644 --- a/src/config/configuration.cpp +++ b/src/config/configuration.cpp @@ -10,12 +10,12 @@ using namespace std; Configuration::Configuration() : ConfigFileName( "" ), - LimitHostsDown( 0 ), - MinLimitHostsDown( 0 ), - MaxLimitHostsDown( 50 ), - LimitPingFail( 0 ), - MinLimitPingFail( 0 ), - MaxLimitPingFail( 100 ), + HostsDownLimit( 0 ), + MinHostsDownLimit( 0 ), + MaxHostsDownLimit( 50 ), + PingFailLimit( 0 ), + MinPingFailLimit( 0 ), + MaxPingFailLimit( 100 ), StatusNotifierCmd( "" ), Hosts() { @@ -37,26 +37,26 @@ void Configuration::set_config_file_name( const std::string &config_file_name ) this->ConfigFileName = config_file_name; } -int Configuration::get_limit_hosts_down() const +int Configuration::get_hosts_down_limit() const { - return LimitHostsDown; + return HostsDownLimit; } -void Configuration::set_limit_hosts_down( const int limit_hosts_down ) +void Configuration::set_hosts_down_limit( const int hosts_down_limit ) { - BOOST_ASSERT( ( MinLimitHostsDown <= limit_hosts_down ) && ( limit_hosts_down <= MaxLimitHostsDown) ); + BOOST_ASSERT( ( MinHostsDownLimit <= hosts_down_limit ) && ( hosts_down_limit <= MaxHostsDownLimit) ); - this->LimitHostsDown = limit_hosts_down; + this->HostsDownLimit = hosts_down_limit; } -int Configuration::get_limit_ping_fail() const +int Configuration::get_ping_fail_limit() const { - return LimitPingFail; + return PingFailLimit; } -void Configuration::set_limit_ping_fail( const int limit_ping_fail ) +void Configuration::set_ping_fail_limit( const int ping_fail_limit ) { - LimitPingFail = limit_ping_fail; + PingFailLimit = ping_fail_limit; } string Configuration::get_status_notifier_cmd() const diff --git a/src/config/configuration.h b/src/config/configuration.h index b06093a..ab11e55 100644 --- a/src/config/configuration.h +++ b/src/config/configuration.h @@ -21,11 +21,11 @@ public: std::string get_config_file_name() const; void set_config_file_name( const std::string &config_file_name ); - int get_limit_hosts_down() const; - void set_limit_hosts_down( const int limit_hosts_down ); + int get_hosts_down_limit() const; + void set_hosts_down_limit( const int hosts_down_limit ); - int get_limit_ping_fail() const; - void set_limit_ping_fail( const int limit_ping_fail ); + int get_ping_fail_limit() const; + void set_ping_fail_limit( const int ping_fail_limit ); std::string get_status_notifier_cmd() const; void set_status_notifier_cmd( const std::string &status_notifier_cmd ); @@ -35,12 +35,12 @@ public: private: std::string ConfigFileName; - int LimitHostsDown; - const int MinLimitHostsDown; - const int MaxLimitHostsDown; - int LimitPingFail; - const int MinLimitPingFail; - const int MaxLimitPingFail; + int HostsDownLimit; + const int MinHostsDownLimit; + const int MaxHostsDownLimit; + int PingFailLimit; + const int MinPingFailLimit; + const int MaxPingFailLimit; std::string StatusNotifierCmd; std::vector Hosts; diff --git a/src/config/configurationreader.cpp b/src/config/configurationreader.cpp index 7a63808..2f472d3 100644 --- a/src/config/configurationreader.cpp +++ b/src/config/configurationreader.cpp @@ -23,17 +23,17 @@ ConfigurationReader::ConfigurationReader() : DefaultConfigFileName( "pingcheck.conf" ), ConfigFileCmdStr( "config-file" ), ConfigFileCmdDesc( "Name of the configuration file." ), - DefaultLimitHostsDown( 1 ), - LimitHostsDownCmdStr( "limit-hosts-down" ), - LimitHostsDownCmdDesc( "Limit of host that have to be down in order to notify." ), - DefaultLimitPingFail( 50 ), - LimitPingFailCmdStr( "limit-ping-fail" ), - LimitPingFailCmdDesc( "Maximum percentage of pings that can fail for a given host." ), + DefaultHostsDownLimit( 1 ), // 1 host down at most + HostsDownLimitCmdStr( "hosts-down-limit" ), + HostsDownLimitCmdDesc( "Limit of host that have to be down in order to notify." ), + DefaultPingFailLimit( 50 ), // 50 pings can fail at most + PingFailLimitCmdStr( "ping-fail-limit" ), + PingFailLimitCmdDesc( "Maximum percentage of pings that can fail for a given host." ), StatusNotifierCmdCmdStr( "status-notifier-cmd" ), StatusNotifierCmdCmdDesc( "The command to execute to alert about host status." ), HostNameCmdStr( "host.name" ), HostNameCmdDesc( "Host address" ), - DefaultHostInterval( 1 ), + DefaultHostInterval( 60 ), // 60 seconds HostIntervalCmdStr( "host.interval" ), HostIntervalCmdDesc( "Interval between each ping to the host" ) { @@ -114,8 +114,8 @@ options_description ConfigurationReader::get_configuration_options() const { options_description options( "Configuration" ); options.add_options() - ( LimitHostsDownCmdStr.c_str(), value()->default_value( DefaultLimitHostsDown ), LimitHostsDownCmdDesc.c_str() ) - ( LimitPingFailCmdStr.c_str(), value()->default_value( DefaultLimitPingFail ), LimitPingFailCmdDesc.c_str() ) + ( HostsDownLimitCmdStr.c_str(), value()->default_value( DefaultHostsDownLimit ), HostsDownLimitCmdDesc.c_str() ) + ( PingFailLimitCmdStr.c_str(), value()->default_value( DefaultPingFailLimit ), PingFailLimitCmdDesc.c_str() ) ( StatusNotifierCmdCmdStr.c_str(), value(), StatusNotifierCmdCmdDesc.c_str() ) ( HostNameCmdStr.c_str(), value< vector >(), HostNameCmdDesc.c_str() ) ( HostIntervalCmdStr.c_str(), value< vector >(), HostIntervalCmdDesc.c_str() ) @@ -135,23 +135,23 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) cout << ConfigFileCmdStr << "=" << config_file_name << endl; } - // limit-hosts-down - int limit_host_down = 0; - if ( vm.count( LimitHostsDownCmdStr ) ) + // hosts-down-limit + int host_down_limit = 0; + if ( vm.count( HostsDownLimitCmdStr ) ) { - limit_host_down = vm[ LimitHostsDownCmdStr ].as (); - Config.set_limit_hosts_down( limit_host_down ); + host_down_limit = vm[ HostsDownLimitCmdStr ].as (); + Config.set_hosts_down_limit( host_down_limit ); - cout << LimitHostsDownCmdStr << "=" << limit_host_down << endl; + cout << HostsDownLimitCmdStr << "=" << host_down_limit << endl; } - // limit-ping-fail - if ( vm.count( LimitPingFailCmdStr ) ) + // ping-fail-limit + if ( vm.count( PingFailLimitCmdStr ) ) { - int limit_ping_fail = vm[ LimitPingFailCmdStr ].as (); - Config.set_limit_ping_fail( limit_ping_fail ); + int ping_fail_limit = vm[ PingFailLimitCmdStr ].as (); + Config.set_ping_fail_limit( ping_fail_limit ); - cout << LimitPingFailCmdStr << "=" << limit_ping_fail << endl; + cout << PingFailLimitCmdStr << "=" << ping_fail_limit << endl; } // status-notifier-cmd @@ -164,7 +164,7 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) } // [host] name - int hosts_names_total = 0; + int hosts_names_count = 0; if ( vm.count( HostNameCmdStr ) ) { vector hosts_list; @@ -180,13 +180,13 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) Config.set_hosts( hosts_list ); - hosts_names_total = hosts_names.size(); + hosts_names_count = hosts_names.size(); - BOOST_ASSERT( hosts_names_total >= limit_host_down ); + BOOST_ASSERT( hosts_names_count >= host_down_limit ); } // [host] interval - int hosts_interval_total = 0; + int hosts_interval_count = 0; if ( vm.count( HostIntervalCmdStr ) ) { vector hosts_list = Config.get_hosts(); @@ -202,12 +202,12 @@ bool ConfigurationReader::parse_configuration_options( const variables_map &vm ) cout << HostIntervalCmdStr << "=" << host_interval << endl; } - hosts_interval_total = hosts_intervals.size(); + hosts_interval_count = hosts_intervals.size(); } // TODO deal when interval for a given host was not set. use DefaultHostInterval - BOOST_ASSERT( hosts_names_total == hosts_interval_total ); + BOOST_ASSERT( hosts_names_count == hosts_interval_count ); return true; } diff --git a/src/config/configurationreader.h b/src/config/configurationreader.h index 75fb163..620c2c3 100644 --- a/src/config/configurationreader.h +++ b/src/config/configurationreader.h @@ -61,12 +61,12 @@ private: const std::string DefaultConfigFileName; const std::string ConfigFileCmdStr; const std::string ConfigFileCmdDesc; - const int DefaultLimitHostsDown; - const std::string LimitHostsDownCmdStr; - const std::string LimitHostsDownCmdDesc; - const int DefaultLimitPingFail; - const std::string LimitPingFailCmdStr; - const std::string LimitPingFailCmdDesc; + const int DefaultHostsDownLimit; + const std::string HostsDownLimitCmdStr; + const std::string HostsDownLimitCmdDesc; + const int DefaultPingFailLimit; + const std::string PingFailLimitCmdStr; + const std::string PingFailLimitCmdDesc; const std::string StatusNotifierCmdCmdStr; const std::string StatusNotifierCmdCmdDesc; const std::string HostNameCmdStr; diff --git a/src/main.cpp b/src/main.cpp index dc4d4ff..6ffff97 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,13 +24,13 @@ int main( int argc, char* argv[] ) Configuration config = config_reader.get_configuration(); - int limit_ping_fail = config.get_limit_ping_fail(); + int ping_fail_limit = config.get_ping_fail_limit(); // TODO init_notifier and get_notifier - int limit_hosts_down = config.get_limit_hosts_down(); + int hosts_down_limit = config.get_hosts_down_limit(); string status_notifier_cmd = config.get_status_notifier_cmd(); shared_ptr notifier( - new StatusNotifier( limit_hosts_down, status_notifier_cmd ) + new StatusNotifier( hosts_down_limit, status_notifier_cmd ) ); // TODO init_pingers() @@ -43,7 +43,7 @@ int main( int argc, char* argv[] ) PingSchedulerItem scheduler( new PingScheduler( io_service, ping_address, ping_interval, - limit_ping_fail, notifier + ping_fail_limit, notifier ) ); scheduler_list.push_back( scheduler ); diff --git a/src/notify/statusnotifier.cpp b/src/notify/statusnotifier.cpp index 7493a3f..b1bca0e 100644 --- a/src/notify/statusnotifier.cpp +++ b/src/notify/statusnotifier.cpp @@ -11,14 +11,14 @@ using namespace std; //----------------------------------------------------------------------------- StatusNotifier::StatusNotifier( - const int limit_hosts_down, + const int hosts_down_limit, const string &status_notifier_cmd ) : - LimitHostsDown( limit_hosts_down ), + HostsDownLimit( hosts_down_limit ), StatusNotifierCmd( status_notifier_cmd ), HostsDownList() { - BOOST_ASSERT( 0 <= limit_hosts_down ); + BOOST_ASSERT( 0 <= hosts_down_limit ); BOOST_ASSERT( !status_notifier_cmd.empty() ); } @@ -30,11 +30,11 @@ void StatusNotifier::notify_host_up( const string &host_address ) { BOOST_ASSERT( !host_address.empty() ); - cout << "- Link up: " << host_address << endl; // TODO + cout << "- Host up: " << host_address << endl; // TODO add_host_up( host_address ); - if ( !exceeded_host_down_count_limit() ) + if ( !exceeded_host_down_limit() ) { notify_system_up(); } @@ -47,11 +47,11 @@ void StatusNotifier::notify_host_down( const string &host_address ) { BOOST_ASSERT( !host_address.empty() ); - cout << "- Link down: " << host_address << endl; // TODO + cout << "- Host down: " << host_address << endl; // TODO add_host_down( host_address ); - if ( exceeded_host_down_count_limit() ) + if ( exceeded_host_down_limit() ) { notify_system_down(); } @@ -73,10 +73,10 @@ void StatusNotifier::add_host_down( const string &host_address ) HostsDownList.insert( host_address ); } -bool StatusNotifier::exceeded_host_down_count_limit() const +bool StatusNotifier::exceeded_host_down_limit() const { int host_down_count = HostsDownList.size(); - return ( host_down_count >= LimitHostsDown ); + return ( host_down_count > HostsDownLimit ); } void StatusNotifier::notify_system_up() diff --git a/src/notify/statusnotifier.h b/src/notify/statusnotifier.h index 18829cc..6793c9f 100644 --- a/src/notify/statusnotifier.h +++ b/src/notify/statusnotifier.h @@ -19,7 +19,7 @@ class StatusNotifier { public: StatusNotifier( - const int limit_hosts_down, + const int hosts_down_limit, const std::string &status_notifier_cmd ); virtual ~StatusNotifier(); @@ -31,13 +31,13 @@ private: void add_host_up( const std::string &host_address ); void add_host_down( const std::string &host_address ); - bool exceeded_host_down_count_limit() const; + bool exceeded_host_down_limit() const; void notify_system_up(); void notify_system_down(); private: - const int LimitHostsDown; + const int HostsDownLimit; StatusNotifierCommand StatusNotifierCmd; std::set HostsDownList; diff --git a/src/ping/pinganalyzer.cpp b/src/ping/pinganalyzer.cpp index fc3ee52..b72d4c1 100644 --- a/src/ping/pinganalyzer.cpp +++ b/src/ping/pinganalyzer.cpp @@ -15,19 +15,19 @@ using namespace boost; PingAnalyzer::PingAnalyzer( const string &host_address, - const int limit_ping_fail_percentage, + const int ping_fail_percentage_limit, shared_ptr notifier ) : HostAddress( host_address ), Notifier( notifier ), - LimitPingFailPercentage( limit_ping_fail_percentage ), + PingFailPercentageLimit( ping_fail_percentage_limit ), ResolvedIpCount( 0 ), PingsPerformedCount( 0 ), PingsFailedCount( 0 ), - ExceededPingFailedCountLimit( false ) + ExceededPingFailedLimit( false ) { BOOST_ASSERT( !HostAddress.empty() ); - BOOST_ASSERT( ( 0 <= LimitPingFailPercentage ) && ( LimitPingFailPercentage <= 100 ) ); + BOOST_ASSERT( ( 0 <= PingFailPercentageLimit ) && ( PingFailPercentageLimit <= 100 ) ); } PingAnalyzer::~PingAnalyzer() @@ -41,9 +41,9 @@ void PingAnalyzer::set_resolved_ip_count( const int resolved_ip_count ) ResolvedIpCount = resolved_ip_count; } -bool PingAnalyzer::exceeded_ping_failed_count_limit() const +bool PingAnalyzer::exceeded_ping_failed_limit() const { - return ExceededPingFailedCountLimit; + return ExceededPingFailedLimit; } void PingAnalyzer::update_ping_statistics( bool ping_success ) @@ -84,7 +84,7 @@ void PingAnalyzer::analyze_ping_statistics() BOOST_ASSERT( PingsPerformedCount == ResolvedIpCount ); // notify if the amount of pings that failed exceed the limit - if ( exceeded_ping_failed_count_limit() ) + if ( exceeded_ping_failed_limit() ) { Notifier->notify_host_down( HostAddress ); } @@ -119,11 +119,11 @@ void PingAnalyzer::increase_ping_failed_count() void PingAnalyzer::analyze_ping_failed_count() { - BOOST_ASSERT( ( 0 <= LimitPingFailPercentage ) && ( LimitPingFailPercentage <= 100 ) ); + BOOST_ASSERT( ( 0 <= PingFailPercentageLimit ) && ( PingFailPercentageLimit <= 100 ) ); BOOST_ASSERT( ( 0 <= PingsFailedCount ) && ( PingsFailedCount <= PingsPerformedCount ) ); - int limit_ping_fail_absolute = LimitPingFailPercentage / 100; // TODO possible precision loss, check with care + int ping_fail_absolute_limit = PingFailPercentageLimit / 100; // TODO possible precision loss, check with care // keep a boolean variable because the PingsFailedCount can be reseted - ExceededPingFailedCountLimit = ( PingsFailedCount > limit_ping_fail_absolute ); + ExceededPingFailedLimit = ( PingsFailedCount > ping_fail_absolute_limit ); } diff --git a/src/ping/pinganalyzer.h b/src/ping/pinganalyzer.h index 0385b41..6f89620 100644 --- a/src/ping/pinganalyzer.h +++ b/src/ping/pinganalyzer.h @@ -21,13 +21,13 @@ class PingAnalyzer public: PingAnalyzer( const std::string &host_address, - const int limit_ping_fail_percentage, + const int ping_fail_percentage_limit, boost::shared_ptr notifier ); virtual ~PingAnalyzer(); void set_resolved_ip_count( const int resolved_ip_count ); - bool exceeded_ping_failed_count_limit() const; + bool exceeded_ping_failed_limit() const; void update_ping_statistics( bool ping_success ); private: @@ -41,11 +41,11 @@ private: private: std::string HostAddress; boost::shared_ptr Notifier; - int LimitPingFailPercentage; + int PingFailPercentageLimit; int ResolvedIpCount; int PingsPerformedCount; int PingsFailedCount; - bool ExceededPingFailedCountLimit; + bool ExceededPingFailedLimit; }; diff --git a/src/ping/pingscheduler.cpp b/src/ping/pingscheduler.cpp index 05c76b8..994a90f 100644 --- a/src/ping/pingscheduler.cpp +++ b/src/ping/pingscheduler.cpp @@ -21,7 +21,7 @@ PingScheduler::PingScheduler( boost::asio::io_service &io_service, const string &ping_address, const long ping_interval_in_sec, - const int limit_ping_fail_percentage, + const int ping_fail_percentage_limit, shared_ptr notifier ) : @@ -30,7 +30,7 @@ PingScheduler::PingScheduler( TimeSentLastPing( microsec_clock::universal_time() ), PingIntervalInSec( ping_interval_in_sec ), IpList( ping_address ), - Analyzer( ping_address, limit_ping_fail_percentage, notifier ) + Analyzer( ping_address, ping_fail_percentage_limit, notifier ) { } @@ -106,16 +106,17 @@ void PingScheduler::update_ping_statistics( const bool ping_success ) { Analyzer.update_ping_statistics( ping_success ); - // TODO FIX this method, once it has a semantic dependency with the + // TODO you must call the method bellow AFTER update_ping_statistics + // Fix this method, once it has a semantic dependency with the // update_ping_statistics method, because it depends on the PingeAnalyzer - // statistics to update the exceeded_ping_failed_count_limit + // statistics to update the exceeded_ping_failed_limit update_ping_interval(); } void PingScheduler::update_ping_interval() { // must to ping more often? - if ( Analyzer.exceeded_ping_failed_count_limit() ) + if ( Analyzer.exceeded_ping_failed_limit() ) { PingIntervalInSec.speed_up(); diff --git a/src/ping/pingscheduler.h b/src/ping/pingscheduler.h index 7795ba0..a5b6683 100644 --- a/src/ping/pingscheduler.h +++ b/src/ping/pingscheduler.h @@ -28,7 +28,7 @@ public: boost::asio::io_service &io_service, const std::string &ping_address, const long ping_interval_in_sec, - const int limit_ping_fail_percentage, + const int ping_fail_percentage_limit, boost::shared_ptr notifier ); virtual ~PingScheduler();