-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcheck_expired_locked_rules
executable file
·56 lines (49 loc) · 1.9 KB
/
check_expired_locked_rules
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
#!/usr/bin/env python
# Copyright European Organization for Nuclear Research (CERN) 2013
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Authors:
# - Cedric Serfon, <[email protected]>, 2015
'''
Probe to check the locked expired rules or datasets with locked rules
'''
import sys
from rucio.db.sqla.session import get_session
# Exit statuses
OK, WARNING, CRITICAL, UNKNOWN = 0, 1, 2, 3
def main():
'''
Probe to check the locked expired rules or datasets with locked rules
'''
status = OK
session = get_session()
try:
query = "select rawtohex(id), scope, name, rse_expression from atlas_rucio.rules where locked=1 and expires_at<sys_extract_utc(localtimestamp)"
print 'Locked expired rules'
for row in session.execute(query):
status = CRITICAL
print row[0], row[1], row[2]
except Exception as error:
print error
status = UNKNOWN
sys.exit(status)
try:
query = """select rawtohex(c.id), c.scope, c.name, c.rse_expression from atlas_rucio.rules c,
(select a.scope, a.name from atlas_rucio.dids a
where a.expired_at is not null and a.expired_at < sys_extract_utc(localtimestamp)
and exists (select 1 from atlas_rucio.rules b where a.scope=b.scope and a.name=b.name and locked=1)) d
where c.scope=d.scope and c.name=d.name and locked=1"""
print 'Datasets expired with locked rules'
for row in session.execute(query):
status = CRITICAL
print row[0], row[1], row[2], row[3]
except Exception as error:
print error
status = UNKNOWN
sys.exit(status)
sys.exit(status)
if __name__ == "__main__":
main()