{
}
+std::string LinkStatus::log_prefix() const
+{
+ stringstream temp;
+ temp << "Status (" << HostsDownList.size() << " down, "
+ << "limit=" << HostsDownLimit << ", ";
+ if ( can_report_link_status() )
+ {
+ ptime now = microsec_clock::universal_time();
+ long seconds_missing;
+ if ( CurrentLinkStatus == Status_Down )
+ {
+ seconds_missing = LinkDownIntervalInSec
+ - (now - TimeLinkStatusChanged).total_seconds();
+ temp << "notify down ";
+ }
+ else // (assume CurrentLinkStatus == Status_Up)
+ {
+ seconds_missing = LinkUpIntervalInSec
+ - (now - TimeLinkStatusChanged).total_seconds();
+ temp << "notify up ";
+ }
+ if (seconds_missing < 0)
+ temp << "now";
+ else
+ temp << "in " << seconds_missing << "s";
+ }
+ else
+ temp << "no notify";
+ temp << "): ";
+ return temp.str();
+}
+
/**
* @brief Notify the system that a given host is up. The object takes an
* appropriated action to deal with that.
bool has_changed = add_host_up( host_address );
- if (has_changed)
- GlobalLogger.notice() << "Status (" << HostsDownList.size()
- << " down, limit=" << HostsDownLimit << "): now up again is "
- << DnsMaster::get_cname_chain_str(host_address) << endl;
- else // less important so log only at info level
- GlobalLogger.info() << "Status (" << HostsDownList.size()
- << " down, limit=" << HostsDownLimit << "): still up is "
- << DnsMaster::get_cname_chain_str(host_address) << endl;
-
if ( !exceeded_host_down_limit() )
{
notify_link_up();
}
+ if (has_changed)
+ GlobalLogger.notice() << log_prefix() << "now up again is "
+ << DnsMaster::get_cname_chain_str(host_address) << endl;
+ else // less important so log only at info level
+ GlobalLogger.info() << log_prefix() << "still up is "
+ << DnsMaster::get_cname_chain_str(host_address) << endl;
+
// removed from the list?
BOOST_ASSERT( HostsDownList.count( host_address ) == 0 );
} //lint !e1788
add_host_down( host_address );
- // report this always at notice level
- GlobalLogger.notice() << "Status (" << HostsDownList.size()
- << " down, limit=" << HostsDownLimit << "): down is "
- << DnsMaster::get_cname_chain_str(host_address) << endl;
-
if ( exceeded_host_down_limit() )
{
notify_link_down();
}
+ // report this always at notice level
+ GlobalLogger.notice() << log_prefix() << "down is "
+ << DnsMaster::get_cname_chain_str(host_address) << endl;
+
// inserted in the list?
BOOST_ASSERT( HostsDownList.count( host_address ) == 1 );
} //lint !e1788
"up"
); //lint !e534
- GlobalLogger.notice() << "Status (" << HostsDownList.size()
- << " down, limit=" << HostsDownLimit << "): report link up" << endl;
+ GlobalLogger.notice() << log_prefix() << "report link up" << endl;
bool executed = StatusNotifierCmd->execute();
if ( executed )
{
CurrentNotificationStatus = NotificationStatus_Reported;
+ LastReportedStatus = CurrentLinkStatus;
}
}
}
BOOST_ASSERT( CurrentLinkStatus == Status_Down );
BOOST_ASSERT( CurrentNotificationStatus == NotificationStatus_NotReported );
- GlobalLogger.notice() << "Status (" << HostsDownList.size()
- << " down, limit=" << HostsDownLimit << "): report link down"
- << endl;
+ GlobalLogger.notice() << log_prefix() << "report link down" << endl;
StatusNotifierCmd->set_token_value(
StatusNotifierCommand::StatusToken,
"down"
if ( executed )
{
CurrentNotificationStatus = NotificationStatus_Reported;
+ LastReportedStatus = CurrentLinkStatus;
}
}
}
return false;
}
+/**
+ * @brief determine if we should report the current link status
+ *
+ * checks if the current status has already been reported; does not take
+ * LinkUp/DownInterval into account
+ *
+ * @returns true if status should be reported
+ */
bool LinkStatus::can_report_link_status() const
{
- return ( CurrentNotificationStatus == NotificationStatus_NotReported );
+ return ( CurrentNotificationStatus == NotificationStatus_NotReported
+ && LastReportedStatus != CurrentLinkStatus );
}
void LinkStatus::set_link_status(