Skip to main content

limon_core/models/monitor/
config.rs

1/// Configuration type for a monitor.
2#[derive(Debug)]
3pub enum Config {
4  /// Ping monitor configuration.
5  Ping(PingConfig),
6
7  /// HTTP monitor configuration.
8  Http(HttpConfig),
9}
10
11/// Configuration for a Ping monitor.
12#[derive(Debug, Default, serde::Deserialize)]
13pub struct PingConfig {
14  /// How often the monitor should perform a check, in seconds.
15  pub check_frequency: i64,
16
17  /// Number of consecutive successful checks required to confirm a state change.
18  pub confirmation_period: i64,
19
20  /// Number of consecutive failed checks required to consider the monitor recovered.
21  pub recovery_period: i64,
22
23  /// Maximum time, in seconds, to wait for a ping response before timing out.
24  pub timeout: i64,
25}
26
27/// Configuration for an `HTTP` monitor.
28#[derive(Debug, Default, serde::Deserialize)]
29pub struct HttpConfig {
30  /// How often the monitor should perform a check, in seconds.
31  pub check_frequency: i64,
32
33  /// Number of consecutive successful checks required to confirm a state change.
34  pub confirmation_period: i64,
35
36  /// Number of consecutive failed checks required to consider the monitor recovered.
37  pub recovery_period: i64,
38
39  /// Maximum time, in seconds, to wait for an `HTTP` response before timing out.
40  pub timeout: i32,
41
42  /// HTTP method to use (e.g., `GET`, `POST`).
43  pub method: String,
44
45  /// Protocol to use (`HTTP` or `HTTPS`).
46  pub protocol: String,
47
48  /// Optional port number. If `None`, defaults to 80 for `HTTP` and 443 for `HTTPS`.
49  pub port: Option<u16>,
50
51  /// Optional request path (e.g., "/health").
52  pub path: Option<String>,
53
54  /// Optional request body for methods like `POST` or `PUT`.
55  pub body: Option<String>,
56
57  /// Optional keyword to search for in the response body.
58  pub keyword: Option<String>,
59
60  /// Expected `HTTP` status code.
61  pub expected_status_code: i32,
62
63  /// Whether to follow `HTTP` redirects.
64  pub follow_redirects: bool,
65
66  /// Whether to keep cookies when following redirects.
67  pub keep_cookies_on_redirects: bool,
68
69  /// Optional `HTTP` headers to include in the request.
70  pub headers: Option<Vec<Header>>,
71}
72
73/// Represents a single `HTTP` header (name-value pair).
74#[derive(Debug, serde::Deserialize)]
75pub struct Header {
76  /// The name of the `HTTP` header (e.g., `"Content-Type"`).
77  pub name: String,
78
79  /// The value of the `HTTP` header (e.g., `"application/json"`).
80  pub value: String,
81}