@@ -246,6 +246,37 @@ before run => sub {
246
246
# Dlog_debug {"Connected to $_"} $self->remote;
247
247
};
248
248
249
+ sub _get_indices_info {
250
+ my ( $self , $irefresh ) = @_ ;
251
+
252
+ if ( $irefresh || scalar ( keys %{ $self -> indices_info } ) == 0 ) {
253
+ my $sinfo_rs = $self -> es-> cat-> indices( h => [ ' index' , ' health' ] );
254
+ my $sindices_parsing = qr / ^([^[:space:]]+) +([^[:space:]]+)/ m ;
255
+
256
+ $self -> indices_info( {} );
257
+
258
+ while ( $sinfo_rs =~ / $sindices_parsing /g ) {
259
+ $self -> indices_info-> {$1 }
260
+ = { ' index_name' => $1 , ' health' => $2 };
261
+ }
262
+ }
263
+ }
264
+
265
+ sub _get_aliases_info {
266
+ my ( $self , $irefresh ) = @_ ;
267
+
268
+ if ( $irefresh || scalar ( keys %{ $self -> aliases_info } ) == 0 ) {
269
+ my $sinfo_rs = $self -> es-> cat-> aliases( h => [ ' alias' , ' index' ] );
270
+ my $saliases_parsing = qr / ^([^[:space:]]+) +([^[:space:]]+)/ m ;
271
+
272
+ $self -> aliases_info( {} );
273
+
274
+ while ( $sinfo_rs =~ / $saliases_parsing /g ) {
275
+ $self -> aliases_info-> {$1 } = { ' alias_name' => $1 , ' index' => $2 };
276
+ }
277
+ }
278
+ }
279
+
249
280
sub check_health {
250
281
my ( $self , $irefresh ) = @_ ;
251
282
my $ihealth = 0;
@@ -255,39 +286,16 @@ sub check_health {
255
286
$ihealth = $self -> await;
256
287
257
288
if ($ihealth ) {
258
- if ( $irefresh || scalar ( keys %{ $self -> indices_info } ) == 0 ) {
259
- my $sinfo_rs
260
- = $self -> es-> cat-> indices( h => [ ' index' , ' health' ] );
289
+ $self -> _get_indices_info($irefresh );
261
290
262
- $self -> indices_info( {} );
263
-
264
- while ( $sinfo_rs =~ / ^([^[:space:]]+) +([^[:space:]]+)/gm ) {
265
- $self -> indices_info-> {$1 }
266
- = { ' index_name' => $1 , ' health' => $2 };
267
-
268
- $ihealth = 0 if ( $2 eq ' red' );
269
- }
270
- }
271
- else {
272
- foreach ( keys %{ $self -> indices_info } ) {
273
- $ihealth = 0
274
- if ( $self -> indices_info-> {$_ }-> {' health' } eq ' red' );
275
- }
291
+ foreach ( keys %{ $self -> indices_info } ) {
292
+ $ihealth = 0
293
+ if ( $self -> indices_info-> {$_ }-> {' health' } eq ' red' );
276
294
}
277
295
}
278
296
279
297
if ($ihealth ) {
280
- if ( $irefresh || scalar ( keys %{ $self -> aliases_info } ) == 0 ) {
281
- my $sinfo_rs
282
- = $self -> es-> cat-> aliases( h => [ ' alias' , ' index' ] );
283
-
284
- $self -> aliases_info( {} );
285
-
286
- while ( $sinfo_rs =~ / ^([^[:space:]]+) +([^[:space:]]+)/gm ) {
287
- $self -> aliases_info-> {$1 }
288
- = { ' alias_name' => $1 , ' index' => $2 };
289
- }
290
- }
298
+ $self -> _get_aliases_info($irefresh );
291
299
292
300
$ihealth = 0 if ( scalar ( keys %{ $self -> aliases_info } ) == 0 );
293
301
}
0 commit comments