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_sec,
46 const int link_down_interval_in_sec,
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 );
55 std::string log_prefix() const;
67 enum NotificationStatus
69 NotificationStatus_NotReported,
70 NotificationStatus_Reported
80 bool add_host_up( const std::string &host_address );
81 void add_host_down( const std::string &host_address );
83 bool exceeded_host_down_limit() const;
85 void notify_link_up();
86 void notify_link_down();
88 bool is_link_up_enough_time() const;
89 bool is_link_down_enough_time() const;
91 bool can_report_link_status() const;
93 const LinkStatus::Status new_link_status
100 /// The maximum amount of hosts which can be down before sound the alarm
101 const int HostsDownLimit;
102 /// List of hosts down (obvious isn't it?)
103 std::set<std::string> HostsDownList;
104 /// Interval the link have to be stable in order to consider it is functional
105 const int LinkUpIntervalInSec;
106 /// Interval the link have to be down in order to consider it is non-functional
107 const int LinkDownIntervalInSec;
108 /// Keep track of the actual link status
109 LinkStatus::Status CurrentLinkStatus;
110 /// Indicates if the last link status change was notified
111 LinkStatus::NotificationStatus CurrentNotificationStatus;
112 /// When was the last time the status changed
113 boost::posix_time::ptime TimeLinkStatusChanged;
114 /// Command used to notify the status of the link
115 StatusNotifierCommandItem StatusNotifierCmd;
116 /// last reported status to prevent multiple calls of same status
117 LinkStatus::Status LastReportedStatus;
121 //-----------------------------------------------------------------------------
123 //-----------------------------------------------------------------------------
125 typedef boost::shared_ptr<LinkStatus> LinkStatusItem;
127 #endif // LINK_STATUS_H