Skip to content

Commit

Permalink
wip(gorgone)
Browse files Browse the repository at this point in the history
MON-157180
  • Loading branch information
Evan-Adam committed Feb 11, 2025
1 parent ceccd6b commit d4d5854
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 20 deletions.
83 changes: 64 additions & 19 deletions gorgone/gorgone/class/core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ sub init_server_keys {
);
return if ($code == 0);
$self->{logger}->writeLogInfo("[core] Private key file '$self->{config}->{configuration}->{gorgone}->{gorgonecore}->{privkey}' written");

$code = gorgone::standard::misc::write_file(
logger => $self->{logger},
filename => $self->{config}->{configuration}->{gorgone}->{gorgonecore}->{pubkey},
Expand Down Expand Up @@ -175,7 +175,8 @@ sub init {
);

$self->init_server_keys();

$self->{config}->{configuration}->{gorgone}->{gorgonecore}->{external_com_msg_size} = 150_000
if (!defined($self->{config}->{configuration}->{gorgone}->{gorgonecore}->{external_com_msg_size}) || $self->{config}->{configuration}->{gorgone}->{gorgonecore}->{external_com_msg_size} !~ /\d+/);
$self->{config}->{configuration}->{gorgone}->{gorgonecore}->{external_com_zmq_tcp_keepalive} =
defined($self->{config}->{configuration}->{gorgone}->{gorgonecore}->{external_com_zmq_tcp_keepalive}) && $self->{config}->{configuration}->{gorgone}->{gorgonecore}->{external_com_zmq_tcp_keepalive} =~ /^(0|1)$/ ? $1 : 1;

Expand Down Expand Up @@ -230,7 +231,7 @@ sub init {
};
}

$self->{config}->{configuration}->{gorgone}->{gorgonecore}->{timeout} =
$self->{config}->{configuration}->{gorgone}->{gorgonecore}->{timeout} =
defined($self->{config}->{configuration}->{gorgone}->{gorgonecore}->{timeout}) && $self->{config}->{configuration}->{gorgone}->{gorgonecore}->{timeout} =~ /(\d+)/ ? $1 : 50;

$self->{config}->{configuration}->{gorgone}->{gorgonecore}->{external_com_cipher} = 'AES'
Expand Down Expand Up @@ -278,7 +279,7 @@ sub init {
$self->{hostname} = $sysname;
}

$self->{config}->{configuration}->{gorgone}->{gorgonecore}->{proxy_name} =
$self->{config}->{configuration}->{gorgone}->{gorgonecore}->{proxy_name} =
(defined($self->{config}->{configuration}->{gorgone}->{gorgonecore}->{proxy_name}) && $self->{config}->{configuration}->{gorgone}->{gorgonecore}->{proxy_name} ne '') ? $self->{config}->{configuration}->{gorgone}->{gorgonecore}->{proxy_name} : 'proxy';
$self->{id} = $self->{config}->{configuration}->{gorgone}->{gorgonecore}->{id};

Expand Down Expand Up @@ -380,7 +381,7 @@ sub handle_CHLD {
$self->{logger}->writeLogDebug("[core] Received SIGCLD signal (pid: $child_pid)");
$self->{return_child}->{$child_pid} = time();
}

$SIG{CHLD} = \&class_handle_CHLD;
}

Expand Down Expand Up @@ -425,7 +426,7 @@ sub load_module {
$self->{logger}->writeLogError("[core] Package '$options{config_module}->{package}' already loaded");
return 0;
}

return 0 if (!defined($options{config_module}->{enable}) || $options{config_module}->{enable} eq 'false');
$self->{logger}->writeLogInfo("[core] Module '" . $options{config_module}->{name} . "' is loading");

