Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
kcenon::monitoring::alert_labels Struct Reference

Key-value labels for alert identification and routing. More...

#include <alert_types.h>

Collaboration diagram for kcenon::monitoring::alert_labels:
Collaboration graph

Public Member Functions

 alert_labels ()=default
 
 alert_labels (std::unordered_map< std::string, std::string > lbl)
 
void set (const std::string &key, const std::string &value)
 Add or update a label.
 
std::string get (const std::string &key) const
 Get a label value.
 
bool has (const std::string &key) const
 Check if a label exists.
 
std::string fingerprint () const
 Generate a fingerprint for deduplication.
 
bool operator== (const alert_labels &other) const
 

Public Attributes

std::unordered_map< std::string, std::string > labels
 

Detailed Description

Key-value labels for alert identification and routing.

Labels are used for alert grouping, deduplication, and routing to appropriate notification channels.

Examples
alert_pipeline_example.cpp.

Definition at line 100 of file alert_types.h.

Constructor & Destructor Documentation

◆ alert_labels() [1/2]

kcenon::monitoring::alert_labels::alert_labels ( )
default

◆ alert_labels() [2/2]

kcenon::monitoring::alert_labels::alert_labels ( std::unordered_map< std::string, std::string > lbl)
inlineexplicit

Definition at line 105 of file alert_types.h.

106 : labels(std::move(lbl)) {}
std::unordered_map< std::string, std::string > labels

Member Function Documentation

◆ fingerprint()

std::string kcenon::monitoring::alert_labels::fingerprint ( ) const
inline

Generate a fingerprint for deduplication.

Returns
Hash string based on sorted labels

Definition at line 140 of file alert_types.h.

140 {
141 std::string result;
142 std::vector<std::pair<std::string, std::string>> sorted_labels(
143 labels.begin(), labels.end());
144 std::sort(sorted_labels.begin(), sorted_labels.end());
145 for (const auto& [key, value] : sorted_labels) {
146 result += key + "=" + value + ",";
147 }
148 return result;
149 }

References labels.

Referenced by kcenon::monitoring::alert::fingerprint().

Here is the caller graph for this function:

◆ get()

std::string kcenon::monitoring::alert_labels::get ( const std::string & key) const
inline

Get a label value.

Parameters
keyLabel key
Returns
Label value or empty string if not found

Definition at line 122 of file alert_types.h.

122 {
123 auto it = labels.find(key);
124 return it != labels.end() ? it->second : "";
125 }

References labels.

Referenced by kcenon::monitoring::alert_aggregator::compute_group_key(), kcenon::monitoring::alert_aggregator::extract_common_labels(), kcenon::monitoring::alert_silence::matches(), kcenon::monitoring::inhibition_rule::matches_source(), kcenon::monitoring::routing_notifier::route_by_label(), kcenon::monitoring::inhibition_rule::should_inhibit(), TEST(), and TEST_F().

Here is the caller graph for this function:

◆ has()

bool kcenon::monitoring::alert_labels::has ( const std::string & key) const
inline

Check if a label exists.

Parameters
keyLabel key
Returns
True if label exists

Definition at line 132 of file alert_types.h.

132 {
133 return labels.find(key) != labels.end();
134 }

References labels.

◆ operator==()

bool kcenon::monitoring::alert_labels::operator== ( const alert_labels & other) const
inline

Definition at line 151 of file alert_types.h.

151 {
152 return labels == other.labels;
153 }

References labels, and kcenon::monitoring::other.

◆ set()

void kcenon::monitoring::alert_labels::set ( const std::string & key,
const std::string & value )
inline

Member Data Documentation

◆ labels


The documentation for this struct was generated from the following file: