项目作者: kumbasar

项目描述 :
An email notification tool for cloud foundry applications
高级语言: Python
项目地址: git://github.com/kumbasar/cf-logs-alert.git
创建时间: 2020-12-19T08:20:33Z
项目社区:https://github.com/kumbasar/cf-logs-alert

开源协议:GNU General Public License v3.0

下载


Cloud Foundry Application Alerter

This tool fetches all app logs from a Cloud Foundry target (org/space) and posts an email notification if it parses a trigger keyword.

Codeship Status for kumbasar/cf-logs-alert
cf-logs-alert

Usage

Before starting the tool, first update the config.json file according to your settings. All input parameters are listed in the table below.

Parameter Info
space CF space value
org CF org value
user CF username
password CF password
api CF target URL
smtp SMTP IP address or hostname
port SMTP port #
sender_email Email poster
receiver_email Receiver list
keys Notifaction keyword list

Execute the below commands to install the dependencies:

  1. pip3 install -r requirements.txt
  2. chmod +x main.py

To start the alert tool:

  1. ./main.py

Also, you might want to build and run the tool in a Docker container. If so, you can check out the provided Dockerfile as an example.

In short, to build and run the tool via Docker:

  1. docker build -t cf-logger .
  2. docker run -t cf-logger

Proxy Configuration

You can set your proxy settings as follows:

  1. export HTTPS_PROXY=<HTTPS_PROXY>
  2. export HTTP_PROXY=<HTTP_PROXY>
  3. ./main.py

or

  1. ./main.py --proxy <HTTPS_PROXY>

Optional: Setup a email server

For testing, you can setup a dummy email server as follows.

First, update the config.json file as follows:

  1. [...]
  2. "email": {
  3. "smtp": "localhost",
  4. "port": "1025",
  5. "sender_email": "test@localhost",
  6. "receiver_email": "test@localhost"
  7. }
  8. [...]

Execute the test server:

  1. python -m smtpd -c DebuggingServer -n localhost:1025

In a different terminal, start the tool.

  1. ./main.py

Also, you can use the docker compose framework for testing. Just, set the smtp value to mailserver.

@config.json:

  1. [...]
  2. "smtp": "mailserver",
  3. [...]

Execute below command to build and start up the containers.

  1. docker-compose up --build

Example alert console output:

  1. mailserver_1 | ---------- MESSAGE FOLLOWS ----------
  2. mailserver_1 | b'Content-Type: text/plain; charset="utf-8"'
  3. mailserver_1 | b'Content-Transfer-Encoding: 7bit'
  4. mailserver_1 | b'MIME-Version: 1.0'
  5. mailserver_1 | b'Subject: CF log alert'
  6. mailserver_1 | b'From: kumbasar@localhost'
  7. mailserver_1 | b'To: volkan@localhost'
  8. mailserver_1 | b'X-Peer: 172.19.0.3'
  9. mailserver_1 | b''
  10. mailserver_1 | b'Org/space: welcome/dev'
  11. mailserver_1 | b'App: roster'
  12. mailserver_1 | b'Key: eventType'
  13. mailserver_1 | b'Log: origin: "rep"'
  14. mailserver_1 | b'eventType: ContainerMetric'
  15. mailserver_1 | b'timestamp: 1615139019420518865'
  16. mailserver_1 | b'containerMetric {'
  17. mailserver_1 | b' applicationId: "85d139e7-9fb3-4041-b80a-5970f624a415"'
  18. mailserver_1 | b' instanceIndex: 0'
  19. mailserver_1 | b' cpuPercentage: 1.0301370119722197'
  20. mailserver_1 | b' memoryBytes: 375887877'
  21. mailserver_1 | b' diskBytes: 163287040'
  22. mailserver_1 | b' memoryBytesQuota: 786432000'
  23. mailserver_1 | b' diskBytesQuota: 1073741824'
  24. mailserver_1 | b'}'
  25. mailserver_1 | b'deployment: "kubecf"'
  26. mailserver_1 | b'job: "diego-cell-loggr-forwarder-agent"'
  27. mailserver_1 | b'index: "diego-cell-2"'
  28. mailserver_1 | b'ip: "192.168.75.215"'
  29. mailserver_1 | b'tags {'
  30. mailserver_1 | b' key: "app_id"'
  31. mailserver_1 | b' value: "85d139e7-9fb3-4041-b80a-5970f624a415"'
  32. mailserver_1 | b'}'
  33. mailserver_1 | b'tags {'
  34. mailserver_1 | b' key: "app_name"'
  35. mailserver_1 | b' value: "roster"'
  36. mailserver_1 | b'}'
  37. mailserver_1 | b'tags {'
  38. mailserver_1 | b' key: "instance_id"'
  39. mailserver_1 | b' value: "0"'
  40. mailserver_1 | b'}'
  41. mailserver_1 | b'tags {'
  42. mailserver_1 | b' key: "organization_id"'
  43. mailserver_1 | b' value: "fa94302b-462d-4e3d-9bc1-7a4af6025fdc"'
  44. mailserver_1 | b'}'
  45. mailserver_1 | b'tags {'
  46. mailserver_1 | b' key: "organization_name"'
  47. mailserver_1 | b' value: "welcome"'
  48. mailserver_1 | b'}'
  49. mailserver_1 | b'tags {'
  50. mailserver_1 | b' key: "process_id"'
  51. mailserver_1 | b' value: "85d139e7-9fb3-4041-b80a-5970f624a415"'
  52. mailserver_1 | b'}'
  53. mailserver_1 | b'tags {'
  54. mailserver_1 | b' key: "process_instance_id"'
  55. mailserver_1 | b' value: "9c890ccb-2268-45f8-400a-6a52"'
  56. mailserver_1 | b'}'
  57. mailserver_1 | b'tags {'
  58. mailserver_1 | b' key: "process_type"'
  59. mailserver_1 | b' value: "web"'
  60. mailserver_1 | b'}'
  61. mailserver_1 | b'tags {'
  62. mailserver_1 | b' key: "source_id"'
  63. mailserver_1 | b' value: "85d139e7-9fb3-4041-b80a-5970f624a415"'
  64. mailserver_1 | b'}'
  65. mailserver_1 | b'tags {'
  66. mailserver_1 | b' key: "space_id"'
  67. mailserver_1 | b' value: "67d9cef1-672d-4126-8969-905e0ad87ce2"'
  68. mailserver_1 | b'}'
  69. mailserver_1 | b'tags {'
  70. mailserver_1 | b' key: "space_name"'
  71. mailserver_1 | b' value: "dev"'
  72. mailserver_1 | b'}'
  73. mailserver_1 | ------------ END MESSAGE ------------