File indexing completed on 2026-11-09 10:47:24
0001
0002 """propose-certificate-pings.py — the host certificate proposer: a ping
0003 on the expiry of the certificate each PanDA and OSG service host serves,
0004 a ping on a certificate served without its issuing intermediate, and a
0005 fulfilment proposal for an open ping whose certificate has since been
0006 renewed (swf-monitor docs/PINGS.md, docs/AI_PROPOSALS.md category
0007 ``ping``). Logic in ``swf_epicprod.certificate_proposer``; the prod-ops
0008 agent's doer for the ``certificate_ping_propose`` chain step, also
0009 runnable by hand.
0010
0011 Usage::
0012
0013 cd /data/wenauseic/github/swf-monitor/src
0014 source ../../swf-testbed/.venv/bin/activate && source ~/.env
0015 python ../scripts/propose-certificate-pings.py [--apply] [--created-by X]
0016
0017 Dry run by default: the findings are printed and nothing is proposed.
0018 """
0019 import argparse
0020 import json
0021 import os
0022 import sys
0023
0024 THIS_DIR = os.path.dirname(os.path.abspath(__file__))
0025 sys.path.insert(0, os.path.join(THIS_DIR, '..', 'src'))
0026 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'swf_monitor_project.settings')
0027
0028 import django
0029 django.setup()
0030
0031 from swf_epicprod.certificate_proposer import (
0032 propose_certificate_pings)
0033
0034
0035 def main():
0036 parser = argparse.ArgumentParser()
0037 parser.add_argument('--apply', action='store_true',
0038 help='submit the proposals (default: report only)')
0039 parser.add_argument('--created-by', default='prodops_agent')
0040 args = parser.parse_args()
0041 result = propose_certificate_pings(created_by=args.created_by,
0042 apply=args.apply)
0043 for f in result['findings']:
0044 chain = ('chain complete' if f['intermediate_served']
0045 else 'NO INTERMEDIATE SERVED')
0046 print(f"finding: {f['host']} expires {f['due']} "
0047 f"({f['days_left']:.1f} days left), {chain}")
0048 if not result['findings']:
0049 print('no host certificate could be read')
0050 pings = result['pings'] or {}
0051 summary = {
0052 'findings': len(result['findings']),
0053 'applied': bool(args.apply),
0054 'proposed': pings.get('proposed', []),
0055 'noop': pings.get('noop', []),
0056 'denied': pings.get('denied', []),
0057 'invalid': pings.get('invalid', []),
0058 'fulfil_proposed': result['fulfil_proposed'],
0059 'withdrawn': result['withdrawn'],
0060 'errors': result['errors'],
0061 }
0062 print('SUMMARY ' + json.dumps(summary))
0063 return 0
0064
0065
0066 if __name__ == '__main__':
0067 sys.exit(main())