started parallel pings, not quite done yet since need to delay them
[pingcheck] / src / host / hoststatus.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*/
6c14bbee
GMF
20#ifndef HOST_STATUS_H
21#define HOST_STATUS_H
ddf41c89
GMF
22
23#include <string>
24
96c4e7a4 25#include "host/pingstatus.h"
72e54d1c 26#include "link/linkstatus.h"
ddf41c89
GMF
27
28//-----------------------------------------------------------------------------
6c14bbee 29// HostStatus
ddf41c89
GMF
30//-----------------------------------------------------------------------------
31
c5e4bfa1 32/**
c01a6023
GMF
33 * @brief This class analyze the host status (up or down) based on the pings
34 * responses (success or failure). And notifies its status.
c5e4bfa1
GMF
35 * Scope: one object per host.
36 */
6c14bbee 37class HostStatus
ddf41c89
GMF
38{
39public:
6c14bbee 40 HostStatus(
ddf41c89 41 const std::string &host_address,
cd4048df 42 const int ping_fail_limit_percentage,
91aa83f9 43 const int n_parallel_pings,
c6c54dfb 44 const LinkStatusItem link_analyzer
ddf41c89 45 );
6c14bbee 46 ~HostStatus();
ddf41c89
GMF
47
48 void set_resolved_ip_count( const int resolved_ip_count );
a341119a 49 bool exceeded_ping_failed_limit() const;
96c4e7a4
CH
50 void update_ping_statistics( const PingStatus &ping_success,
51 const long ping_duration_us );
ddf41c89
GMF
52
53private:
d8a91bd6
GMF
54 bool tried_all_resolved_ip() const;
55 void analyze_ping_statistics();
c1fff16a 56 void reset_ping_counters();
c5e4bfa1
GMF
57 void increase_ping_performed_count();
58 void increase_ping_failed_count();
6827496c 59 void analyze_ping_failed_count();
ddf41c89
GMF
60
61private:
d3e8a9f9 62 /// the DNS address of the host to analyze
c1fff16a 63 std::string HostAddress;
d3e8a9f9 64 /// the object responsible to analyze the link
c6c54dfb 65 const LinkStatusItem LinkAnalyzer;
d3e8a9f9 66 /// the maximum amount of pings that can fail without warning
cd4048df 67 int PingFailLimitPercentage;
d3e8a9f9 68 /// the amount of IPs that are aliases to the host DNS
ddf41c89 69 int ResolvedIpCount;
d3e8a9f9 70 /// the amount of pings sent until now
ddf41c89 71 int PingsPerformedCount;
d3e8a9f9 72 /// the amount of pings sent that failed until now
ddf41c89 73 int PingsFailedCount;
d3e8a9f9
GMF
74 /// boolean flag that indicate if the last set of failed pings exceed the
75 /// limit
a341119a 76 bool ExceededPingFailedLimit;
91aa83f9
CH
77 /// number of pingers that ping the same IP in parallel
78 int NParallelPingers;
ddf41c89
GMF
79
80};
81
6c14bbee 82#endif // HOST_STATUS_H