Expand Down Expand Up @@ -491,7 +492,7 @@ sub load_modules {
$self->load_module(config_module => { name => 'dbcleaner', package => 'gorgone::modules::core::dbcleaner::hooks', enable => 'true' });

# Load internal functions
foreach my $method_name (('addlistener', 'putlog', 'getlog', 'kill', 'ping',
foreach my $method_name (('addlistener', 'putlog', 'getlog', 'kill', 'ping',
'getthumbprint', 'constatus', 'setcoreid', 'synclogs', 'loadmodule', 'unloadmodule', 'information', 'setmodulekey')) {
unless ($self->{internal_register}->{$method_name} = gorgone::standard::library->can($method_name)) {
$self->{logger}->writeLogError("[core] No function '$method_name'");
Expand Down Expand Up @@ -654,7 +655,7 @@ sub message_run {
$token = gorgone::standard::library::generate_token();
}

if ($action !~ /^(?:ADDLISTENER|PUTLOG|GETLOG|KILL|PING|CONSTATUS|SETCOREID|SETMODULEKEY|SYNCLOGS|LOADMODULE|UNLOADMODULE|INFORMATION|GETTHUMBPRINT|BCAST.*)$/ &&
if ($action !~ /^(?:ADDLISTENER|PUTLOG|GETLOG|KILL|PING|CONSTATUS|SETCOREID|SETMODULEKEY|SYNCLOGS|LOADMODULE|UNLOADMODULE|INFORMATION|GETTHUMBPRINT|BCAST.*)$/ &&
!defined($target) && !defined($self->{modules_events}->{$action})) {
gorgone::standard::library::add_history({
dbh => $self->{db_gorgone},
Expand Down Expand Up @@ -684,7 +685,7 @@ sub message_run {

# Check Routing
if (defined($target)) {
if (!defined($self->{modules_id}->{ $self->{config}->{configuration}->{gorgone}->{gorgonecore}->{proxy_name} }) ||
if (!defined($self->{modules_id}->{ $self->{config}->{configuration}->{gorgone}->{gorgonecore}->{proxy_name} }) ||
!defined($self->{modules_register}->{ $self->{modules_id}->{ $self->{config}->{configuration}->{gorgone}->{gorgonecore}->{proxy_name} } })) {
gorgone::standard::library::add_history({
dbh => $self->{db_gorgone},
Expand All @@ -703,7 +704,7 @@ sub message_run {
$self->{modules_register}->{ $self->{modules_id}->{ $self->{config}->{configuration}->{gorgone}->{gorgonecore}->{proxy_name} } }->{routing}->(
gorgone => $self,
dbh => $self->{db_gorgone},
logger => $self->{logger},
logger => $self->{logger},
action => $action,
token => $token,
target => $target,
Expand Down Expand Up @@ -779,17 +780,61 @@ sub router_internal_event {
router_type => 'internal'
}
);

$self->send_internal_response(
identity => $identity,
response_type => $response_type,
data => $response,
code => $code,
token => $token
);
# we don't want to fragment the response if the max size is configured to 0 (which would mean unlimited size)
# so we don't use defined() here.
if ($self->{config}->{configuration}->{gorgone}->{gorgonecore}->{external_com_msg_size}) {
if (defined($response)
and defined($response->{action})
and $response->{action} eq "getlog"
and defined($response->{result})
and ref($response->{result}) eq "ARRAY") {

my $max_msg_size = $self->{config}->{configuration}->{gorgone}->{gorgonecore}->{external_com_msg_size};
my $to_send = { action => "getlog", id => $response->{id}, result => [] };
my $size = 0;
for my $log (@{$response->{result}}) {
if ($size > $max_msg_size) {
$self->send_internal_response(
identity => $identity,
response_type => $response_type,
data => $log,
code => $code,
token => $token
);
$size = 0;
$to_send->{result} = [];
}

if (length($log->{data}) > $max_msg_size) {
$self->{logger}->writeLogError('[core] cannot send log message created at ' .
$log->ctime . ', too big : ' . length($log
->{data}) . ' > ' . $max_msg_size);
next;
}
push(@{$to_send->{result}}, $log->{data});
$size += length($log->{data});
}
if (scalar(@{$to_send->{result}}) > 0) {
$self->send_internal_response(
identity => $identity,
response_type => $response_type,
data => $to_send,
code => $code,
token => $token
);
}
}
} else {
$self->send_internal_response(
identity => $identity,
response_type => $response_type,
data => $response,
code => $code,
token => $token
);
}
}
}

sub is_handshake_done {
my ($self, %options) = @_;

Expand Down
12 changes: 12 additions & 0 deletions gorgone/gorgone/modules/core/pullwss/class.pm
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ sub disconnect_zmq_socket_and_exit {
sub send_message {
my ($self, %options) = @_;
my $message = HTML::Entities::encode_entities($options{message});
if ($options{message} =~ /SETLOGS/ or $options{message} =~ /GETLOG/) {
$connector->{logger}->writeLogDebug("[pullwss-evan] input msg seem like getlog: $options{message}");
}
$self->{tx}->send({text => $message });
}

Expand Down Expand Up @@ -183,6 +186,9 @@ sub wss_connect {

# We skip. Dont need to send it in gorgone-core
return undef if ($msg =~ /^\[ACK\]/);
if ($msg =~ /SETLOGS/ or $msg =~ /GETLOG/) {
$connector->{logger}->writeLogDebug("[pullwss-evan] input msg seem like getlog: $msg");
}

if ($msg =~ /^\[.*\]/) {
$connector->{logger}->writeLogDebug('[pullwss] websocket message: ' . $msg);
Expand Down Expand Up @@ -283,6 +289,12 @@ sub read_zmq_events {

while (!$self->{stop} and $self->{internal_socket}->has_pollin()) {
my ($message) = $connector->read_message();
if ($message !~ /^\[ACK\]/) {
$connector->{logger}->writeLogDebug("[pullwss-evan] read message from internal: $message");
}
if ($message =~ /SETLOGS/ or $message =~ /GETLOG/i) {
$connector->{logger}->writeLogDebug("[pullwss-evan] message seem like setlog!: $message");
}
$message = transmit_back(message => $message);
next if (!defined($message));

Expand Down
60 changes: 59 additions & 1 deletion gorgone/tests/robot/tests/core/pullwss.robot
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Test Timeout 220s

*** Variables ***
@{process_list} pullwss_gorgone_poller_2 pullwss_gorgone_central

${log_size} 10000
${log_count} 1
#6000
*** Test Cases ***
check one poller can connect to a central and gorgone central stop first
[Teardown] Stop Gorgone And Remove Gorgone Config @{process_list} sql_file=${ROOT_CONFIG}db_delete_poller.sql
Expand All @@ -24,3 +26,59 @@ check one poller can connect to a central and gorgone poller stop first
Setup Two Gorgone Instances communication_mode=pullwss central_name=pullwss_gorgone_central poller_name=pullwss_gorgone_poller_2
Ctn Check No Error In Logs pullwss_gorgone_poller_2
Log To Console End of tests.

check Big file can be sent over gorgone pullwss mode
[Tags] bigfile
[Teardown] Stop Gorgone And Remove Gorgone Config @{process_list} sql_file=${ROOT_CONFIG}db_delete_poller.sql
@{process_list} Set Variable pullwss_gorgone_poller_2 pullwss_gorgone_central
Log To Console \nStarting the gorgone setup

Setup Two Gorgone Instances communication_mode=pullwss central_name=pullwss_gorgone_central poller_name=pullwss_gorgone_poller_2
Ctn Check No Error In Logs pullwss_gorgone_poller_2
Log To Console /etc/centreon-gorgone/${process_list}[1]/history.sdb
Connect To Database
... sqlite3
... database=/etc/centreon-gorgone/${process_list}[1]/history.sdb
... isolation_level=${None}
... alias=sqlite_central

Connect To Database
... sqlite3
... database=/etc/centreon-gorgone/${process_list}[0]/history.sdb
... isolation_level=${None}
... alias=sqlite_poller

Execute SQL String DELETE FROM gorgone_history alias=sqlite_central

${token}= Create Big Sqlite Log @{process_list} log_size=${log_size} log_count=${log_count}
Get Log From Central @{process_list} token=${token} log_count=${log_count}

Log To Console End of tests.

*** Keywords ***
Get Log From Central
[Arguments] @{process_list} ${token} ${log_count}=10

${status} ${logs} Ctn Get Api Log With Timeout token=${token} node_path=nodes/2/

Check Row Count SELECT * FROM gorgone_history WHERE token = '${token}' == ${log_count} retry_timeout=15s retry_pause=1s alias=sqlite_central


Create Big Sqlite Log
[Arguments] @{process_list} ${log_size}=1000 ${log_count}=100000

Log To Console /etc/centreon-gorgone/${process_list}[0]/history.sdb


${token}= Generate Random String 5
Execute SQL String DELETE FROM gorgone_history alias=sqlite_poller
Execute SQL String VACUUM alias=sqlite_poller
FOR ${i} IN RANGE ${log_count}
${string}= Generate Random String ${log_size}
Execute SQL String INSERT INTO gorgone_history (token, code, etime, ctime, data) VALUES ('${token}', 2, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'This is test ${i}. ${string}'); alias=sqlite_poller
END

RETURN ${token}



0 comments on commit d4d5854

Please sign in to comment.