Skip to content

Commit e8f1056

Browse files
jrgpdnozay
authored andcommitted
initial commit
0 parents  commit e8f1056

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+8613
-0
lines changed

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*pyc
2+
*swp
3+
/env
4+
*egg-info
5+
/iris-api/docker/logs
6+
/build
7+
/dist
8+
*swo
9+
.cache
10+
.coverage
11+
htmlcov
12+
venv

CONTRIBUTING.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Contribution Agreement
2+
======================
3+
4+
As a contributor, you represent that the code you submit is your
5+
original work or that of your employer (in which case you represent you
6+
have the right to bind your employer). By submitting code, you (and, if
7+
applicable, your employer) are licensing the submitted code to LinkedIn
8+
and the open source community subject to the BSD 2-Clause license.
9+
10+
Responsible Disclosure of Security Vulnerabilities
11+
==================================================
12+
13+
Please do not file reports on Github for security issues.
14+
Please review the guidelines on at (link to more info).
15+
Reports should be encrypted using PGP (link to PGP key) and sent to
16+
[email protected] preferably with the title "Github linkedin/<project> - <short summary>".
17+
18+
Tips for Getting Your Pull Request Accepted
19+
===========================================
20+
21+
*Note: These are suggestions. Customize as needed.*
22+
23+
1. Make sure all new features are tested and the tests pass.
24+
2. Bug fixes must include a test case demonstrating the error that it fixes.
25+
3. Open an issue first and seek advice for your change before submitting
26+
a pull request. Large features which have never been discussed are
27+
unlikely to be accepted. **You have been warned.**

