Introduce EnvResolver

refs #6259
This commit is contained in:
Alexander A. Klimov 2020-09-30 16:16:53 +02:00
parent 14d7ee2777
commit 91901eafd8
3 changed files with 51 additions and 0 deletions

View File

@ -41,6 +41,7 @@ set(icinga_SOURCES
customvarobject.cpp customvarobject.hpp customvarobject-ti.hpp
dependency.cpp dependency.hpp dependency-ti.hpp dependency-apply.cpp
downtime.cpp downtime.hpp downtime-ti.hpp
envresolver.cpp envresolver.hpp
eventcommand.cpp eventcommand.hpp eventcommand-ti.hpp
externalcommandprocessor.cpp externalcommandprocessor.hpp
host.cpp host.hpp host-ti.hpp

View File

@ -0,0 +1,20 @@
/* Icinga 2 | (c) 2020 Icinga GmbH | GPLv2+ */
#include "base/string.hpp"
#include "base/value.hpp"
#include "icinga/envresolver.hpp"
#include "icinga/checkresult.hpp"
#include <cstdlib>
using namespace icinga;
bool EnvResolver::ResolveMacro(const String& macro, const CheckResult::Ptr&, Value *result) const
{
auto value (getenv(macro.CStr()));
if (value) {
*result = value;
}
return value;
}

View File

@ -0,0 +1,30 @@
/* Icinga 2 | (c) 2020 Icinga GmbH | GPLv2+ */
#ifndef ENVRESOLVER_H
#define ENVRESOLVER_H
#include "base/object.hpp"
#include "base/string.hpp"
#include "base/value.hpp"
#include "icinga/macroresolver.hpp"
#include "icinga/checkresult.hpp"
namespace icinga
{
/**
* Resolves env var names.
*
* @ingroup icinga
*/
class EnvResolver final : public Object, public MacroResolver
{
public:
DECLARE_PTR_TYPEDEFS(EnvResolver);
bool ResolveMacro(const String& macro, const CheckResult::Ptr&, Value *result) const override;
};
}
#endif /* ENVRESOLVER_H */