mirror of https://github.com/Icinga/icinga2.git
parent
3b99dc1e84
commit
203cf73bf7
|
@ -26,6 +26,8 @@
|
|||
#include "base/convert.h"
|
||||
#include "base/application.h"
|
||||
#include "base/utility.h"
|
||||
#include "base/exception.h"
|
||||
#include "base/context.h"
|
||||
#include <fstream>
|
||||
|
||||
using namespace icinga;
|
||||
|
@ -48,11 +50,15 @@ void CheckResultReader::Start(void)
|
|||
*/
|
||||
void CheckResultReader::ReadTimerHandler(void) const
|
||||
{
|
||||
CONTEXT("Processing check result files in '" + GetSpoolDir() + "'");
|
||||
|
||||
Utility::Glob(GetSpoolDir() + "/c??????.ok", boost::bind(&CheckResultReader::ProcessCheckResultFile, this, _1));
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -80,8 +86,17 @@ void CheckResultReader::ProcessCheckResultFile(const String& path) const
|
|||
}
|
||||
|
||||
/* Remove the checkresult files. */
|
||||
(void)unlink(path.CStr());
|
||||
(void)unlink(crfile.CStr());
|
||||
if (unlink(path.CStr()) < 0)
|
||||
BOOST_THROW_EXCEPTION(posix_error()
|
||||
<< boost::errinfo_api_function("unlink")
|
||||
<< boost::errinfo_errno(errno)
|
||||
<< boost::errinfo_file_name(path));
|
||||
|
||||
if (unlink(crfile.CStr()) < 0)
|
||||
BOOST_THROW_EXCEPTION(posix_error()
|
||||
<< boost::errinfo_api_function("unlink")
|
||||
<< boost::errinfo_errno(errno)
|
||||
<< boost::errinfo_file_name(crfile));
|
||||
|
||||
Host::Ptr host = Host::GetByName(attrs["host_name"]);
|
||||
|
||||
|
@ -120,4 +135,3 @@ void CheckResultReader::ProcessCheckResultFile(const String& path) const
|
|||
service->SetNextCheck(Utility::GetTime() + service->GetCheckInterval());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,13 +38,25 @@ public:
|
|||
template<typename T>
|
||||
static long ToLong(const T& val)
|
||||
{
|
||||
return boost::lexical_cast<long>(val);
|
||||
try {
|
||||
return boost::lexical_cast<long>(val);
|
||||
} catch (std::exception&) {
|
||||
std::ostringstream msgbuf;
|
||||
msgbuf << "Can't convert '" << val << "' to an integer.";
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str()));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static double ToDouble(const T& val)
|
||||
{
|
||||
return boost::lexical_cast<double>(val);
|
||||
try {
|
||||
return boost::lexical_cast<double>(val);
|
||||
} catch (std::exception&) {
|
||||
std::ostringstream msgbuf;
|
||||
msgbuf << "Can't convert '" << val << "' to a floating point number.";
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str()));
|
||||
}
|
||||
}
|
||||
|
||||
static bool ToBool(const String& val);
|
||||
|
|
Loading…
Reference in New Issue