2016-12-08 01:24:59 +01:00
"""
. . module : lemur . notifications . cli
: platform : Unix
2018-05-29 19:18:16 +02:00
: copyright : ( c ) 2018 by Netflix Inc . , see AUTHORS for more
2016-12-08 01:24:59 +01:00
: license : Apache , see LICENSE for more details .
. . moduleauthor : : Kevin Glisson < kglisson @netflix.com >
"""
from flask_script import Manager
2018-01-03 00:26:31 +01:00
from lemur . constants import SUCCESS_METRIC_STATUS , FAILURE_METRIC_STATUS
from lemur . extensions import sentry , metrics
2016-12-08 01:24:59 +01:00
from lemur . notifications . messaging import send_expiration_notifications
manager = Manager ( usage = " Handles notification related tasks. " )
2017-10-04 23:57:57 +02:00
@manager.option ( ' -e ' , ' --exclude ' , dest = ' exclude ' , action = ' append ' , default = [ ] , help = ' Common name matching of certificates that should be excluded from notification ' )
2017-03-15 19:25:19 +01:00
def expirations ( exclude ) :
2016-12-08 01:24:59 +01:00
"""
Runs Lemur ' s notification engine, that looks for expired certificates and sends
notifications out to those that have subscribed to them .
2017-03-15 19:25:19 +01:00
Every certificate receives notifications by default . When expiration notifications are handled outside of Lemur
we exclude their names ( or matching ) from expiration notifications .
It performs simple subset matching and is case insensitive .
2016-12-08 01:24:59 +01:00
: return :
"""
2018-01-03 00:26:31 +01:00
status = FAILURE_METRIC_STATUS
try :
print ( " Starting to notify subscribers about expiring certificates! " )
success , failed = send_expiration_notifications ( exclude )
print (
" Finished notifying subscribers about expiring certificates! Sent: {success} Failed: {failed} " . format (
success = success ,
failed = failed
)
2016-12-08 01:24:59 +01:00
)
2018-01-03 00:26:31 +01:00
status = SUCCESS_METRIC_STATUS
except Exception as e :
sentry . captureException ( )
metrics . send ( ' expiration_notification_job ' , ' counter ' , 1 , metric_tags = { ' status ' : status } )