feat: add info_syslog() and code-info syslog type

This commit is contained in:
Stéphane Lesimple 2021-12-15 14:05:56 +00:00 committed by Stéphane Lesimple
parent 7cc350b40d
commit c48af00ff8
4 changed files with 41 additions and 17 deletions

View file

@ -136,7 +136,7 @@ duration
warn, die
*********
These logs are produced when Perl emits a warning (using the ``warn()`` call), or respectively when Perl halts abruptly due to a ``die()`` call. This should not happen during nominal use.
These logs are produced when Perl emits a warning (using the ``warn()`` call), or respectively when Perl halts abruptly due to a ``die()`` call. This should not happen during nominal use. You might want to keep a look on those messages if they're produced.
Example::
@ -161,16 +161,32 @@ trace
warn-info, die-info
*******************
These logs are produced when some known portion of code (including libraries) called ``warn()`` or ``die()`` but in a known case that can happen during nominal use.
These logs are produced when some known portion of code (including libraries) called ``warn()`` or ``die()`` but in a known case that can happen during nominal use. Don't use these logs to directly trigger an alert, but you can keep an eye on those, as e.g. an unusually high number of occurences in a short time may be a weak signal that somebody or something is misbehaving.
The fields are the same than the ones specified above for **warn** and **die**.
.. _log_codeinfo:
code-info
*********
These logs are produced when some portion of the code encounters an minor issue that is worth logging, to e.g. help debugging an issue or understanding what happened in a specific use-case, for example if a user-session ended abruptly. These logs are not the result of an error on the bastion configuration and don't mandate immediate admin attention.
Example::
Dec 25 14:56:11 myhostname bastion: code-info uniqid="93b27ad9eb4c" version="3.07.00" pid="3709643" ppid="3709642" sysuser="lechuck" sudo_user="" uid="8423" gid="8423" msg="Configuration error for plugin selfGenerateEgressKey on the 'disabled' key: expected a boolean, casted 'no' into false" FIXME
Fields:
msg
A human-readable text describing the error
.. _log_codewarn:
code-warning
************
This log is produced when some portion of the code encounters an unexpected issue or abnormality that is worth logging.
These logs are produced when some portion of the code encounters an unexpected issue or abnormality that is worth logging. They'll usually not be emitted due to a bad user interaction, but rather if the bastion is misconfigured, or for anything that might need some attention or fixing from the admins.
Example::

View file

@ -57,7 +57,7 @@ use OVH::Result;
use parent qw( Exporter );
our @EXPORT = ## no critic (AutomaticExportation)
qw( osh_header osh_footer osh_exit osh_debug osh_info osh_warn osh_crit osh_ok warn_syslog );
qw( osh_header osh_footer osh_exit osh_debug osh_info osh_warn osh_crit osh_ok warn_syslog info_syslog );
our $AUTOLOAD;
@ -136,7 +136,7 @@ my %_autoload_files = (
execute => [qw{ sysret2human execute execute_simple result_from_helper helper_decapsulate helper }],
interactive => [qw{ interactive }],
jail => [qw{ jailify }],
log => [qw{ syslog syslog_close syslogFormatted warn_syslog log_access_insert log_access_update log_access_get }],
log => [qw{ syslog syslog_close syslogFormatted warn_syslog info_syslog log_access_insert log_access_update log_access_get }],
mock => [
qw{ enable_mocking is_mocking set_mock_data mock_get_account_entry mock_get_account_accesses mock_get_account_personal_accesses mock_get_account_legacy_accesses mock_get_group_accesses mock_get_account_guest_accesses }
],

View file

@ -110,8 +110,8 @@ sub execute {
my $currently_in_json_block = 0;
my %bytesnb;
# maximum number of warns() to call, to avoid flooding the logs
my $warnLimit = 5;
# maximum number of code_info() to call, to avoid flooding the logs
my $infoLimit = 5;
# always monitor our child stdout and stderr
my $select = IO::Select->new($child_stdout, $child_stderr);
@ -157,11 +157,11 @@ sub execute {
# if size 0, it means it's an EOF, if undef, it's an error
if (not $nbread) {
# error, we'll warn and close
# error, we'll log to syslog and close. as this might be user-induced, use info instead of warn
if (not defined $nbread) {
# awwww, not cool at all
warn("execute(): error while sysreading($!), closing fh!");
info_syslog("execute(): error while sysreading($!), closing fh!");
}
# we got an EOF on this fh, remove it from the monitor list
@ -194,13 +194,13 @@ sub execute {
# note that if we're at the position "0", it's still true (see doc).
my $previousError = $!;
if (!sysseek(STDERR, 0, SEEK_CUR)) {
warn("execute(): error while syswriting($previousError/$!) on stderr, the filehandle is closed, will no longer attempt to write to it")
if $warnLimit-- > 0;
info_syslog("execute(): error while syswriting($previousError/$!) on stderr, the filehandle is closed, will no longer attempt to write to it")
if $infoLimit-- > 0;
$noisy_stderr = 0;
}
else {
# oww, abort writing for this cycle
warn("execute(): error while syswriting($previousError) on stderr, aborting this cycle") if $warnLimit-- > 0;
# oww, abort writing for this cycle. as this might be user-induced, use info instead of warn
info_syslog("execute(): error while syswriting($previousError) on stderr, aborting this cycle") if $infoLimit-- > 0;
}
last;
}
@ -243,13 +243,13 @@ sub execute {
# note that if we're at the position "0", it's still true (see doc).
my $previousError = $!;
if (!sysseek(STDOUT, 0, SEEK_CUR)) {
warn("execute(): error while syswriting($previousError/$!) on stdout, the filehandle is closed, will no longer attempt to write to it")
if $warnLimit-- > 0;
info_syslog("execute(): error while syswriting($previousError/$!) on stdout, the filehandle is closed, will no longer attempt to write to it")
if $infoLimit-- > 0;
$noisy_stdout = 0;
}
else {
# oww, abort writing for this cycle
warn("execute(): error while syswriting($previousError) on stdout, aborting this cycle") if $warnLimit-- > 0;
# oww, abort writing for this cycle. as this might be user-induced, use info instead of warn.
info_syslog("execute(): error while syswriting($previousError) on stdout, aborting this cycle") if $infoLimit-- > 0;
}
last;
}

View file

@ -121,6 +121,14 @@ sub warn_syslog {
);
}
sub info_syslog {
my $msg = shift;
return syslogFormatted(
type => 'code-info',
fields => [['msg' => $msg]]
);
}
sub _sql_update_db {
my %params = @_;
my $sqltype = $params{'sqltype'};