Coverage for curator/defaults/filtertypes.py: 96%

1"""Filtertype schema definitions"""

2 import logging

3 from curator.defaults import filter_elements, settings

4

5# pylint: disable=missing-docstring

6

7## Helpers ##

8

9 def _age_elements(action, config):

10 retval = []

11 is_req = True

12 if config['filtertype'] in ['count', 'space']:

13 is_req = True if 'use_age' in config and config['use_age'] else False

14 retval.append(filter_elements.source(action=action, required=is_req))

15 if action in settings.index_actions():

16 retval.append(filter_elements.stats_result())

17 # This is a silly thing here, because the absence of 'source' will

18 # show up in the actual schema check, but it keeps code from breaking here

19 ts_req = False

20 if 'source' in config:

21 if config['source'] == 'name':

22 ts_req = True

23 elif action in settings.index_actions():

24 # field_stats must _only_ exist for Index actions (not Snapshot)

25 if config['source'] == 'field_stats':

26 retval.append(filter_elements.field(required=True))

27 else:

28 retval.append(filter_elements.field(required=False))

29 retval.append(filter_elements.timestring(required=ts_req))

30 else:

31 # If source isn't in the config, then the other elements are not

32 # required, but should be Optional to prevent false positives

33 retval.append(filter_elements.field(required=False))

34 retval.append(filter_elements.timestring(required=ts_req))

35 return retval

36

37### Schema information ###

38

39 def alias(action, config):

40 return [

41 filter_elements.aliases(),

42 filter_elements.exclude(),

43 ]

44

45 def age(action, config):

46 # Required & Optional

47 logger = logging.getLogger('curator.defaults.filtertypes.age')

48 retval = [

49 filter_elements.direction(),

50 filter_elements.unit(),

51 filter_elements.unit_count(),

52 filter_elements.unit_count_pattern(),

53 filter_elements.epoch(),

54 filter_elements.exclude(),

55 ]

56 retval += _age_elements(action, config)

57 logger.debug('AGE FILTER = {0}'.format(retval))

58 return retval

59

60 def allocated(action, config):

61 return [

62 filter_elements.key(),

63 filter_elements.value(),

64 filter_elements.allocation_type(),

65 filter_elements.exclude(exclude=True),

66 ]

67

68 def closed(action, config):

69 return [filter_elements.exclude(exclude=True)]

70

71 def count(action, config):

72 retval = [

73 filter_elements.count(),

74 filter_elements.use_age(),

75 filter_elements.pattern(),

76 filter_elements.reverse(),

77 filter_elements.exclude(exclude=True),

78 ]

79 retval += _age_elements(action, config)

80 return retval

81

82 def forcemerged(action, config):

83 return [

84 filter_elements.max_num_segments(),

85 filter_elements.exclude(exclude=True),

86 ]

87

88 def ilm(action, config):

89 return [filter_elements.exclude(exclude=True)]

90

91 def kibana(action, config):

92 return [filter_elements.exclude(exclude=True)]

93

94 def none(action, config):

95 return []

96

97 def opened(action, config):

98 return [filter_elements.exclude(exclude=True)]

99

100 def pattern(action, config):

101 return [

102 filter_elements.kind(),

103 filter_elements.value(),

104 filter_elements.exclude(),

105 ]

106

107 def period(action, config):

108 retval = [

109 filter_elements.unit(period=True),

110 filter_elements.range_from(),

111 filter_elements.range_to(),

112 filter_elements.week_starts_on(),

113 filter_elements.epoch(),

114 filter_elements.exclude(),

115 filter_elements.period_type(),

116 filter_elements.date_from(),

117 filter_elements.date_from_format(),

118 filter_elements.date_to(),

119 filter_elements.date_to_format(),

120 ]

121 # Only add intersect() to index actions.

122 if action in settings.index_actions():

123 retval.append(filter_elements.intersect())

124 retval += _age_elements(action, config)

125 return retval

126

127 def space(action, config):

128 retval = [

129 filter_elements.disk_space(),

130 filter_elements.reverse(),

131 filter_elements.use_age(),

132 filter_elements.exclude(),

133 filter_elements.threshold_behavior(),

134 ]

135 retval += _age_elements(action, config)

136 return retval

137

138 def state(action, config):

139 return [

140 filter_elements.state(),

141 filter_elements.exclude(),

142 ]

143

144 def shards(action, config):

145 return [

146 filter_elements.number_of_shards(),

147 filter_elements.shard_filter_behavior(),

148 filter_elements.exclude(),

149 ]

150

151 def empty(action, config):

152 return [

153 filter_elements.exclude(),

154 ]

155

156 def size(action, config):

157 return [

158 filter_elements.size_threshold(),

159 filter_elements.threshold_behavior(),

160 filter_elements.size_behavior(),

161 filter_elements.exclude(),

162 ]