#!/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, <cedric.serfon@cern.ch>, 2014
#
import datetime
import sys
from rucio.client import Client

UNKNOWN, OK, WARNING, CRITICAL = -1, 0, 1, 2
host = sys.argv[1]
c = Client()
dict = c.get_rse_usage(host)
if datetime.datetime.utcnow() - dict['updated_at'] < datetime.timedelta(1):
    print 'Used space :', dict['used']
    sys.exit(OK)
else:
    print 'Used space has not been refreshed for more than 1 hour. Last refresh on %s' % str(dict['updated_at'])
    sys.exit(WARNING)
