Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. PUT _xpack/watcher/watch/cluster_health
  2. {
  3. "metadata": {
  4. "not_green_secs": 60,
  5. "monitoring_update_interval": 10
  6. },
  7. "trigger": {
  8. "schedule": {
  9. "interval": "60s"
  10. }
  11. },
  12. "throttle_period": "30m",
  13. "input": {
  14. "search": {
  15. "request": {
  16. "search_type": "query_then_fetch",
  17. "indices": [
  18. ".monitoring-es*"
  19. ],
  20. "types": [
  21. "doc"
  22. ],
  23. "body": {
  24. "query": {
  25. "bool": {
  26. "filter": {
  27. "bool": {
  28. "must": [
  29. {
  30. "range": {
  31. "timestamp": {
  32. "gte": "now-{{ctx.metadata.not_green_secs}}s"
  33. }
  34. }
  35. },
  36. {
  37. "term": {
  38. "type": {
  39. "value": "cluster_stats"
  40. }
  41. }
  42. }
  43. ]
  44. }
  45. }
  46. }
  47. },
  48. "aggs": {
  49. "clusters": {
  50. "terms": {
  51. "field": "cluster_uuid",
  52. "size": 100
  53. },
  54. "aggs": {
  55. "cluster_state": {
  56. "filters": {
  57. "filters": {
  58. "yellow": {
  59. "term": {
  60. "cluster_state.status": "yellow"
  61. }
  62. },
  63. "red": {
  64. "term": {
  65. "cluster_state.status": "red"
  66. }
  67. }
  68. }
  69. }
  70. },
  71. "latest_state": {
  72. "top_hits": {
  73. "size": 1,
  74. "sort": [
  75. {
  76. "timestamp": {
  77. "order": "desc"
  78. }
  79. }
  80. ]
  81. }
  82. }
  83. }
  84. }
  85. },
  86. "size": 0
  87. }
  88. }
  89. }
  90. },
  91. "condition": {
  92. "script": {
  93. "source": "def is_not_green=ctx.payload.aggregations.clusters.buckets.stream().anyMatch(t -> (t.latest_state.hits.hits[0]._source.cluster_state.status== 'yellow' || t.latest_state.hits.hits[0]._source.cluster_state.status == 'red')); if (is_not_green) { def required_periods = (ctx.metadata.not_green_secs-ctx.metadata.monitoring_update_interval)/ctx.metadata.monitoring_update_interval; return ctx.payload.aggregations.clusters.buckets.stream().anyMatch(t -> ((t.cluster_state.buckets.red.doc_count + t.cluster_state.buckets.yellow.doc_count) >= required_periods )); } return false;",
  94. "lang": "painless"
  95. }
  96. },
  97. "transform": {
  98. "script": {
  99. "source": "def required_periods = (ctx.metadata.not_green_secs-ctx.metadata.monitoring_update_interval)/ctx.metadata.monitoring_update_interval; return ctx.payload.aggregations.clusters.buckets.stream().filter(t -> (t.latest_state.hits.hits[0]._source.cluster_state.status == 'yellow' || t.latest_state.hits.hits[0]._source.cluster_state.status == 'red')).filter(t -> (t.cluster_state.buckets.red.doc_count + t.cluster_state.buckets.yellow.doc_count) >= required_periods).map(t -> ['cluster_id':t.key,'cluster_state':t.latest_state.hits.hits[0]._source.cluster_state.status,'cluster_name':t.latest_state.hits.hits[0]._source.cluster_name]).collect(Collectors.toList());",
  100. "lang": "painless"
  101. }
  102. },
  103. "actions": {
  104. "log": {
  105. "logging": {
  106. "text": "Clusters that have not NOT been green for more than {{ctx.metadata.not_green_secs}}s: {{#ctx.payload._value}}{{cluster_id}}-{{cluster_state}}{{/ctx.payload._value}}:"
  107. }
  108. }
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement