mirror of https://github.com/Icinga/icinga2.git
Remove CheckResultReader which has been deprecated for 5 major versions
This commit is contained in:
parent
41065e30c8
commit
cc872dac1f
|
@ -1153,30 +1153,6 @@ use [MaxConcurrentChecks](17-language-reference.md#icinga-constants-global-confi
|
||||||
This also applies to an agent as command endpoint where the checker
|
This also applies to an agent as command endpoint where the checker
|
||||||
feature is disabled.
|
feature is disabled.
|
||||||
|
|
||||||
### CheckResultReader <a id="objecttype-checkresultreader"></a>
|
|
||||||
|
|
||||||
Reads Icinga 1.x check result files from a directory. This functionality is provided
|
|
||||||
to help existing Icinga 1.x users and might be useful for migration scenarios.
|
|
||||||
|
|
||||||
> **Note**
|
|
||||||
>
|
|
||||||
> This feature is DEPRECATED and may be removed in future releases.
|
|
||||||
> Check the [roadmap](https://github.com/Icinga/icinga2/milestones).
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```
|
|
||||||
object CheckResultReader "reader" {
|
|
||||||
spool_dir = "/data/check-results"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Configuration Attributes:
|
|
||||||
|
|
||||||
Name | Type | Description
|
|
||||||
--------------------------|-----------------------|----------------------------------
|
|
||||||
spool\_dir | String | **Optional.** The directory which contains the check result files. Defaults to DataDir + "/spool/checkresults/".
|
|
||||||
|
|
||||||
### CompatLogger <a id="objecttype-compatlogger"></a>
|
### CompatLogger <a id="objecttype-compatlogger"></a>
|
||||||
|
|
||||||
Writes log files in a format that's compatible with Icinga 1.x.
|
Writes log files in a format that's compatible with Icinga 1.x.
|
||||||
|
|
|
@ -1228,32 +1228,6 @@ Detailed information on the commands and their required parameters can be found
|
||||||
on the [Icinga 1.x documentation](https://docs.icinga.com/latest/en/extcommands2.html).
|
on the [Icinga 1.x documentation](https://docs.icinga.com/latest/en/extcommands2.html).
|
||||||
|
|
||||||
|
|
||||||
### Check Result Files <a id="check-result-files"></a>
|
|
||||||
|
|
||||||
> **Note**
|
|
||||||
>
|
|
||||||
> This feature is DEPRECATED and may be removed in future releases.
|
|
||||||
> Check the [roadmap](https://github.com/Icinga/icinga2/milestones).
|
|
||||||
|
|
||||||
Icinga 1.x writes its check result files to a temporary spool directory
|
|
||||||
where they are processed in a regular interval.
|
|
||||||
While this is extremely inefficient in performance regards it has been
|
|
||||||
rendered useful for passing passive check results directly into Icinga 1.x
|
|
||||||
skipping the external command pipe.
|
|
||||||
|
|
||||||
Several clustered/distributed environments and check-aggregation addons
|
|
||||||
use that method. In order to support step-by-step migration of these
|
|
||||||
environments, Icinga 2 supports the `CheckResultReader` object.
|
|
||||||
|
|
||||||
There is no feature configuration available, but it must be defined
|
|
||||||
on-demand in your Icinga 2 objects configuration.
|
|
||||||
|
|
||||||
```
|
|
||||||
object CheckResultReader "reader" {
|
|
||||||
spool_dir = "/data/check-results"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Livestatus <a id="setting-up-livestatus"></a>
|
### Livestatus <a id="setting-up-livestatus"></a>
|
||||||
|
|
||||||
> **Note**
|
> **Note**
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
# Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+
|
# Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+
|
||||||
|
|
||||||
mkclass_target(checkresultreader.ti checkresultreader-ti.cpp checkresultreader-ti.hpp)
|
|
||||||
mkclass_target(compatlogger.ti compatlogger-ti.cpp compatlogger-ti.hpp)
|
mkclass_target(compatlogger.ti compatlogger-ti.cpp compatlogger-ti.hpp)
|
||||||
mkclass_target(externalcommandlistener.ti externalcommandlistener-ti.cpp externalcommandlistener-ti.hpp)
|
mkclass_target(externalcommandlistener.ti externalcommandlistener-ti.cpp externalcommandlistener-ti.hpp)
|
||||||
|
|
||||||
set(compat_SOURCES
|
set(compat_SOURCES
|
||||||
checkresultreader.cpp checkresultreader.hpp checkresultreader-ti.hpp
|
|
||||||
compatlogger.cpp compatlogger.hpp compatlogger-ti.hpp
|
compatlogger.cpp compatlogger.hpp compatlogger-ti.hpp
|
||||||
externalcommandlistener.cpp externalcommandlistener.hpp externalcommandlistener-ti.hpp
|
externalcommandlistener.cpp externalcommandlistener.hpp externalcommandlistener-ti.hpp
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,166 +0,0 @@
|
||||||
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
|
||||||
|
|
||||||
#include "icinga/compatutility.hpp"
|
|
||||||
#include "compat/checkresultreader.hpp"
|
|
||||||
#include "compat/checkresultreader-ti.cpp"
|
|
||||||
#include "icinga/service.hpp"
|
|
||||||
#include "icinga/pluginutility.hpp"
|
|
||||||
#include "icinga/icingaapplication.hpp"
|
|
||||||
#include "base/configtype.hpp"
|
|
||||||
#include "base/objectlock.hpp"
|
|
||||||
#include "base/logger.hpp"
|
|
||||||
#include "base/convert.hpp"
|
|
||||||
#include "base/application.hpp"
|
|
||||||
#include "base/utility.hpp"
|
|
||||||
#include "base/exception.hpp"
|
|
||||||
#include "base/context.hpp"
|
|
||||||
#include "base/statsfunction.hpp"
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
using namespace icinga;
|
|
||||||
|
|
||||||
REGISTER_TYPE(CheckResultReader);
|
|
||||||
|
|
||||||
REGISTER_STATSFUNCTION(CheckResultReader, &CheckResultReader::StatsFunc);
|
|
||||||
|
|
||||||
void CheckResultReader::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
|
|
||||||
{
|
|
||||||
DictionaryData nodes;
|
|
||||||
|
|
||||||
for (const CheckResultReader::Ptr& checkresultreader : ConfigType::GetObjectsByType<CheckResultReader>()) {
|
|
||||||
nodes.emplace_back(checkresultreader->GetName(), 1); //add more stats
|
|
||||||
}
|
|
||||||
|
|
||||||
status->Set("checkresultreader", new Dictionary(std::move(nodes)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @threadsafety Always.
|
|
||||||
*/
|
|
||||||
void CheckResultReader::Start(bool runtimeCreated)
|
|
||||||
{
|
|
||||||
ObjectImpl<CheckResultReader>::Start(runtimeCreated);
|
|
||||||
|
|
||||||
Log(LogInformation, "CheckResultReader")
|
|
||||||
<< "'" << GetName() << "' started.";
|
|
||||||
|
|
||||||
Log(LogWarning, "CheckResultReader")
|
|
||||||
<< "This feature is DEPRECATED and may be removed in future releases. Check the roadmap at https://github.com/Icinga/icinga2/milestones";
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
m_ReadTimer = new Timer();
|
|
||||||
m_ReadTimer->OnTimerExpired.connect([this](const Timer * const&) { ReadTimerHandler(); });
|
|
||||||
m_ReadTimer->SetInterval(5);
|
|
||||||
m_ReadTimer->Start();
|
|
||||||
#endif /* _WIN32 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @threadsafety Always.
|
|
||||||
*/
|
|
||||||
void CheckResultReader::Stop(bool runtimeRemoved)
|
|
||||||
{
|
|
||||||
Log(LogInformation, "CheckResultReader")
|
|
||||||
<< "'" << GetName() << "' stopped.";
|
|
||||||
|
|
||||||
ObjectImpl<CheckResultReader>::Stop(runtimeRemoved);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @threadsafety Always.
|
|
||||||
*/
|
|
||||||
void CheckResultReader::ReadTimerHandler() const
|
|
||||||
{
|
|
||||||
CONTEXT("Processing check result files in '" << GetSpoolDir() << "'");
|
|
||||||
|
|
||||||
Utility::Glob(GetSpoolDir() + "/c??????.ok", [this](const String& path) { ProcessCheckResultFile(path); }, GlobFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckResultReader::ProcessCheckResultFile(const String& path) const
|
|
||||||
{
|
|
||||||
CONTEXT("Processing check result file '" << path << "'");
|
|
||||||
|
|
||||||
String crfile = String(path.Begin(), path.End() - 3); /* Remove the ".ok" extension. */
|
|
||||||
|
|
||||||
std::ifstream fp;
|
|
||||||
fp.exceptions(std::ifstream::badbit);
|
|
||||||
fp.open(crfile.CStr());
|
|
||||||
|
|
||||||
std::map<String, String> attrs;
|
|
||||||
|
|
||||||
while (fp.good()) {
|
|
||||||
std::string line;
|
|
||||||
std::getline(fp, line);
|
|
||||||
|
|
||||||
if (line.empty() || line[0] == '#')
|
|
||||||
continue; /* Ignore comments and empty lines. */
|
|
||||||
|
|
||||||
size_t pos = line.find_first_of('=');
|
|
||||||
|
|
||||||
if (pos == std::string::npos)
|
|
||||||
continue; /* Ignore invalid lines. */
|
|
||||||
|
|
||||||
String key = line.substr(0, pos);
|
|
||||||
String value = line.substr(pos + 1);
|
|
||||||
|
|
||||||
attrs[key] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Remove the checkresult files. */
|
|
||||||
Utility::Remove(path);
|
|
||||||
|
|
||||||
Utility::Remove(crfile);
|
|
||||||
|
|
||||||
Checkable::Ptr checkable;
|
|
||||||
|
|
||||||
Host::Ptr host = Host::GetByName(attrs["host_name"]);
|
|
||||||
|
|
||||||
if (!host) {
|
|
||||||
Log(LogWarning, "CheckResultReader")
|
|
||||||
<< "Ignoring checkresult file for host '" << attrs["host_name"] << "': Host does not exist.";
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (attrs.find("service_description") != attrs.end()) {
|
|
||||||
Service::Ptr service = host->GetServiceByShortName(attrs["service_description"]);
|
|
||||||
|
|
||||||
if (!service) {
|
|
||||||
Log(LogWarning, "CheckResultReader")
|
|
||||||
<< "Ignoring checkresult file for host '" << attrs["host_name"]
|
|
||||||
<< "', service '" << attrs["service_description"] << "': Service does not exist.";
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkable = service;
|
|
||||||
} else
|
|
||||||
checkable = host;
|
|
||||||
|
|
||||||
CheckResult::Ptr result = new CheckResult();
|
|
||||||
String output = CompatUtility::UnEscapeString(attrs["output"]);
|
|
||||||
std::pair<String, Value> co = PluginUtility::ParseCheckOutput(output);
|
|
||||||
result->SetOutput(co.first);
|
|
||||||
result->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
|
|
||||||
result->SetState(PluginUtility::ExitStatusToState(Convert::ToLong(attrs["return_code"])));
|
|
||||||
|
|
||||||
if (attrs.find("start_time") != attrs.end())
|
|
||||||
result->SetExecutionStart(Convert::ToDouble(attrs["start_time"]));
|
|
||||||
else
|
|
||||||
result->SetExecutionStart(Utility::GetTime());
|
|
||||||
|
|
||||||
if (attrs.find("finish_time") != attrs.end())
|
|
||||||
result->SetExecutionEnd(Convert::ToDouble(attrs["finish_time"]));
|
|
||||||
else
|
|
||||||
result->SetExecutionEnd(result->GetExecutionStart());
|
|
||||||
|
|
||||||
checkable->ProcessCheckResult(result);
|
|
||||||
|
|
||||||
Log(LogDebug, "CheckResultReader")
|
|
||||||
<< "Processed checkresult file for object '" << checkable->GetName() << "'";
|
|
||||||
|
|
||||||
/* Reschedule the next check. The side effect of this is that for as long
|
|
||||||
* as we receive check result files for a host/service we won't execute any
|
|
||||||
* active checks. */
|
|
||||||
checkable->SetNextCheck(Utility::GetTime() + checkable->GetCheckInterval());
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
|
||||||
|
|
||||||
#ifndef CHECKRESULTREADER_H
|
|
||||||
#define CHECKRESULTREADER_H
|
|
||||||
|
|
||||||
#include "compat/checkresultreader-ti.hpp"
|
|
||||||
#include "base/timer.hpp"
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
namespace icinga
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An Icinga checkresult reader.
|
|
||||||
*
|
|
||||||
* @ingroup compat
|
|
||||||
*/
|
|
||||||
class CheckResultReader final : public ObjectImpl<CheckResultReader>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
DECLARE_OBJECT(CheckResultReader);
|
|
||||||
DECLARE_OBJECTNAME(CheckResultReader);
|
|
||||||
|
|
||||||
static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void Start(bool runtimeCreated) override;
|
|
||||||
void Stop(bool runtimeRemoved) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Timer::Ptr m_ReadTimer;
|
|
||||||
void ReadTimerHandler() const;
|
|
||||||
void ProcessCheckResultFile(const String& path) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* CHECKRESULTREADER_H */
|
|
|
@ -1,20 +0,0 @@
|
||||||
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
|
||||||
|
|
||||||
#include "base/configobject.hpp"
|
|
||||||
#include "base/application.hpp"
|
|
||||||
|
|
||||||
library compat;
|
|
||||||
|
|
||||||
namespace icinga
|
|
||||||
{
|
|
||||||
|
|
||||||
class CheckResultReader : ConfigObject
|
|
||||||
{
|
|
||||||
activation_priority 100;
|
|
||||||
|
|
||||||
[config] String spool_dir {
|
|
||||||
default {{{ return Configuration::DataDir + "/spool/checkresults/"; }}}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
|
@ -293,7 +293,7 @@ String CompatUtility::EscapeString(const String& str)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Used in ExternalCommandListener and CheckResultReader. */
|
/* Used in ExternalCommandListener. */
|
||||||
String CompatUtility::UnEscapeString(const String& str)
|
String CompatUtility::UnEscapeString(const String& str)
|
||||||
{
|
{
|
||||||
String result = str;
|
String result = str;
|
||||||
|
|
|
@ -9,7 +9,7 @@ icolor brightgreen "object[ \t]+(checkcommand|notificationcommand|eventcommand
|
||||||
icolor brightgreen "object[ \t]+(timeperiod|scheduleddowntime|dependency|perfdatawriter)"
|
icolor brightgreen "object[ \t]+(timeperiod|scheduleddowntime|dependency|perfdatawriter)"
|
||||||
icolor brightgreen "object[ \t]+(graphitewriter|idomysqlconnection|idomysqlconnection)"
|
icolor brightgreen "object[ \t]+(graphitewriter|idomysqlconnection|idomysqlconnection)"
|
||||||
icolor brightgreen "object[ \t]+(livestatuslistener|externalcommandlistener)"
|
icolor brightgreen "object[ \t]+(livestatuslistener|externalcommandlistener)"
|
||||||
icolor brightgreen "object[ \t]+(compatlogger|checkresultreader|checkcomponent|notificationcomponent)"
|
icolor brightgreen "object[ \t]+(compatlogger|checkcomponent|notificationcomponent)"
|
||||||
icolor brightgreen "object[ \t]+(filelogger|sysloglogger|journaldlogger|apilistener|endpoint|zone)"
|
icolor brightgreen "object[ \t]+(filelogger|sysloglogger|journaldlogger|apilistener|endpoint|zone)"
|
||||||
|
|
||||||
## apply def
|
## apply def
|
||||||
|
|
Loading…
Reference in New Issue