Read the interval between each ping to the host
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Fri, 25 Feb 2011 11:01:05 +0000 (12:01 +0100)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Fri, 25 Feb 2011 11:01:05 +0000 (12:01 +0100)
config/pingcheck.cfg
src/config/configurationreader.cpp
src/config/configurationreader.h

index 245388d..08edd6f 100644 (file)
@@ -2,3 +2,4 @@ limit-to-notify=5
 
 [host]
 name=www.intra2net.com
+interval=2
\ No newline at end of file
index 6f95678..00be8e2 100644 (file)
@@ -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<string>()->default_value( DefaultConfigFileName ), ConfigFileCmdDesc.c_str() );
+        ( ConfigFileCmdStr.c_str(), value<string>()->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<int>()->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<int> ();
+        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;
         }
 
     }
index 038368f..db462fc 100644 (file)
@@ -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;
 
 };