├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Dockerfile ├── LICENSE ├── NOTICE ├── README.md ├── VERSION ├── assets ├── check ├── common.sh ├── in └── out └── ci ├── README.md ├── credentials-example.yml └── pipeline.yml /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | credentials.yml 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | services: 4 | - docker 5 | 6 | jobs: 7 | include: 8 | - stage: Build docker image 9 | env: 10 | - DOCKER_IMAGE_NAME=frodenas/alertmanager-resource 11 | - secure: EMasURUYAXvbMQnFZHGX/YJQt5YzBi5kv7eFTSIAI8c1EgLi4C6RmlglJkbHvsb+YV44EYU9QKQdM1WRTrj3j+v/1TNKFtYAFQuDOFV2vR3EUkX43fqIabLwtVJLmW/5gffQdeK1OQLRdhb5hrM5BBoPFdhEizisRu1n7pJ8NNPpTMxsN+3Z6u5s0+9twMEkY3tfR1LOx/tMPTAasmThCPB9/E5LGLSqXtYOjFapK3SKDV3f3dGvYPID6vl2GpwFSwgAawNfgPLxPb5rsbsCQ6l7J9m/qvBSU9imoPTP5QJcQW7u4jUuavDNtP40f9mVBjyTxoH4JjYuiV3hmy6dZJkzamLQhtBRyYorOkcyDR+WJ7lActAR9TVAKU1t2cdxZY0SMR2ezyBFEMwFYqvcqf4jJX4FdNGrOxzl5GIhFtr8n3fidTm4NNYiozLGpX3VG+nipMHj802A6X4G1HRLn3Oycez8Xw4E/DqPGqpccG7iQlM5k8WYyHtQDtMiLV0YdLN3h/ieqglaoYz3n1v6HJWal2/ws9XzIq85pnkAIN4Z4I03rs4uf5FIh93loYCiWfsHvpe2iWqS3qecFHNICKVKPDEa9P6XhWkV+UaZLDLw4jHilRhq2HtVzzwwg7AThpp59pSPJkuogZPa0hjoMVOHn81qjAZETWeRto9Xp50= 12 | - secure: A53c9FRE6Uiwx99QkExUGFrEOehotoW7u230WJfnM9W8+s29EwC88RcvTR2UbdtSDI87K08aJbYmfo2/nTQ1SSF/kYos2Xhkbe8OwgvsxKce3+feFCKXcN+Mf1zI7TljCmOZNGqF84BesWegGO/EozPbG7r4gPCUrLveJn5vWwoulUP4+70QMQwGAbC0XSqd3r8pvTyqLw0lfhibjF0JsmVuaQD5Req7ZhX03/5oEuOrpCizVo7NUHirmkNso4IoXgC623SzAYE98ZbIpchSRbVISW5EydJnjq3yL6WYQL7GOsBxt0OFFXVqm6MYBvssDBk9YolJGorWPcZZnR9AYyschXm0g4En9IMLwmL4TKrTgj8IPya/7hpRcWgxA3GY6seGlbU+6N+UPgkGYOGoTv4LsZUceeO/0B9tvMIGj/KJEgqvzxr3uHGqSGkvGyYoK0dtGhGKY4kcUm6qBqHViw82HzDs0Z3cgqaax6UVLzS0go9+sMzxkLOi6sh9tdJpdqTbiO5pBcNOs/ilB3W0lHu/hPc55tfh+TFmd0e9pUDLcOy/+/qDC7iL0WnJ1jNFJPc+U+YQaAMnunbyL2ytuugmbUuJL66INT73OHl+RilfNLegy64KZWcJcfrHpDArYpiSvieYpOHIu2uqCU9ZUq58WCDdfZoWIxyz9nRnZR0= 13 | script: 14 | - | 15 | if [ -n "$TRAVIS_TAG" ]; then 16 | docker build -t "${DOCKER_IMAGE_NAME}:${TRAVIS_TAG}" . 17 | else 18 | docker build -t "${DOCKER_IMAGE_NAME}:$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi)" . 19 | fi 20 | - | 21 | if [[ "$TRAVIS_TAG" =~ ^v[0-9]+(\.[0-9]+){2}$ ]]; then 22 | docker tag "$DOCKER_IMAGE_NAME:$TRAVIS_TAG" "$DOCKER_IMAGE_NAME:latest" 23 | fi 24 | - docker images 25 | - | 26 | if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then 27 | docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD 28 | docker push $DOCKER_IMAGE_NAME 29 | fi 30 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [INSERT EMAIL ADDRESS]. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project. 4 | 5 | Here are some ways *you* can contribute: 6 | 7 | * by using alpha, beta, and prerelease versions 8 | * by reporting bugs 9 | * by suggesting new features 10 | * by writing or editing documentation 11 | * by writing specifications 12 | * by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace) 13 | * by refactoring code 14 | * by closing [issues](https://github.com/frodenas/alertmanager-resource/issues) 15 | * by reviewing patches 16 | 17 | ## Submitting an Issue 18 | 19 | We use the [GitHub issue tracker](https://github.com/frodenas/alertmanager-resource/issues) to track bugs and features. Before submitting a bug report or feature request, check to make sure it hasn't already been submitted. You can indicate support for an existing issue by voting it up. When submitting a bug report, please include a [Gist](http://gist.github.com/) that includes a stack trace and any details that may be necessary to reproduce the bug. Ideally, a bug report should include a pull request with failing specs. 20 | 21 | ## Submitting a Pull Request 22 | 23 | 1. Fork the project. 24 | 2. Create a topic branch. 25 | 3. Implement your feature or bug fix. 26 | 4. Commit and push your changes. 27 | 5. Submit a pull request. 28 | 29 | ## Code of Conduct 30 | 31 | Please note that this project is released with a [Contributor Code of Conduct](https://github.com/frodenas/alertmanager-resource/blob/master/CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms. 32 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM concourse/buildroot:git 2 | 3 | RUN cat /etc/ssl/certs/*.pem > /etc/ssl/certs/ca-certificates.crt 4 | 5 | ENV jq_version=1.6 6 | ADD https://github.com/stedolan/jq/releases/download/jq-${jq_version}/jq-linux64 /usr/local/bin/jq 7 | RUN chmod +x /usr/local/bin/jq 8 | 9 | ENV alertmanager_version=0.16.0 10 | ADD https://github.com/prometheus/alertmanager/releases/download/v${alertmanager_version}/alertmanager-${alertmanager_version}.linux-amd64.tar.gz /tmp/alertmanager-${alertmanager_version}.linux-amd64.tar.gz 11 | RUN tar xzvf /tmp/alertmanager-${alertmanager_version}.linux-amd64.tar.gz -C /tmp alertmanager-${alertmanager_version}.linux-amd64/amtool && \ 12 | mv /tmp/alertmanager-${alertmanager_version}.linux-amd64/amtool /usr/local/bin/amtool && \ 13 | chmod +x /usr/local/bin/amtool && \ 14 | rm -fr /tmp/alertmanager-* 15 | 16 | ADD assets/ /opt/resource/ 17 | RUN chmod +x /opt/resource/* 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2017-Present Ferran Rodenas 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Concourse Alertmanager resource 2 | Copyright 2017-Present Ferran Rodenas 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Alertmanager Resource [![Build Status](https://travis-ci.org/frodenas/alertmanager-resource.png)](https://travis-ci.org/frodenas/alertmanager-resource) 2 | 3 | A [Concourse](http://concourse.ci/) resource to interact with [Prometheus Alertmanager](https://prometheus.io/docs/alerting/alertmanager/), allowing you to `silence` certain alerts and to `expire` silences. 4 | 5 | ## Source Configuration 6 | 7 | | Field | Required | Type | Description 8 | |:-------|:--------:|:------:|:----------- 9 | | url | Y | String | Alertmanager URL. If alertmanager is protected by an username and password, specify them at the URL (ie http://user:pwd@alertmanager.com). 10 | 11 | *Note*: Self signed SSL certificates are not yet supported, in this case, use the `http` schema. 12 | 13 | ## Behavior 14 | 15 | ### `check`: Does nothing. 16 | 17 | ### `in`: Fetch a silence. 18 | 19 | Places the following file in the destination directory: 20 | 21 | * `silence`: Contains the `id` of the `silence` created by an `out` step. 22 | 23 | ### `out`: Silence an alert or expire a silence. 24 | 25 | Performs one of the following actions: 26 | 27 | #### Parameters 28 | 29 | | Field | Required | Type | Description 30 | |:----------|:--------:|:------:|:----------- 31 | | operation | Y | String | Operation to perform: `silence` or `expire` 32 | 33 | ##### Silence parameters 34 | 35 | | Field | Required | Type | Description 36 | |:---------|:--------:|:------:|:----------- 37 | | matchers | Y | String | The `matcher` groups to silence *[1]* 38 | | creator | N | String | The email of the silence creator 39 | | comments | N | String | A comment to help describe the silence (defaults to the `CI pipeline URL`) 40 | | expires | N | String | Duration of the silence (defaults to `1h`) 41 | 42 | *[1]* The following examples will attempt to show the `matcher` behaviour in action: 43 | 44 | | Matcher | Behaviour 45 | |:--------|:---------- 46 | | `service=cf` | will add a `silence` that matches alerts with the `service=cf` label value pair set 47 | | `alertname=CFCellUnhealthy service=cf` | will add a `silence` for the `CFCellUnhealthy` alert and matches the `service=cf` label value pair set 48 | | `alertname=~CF.*` | the `=~` syntax (similar to prometheus) is used to represent a regex match (regex matching can be used in combination with a direct match) 49 | 50 | ##### Expire parameters 51 | 52 | | Field | Required | Type | Description 53 | |:--------|:--------:|:------:|:----------- 54 | | silence | Y | String | The path of the silence to expire (a directory containing the `silence` file) 55 | 56 | ## Example Configuration 57 | 58 | ### Resource Type 59 | 60 | ```yaml 61 | resource_types: 62 | - name: alertmanager-resource 63 | type: docker-image 64 | source: 65 | repository: frodenas/alertmanager-resource 66 | ``` 67 | 68 | ### Resource 69 | 70 | ``` yaml 71 | resources: 72 | - name: alertmanager 73 | type: alertmanager-resource 74 | source: 75 | url: 76 | ``` 77 | 78 | ### Plan 79 | 80 | The below example manages multiple silences at the same plan. The `silence` parameter for `expire` operations is the name of the step who created the silence. Normally this is just the same as the name of the resource, but if you have custom names for put (for example if you need to silence multiple alerts), you would put that name instead. For example: 81 | 82 | ``` yaml 83 | jobs: 84 | - name: backups 85 | plan: 86 | - put: silence-cf-alerts 87 | resource: alertmanager 88 | params: 89 | operation: silence 90 | matchers: "service=cf" 91 | expires: 30m 92 | 93 | - put: silence-mysql-alerts 94 | resource: alertmanager 95 | params: 96 | operation: silence 97 | matchers: "service=mysql severity=warning" 98 | expires: 30m 99 | 100 | ... do my stuff ... 101 | 102 | - put: expire-cf-silence 103 | resource: alertmanager 104 | params: 105 | operation: expire 106 | silence: silence-cf-alerts 107 | 108 | - put: expire-mysql-silence 109 | resource: alertmanager 110 | params: 111 | operation: expire 112 | silence: silence-mysql-alerts 113 | ``` 114 | 115 | ## Contributing 116 | 117 | Refer to the [contributing guidelines](CONTRIBUTING.md). 118 | 119 | ## License 120 | 121 | Apache License 2.0, see [LICENSE](LICENSE). 122 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 0.3.0 -------------------------------------------------------------------------------- /assets/check: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | exec 3>&1 # make stdout available as fd 3 for the result 6 | exec 1>&2 # redirect all output to stderr for logging 7 | 8 | source $(dirname $0)/common.sh 9 | 10 | echo "[]" >&3 11 | 12 | exit 0 13 | -------------------------------------------------------------------------------- /assets/common.sh: -------------------------------------------------------------------------------- 1 | payload=$(mktemp $TMPDIR/alertmanager-resource-request.XXXXXX) 2 | 3 | cat > ${payload} <&0 4 | 5 | url=$(jq -r '.source.url // ""' < ${payload}) 6 | if [[ -z "${url}" ]]; then 7 | echo >&2 "must specify 'url' source" 8 | exit 1 9 | fi 10 | 11 | operation="$(jq -r '.params.operation // ""' < ${payload})" 12 | matchers="$(jq -r '.params.matchers // ""' < ${payload})" 13 | creator="$(jq -r '.params.creator // ""' < ${payload})" 14 | comments="$(jq -r ".params.comments // \"Silence added by CI pipeline ${ATC_EXTERNAL_URL}/teams/${BUILD_TEAM_NAME}/pipelines/${BUILD_PIPELINE_NAME}/jobs/${BUILD_JOB_NAME}/builds/${BUILD_NAME}\"" < ${payload})" 15 | expires="$(jq -r '.params.expires // "1h"' < ${payload})" 16 | silence="$(jq -r '.params.silence // ""' < ${payload})" 17 | -------------------------------------------------------------------------------- /assets/in: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | exec 3>&1 # make stdout available as fd 3 for the result 6 | exec 1>&2 # redirect all output to stderr for logging 7 | 8 | destination_dir=$1 9 | 10 | if [ -z "${destination_dir}" ]; then 11 | echo "usage: $0 " >&2 12 | exit 1 13 | fi 14 | 15 | mkdir -p "${destination_dir}" 16 | 17 | source $(dirname $0)/common.sh 18 | 19 | silence_id=$(jq -r '.version.ref // ""' < ${payload}) 20 | 21 | echo "${silence_id}" > "${destination_dir}/silence" 22 | 23 | am_active=$(amtool --alertmanager.url ${url} \ 24 | --output json \ 25 | silence query) 26 | 27 | am_expired=$(amtool --alertmanager.url ${url} \ 28 | --output json \ 29 | silence query --expired) 30 | 31 | am_all=$(echo "${am_active}" "${am_expired}" | jq -s add) 32 | 33 | echo "${am_all}" | \ 34 | jq -e ".[] | select(.id == \"${silence_id}\") | { 35 | version: { ref: .id }, 36 | metadata: [ 37 | { name: \"created_by\", value: .createdBy }, 38 | { name: \"comment\", value: .comment }, 39 | { name: \"starts_at\", value: .startsAt }, 40 | { name: \"ends_at\", value: .endsAt }, 41 | { name: \"updated_at\", value: .updatedAt } 42 | ] 43 | }" >&3 44 | 45 | exit 0 46 | -------------------------------------------------------------------------------- /assets/out: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | exec 3>&1 # make stdout available as fd 3 for the result 6 | exec 1>&2 # redirect all output to stderr for logging 7 | 8 | source_dir=$1 9 | 10 | if [ -z "${source_dir}" ]; then 11 | echo "usage: $0 " >&2 12 | exit 1 13 | fi 14 | 15 | mkdir -p "${source_dir}" 16 | 17 | source $(dirname $0)/common.sh 18 | 19 | if [[ "${operation}" == "silence" ]]; then 20 | if [[ -z "${matchers}" ]]; then 21 | echo >&2 "must specify 'matchers' parameter" 22 | exit 1 23 | fi 24 | 25 | silence_id=$(amtool --alertmanager.url ${url} \ 26 | silence add \ 27 | --author "${creator}" \ 28 | --comment "${comments}" \ 29 | --duration="${expires}" \ 30 | ${matchers}) 31 | 32 | amtool --alertmanager.url ${url} \ 33 | --output json \ 34 | silence query | \ 35 | jq -e ".[] | select(.id == \"${silence_id}\") | { 36 | version: { ref: .id }, 37 | metadata: [ 38 | { name: \"created_by\", value: .createdBy }, 39 | { name: \"comment\", value: .comment }, 40 | { name: \"starts_at\", value: .startsAt }, 41 | { name: \"ends_at\", value: .endsAt }, 42 | { name: \"updated_at\", value: .updatedAt } 43 | ] 44 | }" >&3 45 | elif [[ "${operation}" == "expire" ]]; then 46 | silence=$(jq -r '.params.silence // ""' < ${payload}) 47 | if [[ -z "${silence}" ]]; then 48 | echo >&2 "must specify 'silence' parameter" 49 | exit 1 50 | fi 51 | 52 | silence_id=$(cat "${source_dir}/${silence}/silence") 53 | amtool --alertmanager.url ${url} \ 54 | silence expire "${silence_id}" 55 | 56 | amtool --alertmanager.url ${url} \ 57 | --output json \ 58 | silence query --expired | \ 59 | jq -e ".[] | select(.id == \"${silence_id}\") | { 60 | version: { ref: .id }, 61 | metadata: [ 62 | { name: \"created_by\", value: .createdBy }, 63 | { name: \"comment\", value: .comment }, 64 | { name: \"starts_at\", value: .startsAt }, 65 | { name: \"ends_at\", value: .endsAt }, 66 | { name: \"updated_at\", value: .updatedAt } 67 | ] 68 | }" >&3 69 | else 70 | echo >&2 "invalid operation parameter '${operation}' - should be 'silence' or 'expire'" 71 | exit 1 72 | fi 73 | 74 | exit 0 75 | -------------------------------------------------------------------------------- /ci/README.md: -------------------------------------------------------------------------------- 1 | # Alertmanager Resource Concourse Pipeline 2 | 3 | In order to run the Alertmanager Resource Concourse Pipeline you must have an existing [Concourse](http://concourse.ci) environment. 4 | 5 | * Target your Concourse CI environment: 6 | 7 | ``` 8 | fly -t login -c 9 | ``` 10 | 11 | * Create a `credentials.yml` (use the [credentials-example.yml](https://github.com/frodenas/alertmanager-resource/blob/master/ci/credentials-example.yml) file as an example). 12 | 13 | * Set the Alertmanager Resource Concourse Pipeline: 14 | 15 | ``` 16 | fly -t set-pipeline -p alertmanager-resource -c ci/pipeline.yml -l ci/credentials.yml 17 | ``` 18 | 19 | * Unpause the Alermanager Resource Concourse Pipeline: 20 | 21 | ``` 22 | fly -t unpause-pipeline -p alertmanager-resource 23 | ``` 24 | -------------------------------------------------------------------------------- /ci/credentials-example.yml: -------------------------------------------------------------------------------- 1 | --- 2 | docker-hub-username: 3 | docker-hub-password: 4 | -------------------------------------------------------------------------------- /ci/pipeline.yml: -------------------------------------------------------------------------------- 1 | --- 2 | groups: 3 | - name: alertmanager-resource 4 | jobs: 5 | - build-docker-image 6 | 7 | jobs: 8 | - name: build-docker-image 9 | serial: true 10 | plan: 11 | - get: docker-image-src 12 | trigger: true 13 | 14 | - put: docker-image 15 | params: 16 | build: docker-image-src 17 | 18 | resources: 19 | - name: docker-image-src 20 | type: git 21 | source: 22 | uri: https://github.com/frodenas/alertmanager-resource.git 23 | branch: master 24 | 25 | - name: docker-image 26 | type: docker-image 27 | source: 28 | username: {{docker-hub-username}} 29 | password: {{docker-hub-password}} 30 | repository: frodenas/alertmanager-resource 31 | --------------------------------------------------------------------------------