Repository navigation
Expand file tree
/
Copy pathcheck_gracc_count_cache
More file actions
executable file
·88 lines (78 loc) · 2.67 KB
/
Copy pathcheck_gracc_count_cache
File metadata and controls
executable file
·88 lines (78 loc) · 2.67 KB
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
#!/bin/python3
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
import argparse
import socket, select
import struct
import sys
import time
import requests
import json
import htcondor2
#Uncomment to enable debugging of condor collector communication
#htcondor2.param['TOOL_DEBUG'] = 'D_FULLDEBUG,D_SECURITY'
#htcondor2.enable_debug()
# Nagios exit status
STATE_OK = 0
STATE_WARNING = 1
STATE_CRITICAL = 2
STATE_UNKNOWN = 3
def count_history_jobs(hostname):
coll = htcondor2.Collector("%s:9619" % hostname )
schedd_ad = coll.locate(htcondor2.DaemonTypes.Schedd, hostname)
schedd = htcondor2.Schedd(schedd_ad)
job_list = list(schedd.history(requirements='JobCurrentStartDate',
projection=["JobFinishedHookDone"],
since="JobFinishedHookDone < %d" % (time.time()-2*86400),
match=1))
return len(job_list)
def main():
args = parse_args()
api_interface="https://gracc.opensciencegrid.org/q"
index="xrd-stash*"
query_string = "_count?q=(server_hostname:%s) AND (@timestamp:[now-4d TO now])" % args.hostname
api_url = api_interface + '/' + index + '/' + query_string
try:
state = gracc_index_count(api_url, None)
sys.exit(state)
except socket.gaierror as e:
# Could not resolve hostname => UNKNOWN
print('Error: %s' % str(e))
sys.exit(STATE_UNKNOWN)
except Exception as e:
# Calling everything else critical:
# - socket.error (Network is unreachable)
# - socket.timeout
print('Error: %s' % str(e))
sys.exit(STATE_CRITICAL)
def gracc_index_count(api_url, hostname):
r = requests.get(api_url)
data = json.loads(r.text)
count = data['count']
perf_data = ' |count=' + str(count)
#print (data['count'])
if count > 0:
print ('GRACC received ' +str(count) +' records')
state = STATE_OK
elif count == 0:
history_count = 0
if hostname:
history_count = count_history_jobs(hostname)
if history_count:
print ('GRACC received 0 records but there were history ads')
state = STATE_CRITICAL
else:
print ('GRACC received 0 records but there were no history ads')
state = STATE_OK
else:
print ('Invalid output')
state = STATE_UNKNOWN
print (perf_data)
return state
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--hostname', dest='hostname', type=str,
help='Cache hostname for query')
return parser.parse_args()
if __name__ == "__main__":
# Run script as main
main()