projects
/
freeside.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b5f68a6
)
RT#39627: System log daily context also includes Cron::bill and Cron::upload results
author
Jonathan Prykop
<jonathan@freeside.biz>
Fri, 17 Jun 2016 05:31:09 +0000
(
00:31
-0500)
committer
Jonathan Prykop
<jonathan@freeside.biz>
Fri, 17 Jun 2016 05:31:09 +0000
(
00:31
-0500)
FS/FS/Schema.pm
patch
|
blob
|
history
FS/FS/log.pm
patch
|
blob
|
history
FS/FS/log_email.pm
patch
|
blob
|
history
httemplate/edit/log_email.html
patch
|
blob
|
history
httemplate/search/log.html
patch
|
blob
|
history
diff --git
a/FS/FS/Schema.pm
b/FS/FS/Schema.pm
index
3593543
..
a50b551
100644
(file)
--- a/
FS/FS/Schema.pm
+++ b/
FS/FS/Schema.pm
@@
-6635,6
+6635,7
@@
sub tables_hashref {
'min_level', 'int', 'NULL', '', '', '',
'msgnum', 'int', '', '', '', '',
'to_addr', 'varchar', 'NULL', 255, '', '',
'min_level', 'int', 'NULL', '', '', '',
'msgnum', 'int', '', '', '', '',
'to_addr', 'varchar', 'NULL', 255, '', '',
+ 'context_height', 'int', 'NULL', '', '', '',
],
'primary_key' => 'logemailnum',
'unique' => [],
],
'primary_key' => 'logemailnum',
'unique' => [],
diff --git
a/FS/FS/log.pm
b/FS/FS/log.pm
index
95bc4c4
..
1d4df73
100644
(file)
--- a/
FS/FS/log.pm
+++ b/
FS/FS/log.pm
@@
-81,15
+81,16
@@
sub insert {
my $self = shift;
my $error = $self->SUPER::insert;
return $error if $error;
my $self = shift;
my $error = $self->SUPER::insert;
return $error if $error;
- my $contexts = {}; #for quick checks when sending emails
- foreach ( @_ ) {
+ my $contexts = {}; # for quick checks when sending emails
+ my $context_height = @_; # also for email check
+ foreach ( @_ ) { # ordered from least to most specific
my $context = FS::log_context->new({
'lognum' => $self->lognum,
'context' => $_
});
$error = $context->insert;
return $error if $error;
my $context = FS::log_context->new({
'lognum' => $self->lognum,
'context' => $_
});
$error = $context->insert;
return $error if $error;
- $contexts->{$_} =
1
;
+ $contexts->{$_} =
$context_height--
;
}
foreach my $log_email (
qsearch('log_email',
}
foreach my $log_email (
qsearch('log_email',
@@
-102,8
+103,9
@@
sub insert {
}
)
) {
}
)
) {
- # shouldn't be a lot of
these, so not packing thi
s into the qsearch
+ # shouldn't be a lot of
log_email records, so not packing these check
s into the qsearch
next if $log_email->context && !$contexts->{$log_email->context};
next if $log_email->context && !$contexts->{$log_email->context};
+ next if $log_email->context_height && ($contexts->{$log_email->context} > $log_email->context_height);
my $msg_template = qsearchs('msg_template',{ 'msgnum' => $log_email->msgnum });
unless ($msg_template) {
warn "Could not send email when logging, could not load message template for logemailnum " . $log_email->logemailnum;
my $msg_template = qsearchs('msg_template',{ 'msgnum' => $log_email->msgnum });
unless ($msg_template) {
warn "Could not send email when logging, could not load message template for logemailnum " . $log_email->logemailnum;
@@
-346,9
+348,16
@@
sub search {
if ( $params->{'context'} ) {
my $quoted = dbh->quote($params->{'context'});
if ( $params->{'context'} ) {
my $quoted = dbh->quote($params->{'context'});
- push @where,
- "EXISTS(SELECT 1 FROM log_context WHERE log.lognum = log_context.lognum ".
- "AND log_context.context = $quoted)";
+ if ( $params->{'context_height'} =~ /^\d+$/ ) {
+ my $subq = 'SELECT context FROM log_context WHERE log.lognum = log_context.lognum'.
+ ' ORDER BY logcontextnum DESC LIMIT '.$params->{'context_height'};
+ push @where,
+ "EXISTS(SELECT 1 FROM ($subq) AS log_context_x WHERE log_context_x.context = $quoted)";
+ } else {
+ push @where,
+ "EXISTS(SELECT 1 FROM log_context WHERE log.lognum = log_context.lognum ".
+ "AND log_context.context = $quoted)";
+ }
}
# agent virtualization
}
# agent virtualization
diff --git
a/FS/FS/log_email.pm
b/FS/FS/log_email.pm
index
9c53c23
..
a055cb4
100644
(file)
--- a/
FS/FS/log_email.pm
+++ b/
FS/FS/log_email.pm
@@
-42,6
+42,9
@@
The following fields are currently supported:
=item to_addr - who the email will be sent to (in addition to any bcc on the template)
=item to_addr - who the email will be sent to (in addition to any bcc on the template)
+=item context_height - number of context stack levels to match against
+(0 or null matches against full stack, 1 only matches lowest level context, 2 matches lowest two levels, etc.)
+
=back
=head1 METHODS
=back
=head1 METHODS
@@
-88,6
+91,7
@@
sub check {
|| $self->ut_number('min_level')
|| $self->ut_foreign_key('msgnum', 'msg_template', 'msgnum')
|| $self->ut_textn('to_addr')
|| $self->ut_number('min_level')
|| $self->ut_foreign_key('msgnum', 'msg_template', 'msgnum')
|| $self->ut_textn('to_addr')
+ || $self->ut_numbern('context_height')
;
return $error if $error;
;
return $error if $error;
diff --git
a/httemplate/edit/log_email.html
b/httemplate/edit/log_email.html
index
709a240
..
0c98046
100644
(file)
--- a/
httemplate/edit/log_email.html
+++ b/
httemplate/edit/log_email.html
@@
-8,6
+8,12
@@
'labels' => { '' => '(all)', map { $_ => $_ } @contexts },
'curr_value' => scalar($cgi->param('context')),
},
'labels' => { '' => '(all)', map { $_ => $_ } @contexts },
'curr_value' => scalar($cgi->param('context')),
},
+ { 'field' => 'context_height',
+ 'type' => 'checkbox',
+ 'postfix' => 'Only match most specific context',
+ 'value' => 1,
+ 'curr_value' => scalar($cgi->param('context_height')),
+ },
{ 'field' => 'min_level',
'type' => 'select',
'options' => [ 0..7 ],
{ 'field' => 'min_level',
'type' => 'select',
'options' => [ 0..7 ],
@@
-24,6
+30,7
@@
],
'labels' => {
'context' => 'Context',
],
'labels' => {
'context' => 'Context',
+ 'context_height' => '',
'min_level' => 'Min. Level',
'to_addr' => 'To',
'msgnum' => 'Message',
'min_level' => 'Min. Level',
'to_addr' => 'To',
'msgnum' => 'Message',
@@
-44,6
+51,10
@@
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right([ 'View system logs', 'Configuration' ]);
my $msgnum = $cgi->param('msgnum');
unless $FS::CurrentUser::CurrentUser->access_right([ 'View system logs', 'Configuration' ]);
my $msgnum = $cgi->param('msgnum');
+
+# XXX This attempt to set a default message isn't working, not sure why
+# $msgnum gets set correctly, but isn't selected in the popup window...fix later
+
unless ($msgnum) {
my ($msg_template) = qsearch('msg_template',{ msgname => 'System log' });
# doesn't seem worth having a config just for the default selected template
unless ($msgnum) {
my ($msg_template) = qsearch('msg_template',{ msgname => 'System log' });
# doesn't seem worth having a config just for the default selected template
diff --git
a/httemplate/search/log.html
b/httemplate/search/log.html
index
b607f50
..
111200f
100644
(file)
--- a/
httemplate/search/log.html
+++ b/
httemplate/search/log.html
@@
-101,6
+101,12
@@
a:visited {text-decoration: none}
labels => { map {$_, $_} @contexts },
curr_value => ($cgi->param('context') || ''),
&>
labels => { map {$_, $_} @contexts },
curr_value => ($cgi->param('context') || ''),
&>
+ <BR><& /elements/checkbox.html,
+ 'field' => 'context_height',
+ 'postfix' => 'Only match most specific context',
+ 'value' => 1,
+ 'curr_value' => scalar($cgi->param('context_height')),
+ &>
</TD>
</TR>
<TR>
</TD>
</TR>
<TR>
@@
-214,7
+220,7
@@
$cgi->param('max_level', 7) unless defined($cgi->param('max_level'));
my %search = ();
$search{'date'} = [ FS::UI::Web::parse_beginning_ending($cgi) ];
$search{'level'} = [ $cgi->param('min_level'), $cgi->param('max_level') ];
my %search = ();
$search{'date'} = [ FS::UI::Web::parse_beginning_ending($cgi) ];
$search{'level'} = [ $cgi->param('min_level'), $cgi->param('max_level') ];
-foreach my $param (qw(agentnum context tablename tablenum custnum message)) {
+foreach my $param (qw(agentnum context
context_height
tablename tablenum custnum message)) {
if ( $cgi->param($param) ) {
$search{$param} = $cgi->param($param);
}
if ( $cgi->param($param) ) {
$search{$param} = $cgi->param($param);
}