try {
service->BeginExecuteCheck(boost::bind(&CheckerComponent::CheckCompletedHandler, this, service));
} catch (const exception& ex) {
- Logger::Write(LogCritical, "checker", "Exception occured while checking service '" + service->GetName() + "': " + ex.what());
+ Logger::Write(LogCritical, "checker", "Exception occured while checking service '" + service->GetName() + "': " + diagnostic_information(ex));
}
tasks++;
fifo_ok = true;
} else {
if (unlink(commandPath.CStr()) < 0)
- throw_exception(PosixException("unlink() failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("unlink() failed", errno));
}
}
if (!fifo_ok && mkfifo(commandPath.CStr(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
- throw_exception(PosixException("mkfifo() failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("mkfifo() failed", errno));
for (;;) {
int fd = open(commandPath.CStr(), O_RDONLY);
if (fd < 0)
- throw_exception(PosixException("open() failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("open() failed", errno));
FILE *fp = fdopen(fd, "r");
if (fp == NULL) {
close(fd);
- throw_exception(PosixException("fdopen() failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("fdopen() failed", errno));
}
char line[2048];
ExternalCommandProcessor::Execute(command);
} catch (const exception& ex) {
stringstream msgbuf;
- msgbuf << "External command failed: " << ex.what();
+ msgbuf << "External command failed: " << diagnostic_information(ex);
Logger::Write(LogWarning, "compat", msgbuf.str());
}
}
statusfp.close();
if (rename(statuspathtmp.CStr(), statuspath.CStr()) < 0)
- throw_exception(PosixException("rename() failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("rename() failed", errno));
objectfp.close();
if (rename(objectspathtmp.CStr(), objectspath.CStr()) < 0)
- throw_exception(PosixException("rename() failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("rename() failed", errno));
}
EXPORT_COMPONENT(compat, CompatComponent);
object->Register();
} else {
if (object->IsLocal())
- throw_exception(invalid_argument("Replicated remote object is marked as local."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Replicated remote object is marked as local."));
// TODO: disallow config updates depending on endpoint config
Application::Ptr app = Application::GetInstance();
if (!app)
- throw_exception(runtime_error("Configuration must create an Application object."));
+ BOOST_THROW_EXCEPTION(runtime_error("Configuration must create an Application object."));
if (g_AppParams.count("daemonize")) {
Logger::Write(LogInformation, "icinga", "Daemonizing.");
: DynamicObject(serializedUpdate), m_PidFile(NULL)
{
if (!IsLocal())
- throw_exception(runtime_error("Application objects must be local."));
+ BOOST_THROW_EXCEPTION(runtime_error("Application objects must be local."));
#ifdef _WIN32
/* disable GUI-based error messages for LoadLibrary() */
WSADATA wsaData;
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0)
- throw_exception(Win32Exception("WSAStartup failed", WSAGetLastError()));
+ BOOST_THROW_EXCEPTION(Win32Exception("WSAStartup failed", WSAGetLastError()));
#endif /* _WIN32 */
char *debugging = getenv("_DEBUG");
#ifndef _WIN32
char buffer[MAXPATHLEN];
if (getcwd(buffer, sizeof(buffer)) == NULL)
- throw_exception(PosixException("getcwd failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("getcwd failed", errno));
String workingDirectory = buffer;
if (argv0[0] != '/')
if (!foundPath) {
executablePath.Clear();
- throw_exception(runtime_error("Could not determine executable path."));
+ BOOST_THROW_EXCEPTION(runtime_error("Could not determine executable path."));
}
}
}
if (realpath(executablePath.CStr(), buffer) == NULL)
- throw_exception(PosixException("realpath failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("realpath failed", errno));
return buffer;
#else /* _WIN32 */
char FullExePath[MAXPATHLEN];
if (!GetModuleFileName(NULL, FullExePath, sizeof(FullExePath)))
- throw_exception(Win32Exception("GetModuleFileName() failed", GetLastError()));
+ BOOST_THROW_EXCEPTION(Win32Exception("GetModuleFileName() failed", GetLastError()));
return FullExePath;
#endif /* _WIN32 */
try {
throw;
} catch (const std::exception& ex) {
- std::cerr << std::endl;
- std::cerr << "Unhandled exception of type "
- << Utility::GetTypeName(typeid(ex))
- << std::endl;
- std::cerr << "Diagnostic Information: "
- << ex.what()
+ std::cerr << std::endl
+ << diagnostic_information(ex)
<< std::endl;
}
m_PidFile = fopen(filename.CStr(), "w");
if (m_PidFile == NULL)
- throw_exception(runtime_error("Could not open PID file '" + filename + "'"));
+ BOOST_THROW_EXCEPTION(runtime_error("Could not open PID file '" + filename + "'"));
#ifndef _WIN32
if (flock(fileno(m_PidFile), LOCK_EX | LOCK_NB) < 0) {
TResult GetResult(void)
{
if (!m_Finished)
- throw_exception(runtime_error("GetResult called on an unfinished AsyncTask"));
+ BOOST_THROW_EXCEPTION(runtime_error("GetResult called on an unfinished AsyncTask"));
if (m_ResultRetrieved)
- throw_exception(runtime_error("GetResult called on an AsyncTask whose result was already retrieved."));
+ BOOST_THROW_EXCEPTION(runtime_error("GetResult called on an AsyncTask whose result was already retrieved."));
m_ResultRetrieved = true;
assert(Application::IsMainThread());
if (!IsLocal())
- throw_exception(runtime_error("Component objects must be local."));
+ BOOST_THROW_EXCEPTION(runtime_error("Component objects must be local."));
#ifdef _WIN32
HMODULE
try {
if (pCreateComponent == NULL)
- throw_exception(runtime_error("Loadable module does not contain "
+ BOOST_THROW_EXCEPTION(runtime_error("Loadable module does not contain "
"CreateComponent function"));
/* pCreateComponent returns a raw pointer which we must wrap in a shared_ptr */
impl = IComponent::Ptr(pCreateComponent());
if (!impl)
- throw_exception(runtime_error("CreateComponent function returned NULL."));
+ BOOST_THROW_EXCEPTION(runtime_error("CreateComponent function returned NULL."));
} catch (...) {
#ifdef _WIN32
FreeLibrary(hModule);
Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
if (json->type != cJSON_Object)
- throw_exception(invalid_argument("JSON type must be cJSON_Object."));
+ BOOST_THROW_EXCEPTION(invalid_argument("JSON type must be cJSON_Object."));
for (cJSON *i = json->child; i != NULL; i = i->next) {
dictionary->Set(i->string, Value::FromJson(i));
RegisterAttribute("methods", Attribute_Config);
if (!serializedObject->Contains("configTx"))
- throw_exception(invalid_argument("Serialized object must contain a config snapshot."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Serialized object must contain a config snapshot."));
/* apply config state from the config item/remote update;
* The DynamicObject::Create function takes care of restoring
Value oldValue;
if (!allowEditConfig && (tt.first->second.Type & Attribute_Config))
- throw_exception(runtime_error("Config properties are immutable: '" + name + "'."));
+ BOOST_THROW_EXCEPTION(runtime_error("Config properties are immutable: '" + name + "'."));
if (!tt.second && tx >= tt.first->second.Tx) {
oldValue = tt.first->second.Data;
ScriptFunction::Ptr func = ScriptFunction::GetByName(funcName);
if (!func)
- throw_exception(invalid_argument("Function '" + funcName + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Function '" + funcName + "' does not exist."));
ScriptTask::Ptr task = boost::make_shared<ScriptTask>(func, arguments);
task->Start(callback);
fp.open(tempFilename.CStr(), std::ios_base::out);
if (!fp)
- throw_exception(runtime_error("Could not open '" + filename + "' file"));
+ BOOST_THROW_EXCEPTION(runtime_error("Could not open '" + filename + "' file"));
StdioStream::Ptr sfp = boost::make_shared<StdioStream>(&fp, false);
sfp->Start();
#endif /* _WIN32 */
if (rename(tempFilename.CStr(), filename.CStr()) < 0)
- throw_exception(PosixException("rename() failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("rename() failed", errno));
}
void DynamicObject::RestoreObjects(const String& filename)
DynamicType::Ptr dt = DynamicType::GetByName(type);
if (!dt)
- throw_exception(invalid_argument("Invalid type: " + type));
+ BOOST_THROW_EXCEPTION(invalid_argument("Invalid type: " + type));
DynamicObject::Ptr object = dt->GetObject(name);
void DynamicType::RegisterType(const DynamicType::Ptr& type)
{
if (GetByName(type->GetName()))
- throw_exception(runtime_error("Cannot register class for type '" +
+ BOOST_THROW_EXCEPTION(runtime_error("Cannot register class for type '" +
type->GetName() + "': Objects of this type already exist."));
GetTypes()[type->GetName()] = type;
char *newBuffer = static_cast<char *>(realloc(m_Buffer, newSize));
if (newBuffer == NULL)
- throw_exception(bad_alloc());
+ BOOST_THROW_EXCEPTION(bad_alloc());
m_Buffer = newBuffer;
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/program_options.hpp>
+#include <boost/exception/diagnostic_information.hpp>
using boost::shared_ptr;
using boost::weak_ptr;
using boost::system_time;
using boost::posix_time::millisec;
using boost::tie;
-using boost::throw_exception;
using boost::rethrow_exception;
using boost::current_exception;
+using boost::diagnostic_information;
namespace tuples = boost::tuples;
: DynamicObject(properties)
{
if (!IsLocal())
- throw_exception(runtime_error("Logger objects must be local."));
+ BOOST_THROW_EXCEPTION(runtime_error("Logger objects must be local."));
String type = Get("type");
if (type.IsEmpty())
- throw_exception(runtime_error("Logger objects must have a 'type' property."));
+ BOOST_THROW_EXCEPTION(runtime_error("Logger objects must have a 'type' property."));
ILogger::Ptr impl;
#ifndef _WIN32
impl = boost::make_shared<SyslogLogger>();
#else /* _WIN32 */
- throw_exception(invalid_argument("Syslog is not supported on Windows."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Syslog is not supported on Windows."));
#endif /* _WIN32 */
} else if (type == "file") {
String path = Get("path");
if (path.IsEmpty())
- throw_exception(invalid_argument("'log' object of type 'file' must have a 'path' property"));
+ BOOST_THROW_EXCEPTION(invalid_argument("'log' object of type 'file' must have a 'path' property"));
StreamLogger::Ptr slogger = boost::make_shared<StreamLogger>();
slogger->OpenFile(path);
} else if (type == "console") {
impl = boost::make_shared<StreamLogger>(&std::cout);
} else {
- throw_exception(runtime_error("Unknown log type: " + type));
+ BOOST_THROW_EXCEPTION(runtime_error("Unknown log type: " + type));
}
impl->m_Config = this;
case LogCritical:
return "critical";
default:
- throw_exception(invalid_argument("Invalid severity."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Invalid severity."));
}
}
else if (severity == "critical")
return LogCritical;
else
- throw_exception(invalid_argument("Invalid severity: " + severity));
+ BOOST_THROW_EXCEPTION(invalid_argument("Invalid severity: " + severity));
}
/**
char *buffer = static_cast<char *>(malloc(buffer_length));
if (buffer == NULL)
- throw_exception(bad_alloc());
+ BOOST_THROW_EXCEPTION(bad_alloc());
peek_length = stream->Peek(buffer, buffer_length);
/* no leading zeros allowed */
if (buffer[0] == '0' && isdigit(buffer[1])) {
free(buffer);
- throw_exception(invalid_argument("Invalid netString (leading zero)"));
+ BOOST_THROW_EXCEPTION(invalid_argument("Invalid netString (leading zero)"));
}
size_t len, i;
/* length specifier must have at most 9 characters */
if (i >= 9) {
free(buffer);
- throw_exception(invalid_argument("Length specifier must not exceed 9 characters"));
+ BOOST_THROW_EXCEPTION(invalid_argument("Length specifier must not exceed 9 characters"));
}
len = len * 10 + (buffer[i] - '0');
if (new_buffer == NULL) {
free(buffer);
- throw_exception(bad_alloc());
+ BOOST_THROW_EXCEPTION(bad_alloc());
}
buffer = new_buffer;
/* check for the colon delimiter */
if (buffer[i] != ':') {
free(buffer);
- throw_exception(invalid_argument("Invalid NetString (missing :)"));
+ BOOST_THROW_EXCEPTION(invalid_argument("Invalid NetString (missing :)"));
}
/* check for the comma delimiter after the String */
if (buffer[i + 1 + len] != ',') {
free(buffer);
- throw_exception(invalid_argument("Invalid NetString (missing ,)"));
+ BOOST_THROW_EXCEPTION(invalid_argument("Invalid NetString (missing ,)"));
}
*str = String(&buffer[i + 1], &buffer[i + 1 + len]);
dictfp.close();
if (rename("dictionaries.dump.tmp", "dictionaries.dump") < 0)
- throw_exception(PosixException("rename() failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("rename() failed", errno));
String type;
int count;
#endif /* _MSC_VER */
if (m_FP == NULL)
- throw_exception(runtime_error("Could not create process."));
+ BOOST_THROW_EXCEPTION(runtime_error("Could not create process."));
}
bool Process::RunTask(void)
int flags;
flags = fcntl(fd, F_GETFL, 0);
if (flags < 0)
- throw_exception(PosixException("fcntl failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0)
- throw_exception(PosixException("fcntl failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("fcntl failed", errno));
#else /* F_GETFL */
unsigned long lTrue = 1;
ioctlsocket(fd, FIONBIO, &lTrue);
*/
void Socket::HandleException(void)
{
- throw_exception(SocketException("select() returned fd in except fdset", GetError()));
+ BOOST_THROW_EXCEPTION(SocketException("select() returned fd in except fdset", GetError()));
}
/**
if (getnameinfo(address, len, host, sizeof(host), service,
sizeof(service), NI_NUMERICHOST | NI_NUMERICSERV) < 0)
- throw_exception(SocketException("getnameinfo() failed",
+ BOOST_THROW_EXCEPTION(SocketException("getnameinfo() failed",
GetLastSocketError()));
stringstream s;
socklen_t len = sizeof(sin);
if (getsockname(GetFD(), (sockaddr *)&sin, &len) < 0)
- throw_exception(SocketException("getsockname() failed", GetError()));
+ BOOST_THROW_EXCEPTION(SocketException("getsockname() failed", GetError()));
return GetAddressFromSockaddr((sockaddr *)&sin, len);
}
socklen_t len = sizeof(sin);
if (getpeername(GetFD(), (sockaddr *)&sin, &len) < 0)
- throw_exception(SocketException("getpeername() failed", GetError()));
+ BOOST_THROW_EXCEPTION(SocketException("getpeername() failed", GetError()));
return GetAddressFromSockaddr((sockaddr *)&sin, len);
}
try {
if (rc < 0)
- throw_exception(SocketException("select() failed", GetError()));
+ BOOST_THROW_EXCEPTION(SocketException("select() failed", GetError()));
if (FD_ISSET(fd, &readfds))
HandleReadable();
try {
if (rc < 0)
- throw_exception(SocketException("select() failed", GetError()));
+ BOOST_THROW_EXCEPTION(SocketException("select() failed", GetError()));
if (FD_ISSET(fd, &writefds))
HandleWritable();
void Socket::Listen(void)
{
if (listen(GetFD(), SOMAXCONN) < 0)
- throw_exception(SocketException("listen() failed", GetError()));
+ BOOST_THROW_EXCEPTION(SocketException("listen() failed", GetError()));
m_Listening = true;
}
rc = send(GetFD(), data, count, 0);
if (rc <= 0)
- throw_exception(SocketException("send() failed", GetError()));
+ BOOST_THROW_EXCEPTION(SocketException("send() failed", GetError()));
{
boost::mutex::scoped_lock lock(m_QueueMutex);
break;
if (rc <= 0)
- throw_exception(SocketException("recv() failed", GetError()));
+ BOOST_THROW_EXCEPTION(SocketException("recv() failed", GetError()));
{
boost::mutex::scoped_lock lock(m_QueueMutex);
fd = accept(GetFD(), (sockaddr *)&addr, &addrlen);
if (fd < 0)
- throw_exception(SocketException("accept() failed", GetError()));
+ BOOST_THROW_EXCEPTION(SocketException("accept() failed", GetError()));
TcpSocket::Ptr client = boost::make_shared<TcpSocket>();
client->SetFD(fd);
stream->open(filename.CStr(), fstream::out | fstream::trunc);
if (!stream->good())
- throw_exception(runtime_error("Could not open logfile '" + filename + "'"));
+ BOOST_THROW_EXCEPTION(runtime_error("Could not open logfile '" + filename + "'"));
} catch (...) {
delete stream;
throw;
if (getaddrinfo(node.IsEmpty() ? NULL : node.CStr(),
service.CStr(), &hints, &result) < 0)
- throw_exception(SocketException("getaddrinfo() failed", GetLastSocketError()));
+ BOOST_THROW_EXCEPTION(SocketException("getaddrinfo() failed", GetLastSocketError()));
int fd = INVALID_SOCKET;
freeaddrinfo(result);
if (fd == INVALID_SOCKET)
- throw_exception(runtime_error("Could not create a suitable socket."));
+ BOOST_THROW_EXCEPTION(runtime_error("Could not create a suitable socket."));
}
/**
int rc = getaddrinfo(node.CStr(), service.CStr(), &hints, &result);
if (rc < 0)
- throw_exception(SocketException("getaddrinfo() failed", GetLastSocketError()));
+ BOOST_THROW_EXCEPTION(SocketException("getaddrinfo() failed", GetLastSocketError()));
int fd = INVALID_SOCKET;
freeaddrinfo(result);
if (fd == INVALID_SOCKET)
- throw_exception(runtime_error("Could not create a suitable socket."));
+ BOOST_THROW_EXCEPTION(runtime_error("Could not create a suitable socket."));
}
m_SSLContext.reset();
if (!m_SSL)
- throw_exception(OpenSSLException("SSL_new failed", ERR_get_error()));
+ BOOST_THROW_EXCEPTION(OpenSSLException("SSL_new failed", ERR_get_error()));
if (!GetClientCertificate())
- throw_exception(logic_error("No X509 client certificate was specified."));
+ BOOST_THROW_EXCEPTION(logic_error("No X509 client certificate was specified."));
if (!m_SSLIndexInitialized) {
m_SSLIndex = SSL_get_ex_new_index(0, const_cast<char *>("TlsStream"), NULL, NULL, NULL);
return;
default:
I2Stream_check_exception(m_BIO);
- throw_exception(OpenSSLException("SSL_do_handshake failed", ERR_get_error()));
+ BOOST_THROW_EXCEPTION(OpenSSLException("SSL_do_handshake failed", ERR_get_error()));
}
}
}
return;
default:
I2Stream_check_exception(m_BIO);
- throw_exception(OpenSSLException("SSL_read failed", ERR_get_error()));
+ BOOST_THROW_EXCEPTION(OpenSSLException("SSL_read failed", ERR_get_error()));
}
}
}
return;
default:
I2Stream_check_exception(m_BIO);
- throw_exception(OpenSSLException("SSL_write failed", ERR_get_error()));
+ BOOST_THROW_EXCEPTION(OpenSSLException("SSL_write failed", ERR_get_error()));
}
}
}
int fd = socket(AF_UNIX, SOCK_STREAM, PF_UNIX);
if (fd < 0)
- throw_exception(PosixException("socket() failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("socket() failed", errno));
SetFD(fd);
}
sun.sun_path[sizeof(sun.sun_path) - 1] = '\0';
if (bind(GetFD(), (sockaddr *)&sun, SUN_LEN(&sun)) < 0)
- throw_exception(PosixException("bind() failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("bind() failed", errno));
}
void UnixSocket::Connect(const String& path)
sun.sun_path[sizeof(sun.sun_path) - 1] = '\0';
if (connect(GetFD(), (sockaddr *)&sun, SUN_LEN(&sun)) < 0 && errno != EINPROGRESS)
- throw_exception(PosixException("connect() failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("connect() failed", errno));
}
#endif /* _WIN32 */
pid = fork();
if (pid < 0)
- throw_exception(PosixException("fork() failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("fork() failed", errno));
if (pid)
_exit(0);
fd = open("/dev/null", O_RDWR);
if (fd < 0)
- throw_exception(PosixException("open() failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("open() failed", errno));
if (fd != STDIN_FILENO)
dup2(fd, STDIN_FILENO);
close(fd);
if (setsid() < 0)
- throw_exception(PosixException("setsid() failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("setsid() failed", errno));
#endif
}
SSL_CTX_set_mode(sslContext.get(), SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
if (!SSL_CTX_use_certificate_chain_file(sslContext.get(), pubkey.CStr()))
- throw_exception(OpenSSLException("Could not load public X509 key file", ERR_get_error()));
+ BOOST_THROW_EXCEPTION(OpenSSLException("Could not load public X509 key file", ERR_get_error()));
if (!SSL_CTX_use_PrivateKey_file(sslContext.get(), privkey.CStr(), SSL_FILETYPE_PEM))
- throw_exception(OpenSSLException("Could not load private X509 key file", ERR_get_error()));
+ BOOST_THROW_EXCEPTION(OpenSSLException("Could not load private X509 key file", ERR_get_error()));
if (!SSL_CTX_load_verify_locations(sslContext.get(), cakey.CStr(), NULL))
- throw_exception(OpenSSLException("Could not load public CA key file", ERR_get_error()));
+ BOOST_THROW_EXCEPTION(OpenSSLException("Could not load public CA key file", ERR_get_error()));
STACK_OF(X509_NAME) *cert_names;
cert_names = SSL_load_client_CA_file(cakey.CStr());
if (cert_names == NULL)
- throw_exception(OpenSSLException("SSL_load_client_CA_file() failed", ERR_get_error()));
+ BOOST_THROW_EXCEPTION(OpenSSLException("SSL_load_client_CA_file() failed", ERR_get_error()));
SSL_CTX_set_client_CA_list(sslContext.get(), cert_names);
NID_commonName, buffer, sizeof(buffer));
if (rc == -1)
- throw_exception(OpenSSLException("X509 certificate has no CN"
+ BOOST_THROW_EXCEPTION(OpenSSLException("X509 certificate has no CN"
" attribute", ERR_get_error()));
return buffer;
BIO *fpcert = BIO_new(BIO_s_file());
if (fpcert == NULL)
- throw_exception(OpenSSLException("BIO_new failed",
+ BOOST_THROW_EXCEPTION(OpenSSLException("BIO_new failed",
ERR_get_error()));
if (BIO_read_filename(fpcert, pemfile.CStr()) < 0)
- throw_exception(OpenSSLException("BIO_read_filename failed",
+ BOOST_THROW_EXCEPTION(OpenSSLException("BIO_read_filename failed",
ERR_get_error()));
cert = PEM_read_bio_X509_AUX(fpcert, NULL, NULL, NULL);
if (cert == NULL)
- throw_exception(OpenSSLException("PEM_read_bio_X509_AUX failed",
+ BOOST_THROW_EXCEPTION(OpenSSLException("PEM_read_bio_X509_AUX failed",
ERR_get_error()));
BIO_free(fpcert);
String result;
if (dir == NULL)
- throw_exception(bad_alloc());
+ BOOST_THROW_EXCEPTION(bad_alloc());
#ifndef _WIN32
result = dirname(dir);
#else /* _WIN32 */
if (!PathRemoveFileSpec(dir)) {
free(dir);
- throw_exception(Win32Exception("PathRemoveFileSpec() failed",
+ BOOST_THROW_EXCEPTION(Win32Exception("PathRemoveFileSpec() failed",
GetLastError()));
}
String result;
if (dir == NULL)
- throw_exception(bad_alloc());
+ BOOST_THROW_EXCEPTION(bad_alloc());
#ifndef _WIN32
result = basename(dir);
struct timeval tv;
if (gettimeofday(&tv, NULL) < 0)
- throw_exception(PosixException("gettimeofday() failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("gettimeofday() failed", errno));
return tv.tv_sec + tv.tv_usec / 1000000.0;
#endif /* _WIN32 */
HMODULE hModule = LoadLibrary(path.CStr());
if (hModule == NULL)
- throw_exception(Win32Exception("LoadLibrary('" + path + "') failed", GetLastError()));
+ BOOST_THROW_EXCEPTION(Win32Exception("LoadLibrary('" + path + "') failed", GetLastError()));
#else /* _WIN32 */
lt_dlhandle hModule = lt_dlopen(path.CStr());
if (hModule == NULL) {
- throw_exception(runtime_error("Could not load library '" + path + "': " + lt_dlerror()));
+ BOOST_THROW_EXCEPTION(runtime_error("Could not load library '" + path + "': " + lt_dlerror()));
}
#endif /* _WIN32 */
if (errorCode == ERROR_FILE_NOT_FOUND)
return false;
- throw_exception(Win32Exception("FindFirstFile() failed", errorCode));
+ BOOST_THROW_EXCEPTION(Win32Exception("FindFirstFile() failed", errorCode));
}
do {
} while (FindNextFile(handle, &wfd));
if (!FindClose(handle))
- throw_exception(Win32Exception("FindClose() failed", GetLastError()));
+ BOOST_THROW_EXCEPTION(Win32Exception("FindClose() failed", GetLastError()));
return true;
#else /* _WIN32 */
if (rc == GLOB_NOMATCH)
return false;
- throw_exception(PosixException("glob() failed", errno));
+ BOOST_THROW_EXCEPTION(PosixException("glob() failed", errno));
}
if (gr.gl_pathc == 0) {
* (like spawning a process) until the application instance
* has been initialized. */
if (!instance)
- throw_exception(runtime_error("Waiting for predicate failed: Application instance is not initialized."));
+ BOOST_THROW_EXCEPTION(runtime_error("Waiting for predicate failed: Application instance is not initialized."));
instance->ProcessEvents();
}
else if (json->type == cJSON_NULL)
return Value();
else
- throw_exception(invalid_argument("Unsupported JSON type."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Unsupported JSON type."));
}
/**
} else if (m_Value.type() == typeid(boost::blank)) {
return cJSON_CreateNull();
} else {
- throw_exception(runtime_error("Invalid variant type."));
+ BOOST_THROW_EXCEPTION(runtime_error("Invalid variant type."));
}
}
cJSON *json = cJSON_Parse(jsonString.CStr());
if (!json)
- throw_exception(runtime_error("Invalid JSON String"));
+ BOOST_THROW_EXCEPTION(runtime_error("Invalid JSON String"));
Value value = FromJson(json);
cJSON_Delete(json);
Object::Ptr object = dynamic_pointer_cast<Object>(value);
if (!object)
- throw_exception(invalid_argument("shared_ptr value type must inherit from Object class."));
+ BOOST_THROW_EXCEPTION(invalid_argument("shared_ptr value type must inherit from Object class."));
m_Value = object;
}
shared_ptr<T> object = dynamic_pointer_cast<T>(boost::get<Object::Ptr>(m_Value));
if (!object)
- throw_exception(bad_cast());
+ BOOST_THROW_EXCEPTION(bad_cast());
return object;
}
{
stringstream message;
message << *locp << ": " << err;
- throw_exception(runtime_error(message.str()));
+ ConfigCompilerContext::GetContext()->AddError(false, message.str());
}
int yyparse(ConfigCompiler *context);
try {
yyparse(this);
} catch (const exception& ex) {
- ConfigCompilerContext::GetContext()->AddError(false, ex.what());
+ ConfigCompilerContext::GetContext()->AddError(false, boost::diagnostic_information(ex));
}
}
if (!m_Type) {
if ((yyvsp[(1) - (3)].num))
- throw_exception(invalid_argument("partial type definition for unknown type '" + name + "'"));
+ BOOST_THROW_EXCEPTION(invalid_argument("Partial type definition for unknown type '" + name + "'"));
m_Type = boost::make_shared<ConfigType>(name, yylloc);
ConfigCompilerContext::GetContext()->AddType(m_Type);
{
stringstream message;
message << *locp << ": " << err;
- throw_exception(runtime_error(message.str()));
+ ConfigCompilerContext::GetContext()->AddError(false, message.str());
}
int yyparse(ConfigCompiler *context);
try {
yyparse(this);
} catch (const exception& ex) {
- ConfigCompilerContext::GetContext()->AddError(false, ex.what());
+ ConfigCompilerContext::GetContext()->AddError(false, boost::diagnostic_information(ex));
}
}
if (!m_Type) {
if ($1)
- throw_exception(invalid_argument("partial type definition for unknown type '" + name + "'"));
+ BOOST_THROW_EXCEPTION(invalid_argument("Partial type definition for unknown type '" + name + "'"));
m_Type = boost::make_shared<ConfigType>(name, yylloc);
ConfigCompilerContext::GetContext()->AddType(m_Type);
stream.open(path.CStr(), ifstream::in);
if (!stream)
- throw_exception(invalid_argument("Could not open config file: " + path));
+ BOOST_THROW_EXCEPTION(invalid_argument("Could not open config file: " + path));
Logger::Write(LogInformation, "config", "Compiling config file: " + path);
if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CompileFile, _1))) {
stringstream msgbuf;
msgbuf << "Include file '" + include + "' does not exist (or no files found for pattern): " << debuginfo;
- throw_exception(invalid_argument(msgbuf.str()));
+ BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str()));
}
}
stringstream message;
message << "Parent object '" << name << "' does not"
" exist (" << m_DebugInfo << ")";
- throw_exception(domain_error(message.str()));
+ BOOST_THROW_EXCEPTION(domain_error(message.str()));
}
parent->InternalLink(dictionary);
DynamicType::Ptr dtype = DynamicType::GetByName(GetType());
if (!dtype)
- throw_exception(runtime_error("Type '" + GetType() + "' does not exist."));
+ BOOST_THROW_EXCEPTION(runtime_error("Type '" + GetType() + "' does not exist."));
if (!dobj)
dobj = dtype->GetObject(GetName());
if (m_Type.IsEmpty()) {
stringstream msgbuf;
msgbuf << "The type name of an object may not be empty: " << m_DebugInfo;
- throw_exception(invalid_argument(msgbuf.str()));
+ BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str()));
}
if (!DynamicType::GetByName(m_Type)) {
stringstream msgbuf;
msgbuf << "The type '" + m_Type + "' is unknown: " << m_DebugInfo;
- throw_exception(invalid_argument(msgbuf.str()));
+ BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str()));
}
if (m_Name.IsEmpty()) {
stringstream msgbuf;
msgbuf << "The name of an object may not be empty: " << m_DebugInfo;
- throw_exception(invalid_argument(msgbuf.str()));
+ BOOST_THROW_EXCEPTION(invalid_argument(msgbuf.str()));
}
ExpressionList::Ptr exprl = boost::make_shared<ExpressionList>();
ScriptFunction::Ptr func = ScriptFunction::GetByName(validator);
if (!func)
- throw_exception(invalid_argument("Validator function '" + validator + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Validator function '" + validator + "' does not exist."));
vector<Value> arguments;
arguments.push_back(LocationToString(locations));
switch (m_Operator) {
case OperatorExecute:
if (!valueExprl)
- throw_exception(invalid_argument("Operand for OperatorExecute must be an ExpressionList."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Operand for OperatorExecute must be an ExpressionList."));
valueExprl->Execute(dictionary);
" += (non-dictionary and"
" dictionary) ("
<< m_DebugInfo << ")";
- throw_exception(domain_error(message.str()));
+ BOOST_THROW_EXCEPTION(domain_error(message.str()));
}
dict = boost::make_shared<Dictionary>();
stringstream message;
message << "+= only works for dictionaries ("
<< m_DebugInfo << ")";
- throw_exception(domain_error(message.str()));
+ BOOST_THROW_EXCEPTION(domain_error(message.str()));
}
break;
default:
- throw_exception(runtime_error("Not yet implemented."));
+ BOOST_THROW_EXCEPTION(runtime_error("Not yet implemented."));
}
dictionary->Set(m_Key, newValue);
return;
}
- throw_exception(runtime_error("Encountered unknown type while dumping value."));
+ BOOST_THROW_EXCEPTION(runtime_error("Encountered unknown type while dumping value."));
}
void Expression::Dump(ostream& fp, int indent) const
fp << "+=";
break;
default:
- throw_exception(runtime_error("Not yet implemented."));
+ BOOST_THROW_EXCEPTION(runtime_error("Not yet implemented."));
}
fp << " ";
return;
if (line[0] != '[')
- throw_exception(invalid_argument("Missing timestamp in command: " + line));
+ BOOST_THROW_EXCEPTION(invalid_argument("Missing timestamp in command: " + line));
size_t pos = line.FindFirstOf("]");
if (pos == String::NPos)
- throw_exception(invalid_argument("Missing timestamp in command: " + line));
+ BOOST_THROW_EXCEPTION(invalid_argument("Missing timestamp in command: " + line));
String timestamp = line.SubStr(1, pos - 1);
String args = line.SubStr(pos + 2, String::NPos);
double ts = Convert::ToDouble(timestamp);
if (ts == 0)
- throw_exception(invalid_argument("Invalid timestamp in command: " + line));
+ BOOST_THROW_EXCEPTION(invalid_argument("Invalid timestamp in command: " + line));
vector<String> argv = args.Split(is_any_of(";"));
if (argv.size() == 0)
- throw_exception(invalid_argument("Missing arguments in command: " + line));
+ BOOST_THROW_EXCEPTION(invalid_argument("Missing arguments in command: " + line));
vector<String> argvExtra(argv.begin() + 1, argv.end());
Execute(ts, argv[0], argvExtra);
it = m_Commands.find(command);
if (it == m_Commands.end())
- throw_exception(invalid_argument("The external command '" + command + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The external command '" + command + "' does not exist."));
it->second(time, arguments);
}
void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const vector<String>& arguments)
{
if (arguments.size() < 4)
- throw_exception(invalid_argument("Expected 4 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 4 arguments."));
if (!Service::Exists(arguments[1]))
- throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist."));
Service::Ptr service = Service::GetByName(arguments[1]);
if (!service->GetEnablePassiveChecks())
- throw_exception(invalid_argument("Got passive check result for service '" + arguments[1] + "' which has passive checks disabled."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Got passive check result for service '" + arguments[1] + "' which has passive checks disabled."));
int exitStatus = Convert::ToDouble(arguments[2]);
Dictionary::Ptr result = PluginCheckTask::ParseCheckOutput(arguments[3]);
void ExternalCommandProcessor::ScheduleSvcCheck(double, const vector<String>& arguments)
{
if (arguments.size() < 3)
- throw_exception(invalid_argument("Expected 3 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 3 arguments."));
if (!Service::Exists(arguments[1]))
- throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist."));
Service::Ptr service = Service::GetByName(arguments[1]);
void ExternalCommandProcessor::ScheduleForcedSvcCheck(double, const vector<String>& arguments)
{
if (arguments.size() < 3)
- throw_exception(invalid_argument("Expected 3 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 3 arguments."));
if (!Service::Exists(arguments[1]))
- throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist."));
Service::Ptr service = Service::GetByName(arguments[1]);
void ExternalCommandProcessor::EnableSvcCheck(double, const vector<String>& arguments)
{
if (arguments.size() < 2)
- throw_exception(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
if (!Service::Exists(arguments[1]))
- throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist."));
Service::Ptr service = Service::GetByName(arguments[1]);
void ExternalCommandProcessor::DisableSvcCheck(double, const vector<String>& arguments)
{
if (arguments.size() < 2)
- throw_exception(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
if (!Service::Exists(arguments[1]))
- throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist."));
Service::Ptr service = Service::GetByName(arguments[1]);
void ExternalCommandProcessor::ScheduleForcedHostSvcChecks(double, const vector<String>& arguments)
{
if (arguments.size() < 2)
- throw_exception(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
if (!Host::Exists(arguments[0]))
- throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist."));
double planned_check = Convert::ToDouble(arguments[1]);
void ExternalCommandProcessor::ScheduleHostSvcChecks(double, const vector<String>& arguments)
{
if (arguments.size() < 2)
- throw_exception(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
if (!Host::Exists(arguments[0]))
- throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist."));
double planned_check = Convert::ToDouble(arguments[1]);
void ExternalCommandProcessor::EnableHostSvcChecks(double, const vector<String>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
if (!Host::Exists(arguments[0]))
- throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist."));
Host::Ptr host = Host::GetByName(arguments[0]);
void ExternalCommandProcessor::DisableHostSvcChecks(double, const vector<String>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Expected 1 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 arguments."));
if (!Host::Exists(arguments[0]))
- throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist."));
Host::Ptr host = Host::GetByName(arguments[0]);
void ExternalCommandProcessor::AcknowledgeSvcProblem(double, const vector<String>& arguments)
{
if (arguments.size() < 7)
- throw_exception(invalid_argument("Expected 7 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 7 arguments."));
if (!Service::Exists(arguments[1]))
- throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist."));
bool sticky = Convert::ToBool(arguments[2]);
Service::Ptr service = Service::GetByName(arguments[1]);
if (service->GetState() == StateOK)
- throw_exception(invalid_argument("The service '" + arguments[1] + "' is OK."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' is OK."));
Logger::Write(LogInformation, "icinga", "Setting acknowledgement for service '" + service->GetName() + "'");
service->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
void ExternalCommandProcessor::AcknowledgeSvcProblemExpire(double, const vector<String>& arguments)
{
if (arguments.size() < 8)
- throw_exception(invalid_argument("Expected 8 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments."));
if (!Service::Exists(arguments[1]))
- throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist."));
bool sticky = Convert::ToBool(arguments[2]);
double timestamp = Convert::ToDouble(arguments[5]);
Service::Ptr service = Service::GetByName(arguments[1]);
if (service->GetState() == StateOK)
- throw_exception(invalid_argument("The service '" + arguments[1] + "' is OK."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' is OK."));
Logger::Write(LogInformation, "icinga", "Setting timed acknowledgement for service '" + service->GetName() + "'");
service->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
void ExternalCommandProcessor::RemoveSvcAcknowledgement(double, const vector<String>& arguments)
{
if (arguments.size() < 2)
- throw_exception(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
if (!Service::Exists(arguments[1]))
- throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist."));
Service::Ptr service = Service::GetByName(arguments[1]);
void ExternalCommandProcessor::AcknowledgeHostProblem(double, const vector<String>& arguments)
{
if (arguments.size() < 6)
- throw_exception(invalid_argument("Expected 6 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 6 arguments."));
if (!Host::Exists(arguments[0]))
- throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist."));
bool sticky = Convert::ToBool(arguments[0]);
Host::Ptr host = Host::GetByName(arguments[0]);
if (host->IsUp())
- throw_exception(invalid_argument("The host '" + arguments[0] + "' is OK."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' is OK."));
Logger::Write(LogInformation, "icinga", "Setting acknowledgement for host '" + host->GetName() + "'");
host->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
void ExternalCommandProcessor::AcknowledgeHostProblemExpire(double, const vector<String>& arguments)
{
if (arguments.size() < 7)
- throw_exception(invalid_argument("Expected 7 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 7 arguments."));
if (!Host::Exists(arguments[0]))
- throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist."));
bool sticky = Convert::ToBool(arguments[1]);
double timestamp = Convert::ToDouble(arguments[4]);
Host::Ptr host = Host::GetByName(arguments[0]);
if (host->IsUp())
- throw_exception(invalid_argument("The host '" + arguments[0] + "' is OK."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' is OK."));
Logger::Write(LogInformation, "icinga", "Setting timed acknowledgement for host '" + host->GetName() + "'");
host->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
void ExternalCommandProcessor::RemoveHostAcknowledgement(double, const vector<String>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
if (!Host::Exists(arguments[0]))
- throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist."));
Host::Ptr host = Host::GetByName(arguments[0]);
void ExternalCommandProcessor::EnableHostgroupSvcChecks(double, const vector<String>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
if (!HostGroup::Exists(arguments[0]))
- throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
void ExternalCommandProcessor::DisableHostgroupSvcChecks(double, const vector<String>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
if (!HostGroup::Exists(arguments[0]))
- throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
void ExternalCommandProcessor::EnableServicegroupSvcChecks(double, const vector<String>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
if (!ServiceGroup::Exists(arguments[0]))
- throw_exception(invalid_argument("The service group '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service group '" + arguments[0] + "' does not exist."));
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
void ExternalCommandProcessor::DisableServicegroupSvcChecks(double, const vector<String>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
if (!ServiceGroup::Exists(arguments[0]))
- throw_exception(invalid_argument("The service group '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service group '" + arguments[0] + "' does not exist."));
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
void ExternalCommandProcessor::EnablePassiveSvcChecks(double, const vector<String>& arguments)
{
if (arguments.size() < 2)
- throw_exception(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
if (!Service::Exists(arguments[1]))
- throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist."));
Service::Ptr service = Service::GetByName(arguments[1]);
void ExternalCommandProcessor::DisablePassiveSvcChecks(double, const vector<String>& arguments)
{
if (arguments.size() < 2)
- throw_exception(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
if (!Service::Exists(arguments[1]))
- throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist."));
Service::Ptr service = Service::GetByName(arguments[1]);
void ExternalCommandProcessor::EnableServicegroupPassiveSvcChecks(double, const vector<String>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
if (!ServiceGroup::Exists(arguments[0]))
- throw_exception(invalid_argument("The service group '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service group '" + arguments[0] + "' does not exist."));
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
void ExternalCommandProcessor::DisableServicegroupPassiveSvcChecks(double, const vector<String>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
if (!ServiceGroup::Exists(arguments[0]))
- throw_exception(invalid_argument("The service group '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service group '" + arguments[0] + "' does not exist."));
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
void ExternalCommandProcessor::EnableHostgroupPassiveSvcChecks(double, const vector<String>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
if (!HostGroup::Exists(arguments[0]))
- throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
void ExternalCommandProcessor::DisableHostgroupPassiveSvcChecks(double, const vector<String>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
if (!HostGroup::Exists(arguments[0]))
- throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
void ExternalCommandProcessor::ProcessFile(double, const vector<String>& arguments)
{
if (arguments.size() < 2)
- throw_exception(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
String file = arguments[0];
bool del = Convert::ToBool(arguments[1]);
Execute(line);
} catch (const exception& ex) {
stringstream msgbuf;
- msgbuf << "External command failed: " << ex.what();
+ msgbuf << "External command failed: " << diagnostic_information(ex);
Logger::Write(LogWarning, "icinga", msgbuf.str());
}
}
void ExternalCommandProcessor::ScheduleSvcDowntime(double, const vector<String>& arguments)
{
if (arguments.size() < 9)
- throw_exception(invalid_argument("Expected 9 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 9 arguments."));
if (!Service::Exists(arguments[1]))
- throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist."));
Service::Ptr service = Service::GetByName(arguments[1]);
void ExternalCommandProcessor::DelSvcDowntime(double, const vector<String>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
int id = Convert::ToLong(arguments[0]);
Logger::Write(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
void ExternalCommandProcessor::ScheduleHostDowntime(double, const vector<String>& arguments)
{
if (arguments.size() < 8)
- throw_exception(invalid_argument("Expected 8 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments."));
if (!Host::Exists(arguments[0]))
- throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist."));
Host::Ptr host = Host::GetByName(arguments[0]);
void ExternalCommandProcessor::DelHostDowntime(double, const vector<String>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
int id = Convert::ToLong(arguments[0]);
Logger::Write(LogInformation, "icinga", "Removing downtime ID " + arguments[0]);
void ExternalCommandProcessor::ScheduleHostSvcDowntime(double, const vector<String>& arguments)
{
if (arguments.size() < 8)
- throw_exception(invalid_argument("Expected 8 argument."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 argument."));
if (!Host::Exists(arguments[0]))
- throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist."));
Host::Ptr host = Host::GetByName(arguments[0]);
void ExternalCommandProcessor::ScheduleHostgroupHostDowntime(double, const vector<String>& arguments)
{
if (arguments.size() < 8)
- throw_exception(invalid_argument("Expected 8 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments."));
if (!HostGroup::Exists(arguments[0]))
- throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
void ExternalCommandProcessor::ScheduleHostgroupSvcDowntime(double, const vector<String>& arguments)
{
if (arguments.size() < 8)
- throw_exception(invalid_argument("Expected 8 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments."));
if (!HostGroup::Exists(arguments[0]))
- throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
HostGroup::Ptr hg = HostGroup::GetByName(arguments[0]);
void ExternalCommandProcessor::ScheduleServicegroupHostDowntime(double, const vector<String>& arguments)
{
if (arguments.size() < 8)
- throw_exception(invalid_argument("Expected 8 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments."));
if (!ServiceGroup::Exists(arguments[0]))
- throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
void ExternalCommandProcessor::ScheduleServicegroupSvcDowntime(double, const vector<String>& arguments)
{
if (arguments.size() < 8)
- throw_exception(invalid_argument("Expected 8 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 8 arguments."));
if (!ServiceGroup::Exists(arguments[0]))
- throw_exception(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host group '" + arguments[0] + "' does not exist."));
ServiceGroup::Ptr sg = ServiceGroup::GetByName(arguments[0]);
void ExternalCommandProcessor::AddHostComment(double, const vector<String>& arguments)
{
if (arguments.size() < 4)
- throw_exception(invalid_argument("Expected 4 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 4 arguments."));
if (!Host::Exists(arguments[0]))
- throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist."));
Host::Ptr host = Host::GetByName(arguments[0]);
void ExternalCommandProcessor::DelHostComment(double, const vector<String>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
int id = Convert::ToLong(arguments[0]);
Logger::Write(LogInformation, "icinga", "Removing comment ID " + arguments[0]);
void ExternalCommandProcessor::AddSvcComment(double, const vector<String>& arguments)
{
if (arguments.size() < 5)
- throw_exception(invalid_argument("Expected 5 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 5 arguments."));
if (!Service::Exists(arguments[1]))
- throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist."));
Service::Ptr service = Service::GetByName(arguments[1]);
void ExternalCommandProcessor::DelSvcComment(double, const vector<String>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
int id = Convert::ToLong(arguments[0]);
Logger::Write(LogInformation, "icinga", "Removing comment ID " + arguments[0]);
void ExternalCommandProcessor::DelAllHostComments(double, const vector<String>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Expected 1 argument."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
if (!Host::Exists(arguments[0]))
- throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The host '" + arguments[0] + "' does not exist."));
Host::Ptr host = Host::GetByName(arguments[0]);
void ExternalCommandProcessor::DelAllSvcComments(double, const vector<String>& arguments)
{
if (arguments.size() < 2)
- throw_exception(invalid_argument("Expected 2 arguments."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
if (!Service::Exists(arguments[1]))
- throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("The service '" + arguments[1] + "' does not exist."));
Service::Ptr service = Service::GetByName(arguments[1]);
DynamicObject::Ptr configObject = DynamicObject::GetObject("Host", name);
if (!configObject)
- throw_exception(invalid_argument("Host '" + name + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Host '" + name + "' does not exist."));
return dynamic_pointer_cast<Host>(configObject);
}
CopyServiceAttributes(host, service, builder);
} else {
- throw_exception(invalid_argument("Service description must be either a string or a dictionary."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Service description must be either a string or a dictionary."));
}
ConfigItem::Ptr serviceItem = builder->Compile();
void Host::ValidateServiceDictionary(const ScriptTask::Ptr& task, const vector<Value>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Missing argument: Location must be specified."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Location must be specified."));
if (arguments.size() < 2)
- throw_exception(invalid_argument("Missing argument: Attribute dictionary must be specified."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Attribute dictionary must be specified."));
String location = arguments[0];
Dictionary::Ptr attrs = arguments[1];
DynamicObject::Ptr configObject = DynamicObject::GetObject("HostGroup", name);
if (!configObject)
- throw_exception(invalid_argument("HostGroup '" + name + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("HostGroup '" + name + "' does not exist."));
return dynamic_pointer_cast<HostGroup>(configObject);
}
pos_second = result.FindFirstOf("$", pos_first + 1);
if (pos_second == String::NPos)
- throw_exception(runtime_error("Closing $ not found in macro format String."));
+ BOOST_THROW_EXCEPTION(runtime_error("Closing $ not found in macro format String."));
String name = result.SubStr(pos_first + 1, pos_second - pos_first - 1);
String value;
}
if (!resolved)
- throw_exception(runtime_error("Macro '" + name + "' is not defined."));
+ BOOST_THROW_EXCEPTION(runtime_error("Macro '" + name + "' is not defined."));
}
return result;
void NullCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Missing argument: Service must be specified."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Service must be specified."));
Dictionary::Ptr cr = boost::make_shared<Dictionary>();
cr->Set("state", StateUnknown);
void PluginCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Value>& arguments)
{
if (arguments.size() < 1)
- throw_exception(invalid_argument("Missing argument: Service must be specified."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Missing argument: Service must be specified."));
Value vservice = arguments[0];
if (!vservice.IsObjectType<DynamicObject>())
- throw_exception(invalid_argument("Argument must be a config object."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Argument must be a config object."));
Service::Ptr service = static_cast<Service::Ptr>(vservice);
DynamicObject::Ptr configObject = DynamicObject::GetObject("Service", name);
if (!configObject)
- throw_exception(invalid_argument("Service '" + name + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Service '" + name + "' does not exist."));
return dynamic_pointer_cast<Service>(configObject);
}
String hostname = Get("host_name");
if (hostname.IsEmpty())
- throw_exception(runtime_error("Service object is missing the 'host_name' property."));
+ BOOST_THROW_EXCEPTION(runtime_error("Service object is missing the 'host_name' property."));
return Host::GetByName(hostname);
}
value = Get("next_check");
if (value.IsEmpty())
- throw_exception(runtime_error("Failed to schedule next check."));
+ BOOST_THROW_EXCEPTION(runtime_error("Failed to schedule next check."));
}
return value;
} catch (const exception& ex) {
stringstream msgbuf;
msgbuf << "Exception occured during check for service '"
- << GetName() << "': " << ex.what();
+ << GetName() << "': " << diagnostic_information(ex);
String message = msgbuf.str();
Logger::Write(LogWarning, "checker", message);
DynamicObject::Ptr configObject = DynamicObject::GetObject("ServiceGroup", name);
if (!configObject)
- throw_exception(invalid_argument("ServiceGroup '" + name + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("ServiceGroup '" + name + "' does not exist."));
return dynamic_pointer_cast<ServiceGroup>(configObject);
}
DynamicObject::Ptr configObject = DynamicObject::GetObject("TimePeriod", name);
if (!configObject)
- throw_exception(invalid_argument("TimePeriod '" + name + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("TimePeriod '" + name + "' does not exist."));
return dynamic_pointer_cast<TimePeriod>(configObject);
}
DynamicObject::Ptr configObject = DynamicObject::GetObject("Endpoint", name);
if (!configObject)
- throw_exception(invalid_argument("Endpoint '" + name + "' does not exist."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Endpoint '" + name + "' does not exist."));
return dynamic_pointer_cast<Endpoint>(configObject);
}
//m_TopicHandlers[method] -= callback;
//UnregisterSubscription(method);
- throw_exception(NotImplementedException());
+ BOOST_THROW_EXCEPTION(NotImplementedException());
}
void Endpoint::OnAttributeChanged(const String& name, const Value& oldValue)
GetClient()->CheckException();
} catch (const exception& ex) {
stringstream message;
- message << "Error occured for JSON-RPC socket: Message=" << ex.what();
+ message << "Error occured for JSON-RPC socket: Message=" << diagnostic_information(ex);
Logger::Write(LogWarning, "jsonrpc", message.str());
}*/
shared_ptr<SSL_CTX> sslContext = GetSSLContext();
if (!sslContext)
- throw_exception(logic_error("SSL context is required for AddListener()"));
+ BOOST_THROW_EXCEPTION(logic_error("SSL context is required for AddListener()"));
stringstream s;
s << "Adding new listener: port " << service;
shared_ptr<SSL_CTX> sslContext = GetSSLContext();
if (!sslContext)
- throw_exception(logic_error("SSL context is required for AddConnection()"));
+ BOOST_THROW_EXCEPTION(logic_error("SSL context is required for AddConnection()"));
TcpSocket::Ptr client = boost::make_shared<TcpSocket>();
client->Connect(node, service);
{
String method;
if (!message.GetMethod(&method))
- throw_exception(invalid_argument("Message is missing the 'method' property."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Message is missing the 'method' property."));
vector<Endpoint::Ptr> candidates;
DynamicObject::Ptr object;
{
String id;
if (message.GetID(&id))
- throw_exception(invalid_argument("Multicast requests must not have an ID."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Multicast requests must not have an ID."));
String method;
if (!message.GetMethod(&method))
- throw_exception(invalid_argument("Message is missing the 'method' property."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Message is missing the 'method' property."));
DynamicObject::Ptr object;
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Endpoint")->GetObjects()) {
{
String id;
if (!message.GetID(&id))
- throw_exception(invalid_argument("Response message must have a message ID."));
+ BOOST_THROW_EXCEPTION(invalid_argument("Response message must have a message ID."));
map<String, PendingRequest>::iterator it;
it = m_Requests.find(id);
Value value = Value::Deserialize(jsonString);
if (!value.IsObjectType<Dictionary>()) {
- throw_exception(invalid_argument("JSON-RPC"
+ BOOST_THROW_EXCEPTION(invalid_argument("JSON-RPC"
" message must be a dictionary."));
}
} catch (const exception& ex) {
Logger::Write(LogCritical, "remoting", "Exception"
" while processing message from JSON-RPC client: " +
- String(ex.what()));
+ diagnostic_information(ex));
}
}
}