Kea 3.3.3
alarm.h
Go to the documentation of this file.
1// Copyright (C) 2024-2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef _ALARM_H
8#define _ALARM_H
9
10#include <dhcp/pkt.h>
11#include <dhcpsrv/subnet_id.h>
13
14#include <cstdint>
15
16#include <boost/date_time/posix_time/posix_time.hpp>
17
18namespace isc {
19namespace perfmon {
20
22class Alarm : public DurationKey {
23public:
25 enum State : uint16_t {
26 CLEAR, // Enabled and not currently triggered
27 TRIGGERED, // High water has been exceeded
28 DISABLED // Disabled
29 };
30
42 Alarm(uint16_t family, uint8_t query_type, uint8_t response_type,
43 const std::string& start_event_label, const std::string& stop_event_label,
44 dhcp::SubnetID subnet_id,
45 const Duration& low_water, const Duration& high_water, bool enabled = true);
46
53 Alarm(const DurationKey& key, const Duration& low_water, const Duration& high_water, bool enabled = true);
54
56 virtual ~Alarm() = default;
57
62 return (low_water_);
63 }
64
70 void setLowWater(const Duration& low_water);
71
76 return (high_water_);
77 }
78
84 void setHighWater(const Duration& high_water);
85
88 return (state_);
89 }
90
98 void setState(State state);
99
104 return (stos_time_);
105 }
106
111 return (last_high_water_report_);
112 }
113
121 last_high_water_report_ = timestamp;
122 }
123
125 void clear();
126
128 void disable();
129
150 bool checkSample(const Duration& sample, const Duration& report_interval);
151
152private:
154 Duration low_water_;
155
157 Duration high_water_;
158
160 State state_;
161
163 Timestamp stos_time_;
164
166 Timestamp last_high_water_report_;
167};
168
170typedef boost::shared_ptr<Alarm> AlarmPtr;
171
172} // end of namespace isc::perfmon
173} // end of namespace isc
174
175#endif
static boost::posix_time::ptime now()
Fetch the current UTC system time, microsecond precision.
Definition pkt.h:118
State
Defines Alarm states.
Definition alarm.h:25
void setHighWater(const Duration &high_water)
Set the high water threshold.
Definition alarm.cc:69
Timestamp getLastHighWaterReport()
Get the timestamp of the last high water report.
Definition alarm.h:110
void clear()
Sets the alarm back to the CLEAR state.
Definition alarm.cc:86
void setState(State state)
Sets the alarm state.
Definition alarm.cc:79
virtual ~Alarm()=default
Destructor.
void setLastHighWaterReport(const Timestamp &timestamp=dhcp::PktEvent::now())
Set the timestamp of the last high water report.
Definition alarm.h:120
bool checkSample(const Duration &sample, const Duration &report_interval)
Checks a duration against the high and low water thresholds and calls the appropriate event handler.
Definition alarm.cc:96
void disable()
Disables the alarm by setting the state to DISABLED.
Definition alarm.cc:91
Duration getHighWater() const
Get the high water threshold.
Definition alarm.h:75
void setLowWater(const Duration &low_water)
Set the low water threshold.
Definition alarm.cc:59
Alarm(uint16_t family, uint8_t query_type, uint8_t response_type, const std::string &start_event_label, const std::string &stop_event_label, dhcp::SubnetID subnet_id, const Duration &low_water, const Duration &high_water, bool enabled=true)
Constructor.
Definition alarm.cc:21
State getState()
Get the alarm's state.
Definition alarm.h:87
Timestamp getStosTime()
Get the time the current state began.
Definition alarm.h:103
Duration getLowWater() const
Get the low water threshold.
Definition alarm.h:61
Houses the composite key that uniquely identifies a duration:
DurationKey(uint16_t family, uint8_t query_type, uint8_t response_type, const std::string &start_event_label, const std::string &stop_event_label, dhcp::SubnetID subnet_id)
Constructor.
Defines a State within the State Model.
Definition state_model.h:64
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
boost::posix_time::time_duration Duration
boost::posix_time::ptime Timestamp
boost::shared_ptr< Alarm > AlarmPtr
Defines a pointer to an Alarm instance.
Definition alarm.h:170
Defines the logger used by the top-level component of kea-lfc.