-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
685600e
commit 960ded5
Showing
9 changed files
with
487 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
agent/native_windows/inc/com/centreon/agent/check_event_log_container.hh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* Copyright 2024 Centreon | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* For more information : [email protected] | ||
*/ | ||
|
||
#ifndef CENTREON_AGENT_CHECK_EVENT_LOG_CONTAINER_HH | ||
#define CENTREON_AGENT_CHECK_EVENT_LOG_CONTAINER_HH | ||
|
||
#include "check_event_log_data.hh" | ||
|
||
namespace com::centreon::agent::check_event_log_detail { | ||
|
||
class event_container { | ||
public: | ||
using event_set = boost::multi_index::multi_index_container< | ||
event, | ||
boost::multi_index::indexed_by< | ||
boost::multi_index::ordered_non_unique< | ||
BOOST_MULTI_INDEX_CONST_MEM_FUN( | ||
event, | ||
std::chrono::file_clock::time_point, | ||
time)>, | ||
boost::multi_index::ordered_non_unique< | ||
BOOST_MULTI_INDEX_CONST_MEM_FUN(event, e_status, status)>>>; | ||
|
||
private: | ||
duration _scan_range; | ||
|
||
std::wstring _file; | ||
std::unique_ptr<event_filter> _primary_filter; | ||
std::unique_ptr<event_filter> _warning_filter; | ||
std::unique_ptr<event_filter> _critical_filter; | ||
|
||
event_set _events ABSL_GUARDED_BY(_events_m); | ||
unsigned _insertion_cpt ABSL_GUARDED_BY(_events_m); | ||
unsigned _nb_warning ABSL_GUARDED_BY(_events_m); | ||
unsigned _nb_critical ABSL_GUARDED_BY(_events_m); | ||
absl::Mutex _events_m; | ||
|
||
EVT_HANDLE _render_context; | ||
EVT_HANDLE _subscription; | ||
|
||
using provider_metadata = absl::flat_hash_map<std::wstring, EVT_HANDLE>; | ||
provider_metadata _provider_metadata ABSL_GUARDED_BY(_events_m); | ||
|
||
void* _read_event_buffer ABSL_GUARDED_BY(_events_m); | ||
DWORD _buffer_size ABSL_GUARDED_BY(_events_m); | ||
|
||
bool _need_to_decode_message_content; | ||
LPWSTR _read_message_buffer ABSL_GUARDED_BY(_events_m); | ||
DWORD _message_buffer_size ABSL_GUARDED_BY(_events_m); // size in wchar_t | ||
|
||
std::shared_ptr<spdlog::logger> _logger; | ||
|
||
static DWORD WINAPI _subscription_callback(EVT_SUBSCRIBE_NOTIFY_ACTION action, | ||
PVOID p_context, | ||
EVT_HANDLE h_event); | ||
|
||
void _on_event(EVT_HANDLE event_handle); | ||
|
||
LPWSTR _get_message_string(EVT_HANDLE h_metadata, EVT_HANDLE h_event); | ||
|
||
public: | ||
event_container(const std::string_view& file, | ||
const std::string_view& primary_filter, | ||
const std::string_view& warning_filter, | ||
const std::string_view& critical_filter, | ||
duration scan_range, | ||
const std::shared_ptr<spdlog::logger>& logger); | ||
void start(); | ||
|
||
~event_container(); | ||
|
||
void lock() { _events_m.Lock(); } | ||
void unlock() { _events_m.Unlock(); } | ||
|
||
const event_set& get_events() const ABSL_EXCLUSIVE_LOCKS_REQUIRED(_events_m) { | ||
return _events; | ||
} | ||
}; | ||
|
||
} // namespace com::centreon::agent::check_event_log_detail | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
agent/native_windows/inc/com/centreon/agent/check_event_log_uniq.hh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* Copyright 2024 Centreon | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* For more information : [email protected] | ||
*/ | ||
|
||
#ifndef CENTREON_AGENT_CHECK_EVENT_LOG_UNIQ_HH | ||
#define CENTREON_AGENT_CHECK_EVENT_LOG_UNIQ_HH | ||
|
||
#include "check_event_log_data.hh" | ||
|
||
namespace com::centreon::agent::check_event_log_detail { | ||
|
||
class event_comparator { | ||
using field_event_hasher = std::function<size_t(const event&)>; | ||
using field_event_compare = std::function<bool(const event&, const event&)>; | ||
|
||
std::vector<field_event_hasher> _hash; | ||
std::vector<field_event_compare> _compare; | ||
|
||
public: | ||
event_comparator(std::string_view fields, | ||
const std::shared_ptr<spdlog::logger>& logger); | ||
|
||
bool operator()(const event* left, const event* right) const; | ||
std::size_t operator()(const event* evt) const; | ||
}; | ||
|
||
class unique_event { | ||
event_comparator _comparator; | ||
|
||
public: | ||
unique_event(const std::string_view& fields, | ||
const std::shared_ptr<spdlog::logger>& logger); | ||
|
||
template <class event_iter, typename out_iter> | ||
void unique(event_iter begin, | ||
event_iter end, | ||
out_iter&& warning_inserter, | ||
out_iter&& critical_inserter); | ||
}; | ||
|
||
template <class event_iter, typename out_iter> | ||
void unique_event::unique(event_iter begin, | ||
event_iter end, | ||
out_iter&& warning_inserter, | ||
out_iter&& critical_inserter) { | ||
absl::flat_hash_set<const event*, event_comparator, event_comparator> warning( | ||
0, _comparator, _comparator); | ||
absl::flat_hash_set<const event*, event_comparator, event_comparator> | ||
critical(0, _comparator, _comparator); | ||
|
||
for (; begin != end; ++begin) { | ||
if (begin->status() == e_status::warning) { | ||
if (warning.insert(&*begin).second) { | ||
warning_inserter(*begin); | ||
} | ||
} else { | ||
if (critical.insert(&*begin).second) { | ||
critical_inserter(*begin); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} // namespace com::centreon::agent::check_event_log_detail | ||
|
||
#endif |
Oops, something went wrong.