32e9d1361bfa93690a254c7800741e359a3214aa
[pingcheck] / src / config / configuration.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 CONFIGURATION_H
21 #define CONFIGURATION_H
22
23 #include <stdint.h>
24
25 #include <string>
26 #include <vector>
27
28 #include <logfunc.hpp>
29
30 #include <boost/shared_ptr.hpp>
31 #include <boost/random/linear_congruential.hpp>
32
33 #include "config/host.h"
34 #include "host/loglevel.h"
35 #include "host/logoutput.h"
36
37 //-----------------------------------------------------------------------------
38 // Configuration
39 //-----------------------------------------------------------------------------
40
41 typedef boost::rand48 rand_gen_type;
42
43 /**
44  * @brief This class works like a POD (Plain Old Data) for configuration options.
45  */
46 class Configuration
47 {
48 public:
49     Configuration();
50     virtual ~Configuration();
51
52     bool get_daemon() const;
53     void set_daemon( bool daemon );
54
55     std::string get_config_file_name() const;
56     void set_config_file_name( const std::string &config_file_name );
57
58     I2n::Logger::LogLevel get_log_level() const;
59     void set_log_level( const I2n::Logger::LogLevel &log_level );
60
61     LogOutput get_log_output() const;
62     void set_log_output( const LogOutput &log_output );
63
64     std::string get_log_file() const;
65     void set_log_file( const std::string &log_file );
66
67     std::string get_nameserver() const;
68     void set_nameserver( const std::string &nameserver );
69
70     std::string get_source_network_interface() const;
71     void set_source_network_interface(
72             const std::string &source_network_interface
73     );
74
75     int get_hosts_down_limit() const;
76     void set_hosts_down_limit( const int hosts_down_limit );
77
78     int get_ping_fail_limit() const;
79     void set_ping_fail_limit( const int ping_fail_limit );
80
81     std::string get_status_notifier_cmd() const;
82     void set_status_notifier_cmd( const std::string &status_notifier_cmd );
83
84     int get_link_up_interval_in_min() const;
85     void set_link_up_interval_in_min( const int link_up_interval_in_min );
86
87     int get_link_down_interval_in_min() const;
88     void set_link_down_interval_in_min( const int link_down_interval_in_min );
89
90     int get_ping_reply_timeout() const;
91     void set_ping_reply_timeout( const int ping_reply_timeout );
92
93     int get_max_address_resolution_attempts() const;
94     void set_max_address_resolution_attempts(
95             const int max_address_resolution_attempts );
96
97     int get_resolved_ip_ttl_threshold() const;
98     void set_resolved_ip_ttl_threshold(
99             const int resolved_ip_ttl_threshold );
100
101     int get_min_time_between_resolves() const;
102     void set_min_time_between_resolves(
103             const int min_time_between_resolves );
104
105     std::string get_dns_cache_file() const;
106     void set_dns_cache_file(const std::string &dns_cache_file);
107
108     float get_ratio_random_hosts() const;
109     void set_ratio_random_hosts( const float ratio );
110
111     HostList get_hosts() const;
112     void set_hosts( const HostList &hosts_list );
113
114     int get_random_number(const int lowest, const int highest);
115
116     void set_print_version( const bool do_print );
117     bool get_print_version();
118
119     bool randomize_hosts();
120
121 private:
122     bool Daemon;
123     I2n::Logger::LogLevel LoggingLevel;
124     LogOutput LoggingOutput;
125     std::string LogFileName;
126     std::string ConfigFileName;
127     std::string SourceNetworkInterface;
128     std::string NameServer;
129     int HostsDownLimit;
130     int MinHostsDownLimit;
131     int MaxHostsDownLimit;
132     int PingFailLimit;
133     int MinPingFailLimit;
134     int MaxPingFailLimit;
135     std::string StatusNotifierCmd;
136     int LinkUpIntervalInMin;
137     int LinkDownIntervalInMin;
138     int MinStableLinkIntervalInMin;
139     int MaxStableLinkIntervalInMin;
140     int PingReplyTimeout;
141     int MaxAddressResolutionAttempts;
142     int ResolvedIpTtlThreshold;
143     int MinTimeBetweenResolves;
144     std::string DnsCacheFile;
145     HostList Hosts;
146     float RatioRandomHosts;
147     bool PrintVersion;
148     rand_gen_type RandomNumberGenerator;
149 };
150
151 //-----------------------------------------------------------------------------
152 // ConfigurationItem
153 //-----------------------------------------------------------------------------
154
155 typedef boost::shared_ptr<Configuration> ConfigurationItem;
156
157 #endif // CONFIGURATION_H