Skip to content

Commit ffac739

Browse files
committed
added nagios script
1 parent 7d66963 commit ffac739

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ A demo is currently hosted on our server. *No need for registration!*
1010
## Development
1111
The development is currently coordinated at our [trac project management](https://sems.uni-rostock.de/trac/combinearchive-web).
1212

13+
## Additional Resources
14+
Some helpful resources can be found in the resources folder. It contains a default context configuration for tomcat, a default
15+
VHost configuration for the Apache WebServer and a folder called "nagios" containing a simple python3 script for nagios, to
16+
check if the webCAT instance is up and running. In case a stats secret is provided (and configured in the python script) it
17+
also checks for the maximum space quota.
18+
1319
## Licence
1420
CombineArchiveWeb - a WebInterface to read/create/write/manipulate/... COMBINE archives
1521
Copyright (C) 2014-2015:

resources/nagios/checkWebCat.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/python3
2+
3+
import os, sys, json, time, math
4+
import requests
5+
6+
# settings
7+
url = "http://localhost:8080/CombineArchiveWeb/rest/v1/stats"
8+
secret = "1234"
9+
timeout = 0.02
10+
11+
# trying to establish connection
12+
try:
13+
req = requests.get(url, params=[("secret", secret)], timeout=timeout)
14+
stats = req.json()
15+
except requests.exceptions.ConnectionError as err:
16+
print( "Connection Error: {0}".format(err) )
17+
sys.exit(2)
18+
except requests.exceptions.HTTPError as err:
19+
print( "HTTP Error: {0}".format(err) )
20+
sys.exit(2)
21+
except requests.exceptions.Timeout as err:
22+
print( "Timeout of {1} exceeded: {0}".format(err, timeout) )
23+
sys.exit(2)
24+
except requests.exceptions.TooManyRedirects as err:
25+
print( "Too many redirects while requesting stats: {0}".format(err) )
26+
sys.exit(2)
27+
except ValueError as err:
28+
print( "Error decoding json: {0}".format(err) )
29+
sys.exit(2)
30+
except:
31+
print( "Unknown exception: {0}".format(sys.exc_info()[0]) )
32+
sys.exit(2)
33+
34+
if 'maxStatsAge' and 'generated' in stats:
35+
now = int( time.time() ) * 1000
36+
if math.fabs( now - int(stats['generated']) ) >= int(stats['maxStatsAge']) * 1000 :
37+
print( "Stats are too old. Is System running?" )
38+
sys.exit(1)
39+
40+
if 'totalSizeQuota' in stats:
41+
if stats['totalSizeQuota'] >= 0.90:
42+
print("Total quoata is about to exceed: {0}%".format(stats['totalSizeQuota']*100) )
43+
sys.exit(1)
44+
elif stats['totalSizeQuota'] >= 0.99:
45+
print( "Total quota is exceeded: {0}%".format(stats['totalSizeQuota']*100) )
46+
sys.exit(2)
47+
else:
48+
print("quota is ok: {0}% ".format(stats['totalSizeQuota']*100) )
49+
sys.exit(0)
50+
else:
51+
sys.exit(0)
52+
53+
54+
# no normal ending
55+
print( "script terminated unexpected" )
56+
sys.exit(2)

0 commit comments

Comments
 (0)