Created
January 22, 2018 13:15
-
-
Save scottcowan/ae51d1432ff14316d08b74a4298f557e to your computer and use it in GitHub Desktop.
logstash email watcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XPUT "https://10.0.2.15:9200/_xpack/watcher/watch/fat-apps-errors-prod" -d' | |
{ | |
"trigger": { | |
"schedule": { | |
"daily": { | |
"at": [ | |
"07:00" | |
] | |
} | |
} | |
}, | |
"input": { | |
"search": { | |
"request": { | |
"search_type": "query_then_fetch", | |
"indices": [ | |
"<das-logstash-{now}>", | |
"<das-logstash-{now-1d}>" | |
], | |
"types": [ | |
"redis-input" | |
], | |
"body": { | |
"size": 0, | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"term": { | |
"Environment.keyword": { | |
"value": "PROD" | |
} | |
} | |
}, | |
{ | |
"terms": { | |
"app_Name.keyword": [ | |
"das-fat-web", | |
"das-provider-indexer", | |
"das-epao-indexer", | |
"roatp-indexer", | |
"roatp-web", | |
"das-fat-worker", | |
"das-console-web", | |
"das-emf-web", | |
"das-apprenticeships-api", | |
"das-apprenticeship-programmes-indexer", | |
"das-lars-indexer" | |
] | |
} | |
}, | |
{ | |
"terms": { | |
"level.keyword": [ | |
"Fatal", | |
"Error", | |
"Warn" | |
] | |
} | |
} | |
] | |
} | |
}, | |
"aggs": { | |
"applications": { | |
"terms": { | |
"field": "app_Name.keyword", | |
"size": 10 | |
}, | |
"aggs": { | |
"levels": { | |
"terms": { | |
"field": "level.keyword", | |
"size": 10 | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}, | |
"condition": { | |
"compare": { | |
"ctx.payload.hits.total": { | |
"gt": 0 | |
} | |
} | |
}, | |
"actions": { | |
"send_email": { | |
"email": { | |
"profile": "standard", | |
"from": "sfa-logging@no-reply.com", | |
"to": [ | |
"me@gmail.com" | |
], | |
"subject": "DAS - daily log summary", | |
"body": { | |
"html": "<!DOCTYPE html><html><head> <title>Error alert message</title> <meta charset=\"utf-8\"> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" /> <style type=\"text/css\"> /* CLIENT-SPECIFIC STYLES */ body, table, td, a { -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; } table, td { mso-table-lspace: 0pt; mso-table-rspace: 0pt; } img { -ms-interpolation-mode: bicubic; } /* RESET STYLES */ img { border: 0; height: auto; line-height: 100%; outline: none; text-decoration: none; } table { border-collapse: collapse !important; } body { height: 100% !important; margin: 0 !important; padding: 0 !important; width: 100% !important; } /* iOS BLUE LINKS */ a[x-apple-data-detectors] { color: inherit !important; text-decoration: none !important; font-size: inherit !important; font-family: inherit !important; font-weight: inherit !important; line-height: inherit !important; } /* MOBILE STYLES */ @media screen and (max-width: 525px) { /* ALLOWS FOR FLUID TABLES */ .wrapper { width: 100% !important; max-width: 100% !important; } /* ADJUSTS LAYOUT OF LOGO IMAGE */ .logo img { margin: 0 auto !important; } /* USE THESE CLASSES TO HIDE CONTENT ON MOBILE */ .mobile-hide { display: none !important; } .img-max { max-width: 100% !important; width: 100% !important; height: auto !important; } /* FULL-WIDTH TABLES */ .responsive-table { width: 100% !important; } /* UTILITY CLASSES FOR ADJUSTING PADDING ON MOBILE */ .padding { padding: 10px 5% 15px 5% !important; } .padding-meta { padding: 30px 5% 0px 5% !important; text-align: center; } .padding-copy { padding: 10px 5% 10px 5% !important; text-align: center; } .no-padding { padding: 0 !important; } .section-padding { padding: 50px 15px 50px 15px !important; } /* ADJUST BUTTONS ON MOBILE */ .mobile-button-container { margin: 0 auto; width: 100% !important; } .mobile-button { padding: 15px !important; border: 0 !important; font-size: 16px !important; display: block !important; } } /* ANDROID CENTER FIX */ div[style*=\"margin: 16px 0;\"] { margin: 0 !important; } </style></head><body style=\"margin: 0 !important; padding: 0 !important;\"> <!-- HIDDEN PREHEADER TEXT --> <div style=\"display: none; font-size: 1px; color: #fefefe; line-height: 1px; font-family: Helvetica, Arial, sans-serif; max-height: 0px; max-width: 0px; opacity: 0; overflow: hidden;\">{{ctx.payload.hits.total}} errors/warnings across the Production Environment.</div> <!-- HEADER --> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"> <tr> <td bgcolor=\"#ffffff\" align=\"center\"> <!--[if (gte mso 9)|(IE)]> <table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"500\"> <tr> <td align=\"center\" valign=\"top\" width=\"500\"> <![endif]--> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"max-width: 500px;\" class=\"wrapper\"> <tr> <td align=\"center\" valign=\"top\" style=\"padding: 15px 0;\" class=\"logo\"> </td> </tr> </table> <!--[if (gte mso 9)|(IE)]> </td> </tr> </table> <![endif]--> </td> </tr> <tr> <td bgcolor=\"#ffffff\" align=\"center\" style=\"padding: 15px;\"> <!--[if (gte mso 9)|(IE)]> <table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"500\"> <tr> <td align=\"center\" valign=\"top\" width=\"500\"> <![endif]--> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"max-width: 500px;\" class=\"responsive-table\"> <tr> <td> <!-- COPY --> <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td align=\"center\" style=\"font-size: 32px; font-family: Helvetica, Arial, sans-serif; color: #333333; padding-top: 0px;\" class=\"padding-copy\"> Summary of CI Logs for last 24 hours across the Production Environment:</td> </tr> <tr> <td align=\"left\" style=\"padding: 20px 0 0 0; font-size: 16px; line-height: 25px; font-family: Helvetica, Arial, sans-serif; color: #666666;\" class=\"padding-copy\"> <ul> {{#ctx.payload.aggregations.applications.buckets}} <li>{{key}} ({{doc_count}}) <ul>{{#levels.buckets}} <li>{{key}} ({{doc_count}})</li>{{/levels.buckets}} </ul> </li> {{/ctx.payload.aggregations.applications.buckets}} </ul> </td> </tr> </table> </td> </tr> </table> <!--[if (gte mso 9)|(IE)]> </td> </tr> </table> <![endif]--> </td> </tr> </table></body></html>" | |
} | |
} | |
} | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment