- limit-ping-fail: 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
+ up. Accepted variables are ${host}, ${status}
4.2. Host
---------------------------------------
-- address: the DNS or IP of the host to ping. Take in consideration that, if a
+- name: the DNS or IP of the host to ping. Take in consideration that, if a
DNS is given, the application pings all IPs in the look up table, however, if
IP is provide, it is the only which will be pinged.
+- interval: the host will be pinged every "interval" seconds.
LimitPingFail( 0 ),
MinLimitPingFail( 0 ),
MaxLimitPingFail( 100 ),
+ StatusNotifierCmd( "" ),
Hosts()
{
}
LimitPingFail = limit_ping_fail;
}
+string Configuration::get_status_notifier_cmd() const
+{
+ return StatusNotifierCmd;
+}
+
+void Configuration::set_status_notifier_cmd( const string &status_notifier_cmd )
+{
+ BOOST_ASSERT( !status_notifier_cmd.empty() );
+
+ StatusNotifierCmd = status_notifier_cmd;
+}
+
vector< HostItem > Configuration::get_hosts() const
{
return Hosts;
int get_limit_ping_fail() const;
void set_limit_ping_fail( const int limit_ping_fail );
+ std::string get_status_notifier_cmd() const;
+ void set_status_notifier_cmd( const std::string &status_notifier_cmd );
+
std::vector<HostItem> get_hosts() const;
void set_hosts( const std::vector<HostItem> &hosts_list );
int LimitPingFail;
const int MinLimitPingFail;
const int MaxLimitPingFail;
+ std::string StatusNotifierCmd;
std::vector<HostItem> Hosts;
};
DefaultLimitPingFail( 50 ),
LimitPingFailCmdStr( "limit-ping-fail" ),
LimitPingFailCmdDesc( "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 ),
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() )
+ ( 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() )
;
}
// limit-hosts-down
+ int limit_host_down = 0;
if ( vm.count( LimitHostsDownCmdStr ) )
{
- int limit_host_down = vm[ LimitHostsDownCmdStr ].as<int> ();
+ limit_host_down = vm[ LimitHostsDownCmdStr ].as<int> ();
Config.set_limit_hosts_down( limit_host_down );
cout << LimitHostsDownCmdStr << "=" << limit_host_down << endl;
cout << LimitPingFailCmdStr << "=" << limit_ping_fail << endl;
}
+ // status-notifier-cmd
+ if ( vm.count( StatusNotifierCmdCmdStr ) )
+ {
+ string status_notifier_cmd = vm[ StatusNotifierCmdCmdStr ].as<string>();
+ Config.set_status_notifier_cmd( status_notifier_cmd );
+
+ cout << StatusNotifierCmdCmdStr << "=" << status_notifier_cmd << endl;
+ }
+
// [host] name
int hosts_names_total = 0;
if ( vm.count( HostNameCmdStr ) )
Config.set_hosts( hosts_list );
hosts_names_total = hosts_names.size();
+
+ BOOST_ASSERT( hosts_names_total >= limit_host_down );
}
// [host] interval
bool ConfigurationReader::process_configuration_file( variables_map &vm )
{
string config_file_name = "";
+ // parse the command line options to retrieve the config file name
if ( parse_configuration_options( vm ) )
config_file_name = Config.get_config_file_name();