HEX
Server: Apache
System: Linux ecres233.servconfig.com 4.18.0-553.94.1.lve.el8.x86_64 #1 SMP Thu Jan 22 12:37:22 UTC 2026 x86_64
User: gonnelllaw (9952)
PHP: 7.2.34
Disabled: NONE
Upload Files
File: //opt/sharedrads/exclude_sender
#!/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()