/usr/share/otrs/Kernel/GenericInterface/Debugger.pm is in otrs2 6.0.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | # --
# Copyright (C) 2001-2018 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::GenericInterface::Debugger;
use strict;
use warnings;
use Kernel::System::VariableCheck qw(IsString IsStringWithData IsHashRefWithData);
our $ObjectManagerDisabled = 1;
=head1 NAME
Kernel::GenericInterface::Debugger
=head1 DESCRIPTION
GenericInterface data debugger interface.
For every communication process, one Kernel::GenericInterface::Debugger object
should be constructed and fed with data at the various stages
of the process. It will collect the data and write it into the database,
based on the configured debug level.
=head1 PUBLIC INTERFACE
=head2 new()
create an object.
use Kernel::GenericInterface::Debugger;
my $DebuggerObject = Kernel::GenericInterface::Debugger->new(
DebuggerConfig => {
DebugThreshold => 'debug',
TestMode => 0, # optional, in testing mode the data will not be written to the DB
# ...
},
WebserviceID => 12,
CommunicationType => Requester, # Requester or Provider
RemoteIP => 192.168.1.1, # optional
CommunicationID => '02a381c622d5f93df868a42151db1983', # optional
);
=cut
sub new {
my ( $Type, %Param ) = @_;
my $Self = {};
bless( $Self, $Type );
# check DebuggerConfig - we need a hash ref with at least one entry
if ( !IsHashRefWithData( $Param{DebuggerConfig} ) ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => 'Need DebuggerConfig!',
);
return;
}
# DebugThreshold
$Param{DebugThreshold} = $Param{DebuggerConfig}->{DebugThreshold} || 'error';
# check for mandatory values
for my $Needed (qw(WebserviceID CommunicationType DebugThreshold)) {
if ( !IsStringWithData( $Param{$Needed} ) ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!"
);
return;
}
$Self->{$Needed} = $Param{$Needed};
}
# check correct DebugThreshold
if ( $Self->{DebugThreshold} !~ /^(debug|info|notice|error)/i ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => 'DebugThreshold is not allowed.',
);
return;
}
# check correct CommunicationType
if ( lc $Self->{CommunicationType} !~ /^(provider|requester)/i ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => 'CommunicationType is not allowed.',
);
return;
}
# TestMode
$Self->{TestMode} = $Param{DebuggerConfig}->{TestMode} || 0;
# remote IP optional
if ( defined $Param{RemoteIP} && !IsStringWithData( $Param{RemoteIP} ) ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => 'Need RemoteIP address!'
);
return;
}
$Self->{RemoteIP} = $Param{RemoteIP};
# use communication ID passed in constructor
if ( $Param{CommunicationID} ) {
$Self->{CommunicationID} = $Param{CommunicationID};
}
# create new communication ID
else {
# communication ID MD5 (system time + random #)
my $CurrentTime = $Kernel::OM->Create('Kernel::System::DateTime')->ToEpoch();
my $MD5String = $Kernel::OM->Get('Kernel::System::Main')->MD5sum(
String => $CurrentTime . int( rand(1000000) ),
);
$Self->{CommunicationID} = $MD5String;
}
return $Self;
}
=head2 DebugLog()
add one piece of data to the logging of this communication process.
$DebuggerObject->DebugLog(
DebugLevel => 'debug',
Summary => 'Short summary, one line',
Data => $Data, # optional, $Data can be a string or a scalar reference
);
Available debug levels are: 'debug', 'info', 'notice' and 'error'.
Any messages with 'error' priority will also be written to Kernel::System::Log.
=cut
sub DebugLog {
my ( $Self, %Param ) = @_;
if ( !$Param{Summary} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => 'Need Summary!',
);
return;
}
# if DebugLevel is not set DebugLevel from constructor is used
$Param{DebugLevel} = $Param{DebugLevel} || $Self->{DebugLevel};
# check correct DebugLevel
if ( $Param{DebugLevel} !~ /^(debug|info|notice|error)/i ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => 'DebugLevel is not allowed.',
);
return;
}
my %DebugLevels = (
debug => 1,
info => 2,
notice => 3,
error => 4
);
# create log message
my $DataString = '';
if ( IsHashRefWithData( $Param{Data} ) ) {
$DataString = $Kernel::OM->Get('Kernel::System::Main')->Dump( $Param{Data} );
}
elsif ( IsStringWithData( $Param{Data} ) ) {
$DataString = $Param{Data};
}
else {
$DataString = 'No data provided';
}
if ( !$Self->{TestMode} ) {
if ( $DebugLevels{ $Param{DebugLevel} } >= $DebugLevels{ $Self->{DebugThreshold} } ) {
# call AddLog function
$Kernel::OM->Get('Kernel::System::GenericInterface::DebugLog')->LogAdd(
CommunicationID => $Self->{CommunicationID},
CommunicationType => $Self->{CommunicationType},
RemoteIP => $Self->{RemoteIP},
Summary => $Param{Summary},
WebserviceID => $Self->{WebserviceID},
DebugLevel => $Param{DebugLevel},
Data => $DataString,
);
}
return 1 if $Param{DebugLevel} ne 'error';
}
my $LogMessage = <<"EOF";
DebugLog $Param{DebugLevel}:
Summary: $Param{Summary}
Data : $DataString.
EOF
if ( $Param{DebugLevel} eq 'error' ) {
$LogMessage =~ s/\n//g;
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => $LogMessage,
);
return 1 if !$Self->{TestMode};
$LogMessage .= "\n";
}
print STDERR $LogMessage;
return 1;
}
=head2 Debug()
passes data to DebugLog with debug level 'debug'
$DebuggerObject->Debug(
Summary => 'Short summary, one line',
Data => $Data, # optional, $Data can be a string or a scalar reference
);
=cut
sub Debug {
my ( $Self, %Param ) = @_;
return if !$Self->DebugLog(
%Param,
DebugLevel => 'debug',
);
return 1;
}
=head2 Info()
passes data to DebugLog with debug level 'info'
$DebuggerObject->Info(
Summary => 'Short summary, one line',
Data => $Data, # optional, $Data can be a string or a scalar reference
);
=cut
sub Info {
my ( $Self, %Param ) = @_;
return if !$Self->DebugLog(
%Param,
DebugLevel => 'info',
);
return 1;
}
=head2 Notice()
passes data to DebugLog with debug level 'notice'
$DebuggerObject->Notice(
Summary => 'Short summary, one line',
Data => $Data, # optional, $Data can be a string or a scalar reference
);
=cut
sub Notice {
my ( $Self, %Param ) = @_;
return if !$Self->DebugLog(
%Param,
DebugLevel => 'notice',
);
return 1;
}
=head2 Error()
passes data to DebugLog with debug level 'error'
then returns data structure to be used as return value in calling function
$DebuggerObject->Error(
Summary => 'Short summary, one line',
Data => $Data, # optional, $Data can be a string or a scalar reference
);
=cut
sub Error {
my ( $Self, %Param ) = @_;
return if !$Self->DebugLog(
%Param,
DebugLevel => 'error',
);
return {
Success => 0,
ErrorMessage => $Param{Summary},
};
}
=begin Internal:
=cut
=head2 DESTROY()
destructor, this will write the log entries to the database.
=cut
sub DESTROY {
my $Self = shift;
#TODO: implement storing of the debug messages
return;
}
1;
=end Internal:
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<http://otrs.org/>).
This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (AGPL). If you
did not receive this file, see L<http://www.gnu.org/licenses/agpl.txt>.
=cut
|