Guest User

Elastic Watch for Heartbeat

a guest
Jul 24th, 2017
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 2.00 KB | None | 0 0
  1. {
  2.   "trigger": {
  3.     "schedule": {
  4.       "interval": "1m"
  5.     }
  6.   },
  7.   "input": {
  8.     "search": {
  9.       "request": {
  10.         "indices": [
  11.           "heartbeat-*"
  12.         ],
  13.         "body": {
  14.           "size": 0,
  15.           "query": {
  16.             "bool": {
  17.               "filter": [
  18.                 {
  19.                   "range": {
  20.                     "@timestamp": {
  21.                       "from": "now-1m"
  22.                     }
  23.                   }
  24.                 }
  25.               ],
  26.               "must": [
  27.                 {
  28.                   "term": {
  29.                     "up": false
  30.                   }
  31.                 }
  32.               ]
  33.             }
  34.           },
  35.           "aggregations": {
  36.             "by_monitors": {
  37.               "terms": {
  38.                 "field": "monitor"
  39.               }
  40.             }
  41.           }
  42.         }
  43.       }
  44.     }
  45.   },
  46.   "condition": {
  47.     "script": {
  48.       "inline": "ctx.payload.aggregations.by_monitors.buckets.size() > 0",
  49.       "lang": "painless"
  50.     }
  51.   },
  52.   "actions": {
  53.     "log_error": {
  54.       "transform": {
  55.         "script": {
  56.           "inline": "def alerts = ctx.payload.aggregations.by_monitors.buckets.stream().map(b->b.key).collect(Collectors.toList()); return [\"alerts\":alerts];",
  57.           "lang": "painless"
  58.         }
  59.       },
  60.       "logging": {
  61.         "text": "The following hosts are down:\n          \n{{#ctx.payload.alerts}}\n    {{.}}\n{{/ctx.payload.alerts}}"
  62.       }
  63.     },
  64.     "notify-slack": {
  65.       "throttle_period": "15m",
  66.       "slack": {
  67.         "account": "monitoring",
  68.         "message": {
  69.           "from": "Heartbeat",
  70.           "text": "Some hosts are unresponsive.",
  71.           "dynamic_attachments": {
  72.             "list_path": "ctx.payload.aggregations.by_monitors.buckets",
  73.             "attachment_template": {
  74.               "title": "{{key}}",
  75.               "text": "Total events: {{doc_count}}",
  76.               "color": "warning"
  77.             }
  78.           }
  79.         }
  80.       }
  81.     }
  82.   }
  83. }
Add Comment
Please, Sign In to add comment