-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_aws_ses_rejected_stats.py
executable file
·95 lines (87 loc) · 1.76 KB
/
check_aws_ses_rejected_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
#
import argparse
import boto3
import datetime
import operator
import sys
parser=argparse.ArgumentParser(
description='Check the total rejected emails for SES in AWS')
parser.add_argument(
'-H',
metavar='HOURS',
required=True,
action='store',
help='Number of hours to look back',
dest='hours',
type=int)
parser.add_argument(
'-w',
metavar='WARNING',
required=True,
action='store',
help='Exit with WARNING status if greater than FLOAT',
dest='warning',
type=float)
parser.add_argument(
'-c',
metavar='CRITICAL',
required=True,
action='store',
help='Exit with CRITICAL status if greater than FLOAT',
dest='critical',
type=float)
parser.add_argument(
'-r',
metavar='AWS_REGION',
required=True,
action='store',
help='AWS region',
dest='region',
type=str)
parser.add_argument(
'-i',
metavar='AWS_ACCESS_KEY_ID',
required=True,
action='store',
help='AWS access key id',
dest='id',
type=str)
parser.add_argument(
'-k',
metavar='AWS_SECRET_ACCESS_KEY',
required=True,
action='store',
help='AWS secret access key',
dest='key',
type=str)
args=parser.parse_args()
client=boto3.client(
'ses',
aws_access_key_id=args.id,
aws_secret_access_key=args.key,
region_name=args.region
)
response=client.get_send_statistics()
sent=sorted(response['SendDataPoints'], key=operator.itemgetter('Timestamp'), reverse=True)
rejects=0
for i in sent[:4]:
rejects=rejects+i['Rejects']
state='UNKNOWN'
status=3
if rejects >= args.critical:
state='CRITICAL'
status=2
elif rejects >= args.warning:
state='WARNING'
status=1
elif rejects < args.warning:
state='OK'
status=0
print "{0} - {1} is the total rejected emails for SES in AWS {2} | rejected={1};{3};{4}".format(
state,
rejects,
args.region,
args.warning,
args.critical)
sys.exit(status)