2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
26 #include <boost/asio.hpp>
27 #include <boost/shared_ptr.hpp>
29 #include "link/statusnotifiercommand.h"
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
36 * @brief This class analyzes and notifies the link status, through keeping
37 * track of the amount of hosts down.
38 * Scope: one object for many hosts.
44 const int hosts_down_limit,
45 const int link_up_interval_in_min,
46 const int link_down_interval_in_min,
47 const std::string &status_notifier_cmd
51 void notify_host_up( const std::string &host_address );
52 void notify_host_down( const std::string &host_address );
65 enum NotificationStatus
67 NotificationStatus_NotReported,
68 NotificationStatus_Reported
78 bool add_host_up( const std::string &host_address );
79 void add_host_down( const std::string &host_address );
81 bool exceeded_host_down_limit() const;
83 void notify_link_up();
84 void notify_link_down();
86 bool is_link_up_enough_time() const;
87 bool is_link_down_enough_time() const;
89 bool can_report_link_status() const;
91 const LinkStatus::Status new_link_status
98 /// The maximum amount of hosts which can be down before sound the alarm
99 const int HostsDownLimit;
100 /// List of hosts down (obvious isn't it?)
101 std::set<std::string> HostsDownList;
102 /// Interval the link have to be stable in order to consider it is functional
103 const int LinkUpIntervalInMin;
104 /// Interval the link have to be down in order to consider it is non-functional
105 const int LinkDownIntervalInMin;
106 /// Keep track of the actual link status
107 LinkStatus::Status CurrentLinkStatus;
108 /// Indicates if the last link status change was notified
109 LinkStatus::NotificationStatus CurrentNotificationStatus;
110 /// When was the last time the status changed
111 boost::posix_time::ptime TimeLinkStatusChanged;
112 /// Command used to notify the status of the link
113 StatusNotifierCommandItem StatusNotifierCmd;
117 //-----------------------------------------------------------------------------
119 //-----------------------------------------------------------------------------
121 typedef boost::shared_ptr<LinkStatus> LinkStatusItem;
123 #endif // LINK_STATUS_H