Kea 2.7.6
alarm.h
Go to the documentation of this file.
1// Copyright (C) 2024 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>
12#include <monitored_duration.h>
13
14#include <boost/date_time/posix_time/posix_time.hpp>
15
16namespace isc {
17namespace perfmon {
18
20class Alarm : public DurationKey {
21public:
23 enum State {
24 CLEAR, // Enabled and not currently triggered
25 TRIGGERED, // High water has been exceeded
26 DISABLED // Disabled
27 };
28
40 Alarm(uint16_t family, uint8_t query_type, uint8_t response_type,
41 const std::string& start_event_label, const std::string& stop_event_label,
42 dhcp::SubnetID subnet_id,
43 const Duration& low_water, const Duration& high_water, bool enabled = true);
44
51 Alarm(const DurationKey& key, const Duration& low_water, const Duration& high_water, bool enabled = true);
52
54 virtual ~Alarm() = default;
55
60 return (low_water_);
61 }
62
68 void setLowWater(const Duration& low_water);
69
74 return (high_water_);
75 }
76
82 void setHighWater(const Duration& high_water);
83
86 return (state_);
87 }
88
96 void setState(State state);
97
102 return (stos_time_);
103 }
104
109 return (last_high_water_report_);
110 }
111
119 last_high_water_report_ = timestamp;
120 }
121
123 void clear();
124
126 void disable();
127
148 bool checkSample(const Duration& sample, const Duration& report_interval);
149
150private:
152 Duration low_water_;
153
155 Duration high_water_;
156
158 State state_;
159
161 Timestamp stos_time_;
162
164 Timestamp last_high_water_report_;
165};
166
168typedef boost::shared_ptr<Alarm> AlarmPtr;
169
170} // end of namespace isc::perfmon
171} // end of namespace isc
172
173#endif
static boost::posix_time::ptime now()
Fetch the current UTC system time, microsecond precision.
Definition pkt.h:117
Defines an alarm for a duration.
Definition alarm.h:20
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:108
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:118
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:73
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:85
State
Defines Alarm states.
Definition alarm.h:23
Timestamp getStosTime()
Get the time the current state began.
Definition alarm.h:101
Duration getLowWater() const
Get the low water threshold.
Definition alarm.h:59
Houses the composite key that uniquely identifies a duration:
Defines a State within the State Model.
Definition state_model.h:61
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:168
Defines the logger used by the top-level component of kea-lfc.