4.1. General
---------------------------------------
This configurations are shared among and affect all the hosts.
+- source-network-interface: the local network interface from where the ping
+ packages with originate.
+- nameserver: the server which the hosts names will be resolved. It is the
+ lookup server which the application will query first. If left blank or omited,
+ it will use the /etc/resolv.conf.
- 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.
source-network-interface=eth1
+nameserver=127.0.0.1
hosts-down-limit=4
ping-fail-limit=40
status-notifier-cmd=./system_status_alert.sh ${status}
Configuration::Configuration() :
ConfigFileName( "" ),
SourceNetworkInterface( "" ),
+ NameServer( "" ),
HostsDownLimit( 0 ),
MinHostsDownLimit( 0 ),
MaxHostsDownLimit( 50 ),
this->ConfigFileName = config_file_name;
}
+std::string Configuration::get_nameserver() const
+{
+ return NameServer;
+}
+
+void Configuration::set_nameserver( const std::string &nameserver )
+{
+ NameServer = nameserver;
+}
+
string Configuration::get_source_network_interface() const
{
return SourceNetworkInterface;
std::string get_config_file_name() const;
void set_config_file_name( const std::string &config_file_name );
+ std::string get_nameserver() const;
+ void set_nameserver( const std::string &nameserver );
+
std::string get_source_network_interface() const;
void set_source_network_interface(
const std::string &source_network_interface
private:
std::string ConfigFileName;
std::string SourceNetworkInterface;
+ std::string NameServer;
int HostsDownLimit;
const int MinHostsDownLimit;
const int MaxHostsDownLimit;
ConfigFileCmdDesc( "Name of the configuration file." ),
SourceNetworkInterfaceCmdStr( "source-network-interface" ),
SourceNetworkInterfaceCmdDesc( "The network interface from where the packets will be received and originated" ),
+ NameServerCmdStr( "nameserver" ),
+ NameServerCmdDesc( "The local address from where the DNS query will be made." ),
DefaultHostsDownLimit( 1 ), // 1 host down at most
HostsDownLimitCmdStr( "hosts-down-limit" ),
HostsDownLimitCmdDesc( "Limit of host that have to be down in order to notify." ),
options_description options( "Configuration" );
options.add_options()
( SourceNetworkInterfaceCmdStr.c_str(), value<string>(), SourceNetworkInterfaceCmdDesc.c_str() )
+ ( NameServerCmdStr.c_str(), value<string>(), NameServerCmdDesc.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() )
<< endl;
}
+ // nameserver
+ if ( vm.count( NameServerCmdStr ) )
+ {
+ string nameserver = vm[ NameServerCmdStr ].as<string> ();
+ Config.set_nameserver( nameserver );
+
+ cout << NameServerCmdStr << "=" << nameserver << endl;
+ }
+
// hosts-down-limit
int host_down_limit = 0;
if ( vm.count( HostsDownLimitCmdStr ) )
const std::string ConfigFileCmdDesc;
const std::string SourceNetworkInterfaceCmdStr;
const std::string SourceNetworkInterfaceCmdDesc;
+ const std::string NameServerCmdStr;
+ const std::string NameServerCmdDesc;
const int DefaultHostsDownLimit;
const std::string HostsDownLimitCmdStr;
const std::string HostsDownLimitCmdDesc;
// DnsResolver
//-----------------------------------------------------------------------------
-DnsResolver::DnsResolver( const string &dns_address ) :
+DnsResolver::DnsResolver(
+ const string &dns_address,
+ const string &nameserver
+) :
ResolvedHostAddressList(),
- HostDnsAddress( dns_address )
+ HostDnsAddress( dns_address ),
+ NameServer( nameserver )
{
}
bool DnsResolver::resolve()
{
BOOST_ASSERT( !HostDnsAddress.empty() );
+ BOOST_ASSERT( !NameServer.empty() );
cout << "Resolved IP(s) for host : " << HostDnsAddress << endl;
try
{
- address nameServer( address::from_string( "127.0.0.1" ) );
+ address nameServer( address::from_string( NameServer ) );
boost::net::dns::resolve resolver;
resolver.addServer( nameServer );
message dns_message( HostDnsAddress, boost::net::dns::type_a );
class DnsResolver
{
public:
- explicit DnsResolver( const std::string &dns_address );
+ DnsResolver(
+ const std::string &dns_address,
+ const std::string &nameserver
+ );
~DnsResolver();
bool resolve();
private:
std::list<HostAddress> ResolvedHostAddressList;
const std::string HostDnsAddress;
+ const std::string NameServer;
};
const string &destination_address,
const long ping_interval_in_sec,
const int ping_fail_percentage_limit,
+ const string &nameserver,
shared_ptr<LinkStatusAnalyzer> link_analyzer
) :
NextPingTimer( io_serv ),
TimeSentLastPing( microsec_clock::universal_time() ),
PingIntervalInSec( ping_interval_in_sec ),
- IpList( destination_address ),
+ IpList( destination_address, nameserver ),
HostAnalyzer( destination_address, ping_fail_percentage_limit, link_analyzer )
{
}
const std::string &destination_address,
const long ping_interval_in_sec,
const int ping_fail_percentage_limit,
+ const std::string &nameserver,
boost::shared_ptr<LinkStatusAnalyzer> link_analyzer
);
~PingScheduler();
)
);
- string ping_interface = config.get_source_network_interface();
+ string local_interface = config.get_source_network_interface();
+ string nameserver = config.get_nameserver();
// TODO init_pingers()
vector< HostItem > hosts = config.get_hosts();
vector< PingSchedulerItem > scheduler_list;
BOOST_FOREACH( HostItem host, hosts )
{
- string ping_address = (*host).get_address();
+ string destination_address = (*host).get_address();
int ping_interval_in_sec = (*host).get_interval_in_sec();
PingSchedulerItem scheduler(
new PingScheduler(
io_serv,
- ping_interface,
- ping_address,
+ local_interface,
+ destination_address,
ping_interval_in_sec,
ping_fail_limit,
+ nameserver,
link_analyzer
)
);