removed the HostStatus::report_dns_resolution_failure (not used any more)
[pingcheck] / src / host / hoststatus.h
1 /*
2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
4
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
7
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.
13
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.
16
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.
19 */
20 #ifndef HOST_STATUS_H
21 #define HOST_STATUS_H
22
23 #include <string>
24
25 #include "link/linkstatus.h"
26
27 //-----------------------------------------------------------------------------
28 // HostStatus
29 //-----------------------------------------------------------------------------
30
31 /**
32  * @brief This class analyze the host status (up or down) based on the pings
33  * responses (success or failure). And notifies its status.
34  * Scope: one object per host.
35  */
36 class HostStatus
37 {
38 public:
39     HostStatus(
40             const std::string &host_address,
41             const int ping_fail_limit_percentage,
42             const LinkStatusItem link_analyzer
43     );
44     ~HostStatus();
45
46     void set_resolved_ip_count( const int resolved_ip_count );
47     bool exceeded_ping_failed_limit() const;
48     void update_ping_statistics( bool ping_success );
49
50 private:
51     bool tried_all_resolved_ip() const;
52     void analyze_ping_statistics();
53     void reset_ping_counters();
54     void increase_ping_performed_count();
55     void increase_ping_failed_count();
56     void analyze_ping_failed_count();
57
58 private:
59     /// the DNS address of the host to analyze
60     std::string HostAddress;
61     /// the object responsible to analyze the link
62     const LinkStatusItem LinkAnalyzer;
63     /// the maximum amount of pings that can fail without warning
64     int PingFailLimitPercentage;
65     /// the amount of IPs that are aliases to the host DNS
66     int ResolvedIpCount;
67     /// the amount of pings sent until now
68     int PingsPerformedCount;
69     /// the amount of pings sent that failed until now
70     int PingsFailedCount;
71     /// boolean flag that indicate if the last set of failed pings exceed the
72     /// limit
73     bool ExceededPingFailedLimit;
74
75 };
76
77 #endif // HOST_STATUS_H