- this keeps a pleasing symmetry with other qualifiers, for example xxx_count, xxx_limit, xxx_index
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
-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]
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()
{
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
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 );
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<HostItem> Hosts;
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" )
{
{
options_description options( "Configuration" );
options.add_options()
- ( LimitHostsDownCmdStr.c_str(), value<int>()->default_value( DefaultLimitHostsDown ), LimitHostsDownCmdDesc.c_str() )
- ( LimitPingFailCmdStr.c_str(), value<int>()->default_value( DefaultLimitPingFail ), LimitPingFailCmdDesc.c_str() )
+ ( HostsDownLimitCmdStr.c_str(), value<int>()->default_value( DefaultHostsDownLimit ), HostsDownLimitCmdDesc.c_str() )
+ ( PingFailLimitCmdStr.c_str(), value<int>()->default_value( DefaultPingFailLimit ), PingFailLimitCmdDesc.c_str() )
( StatusNotifierCmdCmdStr.c_str(), value<string>(), StatusNotifierCmdCmdDesc.c_str() )
( HostNameCmdStr.c_str(), value< vector<string> >(), HostNameCmdDesc.c_str() )
( HostIntervalCmdStr.c_str(), value< vector<int> >(), HostIntervalCmdDesc.c_str() )
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<int> ();
- Config.set_limit_hosts_down( limit_host_down );
+ host_down_limit = vm[ HostsDownLimitCmdStr ].as<int> ();
+ 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<int> ();
- Config.set_limit_ping_fail( limit_ping_fail );
+ int ping_fail_limit = vm[ PingFailLimitCmdStr ].as<int> ();
+ Config.set_ping_fail_limit( ping_fail_limit );
- cout << LimitPingFailCmdStr << "=" << limit_ping_fail << endl;
+ cout << PingFailLimitCmdStr << "=" << ping_fail_limit << endl;
}
// status-notifier-cmd
}
// [host] name
- int hosts_names_total = 0;
+ int hosts_names_count = 0;
if ( vm.count( HostNameCmdStr ) )
{
vector<HostItem> hosts_list;
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<HostItem> hosts_list = Config.get_hosts();
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;
}
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;
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<StatusNotifier> notifier(
- new StatusNotifier( limit_hosts_down, status_notifier_cmd )
+ new StatusNotifier( hosts_down_limit, status_notifier_cmd )
);
// TODO init_pingers()
PingSchedulerItem scheduler(
new PingScheduler(
io_service, ping_address, ping_interval,
- limit_ping_fail, notifier
+ ping_fail_limit, notifier
)
);
scheduler_list.push_back( scheduler );
//-----------------------------------------------------------------------------
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() );
}
{
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();
}
{
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();
}
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()
{
public:
StatusNotifier(
- const int limit_hosts_down,
+ const int hosts_down_limit,
const std::string &status_notifier_cmd
);
virtual ~StatusNotifier();
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<std::string> HostsDownList;
PingAnalyzer::PingAnalyzer(
const string &host_address,
- const int limit_ping_fail_percentage,
+ const int ping_fail_percentage_limit,
shared_ptr<StatusNotifier> 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()
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 )
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 );
}
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 );
}
public:
PingAnalyzer(
const std::string &host_address,
- const int limit_ping_fail_percentage,
+ const int ping_fail_percentage_limit,
boost::shared_ptr<StatusNotifier> 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:
private:
std::string HostAddress;
boost::shared_ptr<StatusNotifier> Notifier;
- int LimitPingFailPercentage;
+ int PingFailPercentageLimit;
int ResolvedIpCount;
int PingsPerformedCount;
int PingsFailedCount;
- bool ExceededPingFailedCountLimit;
+ bool ExceededPingFailedLimit;
};
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<StatusNotifier> notifier
) :
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 )
{
}
{
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();
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<StatusNotifier> notifier
);
virtual ~PingScheduler();