icmp/icmppinger.cpp
ip/ipv4header.cpp
ip/ipv6header.cpp
- link/linkstatusanalyzer.cpp
+ link/linkstatus.cpp
link/statusnotifiercommand.cpp
tcp/tcpheader.cpp
tcp/tcppinger.cpp
HostStatus::HostStatus(
const string &host_address,
const int ping_fail_limit_percentage,
- const shared_ptr<LinkStatusAnalyzer> link_analyzer
+ const shared_ptr<LinkStatus> link_analyzer
) :
HostAddress( host_address ),
LinkAnalyzer( link_analyzer ),
#include <boost/shared_ptr.hpp>
-#include "link/linkstatusanalyzer.h"
+#include "link/linkstatus.h"
//-----------------------------------------------------------------------------
// HostStatus
HostStatus(
const std::string &host_address,
const int ping_fail_limit_percentage,
- const boost::shared_ptr<LinkStatusAnalyzer> link_analyzer
+ const boost::shared_ptr<LinkStatus> link_analyzer
);
~HostStatus();
/// the DNS address of the host to analyze
std::string HostAddress;
/// the object responsible to analyze the link
- const boost::shared_ptr<LinkStatusAnalyzer> LinkAnalyzer;
+ const boost::shared_ptr<LinkStatus> LinkAnalyzer;
/// the maximum amount of pings that can fail without warning
int PingFailLimitPercentage;
/// the amount of IPs that are aliases to the host DNS
#include "dns/dnsresolver.h"
#include "icmp/icmppinger.h"
-#include "link/linkstatusanalyzer.h"
+#include "link/linkstatus.h"
using namespace std;
using boost::asio::io_service;
const long ping_interval_in_sec,
const int ping_fail_percentage_limit,
const string &nameserver,
- shared_ptr<LinkStatusAnalyzer> link_analyzer
+ shared_ptr<LinkStatus> link_analyzer
) :
IoService(),
#include <boost/thread.hpp>
#include "dns/dnsresolver.h"
-#include "link/linkstatusanalyzer.h"
+#include "link/linkstatus.h"
#include "host/hoststatus.h"
#include "host/pinger.h"
#include "host/pingerfactory.h"
const long ping_interval_in_sec,
const int ping_fail_percentage_limit,
const std::string &nameserver,
- boost::shared_ptr<LinkStatusAnalyzer> link_analyzer
+ boost::shared_ptr<LinkStatus> link_analyzer
);
~PingScheduler();
This exception does not invalidate any other reasons why a work based
on this file might be covered by the GNU General Public License.
*/
-#include "link/linkstatusanalyzer.h"
+#include "link/linkstatus.h"
#include <iostream>
typedef lock_guard<mutex> mutex_lock_guard;
//-----------------------------------------------------------------------------
-// LinkStatusAnalyzer
+// LinkStatus
//-----------------------------------------------------------------------------
/**
* @brief Creates a link status object.
*
- * @param hosts_down_limit the maximum amount of different hosts that can be
+ * @param hosts_down_limit The maximum amount of different hosts that can be
* down before the system take any action.
- * @param link_up_interval_in_min the amount of time required to the link to
+ * @param link_up_interval_in_min The amount of time required to the link to
* stay up before notify.
- * @param link_down_interval_in_min the amount of time required to the link to
+ * @param link_down_interval_in_min The amount of time required to the link to
* stay down before notify.
- * @param status_notifier_cmd the command used to notify about link status
+ * @param status_notifier_cmd The command used to notify about link status
* changes.
*/
-LinkStatusAnalyzer::LinkStatusAnalyzer(
+LinkStatus::LinkStatus(
const int hosts_down_limit,
const int link_up_interval_in_min,
const int link_down_interval_in_min,
HostsDownList(),
LinkUpIntervalInMin( link_up_interval_in_min ),
LinkDownIntervalInMin( link_down_interval_in_min ),
- CurrentLinkStatus( LinkStatus_Down ),
+ CurrentLinkStatus( Status_Down ),
CurrentNotificationStatus( NotificationStatus_NotReported ),
TimeLinkStatusChanged( microsec_clock::universal_time() ),
StatusNotifierCmd( status_notifier_cmd ),
BOOST_ASSERT( 0 <= link_down_interval_in_min );
}
-LinkStatusAnalyzer::~LinkStatusAnalyzer()
+LinkStatus::~LinkStatus()
{
}
*
* @param host_address the DNS/IP address of the host that is up.
*/
-void LinkStatusAnalyzer::notify_host_up( const string &host_address )
+void LinkStatus::notify_host_up( const string &host_address )
{
BOOST_ASSERT( !host_address.empty() );
* Note: this object does not resolves IPs, thus you have to send the same host
* address in order to the object to consider the same host.
*
- * @param host_address the DNS/IP address of the host that is down.
+ * @param host_address The DNS/IP address of the host that is down.
*/
-void LinkStatusAnalyzer::notify_host_down( const string &host_address )
+void LinkStatus::notify_host_down( const string &host_address )
{
BOOST_ASSERT( !host_address.empty() );
BOOST_ASSERT( HostsDownList.count( host_address ) == 1 );
}
-void LinkStatusAnalyzer::add_host_up( const string &host_address )
+void LinkStatus::add_host_up( const string &host_address )
{
if ( HostsDownList.count( host_address ) > 0 )
{
}
}
-void LinkStatusAnalyzer::add_host_down( const string &host_address )
+void LinkStatus::add_host_down( const string &host_address )
{
(void) HostsDownList.insert( host_address );
}
-bool LinkStatusAnalyzer::exceeded_host_down_limit() const
+bool LinkStatus::exceeded_host_down_limit() const
{
int host_down_count = static_cast<int>( HostsDownList.size() );
return ( host_down_count > HostsDownLimit );
}
-void LinkStatusAnalyzer::notify_link_up()
+void LinkStatus::notify_link_up()
{
- set_link_status( LinkStatus_Up );
+ set_link_status( Status_Up );
// report the link status only if: it is up longer than a configured amount
// of time, and if we haven't reported the new status yet
if ( is_link_up_enough_time() && can_report_link_status() )
{
- BOOST_ASSERT( CurrentLinkStatus == LinkStatus_Up );
+ BOOST_ASSERT( CurrentLinkStatus == Status_Up );
BOOST_ASSERT( CurrentNotificationStatus == NotificationStatus_NotReported );
StatusNotifierCmd.set_token_value(
}
}
-void LinkStatusAnalyzer::notify_link_down()
+void LinkStatus::notify_link_down()
{
- set_link_status( LinkStatus_Down );
+ set_link_status( Status_Down );
// report the link status only if: it is down longer than a configured amount
// of time, and if we haven't reported the new status yet
if ( is_link_down_enough_time() && can_report_link_status() )
{
- BOOST_ASSERT( CurrentLinkStatus == LinkStatus_Down );
+ BOOST_ASSERT( CurrentLinkStatus == Status_Down );
BOOST_ASSERT( CurrentNotificationStatus == NotificationStatus_NotReported );
StatusNotifierCmd.set_token_value(
}
}
-bool LinkStatusAnalyzer::is_link_up_enough_time() const
+bool LinkStatus::is_link_up_enough_time() const
{
- if ( CurrentLinkStatus == LinkStatus_Up )
+ if ( CurrentLinkStatus == Status_Up )
{
ptime now = microsec_clock::universal_time();
long amount_time_link_is_up = (now - TimeLinkStatusChanged).total_seconds();
return false;
}
-bool LinkStatusAnalyzer::is_link_down_enough_time() const
+bool LinkStatus::is_link_down_enough_time() const
{
- if ( CurrentLinkStatus == LinkStatus_Down )
+ if ( CurrentLinkStatus == Status_Down )
{
ptime now = microsec_clock::universal_time();
long amount_time_link_is_down = (now - TimeLinkStatusChanged).total_seconds();
return false;
}
-bool LinkStatusAnalyzer::can_report_link_status() const
+bool LinkStatus::can_report_link_status() const
{
return ( CurrentNotificationStatus == NotificationStatus_NotReported );
}
-void LinkStatusAnalyzer::set_link_status(
- const LinkStatusAnalyzer::LinkStatus new_link_status
+void LinkStatus::set_link_status(
+ const LinkStatus::Status new_link_status
)
{
// only reset the control flags if the link status has changed
This exception does not invalidate any other reasons why a work based
on this file might be covered by the GNU General Public License.
*/
-#ifndef LINK_STATUS_ANALYZER_H
-#define LINK_STATUS_ANALYZER_H
+#ifndef LINK_STATUS_H
+#define LINK_STATUS_H
#include <set>
#include <string>
#include "link/statusnotifiercommand.h"
//-----------------------------------------------------------------------------
-// LinkStatusAnalyzer
+// LinkStatus
//-----------------------------------------------------------------------------
/**
* track of the amount of hosts down.
* Scope: one object for many hosts.
*/
-class LinkStatusAnalyzer
+class LinkStatus
{
public:
- LinkStatusAnalyzer(
+ LinkStatus(
const int hosts_down_limit,
const int link_up_interval_in_min,
const int link_down_interval_in_min,
const std::string &status_notifier_cmd
);
- ~LinkStatusAnalyzer();
+ ~LinkStatus();
void notify_host_up( const std::string &host_address );
void notify_host_down( const std::string &host_address );
private:
- enum LinkStatus
+ enum Status
{
- LinkStatus_Up,
- LinkStatus_Down
+ Status_Up,
+ Status_Down
};
enum NotificationStatus
bool can_report_link_status() const;
void set_link_status(
- const LinkStatusAnalyzer::LinkStatus new_link_status
+ const LinkStatus::Status new_link_status
);
private:
- /// the maximum amount of hosts which can be down before sound the alarm
+ /// The maximum amount of hosts which can be down before sound the alarm
const int HostsDownLimit;
- /// list of hosts down (obvious isn't it?)
+ /// List of hosts down (obvious isn't it?)
std::set<std::string> HostsDownList;
- /// interval the link have to be stable in order to consider it is functional
+ /// Interval the link have to be stable in order to consider it is functional
const int LinkUpIntervalInMin;
- /// interval the link have to be down in order to consider it is non-functional
+ /// Interval the link have to be down in order to consider it is non-functional
const int LinkDownIntervalInMin;
- /// keep track of the actual link status
- LinkStatusAnalyzer::LinkStatus CurrentLinkStatus;
- /// indicates if the last link status change was notified
- LinkStatusAnalyzer::NotificationStatus CurrentNotificationStatus;
- /// when was the last time the status changed
+ /// Keep track of the actual link status
+ LinkStatus::Status CurrentLinkStatus;
+ /// Indicates if the last link status change was notified
+ LinkStatus::NotificationStatus CurrentNotificationStatus;
+ /// When was the last time the status changed
boost::posix_time::ptime TimeLinkStatusChanged;
- /// command used to notify the status of the link
+ /// Command used to notify the status of the link
StatusNotifierCommand StatusNotifierCmd;
- /// mutual exclusion variable to avoid data races
+ /// Mutual exclusion variable to avoid data races
boost::mutex Mutex;
};
//-----------------------------------------------------------------------------
-// LinkStatusAnalyzerItem
+// LinkStatusItem
//-----------------------------------------------------------------------------
-typedef boost::shared_ptr<LinkStatusAnalyzer> LinkStatusAnalyzerItem;
+typedef boost::shared_ptr<LinkStatus> LinkStatusItem;
-#endif // LINK_STATUS_ANALYZER_H
+#endif // LINK_STATUS_H
#include "config/configurationreader.h"
#include "config/host.h"
-#include "link/linkstatusanalyzer.h"
+#include "link/linkstatus.h"
#include "host/pingerfactory.h"
#include "host/pingprotocol.h"
#include "host/pingscheduler.h"
return configuration;
}
-LinkStatusAnalyzerItem get_status_notifier(
+LinkStatusItem get_status_notifier(
const ConfigurationItem &configuration
)
{
int link_up_interval_in_min = configuration->get_link_up_interval_in_min();
int link_down_interval_in_min = configuration->get_link_down_interval_in_min();
string status_notifier_cmd = configuration->get_status_notifier_cmd();
- LinkStatusAnalyzerItem link_analyzer(
- new LinkStatusAnalyzer(
+ LinkStatusItem link_analyzer(
+ new LinkStatus(
hosts_down_limit,
link_up_interval_in_min,
link_down_interval_in_min,
void init_pingers(
const ConfigurationItem &configuration,
- const LinkStatusAnalyzerItem &status_notifier,
+ const LinkStatusItem &status_notifier,
PingSchedulerList *scheduler_list
)
{
I2n::Daemon::daemonize();
}
- LinkStatusAnalyzerItem status_notifier = get_status_notifier( configuration );
+ LinkStatusItem status_notifier = get_status_notifier( configuration );
PingSchedulerList scheduler_list;
init_pingers( configuration, status_notifier, &scheduler_list );
on this file might be covered by the GNU General Public License.
*/
-#ifndef LINK_STATUS_ANALYZER_H
-#define LINK_STATUS_ANALYZER_H
+#ifndef LINK_STATUS_H
+#define LINK_STATUS_H
#include <string>
#include <boost/shared_ptr.hpp>
//-----------------------------------------------------------------------------
-// LinkStatusAnalyzer
+// LinkStatus
//-----------------------------------------------------------------------------
/**
* @brief This is a fake link status class.
* Scope: one object for many hosts.
*/
-class LinkStatusAnalyzer
+class LinkStatus
{
public:
- LinkStatusAnalyzer();
- ~LinkStatusAnalyzer();
+ LinkStatus();
+ ~LinkStatus();
void notify_host_up( const std::string &host_address );
void notify_host_down( const std::string &host_address );
//-----------------------------------------------------------------------------
-LinkStatusAnalyzer::LinkStatusAnalyzer()
+LinkStatus::LinkStatus()
{
}
-LinkStatusAnalyzer::~LinkStatusAnalyzer()
+LinkStatus::~LinkStatus()
{
}
-void LinkStatusAnalyzer::notify_host_up( const std::string &host_address )
+void LinkStatus::notify_host_up( const std::string &host_address )
{
}
-void LinkStatusAnalyzer::notify_host_down( const std::string &host_address )
+void LinkStatus::notify_host_down( const std::string &host_address )
{
}
//-----------------------------------------------------------------------------
-// LinkStatusAnalyzerItem
+// LinkStatusItem
//-----------------------------------------------------------------------------
-typedef boost::shared_ptr<LinkStatusAnalyzer> LinkStatusAnalyzerItem;
+typedef boost::shared_ptr<LinkStatus> LinkStatusItem;
-#endif // LINK_STATUS_ANALYZER_H
+#endif // LINK_STATUS_H
#include <boost/asio.hpp>
#include <boost/test/unit_test.hpp>
-#include "mock_linkstatusanalyzer.h"
+#include "mock_linkstatus.h"
#include "host/hoststatus.h"
int ping_fail_percentage_limit = 10;
int resolved_ip_count = 10;
- LinkStatusAnalyzerItem link_status( new LinkStatusAnalyzer );
+ LinkStatusItem link_status( new LinkStatus );
HostStatus host_status( "localhost", ping_fail_percentage_limit, link_status );
host_status.set_resolved_ip_count( resolved_ip_count );
int ping_fail_percentage_limit = 50;
int resolved_ip_count = 10;
- LinkStatusAnalyzerItem link_status( new LinkStatusAnalyzer );
+ LinkStatusItem link_status( new LinkStatus );
HostStatus host_status( "localhost", ping_fail_percentage_limit, link_status );
host_status.set_resolved_ip_count( resolved_ip_count );
int ping_fail_percentage_limit = 80;
int resolved_ip_count = 10;
- LinkStatusAnalyzerItem link_status( new LinkStatusAnalyzer );
+ LinkStatusItem link_status( new LinkStatus );
HostStatus host_status( "localhost", ping_fail_percentage_limit, link_status );
host_status.set_resolved_ip_count( resolved_ip_count );