From: Guilherme Maciel Ferreira Date: Fri, 25 Feb 2011 11:01:05 +0000 (+0100) Subject: Read the interval between each ping to the host X-Git-Tag: v1.0~178 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=39775e5b8cacaa8849233f40a0886f98e5a83500;p=pingcheck Read the interval between each ping to the host --- diff --git a/config/pingcheck.cfg b/config/pingcheck.cfg index 245388d..08edd6f 100644 --- a/config/pingcheck.cfg +++ b/config/pingcheck.cfg @@ -2,3 +2,4 @@ limit-to-notify=5 [host] name=www.intra2net.com +interval=2 \ No newline at end of file diff --git a/src/config/configurationreader.cpp b/src/config/configurationreader.cpp index 6f95678..00be8e2 100644 --- a/src/config/configurationreader.cpp +++ b/src/config/configurationreader.cpp @@ -25,7 +25,10 @@ ConfigurationReader::ConfigurationReader() : LimitToNotifyCmdStr( "limit-to-notify" ), LimitToNotifyCmdDesc( "Limit of host that have to be down in order to notify." ), HostNameCmdStr( "host.name" ), - HostNameCmdDesc( "Host address" ) + HostNameCmdDesc( "Host address" ), + DefaultHostInterval( 1 ), + HostIntervalCmdStr( "host.interval" ), + HostIntervalCmdDesc( "Interval between each ping to the host" ) { } @@ -65,7 +68,8 @@ options_description ConfigurationReader::get_generic_options() const options.add_options() ( VersionCmdStr.c_str(), VersionCmdDesc.c_str() ) ( HelpCmdStr.c_str(), HelpCmdDesc.c_str() ) - ( ConfigFileCmdStr.c_str(), value()->default_value( DefaultConfigFileName ), ConfigFileCmdDesc.c_str() ); + ( ConfigFileCmdStr.c_str(), value()->default_value( DefaultConfigFileName ), ConfigFileCmdDesc.c_str() ) + ; return options; } @@ -104,7 +108,9 @@ options_description ConfigurationReader::get_configuration_options() const options_description options( "Configuration" ); options.add_options() ( LimitToNotifyCmdStr.c_str(), value()->default_value( DefaultLimitToNotify ), LimitToNotifyCmdDesc.c_str() ) - ( HostNameCmdStr.c_str(), value< string >(), HostNameCmdDesc.c_str() ); + ( HostNameCmdStr.c_str(), value< string >(), HostNameCmdDesc.c_str() ) + ( HostIntervalCmdStr.c_str(), value< int >()->default_value( DefaultHostInterval ), HostIntervalCmdDesc.c_str() ) + ; return options; } @@ -137,6 +143,16 @@ bool ConfigurationReader::parse_configuration_options( const variables_map& vm ) cout << HostNameCmdStr << "=" << host_name << endl; } + if ( vm.count( HostIntervalCmdStr ) ) + { + int host_interval = vm[ HostIntervalCmdStr ].as (); + Host host = Config.get_host(); + host.set_interval( host_interval ); + Config.set_host( host ); + + cout << HostIntervalCmdStr << "=" << host_interval << endl; + } + return true; } @@ -159,6 +175,7 @@ bool ConfigurationReader::process_command_line( positional_options_description p; p.add( HostNameCmdStr.c_str(), -1 ); + //p.add( HostIntervalCmdStr.c_str(), -1 ); store( command_line_parser( argc, argv ). options( cmdline_options ). @@ -167,7 +184,9 @@ bool ConfigurationReader::process_command_line( if ( is_generic_options( vm ) ) { - return parse_generic_options( vm, visible ); + parse_generic_options( vm, visible ); + + return false; } } diff --git a/src/config/configurationreader.h b/src/config/configurationreader.h index 038368f..db462fc 100644 --- a/src/config/configurationreader.h +++ b/src/config/configurationreader.h @@ -65,6 +65,9 @@ private: const std::string LimitToNotifyCmdDesc; const std::string HostNameCmdStr; const std::string HostNameCmdDesc; + const uint32_t DefaultHostInterval; + const std::string HostIntervalCmdStr; + const std::string HostIntervalCmdDesc; };