Unverified Commit 37dfac7e authored by David Boucher's avatar David Boucher Committed by GitHub
Browse files

fix(timeout): timeout is a timestamp, more accurate than time_t (#15)

parent 0a2f2105
......@@ -28,7 +28,7 @@ include_directories("${PROJECT_SOURCE_DIR}/inc")
# Project version.
set(CONNECTOR_PERL_MAJOR 19)
set(CONNECTOR_PERL_MINOR 04)
set(CONNECTOR_PERL_PATCH 0)
set(CONNECTOR_PERL_PATCH 1)
set(CONNECTOR_PERL_VERSION "${CONNECTOR_PERL_MAJOR}.${CONNECTOR_PERL_MINOR}.${CONNECTOR_PERL_PATCH}")
add_definitions(-DCENTREON_CONNECTOR_PERL_VERSION=\"${CONNECTOR_PERL_VERSION}\")
......
===============================
Centreon Perl Connector 19.04.1
===============================
*********
Bug fixes
*********
wrong check timeout
===================
The timeout given by Engine to the connector was decremented by 1. Moreover it
was not sufficiently accurate, so the timeout was reached too soon. Now it is
considered as milliseconds with the good value.
......@@ -24,6 +24,7 @@
# include "com/centreon/connector/perl/namespace.hh"
# include "com/centreon/connector/perl/pipe_handle.hh"
# include "com/centreon/handle_listener.hh"
# include "com/centreon/timestamp.hh"
CCCP_BEGIN()
......@@ -46,7 +47,7 @@ namespace checks {
pid_t execute(
unsigned long long cmd_id,
std::string const& cmd,
time_t tmt);
const timestamp& tmt);
void listen(listener* listnr);
void on_timeout(bool final = true);
void read(handle& h);
......
......@@ -22,6 +22,7 @@
# include <ctime>
# include <string>
# include "com/centreon/connector/perl/namespace.hh"
# include "com/centreon/timestamp.hh"
CCCP_BEGIN()
......@@ -43,7 +44,7 @@ namespace orders {
virtual void on_error() = 0;
virtual void on_execute(
unsigned long long cmd_id,
time_t timeout,
const timestamp& timeout,
std::string const& cmd) = 0;
virtual void on_quit() = 0;
virtual void on_version() = 0;
......
......@@ -27,6 +27,7 @@
# include "com/centreon/connector/perl/orders/parser.hh"
# include "com/centreon/connector/perl/reporter.hh"
# include "com/centreon/io/file_stream.hh"
# include "com/centreon/timestamp.hh"
CCCP_BEGIN()
......@@ -51,7 +52,7 @@ public:
void on_error();
void on_execute(
unsigned long long cmd_id,
time_t timeout,
const timestamp& timeout,
std::string const& cmd);
void on_quit();
void on_result(checks::result const& r);
......
......@@ -65,7 +65,6 @@ void check::error(handle& h) {
result r;
r.set_command_id(_cmd_id);
_send_result_and_unregister(r);
return ;
}
/**
......@@ -80,7 +79,7 @@ void check::error(handle& h) {
pid_t check::execute(
unsigned long long cmd_id,
std::string const& cmd,
time_t tmt) {
const timestamp& tmt) {
// Run process.
int fds[3];
_child = embedded_perl::instance().run(cmd, fds);
......@@ -105,7 +104,7 @@ pid_t check::execute(
std::auto_ptr<timeout> t(new timeout(this, false));
_timeout = multiplexer::instance().com::centreon::task_manager::add(
t.get(),
tmt - 1,
tmt,
false,
true);
t.release();
......@@ -122,7 +121,6 @@ void check::listen(listener* listnr) {
log_debug(logging::medium) << "check " << this
<< " is listened by " << listnr;
_listnr = listnr;
return ;
}
/**
......@@ -159,7 +157,6 @@ void check::on_timeout(bool final) {
true);
t.release();
}
return ;
}
/**
......@@ -180,7 +177,6 @@ void check::read(handle& h) {
<< _child << "' stderr";
_stdout.append(buffer, rb);
}
return ;
}
/**
......@@ -222,8 +218,6 @@ void check::terminated(int exit_code) {
r.set_error(_stderr);
r.set_output(_stdout);
_send_result_and_unregister(r);
return ;
}
/**
......@@ -235,7 +229,6 @@ void check::unlisten(listener* listnr) {
log_debug(logging::medium) << "listener " << listnr
<< " stops listening check " << this;
_listnr = NULL;
return ;
}
/**
......@@ -259,7 +252,6 @@ void check::write(handle& h) {
result r;
r.set_command_id(_cmd_id);
_send_result_and_unregister(r);
return ;
}
/**************************************
......@@ -302,6 +294,4 @@ void check::_send_result_and_unregister(result const& r) {
if (_listnr)
_listnr->on_result(r);
}
return ;
}
......@@ -22,6 +22,7 @@
#include "com/centreon/connector/perl/orders/parser.hh"
#include "com/centreon/exceptions/basic.hh"
#include "com/centreon/logging/logger.hh"
#include "com/centreon/timestamp.hh"
using namespace com::centreon::connector::perl::orders;
......@@ -74,7 +75,6 @@ void parser::error(handle& h) {
(void)h;
if (_listnr)
_listnr->on_error();
return ;
}
/**
......@@ -102,7 +102,6 @@ listener* parser::get_listener() const throw () {
*/
void parser::listen(listener* l) throw () {
_listnr = l;
return ;
}
/**
......@@ -158,7 +157,6 @@ void parser::read(handle& h) {
bound = _buffer.find(boundary, 0, sizeof(boundary));
}
}
return ;
}
/**
......@@ -195,7 +193,6 @@ bool parser::want_write(handle& h) {
void parser::_copy(parser const& p) {
_buffer = p._buffer;
_listnr = p._listnr;
return ;
}
/**
......@@ -233,14 +230,13 @@ void parser::_parse(std::string const& cmd) {
pos = end + 1;
// Find timeout value.
end = cmd.find('\0', pos);
time_t timeout(static_cast<time_t>(strtoull(
cmd.c_str() + pos,
&ptr,
10)));
time_t timeout = static_cast<time_t>(strtoull(cmd.c_str() + pos, &ptr, 10));
timestamp ts_timeout = timestamp::now();
if (*ptr)
throw (basic_error() << "invalid execution request received:" \
" bad timeout (" << cmd.c_str() + pos << ")");
timeout += time(NULL);
ts_timeout += timeout;
pos = end + 1;
// Find start time.
end = cmd.find('\0', pos);
......@@ -257,7 +253,7 @@ void parser::_parse(std::string const& cmd) {
if (_listnr)
_listnr->on_execute(
cmd_id,
timeout,
ts_timeout,
cmdline);
}
break ;
......@@ -269,5 +265,4 @@ void parser::_parse(std::string const& cmd) {
throw (basic_error() << "invalid command received (ID "
<< id << ")");
};
return ;
}
......@@ -111,7 +111,7 @@ void policy::on_error() {
*/
void policy::on_execute(
unsigned long long cmd_id,
time_t timeout,
const timestamp& timeout,
std::string const& cmd) {
std::auto_ptr<checks::check> chk(new checks::check);
chk->listen(this);
......
......@@ -28,7 +28,7 @@ include_directories("${PROJECT_SOURCE_DIR}/inc")
# Project version.
set(CONNECTOR_SSH_MAJOR 19)
set(CONNECTOR_SSH_MINOR 04)
set(CONNECTOR_SSH_PATCH 0)
set(CONNECTOR_SSH_PATCH 1)
set(CONNECTOR_SSH_VERSION "${CONNECTOR_SSH_MAJOR}.${CONNECTOR_SSH_MINOR}.${CONNECTOR_SSH_PATCH}")
add_definitions(-DCENTREON_CONNECTOR_SSH_VERSION=\"${CONNECTOR_SSH_VERSION}\")
......
==============================
Centreon SSH Connector 19.04.1
==============================
*********
Bug fixes
*********
wrong check timeout
===================
The timeout given by Engine to the connector was decremented by 1. Moreover it
was not sufficiently accurate, so the timeout was reached too soon. Now it is
considered as milliseconds with the good value.
......@@ -26,6 +26,7 @@
# include "com/centreon/connector/ssh/namespace.hh"
# include "com/centreon/connector/ssh/sessions/listener.hh"
# include "com/centreon/connector/ssh/sessions/session.hh"
# include "com/centreon/timestamp.hh"
CCCS_BEGIN()
......@@ -49,7 +50,7 @@ namespace checks {
sessions::session& sess,
unsigned long long cmd_id,
std::list<std::string> const& cmds,
time_t tmt);
const timestamp& tmt);
void listen(checks::listener* listnr);
void on_available(sessions::session& sess);
void on_close(sessions::session& sess);
......
......@@ -23,6 +23,7 @@
# include <list>
# include <string>
# include "com/centreon/connector/ssh/namespace.hh"
# include "com/centreon/timestamp.hh"
CCCS_BEGIN()
......@@ -46,7 +47,7 @@ namespace orders {
char const* msg) = 0;
virtual void on_execute(
unsigned long long cmd_id,
time_t timeout,
const timestamp& timeout,
std::string const& host,
unsigned short port,
std::string const& user,
......
......@@ -28,6 +28,7 @@
# include "com/centreon/connector/ssh/reporter.hh"
# include "com/centreon/connector/ssh/sessions/credentials.hh"
# include "com/centreon/io/file_stream.hh"
# include "com/centreon/timestamp.hh"
CCCS_BEGIN()
......@@ -57,7 +58,7 @@ public:
char const* msg);
void on_execute(
unsigned long long cmd_id,
time_t timeout,
const timestamp& timeout,
std::string const& host,
unsigned short port,
std::string const& user,
......
......@@ -95,7 +95,7 @@ void check::execute(
sessions::session& sess,
unsigned long long cmd_id,
std::list<std::string> const& cmds,
time_t tmt) {
const timestamp& tmt) {
// Log message.
log_debug(logging::low) << "check "
<< this << " has ID " << cmd_id;
......
......@@ -241,10 +241,12 @@ void parser::_parse(std::string const& cmd) {
cmd.c_str() + pos,
&ptr,
10)));
timestamp ts_timeout = timestamp::now();
if (*ptr)
throw (basic_error() << "invalid execution request received:" \
" bad timeout (" << cmd.c_str() + pos << ")");
timeout += time(NULL);
ts_timeout += timeout;
pos = end + 1;
// Find start time.
end = cmd.find('\0', pos);
......@@ -272,7 +274,7 @@ void parser::_parse(std::string const& cmd) {
if (opt.get_timeout()
&& opt.get_timeout() < static_cast<unsigned int>(timeout))
timeout = time(NULL) + opt.get_timeout();
ts_timeout = timestamp::now() + opt.get_timeout();
else if (opt.get_timeout() > static_cast<unsigned int>(timeout))
throw (basic_error() << "invalid execution request " \
"received: timeout > to monitoring engine timeout");
......@@ -287,7 +289,7 @@ void parser::_parse(std::string const& cmd) {
if (_listnr)
_listnr->on_execute(
cmd_id,
timeout,
ts_timeout,
opt.get_host(),
opt.get_port(),
opt.get_user(),
......@@ -307,5 +309,4 @@ void parser::_parse(std::string const& cmd) {
throw (basic_error() << "invalid command received (ID "
<< id << ")");
};
return ;
}
......@@ -143,7 +143,7 @@ void policy::on_error(unsigned long long cmd_id, char const* msg) {
*/
void policy::on_execute(
unsigned long long cmd_id,
time_t timeout,
const timestamp& timeout,
std::string const& host,
unsigned short port,
std::string const& user,
......@@ -157,7 +157,7 @@ void policy::on_execute(
// Log message.
log_info(logging::medium) << "got request to execute check "
<< cmd_id << " on session " << user << "@" << host
<< " (timeout " << timeout << ", first command \""
<< " (timeout " << timeout.to_seconds() << ", first command \""
<< cmds.front() << "\")";
// Credentials.
......
......@@ -77,7 +77,6 @@ void fake_listener::on_eof() {
callback_info ci;
ci.callback = cb_eof;
_callbacks.push_back(ci);
return ;
}
/**
......@@ -94,7 +93,6 @@ void fake_listener::on_error(
callback_info ci;
ci.callback = cb_error;
_callbacks.push_back(ci);
return ;
}
/**
......@@ -114,7 +112,7 @@ void fake_listener::on_error(
*/
void fake_listener::on_execute(
unsigned long long cmd_id,
time_t timeout,
const timestamp& timeout,
std::string const& host,
unsigned short port,
std::string const& user,
......@@ -138,7 +136,6 @@ void fake_listener::on_execute(
ci.skip_stderr = skip_stderr;
ci.is_ipv6 = is_ipv6;
_callbacks.push_back(ci);
return ;
}
/**
......@@ -148,7 +145,6 @@ void fake_listener::on_quit() {
callback_info ci;
ci.callback = cb_quit;
_callbacks.push_back(ci);
return ;
}
/**
......@@ -158,7 +154,6 @@ void fake_listener::on_version() {
callback_info ci;
ci.callback = cb_version;
_callbacks.push_back(ci);
return ;
}
/**************************************
......@@ -174,7 +169,6 @@ void fake_listener::on_version() {
*/
void fake_listener::_copy(fake_listener const& fl) {
_callbacks = fl._callbacks;
return ;
}
/**************************************
......@@ -207,7 +201,7 @@ bool operator==(
if ((it1->callback != it2->callback)
|| ((it1->callback == fake_listener::cb_execute)
&& ((it1->cmd_id != it2->cmd_id)
|| (fabs(it1->timeout - it2->timeout) >= 1.0)
|| (fabs(it1->timeout.to_seconds() - it2->timeout.to_seconds()) >= 1.0)
|| (it1->host != it2->host)
|| (it1->port != it2->port)
|| (it1->user != it2->user)
......
......@@ -21,6 +21,9 @@
# include <list>
# include "com/centreon/connector/ssh/orders/listener.hh"
# include "com/centreon/timestamp.hh"
using namespace com::centreon;
/**
* @class fake_listener fake_listener.hh "test/orders/fake_listener.hh"
......@@ -42,7 +45,7 @@ public:
e_callback callback;
unsigned long long
cmd_id;
time_t timeout;
timestamp timeout;
std::string host;
unsigned short port;
std::string user;
......@@ -67,7 +70,7 @@ public:
char const* msg);
void on_execute(
unsigned long long cmd_id,
time_t timeout,
const timestamp& timeout,
std::string const& host,
unsigned short port,
std::string const& user,
......
......@@ -68,7 +68,7 @@ int main() {
retval = 1;
else {
fake_listener::callback_info info1, info2;
time_t comparison_timeout(time(NULL) + 4242);
timestamp comparison_timeout = timestamp::now() + 4242;
info1 = *listnr.get_callbacks().begin();
info2 = *++listnr.get_callbacks().begin();
std::cout << "order ID: " << fake_listener::cb_execute
......@@ -76,8 +76,8 @@ int main() {
<< " " << info1.callback << std::endl
<< "command ID: " << 1478523697531598258ull << std::endl
<< " " << info1.cmd_id << std::endl
<< "timeout: " << comparison_timeout << std::endl
<< " " << info1.timeout << std::endl
<< "timeout: " << comparison_timeout.to_seconds() << std::endl
<< " " << info1.timeout.to_seconds() << std::endl
<< "host: " << "localhost" << std::endl
<< " " << info1.host << std::endl
<< "user: " << "root" << std::endl
......@@ -89,7 +89,7 @@ int main() {
<< " " << info1.cmds.front() << std::endl;
retval |= ((info1.callback != fake_listener::cb_execute)
|| (info1.cmd_id != 1478523697531598258ull)
|| ((comparison_timeout - info1.timeout) > 1)
|| ((comparison_timeout.to_mseconds() - info1.timeout.to_mseconds()) > 1)
|| (info1.host != "localhost")
|| (info1.user != "root")
|| (info1.password != "myverysecretpassword")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment