-
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.
feat(agent, engine, broker): CEIP collects statistics abour agent usage fix(test): agent tests * add os version to agent info
- Loading branch information
1 parent
8f6f413
commit 294b720
Showing
51 changed files
with
975 additions
and
147 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
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,31 @@ | ||
/** | ||
* 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_AGENT_INFO_HH | ||
#define CENTREON_AGENT_AGENT_INFO_HH | ||
|
||
#include "agent.pb.h" | ||
|
||
namespace com::centreon::agent { | ||
|
||
void read_os_version(); | ||
|
||
void fill_agent_info(const std::string& supervised_host, | ||
::com::centreon::agent::AgentInfo* agent_info); | ||
} // namespace com::centreon::agent | ||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* 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] | ||
*/ | ||
|
||
#include "agent_info.hh" | ||
#include "version.hh" | ||
|
||
static std::string _os; | ||
static std::string _os_version; | ||
|
||
/** | ||
* @brief read os version | ||
* to call at the beginning of program | ||
* | ||
*/ | ||
void com::centreon::agent::read_os_version() { | ||
std::fstream os_release("/etc/os-release", std::fstream::in); | ||
if (os_release.is_open()) { | ||
enum { os_found = 1, version_found = 2, all_found = 3 }; | ||
unsigned found = 0; | ||
std::string line; | ||
while (std::getline(os_release, line) && found != all_found) { | ||
if (!line.compare(0, 3, "ID=")) { | ||
line.erase(0, 3); | ||
boost::algorithm::trim_if(line, [](const char c) { | ||
return c == '"' || c == ' ' || c == '\''; | ||
}); | ||
_os = line; | ||
found |= os_found; | ||
} else if (!line.compare(0, 11, "VERSION_ID=")) { | ||
line.erase(0, 11); | ||
boost::algorithm::trim_if(line, [](const char c) { | ||
return c == '"' || c == ' ' || c == '\''; | ||
}); | ||
_os_version = line; | ||
found |= version_found; | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @brief fill agent_info with agent and os versions | ||
* | ||
* @param supervised_host host configured | ||
* @param agent_info pointer to object to fill | ||
*/ | ||
void com::centreon::agent::fill_agent_info( | ||
const std::string& supervised_host, | ||
::com::centreon::agent::AgentInfo* agent_info) { | ||
agent_info->mutable_centreon_version()->set_major( | ||
CENTREON_AGENT_VERSION_MAJOR); | ||
agent_info->mutable_centreon_version()->set_minor( | ||
CENTREON_AGENT_VERSION_MINOR); | ||
agent_info->mutable_centreon_version()->set_patch( | ||
CENTREON_AGENT_VERSION_PATCH); | ||
agent_info->set_host(supervised_host); | ||
agent_info->set_os(_os); | ||
agent_info->set_os_version(_os_version); | ||
} |
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
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,51 @@ | ||
/** | ||
* 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_NTDLL_HH | ||
#define CENTREON_AGENT_NTDLL_HH | ||
|
||
namespace com::centreon::agent { | ||
|
||
/**As winternl.h may be included, we define our own | ||
* SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION */ | ||
struct M_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION { | ||
LARGE_INTEGER IdleTime; | ||
LARGE_INTEGER KernelTime; | ||
LARGE_INTEGER UserTime; | ||
LARGE_INTEGER DpcTime; | ||
LARGE_INTEGER InterruptTime; | ||
ULONG InterruptCount; | ||
}; | ||
|
||
void load_nt_dll(); | ||
|
||
typedef LONG(WINAPI* NtQuerySystemInformationPtr)(ULONG SystemInformationClass, | ||
PVOID SystemInformation, | ||
ULONG SystemInformationLength, | ||
PULONG ReturnLength); | ||
|
||
extern NtQuerySystemInformationPtr nt_query_system_information; | ||
|
||
typedef NTSTATUS(NTAPI* RtlGetVersionPtr)( | ||
POSVERSIONINFOEXW lpVersionInformation); | ||
|
||
extern RtlGetVersionPtr rtl_get_version; | ||
|
||
} // namespace com::centreon::agent | ||
|
||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* 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] | ||
*/ | ||
|
||
#include "agent_info.hh" | ||
#include "ntdll.hh" | ||
#include "version.hh" | ||
|
||
static std::string _os; | ||
static std::string _os_version; | ||
|
||
/** | ||
* @brief read os version | ||
* to call at the beginning of program | ||
* | ||
*/ | ||
void com::centreon::agent::read_os_version() { | ||
RTL_OSVERSIONINFOEXW osvi; | ||
ZeroMemory(&osvi, sizeof(osvi)); | ||
osvi.dwOSVersionInfoSize = sizeof(osvi); | ||
if (rtl_get_version(&osvi) == 0) { | ||
_os = osvi.wProductType == VER_NT_SERVER ? "windows-server" : "windows"; | ||
_os_version = std::to_string(osvi.dwMajorVersion) + "." + | ||
std::to_string(osvi.dwMinorVersion) + "." + | ||
std::to_string(osvi.dwBuildNumber); | ||
} | ||
} | ||
|
||
/** | ||
* @brief fill agent_info with agent and os versions | ||
* | ||
* @param supervised_host host configured | ||
* @param agent_info pointer to object to fill | ||
*/ | ||
void com::centreon::agent::fill_agent_info( | ||
const std::string& supervised_host, | ||
::com::centreon::agent::AgentInfo* agent_info) { | ||
agent_info->mutable_centreon_version()->set_major( | ||
CENTREON_AGENT_VERSION_MAJOR); | ||
agent_info->mutable_centreon_version()->set_minor( | ||
CENTREON_AGENT_VERSION_MINOR); | ||
agent_info->mutable_centreon_version()->set_patch( | ||
CENTREON_AGENT_VERSION_PATCH); | ||
agent_info->set_host(supervised_host); | ||
agent_info->set_os(_os); | ||
agent_info->set_os_version(_os_version); | ||
} |
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
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
Oops, something went wrong.