Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Commit 10653fd

Browse files
committed
Merge branch 'main' of github.com:CDLUC3/mrt-admin-lambda
2 parents f7643d8 + 198ad6b commit 10653fd

File tree

6 files changed

+189
-0
lines changed

6 files changed

+189
-0
lines changed

src-admintool/config/reports.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,13 @@ audit_status:
376376
- For status `system-unavailable` or `unverified`, a retry is generally recommended.
377377
- A status of `size-mismatch` or `digest-mismatch` indicates that either a copy error occurred or this could show evidence of bit rot. Immediate investigation is required.
378378
- Files with a status of `verified` are explicitly excluded from this report for performance reasons.
379+
audit_ucb:
380+
link-title: Audit State - new UCB content
381+
breadcrumb: bp_audit
382+
class: AuditNewUCBQuery
383+
category: audit
384+
description: |
385+
Look at audit status for new UCB content.
379386
audit_status_time:
380387
link-title: Audit Status - Recent Processing
381388
breadcrumb: bp_audit
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# frozen_string_literal: true
2+
3+
# Query class - see config/reports.yml for description
4+
class AuditNewUCBQuery < AdminQuery
5+
def initialize(query_factory, path, myparams)
6+
super
7+
@days = get_param('days', 7).to_i
8+
@mindays = 1
9+
end
10+
11+
def get_title
12+
"Audit Status for UCB Objects Modified in the Last #{@days} Days"
13+
end
14+
15+
def get_sql
16+
%{
17+
select distinct
18+
o.id,
19+
o.ark,
20+
o.modified,
21+
count(a.id) as files_count,
22+
max(a.verified) as verified,
23+
a.status as audit_status,
24+
case
25+
when a.status in ('size-mismatch','digest-mismatch') then 'Audit Failed'
26+
when ifnull(verified, o.modified) < date_add(o.modified, interval #{@mindays} day) and o.modified > date_add(now(), interval -#{@mindays} day) then 'Reset Later'
27+
when a.status = 'verified' and ifnull(verified, o.modified) < date_add(o.modified, interval #{@mindays} day) then 'Reset Needed'
28+
when a.status = 'verified' then 'Audited'
29+
else 'In Progress'
30+
end as category,
31+
case
32+
when a.status in ('size-mismatch','digest-mismatch') then 'FAIL'
33+
when ifnull(verified, o.modified) < date_add(o.modified, interval #{@mindays} day) and o.modified > date_add(now(), interval -#{@mindays} day) then 'INFO'
34+
when a.status = 'verified' and ifnull(verified, o.modified) < date_add(o.modified, interval #{@mindays} day) then 'WARN'
35+
when a.status = 'verified' then 'PASS'
36+
else 'INFO'
37+
end as status
38+
from
39+
inv.inv_objects o
40+
right join
41+
inv.inv_audits a
42+
on
43+
a.inv_object_id = o.id
44+
and
45+
a.inv_node_id = 16 /*sdsc node*/
46+
where
47+
o.inv_owner_id=14 /*ucb owner*/
48+
and
49+
o.modified > date_add(now(), interval -#{@days.to_i} day)
50+
group by
51+
o.id,
52+
o.ark,
53+
o.modified,
54+
a.status
55+
order by
56+
o.modified desc
57+
;
58+
}
59+
end
60+
61+
def get_headers(_results)
62+
['Object Id', 'Ark', 'Obj Modified', 'Files', 'Verified', 'Audit Status', 'Category', 'Status']
63+
end
64+
65+
def get_types(_results)
66+
%w[objlist ark datetime dataint datetime '' '' status]
67+
end
68+
69+
def get_alternative_queries
70+
[
71+
{
72+
label: 'Last 7 days',
73+
url: 'path=audit_ucb&days=7',
74+
class: 'graph'
75+
},
76+
{
77+
label: 'Last 14 days',
78+
url: 'path=audit_ucb&days=14',
79+
class: 'graph'
80+
},
81+
{
82+
label: 'Last 30 days',
83+
url: 'path=audit_ucb&days=30',
84+
class: 'graph'
85+
}
86+
]
87+
end
88+
89+
def init_status
90+
:PASS
91+
end
92+
end

src-admintool/web/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ <h2>Audit Service</h2>
345345
<h3>Audit Status</h3>
346346
<ul>
347347
<li class="graph"><a href="{{ADMINTOOL_HOME}}?path=audit_status">Audit - Irregular Status</a></li>
348+
<li class="graph"><a href="{{ADMINTOOL_HOME}}?path=audit_ucb">Audit - New UCB Content</a></li>
349+
<li class="graph"><a href="{{COLLADMIN_HOME}}?path=audit_ucb_reset">Audit - Reset New UCB Content</a></li>
348350
</ul>
349351
</div>
350352

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'action'
4+
5+
# Collection Admin Task class - see config/actions.yml for description
6+
class UCBAuditResetAction < AdminAction
7+
def get_title
8+
"UCB Audit Reset"
9+
end
10+
11+
def table_headers
12+
%w[ObjectID Ark Modified Status]
13+
end
14+
15+
def table_types
16+
%w[objidlist ark datetime status]
17+
end
18+
19+
def table_rows(_body)
20+
sql = %{
21+
select distinct
22+
o.id, o.ark, o.modified, 'PASS' as status
23+
from
24+
inv.inv_objects o
25+
inner join
26+
inv.inv_audits a
27+
on
28+
a.inv_object_id = o.id
29+
and
30+
a.inv_node_id = 16 /*sdsc node*/
31+
where
32+
o.inv_owner_id=14 /*ucb owner*/
33+
and
34+
o.modified > date_add(now(), interval -7 day)
35+
and
36+
ifnull(verified, o.modified) < date_add(o.modified, interval 1 day)
37+
and
38+
o.modified < date_add(now(), interval -1 day)
39+
and
40+
a.status = 'verified'
41+
order by o.modified
42+
limit 2
43+
;
44+
}
45+
data = MerrittQuery.new(@config).run_query(sql)
46+
data.each do |r|
47+
objid = r[0]
48+
MerrittQuery.new(@config).run_update(
49+
%(
50+
update
51+
inv_audits
52+
set
53+
verified = null,
54+
status = 'unknown'
55+
where
56+
inv_object_id = ?
57+
and
58+
inv_node_id = ?
59+
),
60+
[objid, 16],
61+
'Audit reset for object'
62+
)
63+
end
64+
data
65+
end
66+
67+
def perform_action
68+
convert_json_to_table({}.to_json)
69+
end
70+
71+
def has_table
72+
true
73+
end
74+
75+
def init_status
76+
:PASS
77+
end
78+
79+
end

src-colladmin/config/actions.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,14 @@ storage-clear-audit-batch:
681681
This function clears all audit batches older than a specified amount of time.
682682
documentation: |
683683
SQL: UPDATE inv_audits SET status='unknown', verified=null
684+
audit_ucb_reset:
685+
link-title: Reset Audit Status for new UCB content
686+
class: UCBAuditResetAction
687+
category: Audit
688+
sensitivity: reversible change
689+
testing: manual
690+
description: |
691+
After 1 (1 or 2) days, trigger an immediate re-audit of new UCB content.
684692
storage-retry-audit-status:
685693
link-title: Trigger an audit retry for all audit records with a specific status
686694
class: StorageAction

src-colladmin/lambda_function.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
require_relative 'actions/consistency_report_cleanup_action'
3131
require_relative 'actions/lambda_tag_action'
3232
require_relative 'actions/system_state_action'
33+
require_relative 'actions/ucb_audit_reset_action'
3334
require 'yaml'
3435

3536
# Handle GET or POST event structures pass in via the ALB

0 commit comments

Comments
 (0)