File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
backend/src/main/java/com/park/utmstack Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ public void automaticReview() {
145145 final String ctx = CLASSNAME + ".automaticReview" ;
146146 try {
147147 // If no new alerts have been received, stop execution
148- if (alertUtil .countAlertsByStatus (AlertStatus .AUTOMATIC_REVIEW .getCode ()) == 0 )
148+ if (alertUtil .countAllAlertsByStatus (AlertStatus .AUTOMATIC_REVIEW .getCode ()) == 0 )
149149 return ;
150150
151151 // Getting all registered rules
Original file line number Diff line number Diff line change @@ -48,4 +48,28 @@ public Long countAlertsByStatus(int status) {
4848 throw new RuntimeException (ctx + ": " + e .getMessage ());
4949 }
5050 }
51+
52+ public Long countAllAlertsByStatus (int status ) {
53+ final String ctx = CLASSNAME + ".countAlertsByStatus" ;
54+ final String AGG_NAME = "count_open_alerts" ;
55+ try {
56+ if (!elasticsearchService .indexExist (Constants .SYS_INDEX_PATTERN .get (SystemIndexPattern .ALERTS )))
57+ return 0L ;
58+
59+ List <FilterType > filters = new ArrayList <>();
60+ filters .add (new FilterType (Constants .alertStatus , OperatorType .IS , status ));
61+ filters .add (new FilterType (Constants .alertTags , OperatorType .DOES_NOT_CONTAIN , Constants .FALSE_POSITIVE_TAG ));
62+
63+ SearchRequest .Builder srb = new SearchRequest .Builder ();
64+ srb .query (SearchUtil .toQuery (filters ))
65+ .index (Constants .SYS_INDEX_PATTERN .get (SystemIndexPattern .ALERTS ))
66+ .aggregations (AGG_NAME , a -> a .valueCount (c -> c .field (Constants .alertStatus )))
67+ .size (0 );
68+
69+ SearchResponse <Object > response = elasticsearchService .search (srb .build (), Object .class );
70+ return (long ) response .aggregations ().get (AGG_NAME ).valueCount ().value ();
71+ } catch (Exception e ) {
72+ throw new RuntimeException (ctx + ": " + e .getMessage ());
73+ }
74+ }
5175}
You can’t perform that action at this time.
0 commit comments