??????????????????????????????? ??????????????????????????????? ??????????????????????????????? >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. ??????????????????????????????? ??????????????????????????????? ??????????????????????????????? ??????????????????????????????? ??????????????????????????????? ??????????????????????????????? >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #!/usr/lib/rads/venv/bin/python3 import json import argparse from os import path from datetime import datetime, timedelta parser = argparse.ArgumentParser( description='Add or remove temporary exclusion from sender_volume crit.' ) parser.add_argument( 'Sender', metavar='sender', type=str, help='Email address to ignore.' ) parser.add_argument( '-t', action='store', metavar='hours', type=int, default=1, help='Number of hours to exclude a sender from the crit, Default 1, Max 6.', ) parser.add_argument( '--d', action='store_const', metavar='delete', default=False, const=True, help='Delete the exclusion for the specified user.', ) args = parser.parse_args() EXCLUSION_FILE = "/var/lib/monitoring/sender_volume.json" def get_exclusion_data(): if path.exists(EXCLUSION_FILE): try: with open( EXCLUSION_FILE, encoding='utf-8' ) as exclude_json: data = json.load(exclude_json) except Exception: data = {} else: data = {} return data def write_exclusion_file(data): with open( EXCLUSION_FILE, 'w', encoding='utf-8' ) as exclusion_file: json.dump(data, exclusion_file) def main(): data = get_exclusion_data() if args.d is False: if args.t > 6: expire_time = datetime.now() + timedelta(hours=1) else: expire_time = datetime.now() + timedelta(hours=args.t) data[args.Sender] = str(expire_time) if args.d is True: if args.Sender in data: del data[args.Sender] write_exclusion_file(data) if __name__ == '__main__': main()