changed value of link_up/down_interval from minutes to seconds
[pingcheck] / src / link / linkstatus.h
CommitLineData
91fcc471
TJ
1/*
2The software in this package is distributed under the GNU General
3Public License version 2 (with a special exception described below).
4
5A copy of GNU General Public License (GPL) is included in this distribution,
6in the file COPYING.GPL.
7
8As a special exception, if other files instantiate templates or use macros
9or inline functions from this file, or you compile this file and link it
10with other works to produce a work based on this file, this file
11does not by itself cause the resulting work to be covered
12by the GNU General Public License.
13
14However the source code for this file must still be made available
15in accordance with section (3) of the GNU General Public License.
16
17This exception does not invalidate any other reasons why a work based
18on this file might be covered by the GNU General Public License.
19*/
72e54d1c
GMF
20#ifndef LINK_STATUS_H
21#define LINK_STATUS_H
ddf41c89 22
1266407a 23#include <set>
ddf41c89
GMF
24#include <string>
25
f1bf3249 26#include <boost/asio.hpp>
b09ac07d 27#include <boost/shared_ptr.hpp>
f1bf3249 28
8f66f529 29#include "link/statusnotifiercommand.h"
b279ae09 30
ddf41c89 31//-----------------------------------------------------------------------------
72e54d1c 32// LinkStatus
ddf41c89
GMF
33//-----------------------------------------------------------------------------
34
c1fff16a 35/**
fb469ffa
GMF
36 * @brief This class analyzes and notifies the link status, through keeping
37 * track of the amount of hosts down.
c1fff16a
GMF
38 * Scope: one object for many hosts.
39 */
72e54d1c 40class LinkStatus
ddf41c89
GMF
41{
42public:
72e54d1c 43 LinkStatus(
a341119a 44 const int hosts_down_limit,
97837af8
CH
45 const int link_up_interval_in_sec,
46 const int link_down_interval_in_sec,
c1fff16a
GMF
47 const std::string &status_notifier_cmd
48 );
72e54d1c 49 ~LinkStatus();
ddf41c89 50
feb02c46
GMF
51 void notify_host_up( const std::string &host_address );
52 void notify_host_down( const std::string &host_address );
1266407a
GMF
53
54private:
010b8519
GMF
55 //
56 // Types
57 //
58
72e54d1c 59 enum Status
f1bf3249 60 {
72e54d1c
GMF
61 Status_Up,
62 Status_Down
f1bf3249
GMF
63 };
64
65 enum NotificationStatus
66 {
67 NotificationStatus_NotReported,
68 NotificationStatus_Reported
69 };
70
c5db9dfd
GMF
71#ifdef UNDER_TEST
72public:
c5db9dfd 73#endif
010b8519
GMF
74 //
75 // Methods
76 //
77
f5ffc5df 78 bool add_host_up( const std::string &host_address );
1266407a 79 void add_host_down( const std::string &host_address );
b279ae09 80
a341119a 81 bool exceeded_host_down_limit() const;
ddf41c89 82
fb469ffa
GMF
83 void notify_link_up();
84 void notify_link_down();
b279ae09 85
f1bf3249 86 bool is_link_up_enough_time() const;
1634f2a1 87 bool is_link_down_enough_time() const;
f1bf3249
GMF
88
89 bool can_report_link_status() const;
90 void set_link_status(
72e54d1c 91 const LinkStatus::Status new_link_status
f1bf3249
GMF
92 );
93
010b8519
GMF
94 //
95 // Attributes
96 //
97
72e54d1c 98 /// The maximum amount of hosts which can be down before sound the alarm
a341119a 99 const int HostsDownLimit;
72e54d1c 100 /// List of hosts down (obvious isn't it?)
1266407a 101 std::set<std::string> HostsDownList;
72e54d1c 102 /// Interval the link have to be stable in order to consider it is functional
97837af8 103 const int LinkUpIntervalInSec;
72e54d1c 104 /// Interval the link have to be down in order to consider it is non-functional
97837af8 105 const int LinkDownIntervalInSec;
72e54d1c
GMF
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
f1bf3249 111 boost::posix_time::ptime TimeLinkStatusChanged;
72e54d1c 112 /// Command used to notify the status of the link
709ded82 113 StatusNotifierCommandItem StatusNotifierCmd;
ddf41c89
GMF
114
115};
116
b09ac07d 117//-----------------------------------------------------------------------------
72e54d1c 118// LinkStatusItem
b09ac07d
GMF
119//-----------------------------------------------------------------------------
120
72e54d1c 121typedef boost::shared_ptr<LinkStatus> LinkStatusItem;
b09ac07d 122
72e54d1c 123#endif // LINK_STATUS_H