log_output_string_map[ "SYSLOG" ] = LogOutput_SYSLOG;
log_output_string_map[ "TERMINAL" ] = LogOutput_TERMINAL;
log_output_string_map[ "CONSOLE" ] = LogOutput_TERMINAL;
+ log_output_string_map[ "STDERR" ] = LogOutput_TERMINAL;
log_output_string_map[ "FILE" ] = LogOutput_FILE;
LogOutput protocol = log_output_string_map[ log_output_uppercase_string ];
enum LogOutput
{
LogOutput_First = 0,
- LogOutput_SYSLOG = LogOutput_First,
+ LogOutput_UNDEFINED = LogOutput_First,
+ LogOutput_SYSLOG,
LogOutput_TERMINAL,
LogOutput_FILE,
LogOutput_Last = LogOutput_FILE
void init_logger();
void set_log_output(const ConfigurationItem &);
DelayMap calc_pinger_delays(const HostList &hosts);
-void init_pingers(const IoServiceItem, const ConfigurationItem&,
+bool init_pingers(const IoServiceItem, const ConfigurationItem&,
const LinkStatusItem&, PingSchedulerList*);
void start_pingers(const PingSchedulerList&);
void stop_pingers(const PingSchedulerList&);
string log_file_name = configuration->get_log_file();
switch (log_output)
{
+ case LogOutput_UNDEFINED:
+ GlobalLogger.warning() << "Unknown output target -- use syslog";
case LogOutput_SYSLOG:
GlobalLogger.info() << "Setting log output target to syslog" << endl;
I2n::Logger::enable_syslog(true);
return delay_shifts;
}
-void init_pingers(
+bool init_pingers(
const IoServiceItem io_service,
const ConfigurationItem &configuration,
const LinkStatusItem &status_notifier,
delays[interval_and_delay.first] = 0.0f;
HostList hosts = configuration->get_hosts();
+
+ if (hosts.empty())
+ return false;
+
BOOST_FOREACH( const HostItem &host, hosts )
{
string destination_address = host->get_address();
);
scheduler_list->push_back( scheduler );
}
+
+ return true;
}
void start_pingers(
if ( configuration->get_print_version() ) // do this even if parsing of config failed
{
- GlobalLogger.debug() << "Printing version info (" << VERSION_STRING << ") and exit" << endl;
- cout << PROJECT_NAME << " version " << VERSION_STRING << "."
- << VERSION_REVISION_STRING << " build " << __DATE__ << endl;
+ GlobalLogger.debug() << "Printing version info ("
+ << VERSION_STRING << "." << VERSION_REVISION_STRING
+ << " build " << __DATE__
+ << ") and exit" << endl;
+ cout << PROJECT_NAME << " version "
+ << VERSION_STRING << "." << VERSION_REVISION_STRING
+ << " build " << __DATE__
+ << endl;
return 0;
}
GlobalLogger.info() << "Set LogLevel to " << I2n::Logger::get_log_level_string() << endl;
set_log_output( configuration );
- GlobalLogger.notice() << "started";
+ GlobalLogger.notice() << "started pingcheck version "
+ << VERSION_STRING << "." << VERSION_REVISION_STRING
+ << " build " << __DATE__
+ << endl;
bool daemon_mode = configuration->get_daemon();
if ( daemon_mode )
boost::asio::ip::address name_server_ip =
boost::asio::ip::address::from_string(
configuration->get_nameserver() );
-
- int max_recursion_count = 10;
+ int max_recursion_count = 10; // could make a config var some time
DnsMaster::create_master(
io_service,
name_server_ip,
max_recursion_count,
configuration->get_dns_cache_file() );
- init_pingers( io_service, configuration, status_notifier, &scheduler_list );
+ if ( !init_pingers(io_service, configuration, status_notifier,
+ &scheduler_list) )
+ {
+ GlobalLogger.error() << "Could not initialize pingers or no hosts "
+ << "given to ping --> exit";
+ return 2;
+ }
install_signal_handlers( io_service, log_level );
catch ( const std::exception &ex )
{
GlobalLogger.error() << "Uncaught exception. " << ex.what() << endl;
- ret_code = 2;
+ ret_code = 3;
++n_exceptions;
}
catch (...) {
GlobalLogger.error() << "Caught unknown exception!" << endl;
- ret_code = 3;
+ ret_code = 4;
++n_exceptions;
}
catch ( const std::exception &ex )
{
GlobalLogger.error() << "Uncaught exception while cleaning up: " << ex.what() << endl;
- ret_code += 4;
+ ret_code += 16;
}
catch (...) {
GlobalLogger.error() << "Caught unknown exception while cleaning up!" << endl;
- ret_code += 8;
+ ret_code += 32;
}
GlobalLogger.notice() << "Pingcheck done " << endl;
add_test(test_dns test_dns)
# add data subdir for test data
-add_subdirectory(data)
+# not necessary since is already added by test_icmppacket
+# and if both add it, we get warnings from cmake
+#add_subdirectory(data)
SUBSYS_VPN = 'vpn'
SUBSYS_WEBPROXY = 'webproxy'
SUBSYS_PINGCHECK = 'pingcheck'
+SUBSYS_IPONLINE = 'iponline'
ALL_SUBSYS = (SUBSYS_DNS, SUBSYS_DYNDNS, SUBSYS_MAIL, SUBSYS_NTP, \
- SUBSYS_SOCKS, SUBSYS_VPN, SUBSYS_WEBPROXY, SUBSYS_PINGCHECK)
+ SUBSYS_SOCKS, SUBSYS_VPN, SUBSYS_WEBPROXY, SUBSYS_PINGCHECK, \
+ SUBSYS_IPONLINE)
class ConndState:
""" representation of connd's status as returned by tell-connd --status """
def _handle_new_ip(self, message):
- # "Have IP 172.16.1.1 [61963s] for aqua.m.i2n"
+ # "Have IP 11.22.33.44 [61963s] for host.domain.com"
matches = regexp('Have IP (\d+\.\d+\.\d+\.\d+) \[\d+s\] for (.+)', message)
if matches:
ip,host_name = matches.groups()
BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "syslog" )), static_cast<int>(LogOutput_SYSLOG) );
BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "terminal" )), static_cast<int>(LogOutput_TERMINAL) );
BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "console" )), static_cast<int>(LogOutput_TERMINAL) );
+ BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "stderr" )), static_cast<int>(LogOutput_TERMINAL) );
BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "file" )), static_cast<int>(LogOutput_FILE) );
}
BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "SYSLOG" )), static_cast<int>(LogOutput_SYSLOG) );
BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "TERMINAL" )), static_cast<int>(LogOutput_TERMINAL) );
BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "CONSOLE" )), static_cast<int>(LogOutput_TERMINAL) );
+ BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "STDERR" )), static_cast<int>(LogOutput_TERMINAL) );
BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "FILE" )), static_cast<int>(LogOutput_FILE) );
}
BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "SysLoG" )), static_cast<int>(LogOutput_SYSLOG) );
BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "teRmINAl" )), static_cast<int>(LogOutput_TERMINAL) );
BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "ConSOlE" )), static_cast<int>(LogOutput_TERMINAL) );
+ BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "StdErr" )), static_cast<int>(LogOutput_TERMINAL) );
BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "File" )), static_cast<int>(LogOutput_FILE) );
}
BOOST_AUTO_TEST_CASE( misspelled )
{
- BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "when" )), static_cast<int>(LogOutput_SYSLOG) );
- BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "the" )), static_cast<int>(LogOutput_SYSLOG) );
- BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "word" )), static_cast<int>(LogOutput_SYSLOG) );
- BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "is" )), static_cast<int>(LogOutput_SYSLOG) );
- BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "wrong" )), static_cast<int>(LogOutput_SYSLOG) );
- BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "stick" )), static_cast<int>(LogOutput_SYSLOG) );
- BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "to" )), static_cast<int>(LogOutput_SYSLOG) );
- BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "SYSLOG" )), static_cast<int>(LogOutput_SYSLOG) );
+ BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "when" )), static_cast<int>(LogOutput_UNDEFINED) );
+ BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "the" )), static_cast<int>(LogOutput_UNDEFINED) );
+ BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "word" )), static_cast<int>(LogOutput_UNDEFINED) );
+ BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "is" )), static_cast<int>(LogOutput_UNDEFINED) );
+ BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "wrong" )), static_cast<int>(LogOutput_UNDEFINED) );
+ BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "stick" )), static_cast<int>(LogOutput_UNDEFINED) );
+ BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "to" )), static_cast<int>(LogOutput_UNDEFINED) );
+ BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "UNDEFINED" )), static_cast<int>(LogOutput_UNDEFINED) );
}
BOOST_AUTO_TEST_SUITE_END()