Dockerfile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM ubuntu:16.04
2+
3+
RUN apt-get update && apt-get -y dist-upgrade \
4+
&& apt-get -y install python-pip uwsgi virtualenv sudo python-dev libyaml-dev \
5+
libsasl2-dev libldap2-dev nginx uwsgi-plugin-python mysql-client \
6+
&& rm -rf /var/cache/apt/archives/*
7+
8+
RUN useradd -m -s /bin/bash iris
9+
10+
COPY setup.py /home/iris/setup.py
11+
COPY docker/entrypoint.py /home/iris/entrypoint.py
12+
ADD docker/daemons /home/iris/daemons
13+
ADD db /home/iris/db
14+
ADD src /home/iris/src
15+
16+
RUN chown -R iris:iris /home/iris /var/log/nginx /var/lib/nginx \
17+
&& sudo -Hu iris mkdir -p /home/iris/var/log/uwsgi /home/iris/var/log/nginx /home/iris/var/run \
18+
&& sudo -Hu iris virtualenv /home/iris/env \
19+
&& sudo -Hu iris /bin/bash -c 'source /home/iris/env/bin/activate && cd /home/iris && python setup.py install'
20+
21+
EXPOSE 16649
22+
23+
CMD ["bash", "-c", "source /home/iris/env/bin/activate && python /home/iris/entrypoint.py"]

LICENSE

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
BSD 2-CLAUSE LICENSE
2+
3+
Copyright 2017 LinkedIn Corporation.
4+
All Rights Reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Makefile

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
all: serve
2+
3+
serve:
4+
gunicorn --reload --access-logfile=- -b '0.0.0.0:16649' --worker-class gevent \
5+
-e CONFIG=./configs/config.dev.yaml \
6+
iris_api.wrappers.gunicorn:application
7+
8+
test:
9+
make unit
10+
make e2e
11+
12+
e2e:
13+
py.test ./test/e2etest.py
14+
15+
unit:
16+
py.test test
17+
18+
unit-cov:
19+
py.test --cov-report term-missing --cov=iris_api test
20+
21+
e2e-cov:
22+
./test/e2etest_coverage.sh
23+
24+
.PHONY: test

NOTICE

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Copyright 2017 LinkedIn Corporation
2+
All Rights Reserved.
3+
Licensed under the BSD 2-Clause License (the "License"). See License in the project root for license information.

README-Docker.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Iris-API (and iris-sender) under Docker
2+
======================================
3+
4+
### Get started
5+
6+
Build container. This installs all dependencies as well as copies all iris-api source code.
7+
8+
docker build -t iris-api .
9+
10+
Edit iris-api's config file as needed (MySQL and vendor settings and so on):
11+
12+
vim docker/config/config.yaml
13+
14+
Run it, with bind mounts to give access to iris api config file
15+
16+
docker run -p 16649:16649 -v `pwd`/docker/config:/home/iris/config -t iris-api
17+
18+
You can optionally bind mount log directories for uwsgi/nginx:
19+
20+
mkdir -p docker/logs/{uwsgi,nginx}
21+
docker run -p 16649:16649 -v `pwd`/docker/config:/home/iris/config \
22+
-v `pwd`/docker/logs/nginx:/home/iris/var/log/nginx \
23+
-v `pwd`/docker/logs/uwsgi:/home/iris/var/log/uwsgi -t iris-api
24+
25+
You can then hit `http://localhost:16649 ` to access iris-api running within the docker.
26+
27+
### Quick commands
28+
29+
Check what containers are running:
30+
31+
docker ps
32+
33+
Kill and remove a container:
34+
35+
docker rm -f $ID
36+
37+
Execute a bash shell inside container while it's running:
38+
39+
docker exec -i -t $ID /bin/bash

README.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Iris API
2+
========
3+
4+
Iris API core and sender service
5+
6+
7+
Setup database
8+
--------------
9+
10+
1. create mysql schema: `mysql -u USER -p < ./db/schema_0.sql`
11+
1. import dummy data: `mysql -u USER -p -o iris < ./db/dummy_data.sql`
12+
13+
`dummy_data.sql` contains the following entities:
14+
* user `demo`
15+
* team `demo_team`
16+
* application `Autoalerts` with key: `a7a9d7657ac8837cd7dfed0b93f4b8b864007724d7fa21422c24f4ff0adb2e49`
17+
18+
19+
Setup dev environment
20+
---------------------
21+
22+
1. create & source your virtualenv
23+
1. run `python setup.py develop`
24+
1. run `pip install -r dev_requirements.txt`
25+
1. edit ./configs/config.dev.yaml to setup database credential and other settings
26+
27+
28+
Run API server
29+
--------------
30+
31+
```bash
32+
make serve
33+
```
34+
35+
36+
Run sender
37+
---------
38+
39+
```bash
40+
iris-sender configs/config.dev.yaml
41+
```
42+
43+
44+
Tests
45+
-----
46+
47+
Run tests:
48+
49+
```bash
50+
make test # all tests, e2e + unit
51+
make e2e # e2e tests
52+
make unit # unit tests
53+
```
54+
55+
Generate test coverage reports:
56+
57+
```bash
58+
make e2e-cov
59+
make unit-cov
60+
```
61+
62+
63+
Adding new plugins
64+
------------------
65+
66+
1. create the plugin file under `src/iris_api/plugis` dir
67+
1. edit `src/iris_api/plugins/__init__.py` to add plugin module to `__all__` list

configs/config.dev.yaml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
server:
2+
host: 127.0.0.1
3+
port: 16649
4+
disable_auth: True
5+
role_lookup: dummy
6+
metrics: influx
7+
8+
# use this for LDAP settings for sync script lookup
9+
# init_config_hook: iris_internal.api.init_config
10+
11+
#metrics: prometheus
12+
#prometheus:
13+
# iris-sync-targets:
14+
# server_port: 8001
15+
# iris-sender:
16+
# server_port: 8002
17+
#
18+
#
19+
20+
#metrics: influx
21+
#influxdb:
22+
# connect:
23+
# host: localhost
24+
# port: 8086
25+
# database: iris
26+
27+
db: &db
28+
conn:
29+
kwargs:
30+
scheme: mysql+pymysql
31+
user: root
32+
password: ""
33+
host: 127.0.0.1
34+
database: iris
35+
charset: utf8
36+
str: "%(scheme)s://%(user)s:%(password)s@%(host)s/%(database)s?charset=%(charset)s"
37+
query_limit: 500
38+
kwargs:
39+
pool_recycle: 3600
40+
echo: False
41+
pool_size: 100
42+
max_overflow: 100
43+
pool_timeout: 60
44+
sender:
45+
debug: True
46+
host: 127.0.0.1
47+
port: 2321
48+
is_master: True
49+
# slaves:
50+
# - host: 127.0.0.1
51+
# port: 2322
52+
# - host: 127.0.0.1
53+
# port: 2323
54+
55+
vendors: []
56+
#- type: iris_slack
57+
# name: slack
58+
# auth_token: ''
59+
# base_url: 'https://slack.com/api/chat.postMessage'
60+
# proxy: *proxy_shared
61+
# message_attachments:
62+
# fallback: 'Iris Alert Fired!'
63+
# color: 'danger'
64+
# pretext: '<!here> _Iris_ _Alert!_'
65+
66+
# - type: iris_twilio
67+
# name: twilio_1
68+
# account_sid: ''
69+
# auth_token: ''
70+
# twilio_number: ''
71+
# relay_base_url: ''
72+
73+
healthcheck_path: /tmp/status
74+
75+
enable_gmail_oneclick: True
76+
gmail_one_click_url_key: 'foo'
77+
gmail_one_click_url_endpoint: 'http://localhost:16648/api/v0/gmail-oneclick/relay'

db/dummy_data.sql

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
LOCK TABLES `target_type` WRITE;
2+
INSERT IGNORE INTO `target_type` VALUES (2,'team'),(1,'user');
3+
UNLOCK TABLES;
4+
5+
LOCK TABLES `target` WRITE;
6+
INSERT IGNORE INTO `target` VALUES (1,'demo',1,1),(2,'abc',1,1),(3,'foo',1,1),(4,'demo_team',2,1),(5,'foo_team',2,1);
7+
UNLOCK TABLES;
8+
9+
LOCK TABLES `user` WRITE;
10+
INSERT IGNORE INTO `user` VALUES (1),(2),(3);
11+
UNLOCK TABLES;
12+
13+
LOCK TABLES `mode` WRITE;
14+
INSERT IGNORE INTO `mode` VALUES (26,'call'),(35,'email'),(17,'im'),(8,'sms');
15+
UNLOCK TABLES;
16+
17+
LOCK TABLES `priority` WRITE;
18+
INSERT IGNORE INTO `priority` VALUES (8,'urgent',26),(17,'high',8),(26,'medium',35),(35,'low',35);
19+
UNLOCK TABLES;
20+
21+
LOCK TABLES `target_role` WRITE;
22+
INSERT IGNORE INTO `target_role` VALUES (8,'user',1),(17,'manager',1),(35,'team',2),(44,'oncall',1);
23+
UNLOCK TABLES;
24+
25+
LOCK TABLES `target_contact` WRITE;
26+
INSERT IGNORE INTO `target_contact` VALUES (1,8,'+1 123-456-7890'),(1,17,'demo'),(1,26,'+1 123-456-7890'),(1,35,'[email protected]');
27+
UNLOCK TABLES;
28+
29+
LOCK TABLES `application` WRITE;
30+
INSERT INTO `application` VALUES (8,'Autoalerts','a7a9d7657ac8837cd7dfed0b93f4b8b864007724d7fa21422c24f4ff0adb2e49','{{#context}}\n<div style=\"text-align: center;\">\n <a href=\"{{console_url}}\" style=\"margin-right: 10px;\">{{name}}</a>\n <div style=\"margin-bottom: 10px;\">\n <small>\n <span style=\"margin-right: 10px;\">\n <span class=\"light\">Datacenter:</span> {{fabric}}\n </span>\n <span>\n <span class=\"light\">Zones:</span> {{zones}}\n </span>\n </small>\n </div>\n {{#if nodes}}\n <p><small><span class=\"light\">Nodes:</span> {{#each nodes}} {{this}} {{/each}}</small></p>\n {{/if}}\n {{#if notes}}\n <p>Notes: {{notes}}</p>\n {{/if}}\n </div>\n</div>\n{{/context}}','{{#context}}\n<ul>\n {{#if name}}\n <li data-toggle=\"tooltip\" data-placement=\"top\" title=\"{{name}}\">\n <strong> Name: </strong> {{name}}\n </li>\n {{/if}}\n {{#if filename}}\n <li data-toggle=\"tooltip\" data-placement=\"top\" title=\"{{filename}}\">\n <strong> Dashboard: </strong> {{filename}}\n </li>\n {{/if}}\n {{#if fabric}}\n <li data-toggle=\"tooltip\" data-placement=\"top\" title=\"{{fabric}}\">\n <strong>Fabric: </strong> {{fabric}}\n </li>\n {{/if}}\n {{#if zones}}\n <li data-toggle=\"tooltip\" data-placement=\"top\" title=\"{{zones}}\">\n <strong>Zones: </strong> {{zones}}\n </li>\n {{/if}}\n {{#if nodes}}\n <li>\n <strong>Nodes: </strong>\n <ul>\n {{#each nodes}}\n <li data-toggle=\"tooltip\" data-placement=\"top\" title=\"{{this}}\"> {{this}} </li>\n {{/each}}\n </ul>\n </li>\n {{/if}}\n</ul>\n{{/context}}\n','{\n \"console_url\": \"\",\n \"fabric\": \"DC1\",\n \"filename\": \"dashboard\",\n \"graph_image_url\": \"http://url.example.com/foo\",\n \"metanodes\": [\n [\"execution_time.metanode1\", \"threshold: 72 is greater than the max (65)\"],\n ],\n \"name\": \"Name Of Your Alert\",\n \"nodes\": [\n [\"execution_time.server1.example.com\", \"threshold: 72 is greater than the max (65)\"],\n ],\n \"notes\": \"This is a note\",\n \"zones\": [\"zone1\", \"zone2\"]\n}',0,0),(9,'iris-frontend','fooooo',NULL,NULL,NULL,1,1),(10,'test-app','sdffdssdf',NULL,NULL,NULL,0,0);
31+
UNLOCK TABLES;
32+
33+
LOCK TABLES `template_variable` WRITE;
34+
INSERT INTO `template_variable` VALUES (1,8,'fabric',0),(2,8,'console_url',0),(3,8,'filename',0),(4,8,'name',0),(5,8,'graph_image_url',0),(7,8,'zones',0),(8,8,'nodes',0),(9,8,'metanodes',0),(10,8,'notes',0);
35+
UNLOCK TABLES;

0 commit comments

Comments
 (0)