|
| 1 | +# Alerting with  |
| 2 | +<br /> |
| 3 | +This will get you started with Alerting using Yelp's alternative to the alerting feature of X-Pack from Elastic. |
| 4 | + |
| 5 | +### Repository structure |
| 6 | + |
| 7 | +- <i>configurations</i> |
| 8 | + - <i>config.yaml</i> - configurations file for elastalert |
| 9 | + - <i>smtp_auth_file.yaml</i> - authentication file for alerting via email |
| 10 | + - <i>zdaemon.conf</i> - configuration file for runneing elastalert as a daemon using zdaemon |
| 11 | + |
| 12 | +- <i>rules</i> - contains sample configurations rules to alert on CPU, memory and disk usage |
| 13 | + |
| 14 | +- <i>requirements.txt</i> - required python dependencies |
| 15 | +<br /> |
| 16 | + |
| 17 | +## 1. Requirements |
| 18 | +--- |
| 19 | + |
| 20 | +- Elasticsearch |
| 21 | + |
| 22 | +- ISO8601 or Unix timestamped data |
| 23 | + |
| 24 | +- Python 2.7 |
| 25 | +<br /> |
| 26 | + |
| 27 | +## 2. Installation |
| 28 | +--- |
| 29 | + |
| 30 | +If you're using Anaconda, do the following: |
| 31 | + |
| 32 | +- Create a new conda environment: `conda create --name <name> python=2.7 -y`. |
| 33 | + |
| 34 | +- Switch to the created environment: `source activate <name>`. |
| 35 | + |
| 36 | +- Install *pip* in the same environment: `conda install pip`. This is needed because most of the Elasalert package dependencies are not present in the Continuum channels. |
| 37 | + |
| 38 | +Refer <b>https://goo.gl/7QUSo2</b> for details on sharing a Conda environment. |
| 39 | +<br/ > |
| 40 | + |
| 41 | +### Installing Elastalert |
| 42 | + |
| 43 | +- Execute `pip install -r requirements.txt` to install the dependencies. |
| 44 | + |
| 45 | +- Finally, run `pip install elastalert`. |
| 46 | +<br /> |
| 47 | + |
| 48 | +## 3. Getting started |
| 49 | +--- |
| 50 | + |
| 51 | +- Create an index for ElastAlert to write to by running `elastalert-create-index` and follow the input prompts. |
| 52 | + |
| 53 | +- Clone the Elastalert repo: `git clone https://github.com/yelp/elastalert`. |
| 54 | + |
| 55 | +- Navigate to the cloned repo and create *config.yaml* file with these settings: |
| 56 | + |
| 57 | +```yaml |
| 58 | +rules_folder: alert_rules |
| 59 | +run_every: |
| 60 | + seconds: 10 |
| 61 | +buffer_time: |
| 62 | + seconds: 10 |
| 63 | +#es_username: <username> |
| 64 | +#es_password: <password> |
| 65 | +es_host: localhost |
| 66 | +es_port: 9200 |
| 67 | +alert_time_limit: |
| 68 | + days: 1 |
| 69 | +``` |
| 70 | +
|
| 71 | + - Create a directory called *alert_rules*. Navigate to it and create your *yaml* rule files in the same folder. |
| 72 | + <br /> |
| 73 | + |
| 74 | +## 4. Running Elastalert |
| 75 | + --- |
| 76 | +
|
| 77 | +#### Testing a rule |
| 78 | +
|
| 79 | +- `elastalert-test-rule alert_rules/<your_rule_name>.yaml`. |
| 80 | + |
| 81 | +#### Running a single rule |
| 82 | + |
| 83 | +- `python -m elastalert.elastalert --verbose --rule <your_rule_name>.yaml`. |
| 84 | + |
| 85 | +#### Running multiple rules |
| 86 | + |
| 87 | +- `python -m elastalert.elastalert --verbose --config config.yaml` |
| 88 | + |
| 89 | +This will load all the rules present in the *alert_rules* directory. |
| 90 | +<br /><br /> |
| 91 | + |
| 92 | +## 5. Running Elastalert as a daemon |
| 93 | +--- |
| 94 | + |
| 95 | +- Install *zdaemon*: `pip install zdaemon`. (https://goo.gl/FCww8S) |
| 96 | + |
| 97 | +- Create a *zdaemon.conf* file with these contents: |
| 98 | + |
| 99 | +```conf |
| 100 | +<runner> |
| 101 | + program python -m elastalert.elastalert --conf config.yaml |
| 102 | + socket-name /tmp/elastalert.zdsock |
| 103 | + forever true |
| 104 | +</runner> |
| 105 | +``` |
| 106 | + |
| 107 | +- To start Elastalert, execute: `zdaemon -C zdaemon.conf start`. |
| 108 | + |
| 109 | +- To stop Elastalert, execute: `zdaemon -C zdaemon.conf stop`. |
| 110 | +<br /> |
| 111 | + |
| 112 | +## 6. Additional configurations |
| 113 | +--- |
| 114 | + |
| 115 | +- <b>Alerting via Email</b> |
| 116 | + |
| 117 | + - In the *yaml* file of the specific rule, append the following: |
| 118 | + |
| 119 | + ```yaml |
| 120 | + alert: |
| 121 | + - email |
| 122 | + email: |
| 123 | + - "<email-to-which-the-alert-will-be-sent>" |
| 124 | + smtp_host: "smtp.gmail.com" #for google email addresses |
| 125 | + smtp_port: 465 #for google email addresses |
| 126 | + smtp_ssl: true |
| 127 | + from_addr: "<email-from-which-the-alert-will-be-sent>" |
| 128 | + smtp_auth_file: "<name-of-the-authentication-file>.yaml" |
| 129 | + ``` |
| 130 | + |
| 131 | + - Contents of the *smtp_auth_file.yaml* include user and password fields: |
| 132 | + |
| 133 | + ```yaml |
| 134 | + user: "<email-address>" |
| 135 | + password: "<password>" |
| 136 | + ``` |
| 137 | +<br /> |
| 138 | + |
| 139 | +- <b>Alerting via Slack</b> |
| 140 | + |
| 141 | + - In the *yaml* file of the specific rule, append the following: |
| 142 | + |
| 143 | + ```yaml |
| 144 | + alert: |
| 145 | + - slack |
| 146 | + slack_webhook_url: "<webhook-url-of-the-slack-channel>" |
| 147 | + slack_channel_override: "#<channel-name>" |
| 148 | + slack_username_override: "@<user-name>" |
| 149 | + ``` |
| 150 | +<br /> |
| 151 | + |
| 152 | +## License |
| 153 | + |
| 154 | +###  |
| 155 | + |
0 commit comments