private Alert _constructWardenAlertForUser ( PrincipalUser user , PolicyCounter counter ) { String metricExp = _constructWardenMetricExpression ( "-1h" , user , counter ) ; Alert alert = new Alert ( _adminUser , _adminUser , _constructWardenAlertName ( user , counter ) , metricExp , "*/5 * * * *" ) ; List < Trigger > triggers = new ArrayList <> ( ) ; EntityManager em = emf . get ( ) ; double limit = PolicyLimit . getLimitByUserAndCounter ( em , user , counter ) ; Trigger trigger = new Trigger ( alert , counter . getTriggerType ( ) , "counter-value-" + counter . getTriggerType ( ) . toString ( ) + "-policy-limit" , limit , 0.0 , 0L ) ; triggers . add ( trigger ) ; List < Notification > notifications = new ArrayList <> ( ) ; Notification notification = new Notification ( NOTIFICATION_NAME , alert , _getWardenNotifierClass ( counter ) , new ArrayList < String > ( ) , 3600000 ) ; List < String > metricAnnotationList = new ArrayList < String > ( ) ; String wardenMetricAnnotation = MessageFormat . format ( "{0}:{1}'{'user={2}'}':sum" , Counter . WARDEN_TRIGGERS . getScope ( ) , Counter . WARDEN_TRIGGERS . getMetric ( ) , user . getUserName ( ) ) ; metricAnnotationList . add ( wardenMetricAnnotation ) ; notification . setMetricsToAnnotate ( metricAnnotationList ) ; notification . setTriggers ( triggers ) ; notifications . add ( notification ) ; alert . setTriggers ( triggers ) ; alert . setNotifications ( notifications ) ; return alert ; }
Create a warden alert which will annotate the corresponding warden metric with suspension events .