60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/dashboard/src/app/admin/alert/stats-alarm-simple.component.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import {Component, Input} from "@angular/core";
20 | import {Router} from "@angular/router";
21 | import {Observable} from "rxjs/Observable";
22 |
23 | import {Stat} from "../stat";
24 |
25 | @Component({
26 | selector: 'modal-stats-alarm-simple',
27 | templateUrl: './stats-alarm-simple.component.html',
28 | styleUrls: ['../admin.css']
29 | })
30 |
31 | export class StatsAlarmSimple {
32 | @Input() title: string;
33 | @Input() stats: Stat[];
34 | @Input() alarmNames: string[];
35 |
36 | constructor(private router: Router) { }
37 |
38 | gotoDetail(alarmId: String) {
39 | this.router.navigate(['alarms', alarmId]);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/dashboard/src/app/admin/sort-stat.pipe.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import { Pipe, PipeTransform } from '@angular/core';
20 |
21 | import { Stat } from './stat';
22 |
23 | /**
24 | * A pipe to get a top of an array of Stat sorted by the count value.
25 | */
26 | @Pipe({
27 | name: 'sortstat'
28 | })
29 | export class SortStatPipe implements PipeTransform {
30 | STAT_MAXSIZE = 10;
31 |
32 | transform(stats: Stat[]) {
33 | if (stats === undefined) {
34 | // console.error("Alarm array is undefined");
35 | return stats;
36 | }
37 |
38 | return stats.sort(function (a, b){
39 | if (a.count < b.count) {
40 | return 1;
41 | }
42 | if (a.count > b.count) {
43 | return -1;
44 | }
45 | return 0;
46 | }).slice(0, this.STAT_MAXSIZE);
47 | };
48 | }
49 |
--------------------------------------------------------------------------------
/dashboard/src/app/admin/stat.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | export class Stat {
20 |
21 | constructor(
22 | public alarmId: string,
23 | public count: number,
24 | public type: string
25 | ) { }
26 | }
27 |
--------------------------------------------------------------------------------
/dashboard/src/app/admin/subscription/admin-subscriptions.component.html:
--------------------------------------------------------------------------------
1 |
18 |
19 |
97 |
--------------------------------------------------------------------------------
/dashboard/src/app/admin/top-target-graphite.pipe.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import { Pipe, PipeTransform } from '@angular/core';
20 |
21 | import { Alarm } from '../alarm/alarm';
22 |
23 | /**
24 | * A pipe to get a top of an array of Alarm sorted by the target length.
25 | */
26 | @Pipe({
27 | name: 'topTargetGraphite'
28 | })
29 | export class TopTargetGraphitePipe implements PipeTransform {
30 | STAT_MAXSIZE = 10;
31 |
32 | transform(alarms: Alarm[]) {
33 | if (alarms === undefined) {
34 | // console.error("Alarm array is undefined");
35 | return alarms;
36 | }
37 |
38 | return alarms.sort(function (a, b) {
39 | if (a.target.length < b.target.length) {
40 | return 1;
41 | }
42 | if (a.target.length > b.target.length) {
43 | return -1;
44 | }
45 | return 0;
46 | }).slice(0, this.STAT_MAXSIZE);
47 | };
48 | }
49 |
--------------------------------------------------------------------------------
/dashboard/src/app/alarm/alarm-detail.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import { Alarm } from './alarm';
20 |
21 | export class AlarmDetail {
22 |
23 | constructor(
24 | public alarm: Alarm,
25 | public targetGraphiteKeys: string[]
26 | ) { }
27 | }
28 |
--------------------------------------------------------------------------------
/dashboard/src/app/alarm/alarm.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import { Subscription } from '../subscription/subscription';
20 |
21 | export class Alarm {
22 |
23 | constructor(
24 | public id: string,
25 | public name: string,
26 | public description: string,
27 | public target: string,
28 | public from: string,
29 | public until: string,
30 | public graphiteBaseUrl: string,
31 | public warn: number,
32 | public error: number,
33 | public enabled: boolean,
34 | public live: boolean,
35 | public allowNoData: boolean,
36 | public state: string,
37 | public lastCheck: number,
38 | public subscriptions: Subscription[]
39 | ) { }
40 | }
41 |
--------------------------------------------------------------------------------
/dashboard/src/app/alarm/view/alarm-detail.component.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | .subscriptions {
20 | font-size: small;
21 | }
22 |
23 | li {
24 | list-style:none;
25 | }
26 |
27 | .card {
28 | background-color: white;
29 | border-radius:7px;
30 | -moz-box-shadow: 5px 5px 10px 0px #656565;
31 | -webkit-box-shadow: 5px 5px 10px 0px #656565;
32 | -o-box-shadow: 5px 5px 10px 0px #656565;
33 | box-shadow: 5px 5px 10px 0px #656565;
34 | filter:progid:DXImageTransform.Microsoft.Shadow(color=#656565, Direction=134, Strength=10);
35 | margin-bottom: 10px;
36 | width: 33%;
37 | min-height: 190px;
38 | margin-right: 0.1%;
39 | }
40 |
41 | .cardInline {
42 | background-color: white;
43 | border-radius:7px;
44 | -moz-box-shadow: 5px 5px 10px 0px #656565;
45 | -webkit-box-shadow: 5px 5px 10px 0px #656565;
46 | -o-box-shadow: 5px 5px 10px 0px #656565;
47 | box-shadow: 5px 5px 10px 0px #656565;
48 | filter:progid:DXImageTransform.Microsoft.Shadow(color=#656565, Direction=134, Strength=10);
49 | margin-bottom: 10px;
50 | width: 100%;
51 | min-height: 130px;
52 | }
53 |
54 | .card-disabled {
55 | background: rgba(226,226,226,1);
56 | background: -moz-linear-gradient(-45deg, rgba(226,226,226,1) 0%, rgba(219,219,219,1) 50%, rgba(209,209,209,1) 51%, rgba(254,254,254,1) 100%);
57 | background: -webkit-gradient(left top, right bottom, color-stop(0%, rgba(226,226,226,1)), color-stop(50%, rgba(219,219,219,1)), color-stop(51%, rgba(209,209,209,1)), color-stop(100%, rgba(254,254,254,1)));
58 | background: -webkit-linear-gradient(-45deg, rgba(226,226,226,1) 0%, rgba(219,219,219,1) 50%, rgba(209,209,209,1) 51%, rgba(254,254,254,1) 100%);
59 | background: -o-linear-gradient(-45deg, rgba(226,226,226,1) 0%, rgba(219,219,219,1) 50%, rgba(209,209,209,1) 51%, rgba(254,254,254,1) 100%);
60 | background: -ms-linear-gradient(-45deg, rgba(226,226,226,1) 0%, rgba(219,219,219,1) 50%, rgba(209,209,209,1) 51%, rgba(254,254,254,1) 100%);
61 | background: linear-gradient(135deg, rgba(226,226,226,1) 0%, rgba(219,219,219,1) 50%, rgba(209,209,209,1) 51%, rgba(254,254,254,1) 100%);
62 | filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#e2e2e2', endColorstr='#fefefe', GradientType=1 );
63 | }
64 |
65 | .logo{
66 | float:right;
67 | }
68 |
69 | .card>div {
70 | margin-bottom: 3%;
71 | }
72 |
73 | .moove {
74 | display: inline;
75 | }
76 |
77 | .group_actions {
78 | margin: 5px 0px;
79 | text-align: right;
80 | }
--------------------------------------------------------------------------------
/dashboard/src/app/alarm/view/alarm-status.component.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import { Component, Input } from '@angular/core';
20 |
21 | @Component({
22 | selector: 'alarm-status',
23 | template: `
24 | {{ status }}
25 | {{ status }}
26 | {{ status }}
27 | {{ status }}
28 | {{ status }}
29 | `,
30 | })
31 | export class AlarmStatusComponent {
32 | @Input()
33 | status: string;
34 | }
35 |
--------------------------------------------------------------------------------
/dashboard/src/app/alarm/view/alarms.component.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | .selected {
20 | background-color: #CFD8DC !important;
21 | color: white;
22 | }
23 |
24 | .error {
25 | color: red;
26 | }
27 |
28 | .back-bluelight {
29 | background-color: #EAF3F3;
30 | }
31 |
32 | .detailTitle {
33 | font-weight: bold;
34 | }
35 |
36 | /*CSS de la pagination*/
37 | .custom-pagination {
38 | margin: 5px;
39 | }
40 |
41 | .custom-pagination>span {
42 | font-size: 11px;
43 | list-style: none;
44 | margin-right: 2px;
45 | border: solid 1px #9aafe5;
46 | color: #0e509e;
47 | padding: 3px 6px;
48 | text-decoration: none;
49 | cursor: pointer;
50 |
51 | /* désactivation de la selection du texte */
52 | -webkit-touch-callout: none; /* iOS Safari */
53 | -webkit-user-select: none; /* Chrome/Safari/Opera */
54 | -khtml-user-select: none; /* Konqueror */
55 | -moz-user-select: none; /* Firefox */
56 | -ms-user-select: none; /* Internet Explorer/Edge */
57 | user-select: none; /* Non-prefixed version, currently
58 | not supported by any browser */
59 | }
60 |
61 | .custom-pagination .page_number {
62 | min-width: 25px;
63 | display: inline-block;
64 | }
65 |
66 | .custom-pagination .disabled {
67 | border: solid 1px #DEDEDE;
68 | color: #888888;
69 | font-weight: bold;
70 | margin-right: 2px;
71 | padding: 3px 4px;
72 | cursor: default;
73 | }
74 |
75 | .custom-pagination .next, .custom-pagination .previous {
76 | font-weight: bold;
77 | min-width: 80px;
78 | display: inline-block;
79 | }
80 |
81 | .custom-pagination .current {
82 | background: #2e6ab1;
83 | color: #FFFFFF;
84 | font-weight: bold;
85 | padding: 4px 6px;
86 | }
87 |
88 | .custom-pagination>span:hover {
89 | border: solid 1px #0e509e
90 | }
91 |
92 | .custom-pagination .disabled:hover {
93 | border: solid 1px #DEDEDE;
94 | }
--------------------------------------------------------------------------------
/dashboard/src/app/alert/alert.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | @CHARSET "UTF-8";
20 |
21 | .responstable {
22 | margin: 1em 0;
23 | width: 100%;
24 | overflow: hidden;
25 | background: #FFF;
26 | color: #024457;
27 | border-radius: 10px;
28 | border: 1px solid #167F92;
29 | }
30 | .responstable tr {
31 | border: 1px solid #D9E4E6;
32 | }
33 | .responstable tr:nth-child(odd) {
34 | background-color: #EAF3F3;
35 | }
36 | .responstable th {
37 | display: none;
38 | border: 1px solid #FFF;
39 | background-color: #167F92;
40 | color: #FFF;
41 | padding: 1em;
42 | }
43 | .responstable th:first-child {
44 | display: table-cell;
45 | text-align: center;
46 | }
47 | .responstable th:nth-child(2) {
48 | display: table-cell;
49 | }
50 | .responstable th:nth-child(2) span {
51 | display: none;
52 | }
53 | .responstable th:nth-child(2):after {
54 | content: attr(data-th);
55 | }
56 | @media (min-width: 480px) {
57 | .responstable th:nth-child(2) span {
58 | display: block;
59 | }
60 | .responstable th:nth-child(2):after {
61 | display: none;
62 | }
63 | }
64 | .responstable td {
65 | display: block;
66 | word-wrap: break-word;
67 | max-width: 7em;
68 | }
69 | .responstable td:first-child {
70 | display: table-cell;
71 | text-align: center;
72 | border-right: 1px solid #D9E4E6;
73 | }
74 | @media (min-width: 480px) {
75 | .responstable td {
76 | border: 1px solid #D9E4E6;
77 | }
78 | }
79 | .responstable th, .responstable td {
80 | text-align: left;
81 | margin: .5em 1em;
82 | font-size: 11px;
83 | }
84 | @media (min-width: 480px) {
85 | .responstable th, .responstable td {
86 | display: table-cell;
87 | padding: 1em;
88 | }
89 | }
--------------------------------------------------------------------------------
/dashboard/src/app/alert/alert.service.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import {Injectable} from "@angular/core";
20 | import {Http, Response} from "@angular/http";
21 | import {Observable} from "rxjs/Observable";
22 | import {AppConfig} from "../app.config";
23 | import {Alert} from "./alert";
24 | import {Stat} from "../admin/stat";
25 |
26 | @Injectable()
27 | export class AlertService {
28 | private remoteRootUrl = this.config.get("services_url");
29 | private allAlertsUrl = "/alerts";
30 | private statNoChangeUrl = "/alerts/stats/nochanges";
31 | private statChangeUrl = "/alerts/stats/changes";
32 |
33 | constructor(
34 | private http: Http,
35 | private config: AppConfig
36 | ) { }
37 |
38 | getAlerts(): Observable { // get 20 alerts
39 | return this.http.get(this.remoteRootUrl + this.allAlertsUrl)
40 | .map(response => response.json())
41 | .catch(this.handleError);
42 | }
43 |
44 | getAlarmAlerts(id: string): Observable {
45 | return this.http.get(this.remoteRootUrl + "/alarms/" + id + this.allAlertsUrl)
46 | .map(response => response.json())
47 | // .catch(this.handleError)
48 | ;
49 | }
50 |
51 | getStatAlertWithNoChange(from: string): Observable {
52 | return this.http.get(this.remoteRootUrl + this.statNoChangeUrl + "?from=" + from)
53 | .map(response => response.json())
54 | .do(data => console.log(data)) // eyeball results in the console
55 | // .catch(this.handleError)
56 | ;
57 | }
58 |
59 | getStatAlertWithChange(from: string): Observable {
60 | return this.http.get(this.remoteRootUrl + this.statChangeUrl + "?from=" + from)
61 | .map(response => response.json())
62 | .do(data => console.log(data)) // eyeball results in the console
63 | // .catch(this.handleError)
64 | ;
65 | }
66 |
67 | private handleError(errorResponse: any) {
68 | // in a real world app, we may send the server to some remote logging
69 | // infrastructure
70 | // instead of just logging it to the console
71 | if (errorResponse instanceof Response) {
72 | return Observable.throw(errorResponse.json() || 'Server error');
73 | }
74 |
75 | return Observable.throw(errorResponse || 'Server error');
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/dashboard/src/app/alert/alert.spec.ts.txt:
--------------------------------------------------------------------------------
1 | import {Alert} from './alert';
2 |
3 | describe('Alert', () => {
4 |
5 | let alert : Alert;
6 |
7 | beforeEach(() => {
8 | Alert = new Alert("576154cf0cf2f53c12f4e898",
9 | "575e665d0cf267d965c8ccce",null,"Zenith.BEN.WDI.WDI.LIL.PRD1.WAS.WDIOLIP14BEN.25_0.any.AF.getOutwardFares.part.TPF.3.vol.any.10min.count",60,90,"INFO","WARN",1465996494.797000000,"treqtzterz");
10 | });
11 |
12 | it('has id', () => {
13 | expect(alert.id).toEqual("576154cf0cf2f53c12f4e898");
14 | });
15 |
16 | it('has name', () => {
17 | expect(alert.checkId).toEqual('575e665d0cf267d965c8ccce');
18 | });
19 |
20 | });
--------------------------------------------------------------------------------
/dashboard/src/app/alert/alert.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | export class Alert {
20 |
21 | constructor(
22 | public id: string,
23 | public alarmId: string,
24 | public value: number,
25 | public target: string,
26 | public warn: number,
27 | public error: number,
28 | public fromType: string,
29 | public toType: string,
30 | public timestamp: number,
31 | public count : number,
32 | public targetHash: string
33 | ) { }
34 | }
35 |
--------------------------------------------------------------------------------
/dashboard/src/app/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import { NgModule } from '@angular/core';
20 | import { RouterModule, Routes } from '@angular/router';
21 |
22 | import { AddAlarmComponent } from './alarm/add/add-alarm.component';
23 | import { AlarmsComponent } from './alarm/view/alarms.component';
24 | import { AlarmDetailComponent } from './alarm/view/alarm-detail.component';
25 | import { DashboardComponent } from './dashboard/dashboard.component';
26 | import { AdminAlarmsComponent } from './admin/alarm/admin-alarms.component';
27 | import { AdminSubscriptionsComponent } from './admin/subscription/admin-subscriptions.component';
28 | import { AdminAlertsComponent } from './admin/alert/admin-alerts.component';
29 |
30 | const routes: Routes = [
31 | { path: '', redirectTo: '/dashboard', pathMatch: 'full' },
32 | { path: 'dashboard', component: DashboardComponent, data : { name: 'Dashboard' } },
33 | { path: 'alarms/add', component: AddAlarmComponent, data : { name: 'AddAlarm' }, },
34 | { path: 'alarms', component: AlarmsComponent, data : { name: 'Alarms' }, },
35 | { path: 'alarms/:id', component: AlarmDetailComponent, data : { name: 'AlarmDetail' }, },
36 | { path: 'admin/alarms', component: AdminAlarmsComponent, data : { name: 'AdminAlarme' }, },
37 | { path: 'admin/subscriptions', component: AdminSubscriptionsComponent, data : { name: 'AdminSubscriptions' }, },
38 | { path: 'admin/alerts', component: AdminAlertsComponent, data : { name: 'AdminAlert' }, }
39 | ];
40 | @NgModule({
41 | imports: [ RouterModule.forRoot(routes) ],
42 | exports: [ RouterModule ]
43 | })
44 | export class AppRoutingModule {}
45 |
--------------------------------------------------------------------------------
/dashboard/src/app/app.component.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | h1 {
20 | font-size: 3em;
21 | color: white;
22 | margin-bottom: 0;
23 | }
24 | h2 {
25 | font-size: 1.2em;
26 | margin-top: 0;
27 | padding-top: 0;
28 | }
29 | nav a {
30 | padding: 5px 10px;
31 | text-decoration: none;
32 | margin-top: 10px;
33 | display: inline-block;
34 | background-color: #eee;
35 | border-radius: 4px;
36 | }
37 | nav a:visited, a:link {
38 | color: #607D8B;
39 | }
40 | nav a:hover {
41 | color: #039be5;
42 | background-color: #CFD8DC;
43 | }
44 | nav a.router-link-active {
45 | color: #039be5;
46 | }
47 |
48 | .jumbotron {
49 | padding-top: 12px;
50 | padding-bottom: 12px;
51 | background-size: cover;
52 | color: #FFFFFF;
53 | text-shadow: 0px 0px 10px #333333;
54 | text-align: right;
55 | }
56 |
57 | .jumbotron-buttons {
58 | float: left;
59 | padding: 10px;
60 | margin-top: -80px;
61 | text-shadow: none;
62 | }
63 |
64 | .jumbotron p {
65 | font-size: 1.2em;
66 | }
--------------------------------------------------------------------------------
/dashboard/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import { Component, ViewContainerRef } from '@angular/core';
20 | import { ToastsManager } from 'ng2-toastr/ng2-toastr';
21 |
22 | import { AuthService } from './common/auth/basic.auth.service';
23 | import { Profile } from './common/auth/profile';
24 | import { DefaultProfile } from './common/auth/default-profile';
25 | import { AppConfig } from './app.config';
26 |
27 | @Component({
28 | moduleId: module.id,
29 | selector: 'cerebro-app',
30 | templateUrl: 'app.component.html',
31 | styleUrls: ['app.component.css']
32 | })
33 | export class AppComponent {
34 | background:any = {
35 | "background": "url('" + this.config.get("theme").headerImage + "') center center no-repeat"
36 | };
37 |
38 | contacts: any = this.config.get("contacts");
39 | private profile:any = this.authService.getProfile();
40 | hasAuthentication:boolean = !(this.profile instanceof DefaultProfile);
41 |
42 | constructor(
43 | private authService: AuthService,
44 | public toastr: ToastsManager,
45 | vRef: ViewContainerRef,
46 | private config: AppConfig
47 | )
48 | {
49 | this.toastr.setRootViewContainerRef(vRef);
50 | }
51 |
52 | logout() {
53 | this.authService.logout();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/dashboard/src/app/app.config.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import {Injectable} from "@angular/core";
20 | import {Http} from "@angular/http";
21 |
22 | @Injectable()
23 | export class AppConfig {
24 |
25 | private config: Object
26 |
27 | constructor(private http: Http) { }
28 |
29 | public load() {
30 | return new Promise((resolve, reject) => {
31 | this.http.get('../assets/globals.json')
32 | .map( res => res.json() )
33 | .catch((error: any):any => {
34 | console.log('Error reading globals.json configuration file');
35 | resolve(error);
36 | })
37 | .subscribe((responseData) => {
38 | this.config = responseData;
39 | resolve(true);
40 | });
41 | });
42 | }
43 |
44 | get(key: any) {
45 | return this.config[key];
46 | }
47 |
48 | };
49 |
--------------------------------------------------------------------------------
/dashboard/src/app/common/auth/basic.auth.service.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import { Injectable } from "@angular/core";
20 | import { Observable } from 'rxjs/Observable';
21 |
22 | import { Profile } from './profile';
23 | import {AppConfig} from "../../app.config";
24 | import { DefaultProfile } from './default-profile';
25 |
26 | /**
27 | * This is a very simple implementation of AuthService with no authentication provider and use default profile defined in the DefaultProfile class
28 | */
29 | @Injectable()
30 | export class AuthService {
31 | static auth: any = {};
32 |
33 | static refreshToken() {
34 | new Promise((resolve) => {
35 | resolve();
36 | });
37 | }
38 |
39 | static initTokenRefresh(pollingInterval?: number){
40 | if (pollingInterval){
41 | Observable.interval(pollingInterval).subscribe(() => this.refreshToken());
42 | }
43 | }
44 |
45 | static init(): Promise {
46 | return new Promise((resolve) => {
47 | resolve();
48 | });
49 | }
50 |
51 | /**
52 | * @returns {DefaultProfile}
53 | */
54 | getProfile(): Profile {
55 | return new DefaultProfile();
56 | }
57 |
58 | /**
59 | * Do nothing
60 | */
61 | logout() {
62 | //empty
63 | }
64 |
65 | getToken(): Promise {
66 | return new Promise((resolve) => {
67 | resolve();
68 | });
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/dashboard/src/app/common/auth/default-profile.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import { Profile } from './profile';
20 |
21 | /**
22 | * Profile with all properties filled . This class is used by basic.auth.service
23 | */
24 | export class DefaultProfile extends Profile{
25 |
26 | constructor() {
27 | super("Professor X", "professor@yourmail.com", "Charles Francis", "Xavier");
28 | }
29 | }
--------------------------------------------------------------------------------
/dashboard/src/app/common/auth/profile.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | export class Profile {
20 |
21 | constructor(
22 | public username: string,
23 | public email: string,
24 | public firstName: string,
25 | public lastName: string
26 | ) { }
27 | }
--------------------------------------------------------------------------------
/dashboard/src/app/common/datasource.service.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | /*
20 | * This file is part of the Cerebro distribution.
21 | * (https://github.com/voyages-sncf-technologies/cerebro)
22 | * Copyright (C) 2017 VSCT.
23 | *
24 | * Cerebro is free software: you can redistribute it and/or modify
25 | * it under the terms of the GNU Affero General Public License as
26 | * published by the Free Software Foundation, version 3 of the License.
27 | *
28 | * Cerebro is distributed in the hope that it will be useful,
29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 | * GNU Affero General Public License for more details.
32 | *
33 | * You should have received a copy of the GNU Affero General Public License
34 | * along with this program. If not, see .
35 | */
36 |
37 | import { Injectable } from '@angular/core';
38 | import { Http, Response, Headers, RequestOptions, URLSearchParams } from '@angular/http';
39 | import { Observable } from 'rxjs/Observable';
40 |
41 | import { AppConfig } from '../app.config';
42 |
43 | import { CerebroException } from '../common/error/cerebroException';
44 |
45 | @Injectable()
46 | export class DatasourceService {
47 |
48 | private remoteRootUrl = this.config.get("services_url");
49 | private datasourceLocationsUrl = this.remoteRootUrl + "/datasources/locations";
50 |
51 | constructor(
52 | private http: Http,
53 | private config: AppConfig
54 | ) { }
55 |
56 | getLocations(): Observable {
57 | return this.http.get(this.datasourceLocationsUrl)
58 | .map(response => response.json())
59 | .catch(this.handleError)
60 | ;
61 | }
62 |
63 | private handleError(errorResponse: any) {
64 | // in a real world app, we may send the server to some remote logging infrastructure
65 | // instead of just logging it to the console
66 | if (errorResponse instanceof Response) {
67 | return Observable.throw(errorResponse.json() as CerebroException || 'Server error');
68 | }
69 |
70 | return Observable.throw(errorResponse || 'Server error');
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/dashboard/src/app/common/error/cerebroException.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | export class CerebroException {
20 |
21 | constructor(
22 | public errorCode : string,
23 | public errorMessage : string
24 | ) { }
25 | }
--------------------------------------------------------------------------------
/dashboard/src/app/common/error/error-mapping.service.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | export class ErrorMappingService {
20 | private defaultErrorMessage = "An unexpected error has occurred: "
21 | private errorMessage : { [key:string]:string; } = {};
22 |
23 | constructor() {
24 | this.errorMessage["ALARM_UNKNOWN"] = "Error : the alarme cannot be found or does not exist.";
25 | this.errorMessage["ALARM_DUPLICATE_NAME"] = "An alarm with the same name already exists. Impossible to create/edit this alarm.";
26 | this.errorMessage["ALARM_TARGET_INVALID"] = "Error : the target/Graphite key is not valid.";
27 | this.errorMessage["ALARM_DELETE_ERROR"] = "Error : the alarm could not be deleted.";
28 | this.errorMessage["SUBSCRIPTION_DUPLICATE"] = "There is already a similar subscription to this alarm (address, days, hours). You cannot submit this subscription.";
29 | this.errorMessage["SUBSCRIPTION_INVALID"] = "The subscription is invalid, because of no active days or missing target (email address).";
30 | this.errorMessage["SUBSCRIPTION_DELETE_ERROR"] = "The subscription could not be deleted.";
31 | }
32 |
33 | getMessage(error: any) {
34 |
35 | let errorCode = error.errorCode || error;
36 | let message;
37 |
38 | message = this.errorMessage[errorCode || ''] || '';
39 | if(error.errorMessage) {
40 | message = message + '\n'+ error.errorMessage;
41 | }
42 | return message === null ? this.defaultErrorMessage + errorCode : message;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/dashboard/src/app/common/pipe/email-sub.pipe.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import {Pipe, PipeTransform} from "@angular/core";
20 |
21 | @Pipe({
22 | name: 'emailSub'
23 | })
24 | export class EmailSubPipe implements PipeTransform {
25 | MAX_LENGTH: number = 25;
26 |
27 | transform(value: string, args: string[]): any {
28 | if (value == undefined) {
29 | console.error("Alarm array is undefined");
30 | return value;
31 | }
32 | if (value.length < this.MAX_LENGTH) {
33 | return value
34 | } else {
35 | return value.substring(0, this.MAX_LENGTH) + '...';
36 | }
37 | };
38 | }
39 |
--------------------------------------------------------------------------------
/dashboard/src/app/common/pipe/timestamp-to-date-hour.pipe.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import {Pipe, PipeTransform} from "@angular/core";
20 |
21 | @Pipe({
22 | name: 'timestampToDateHour'
23 | })
24 | export class TimestampToDateHourPipe implements PipeTransform {
25 | // STAT_MAXSIZE = 10;
26 |
27 | transform(timestamp: number) : string {
28 | // Timestamp of alarm is like this: 1479918373.252
29 | let date : Date = new Date(timestamp * 1000);
30 |
31 | let hours = this.convertToStringWithTwoDigit(date.getHours());
32 | let minutes = this.convertToStringWithTwoDigit(date.getMinutes());
33 |
34 | return hours + "h" + minutes;
35 | };
36 |
37 | /**
38 | * Convert a number with 1 digit to a string with 2 digit beginning by '0'
39 | */
40 | convertToStringWithTwoDigit(n: number): string {
41 | let ret : string = '' + n;
42 | ret = ret.length == 2 ? ret : '0' + ret;
43 | return ret;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/dashboard/src/app/common/select-option.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | export class SelectOption {
20 |
21 | constructor(
22 | public id: string,
23 | public label: string
24 | ) { }
25 | }
--------------------------------------------------------------------------------
/dashboard/src/app/dashboard/dashboard.component.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | .selected {
20 | background-color: #CFD8DC !important;
21 | color: white;
22 | }
23 |
24 | .error {
25 | color: red;
26 | }
27 |
28 | .back-bluelight {
29 | background-color: #EAF3F3;
30 | }
31 |
32 | .detailTitle {
33 | font-weight: bold;
34 | }
35 |
--------------------------------------------------------------------------------
/dashboard/src/app/dashboard/dashboard.component.html:
--------------------------------------------------------------------------------
1 |
18 |
19 |
64 |
--------------------------------------------------------------------------------
/dashboard/src/app/dashboard/dashboard.component.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import {Component, OnInit} from "@angular/core";
20 | import {Router} from "@angular/router";
21 | import {Alarm} from "../alarm/alarm";
22 | import {AlarmService} from "../alarm/alarm.service";
23 | import {AuthService} from "../common/auth/basic.auth.service";
24 | import {Profile} from "../common/auth/profile";
25 | import {DefaultProfile} from '../common/auth/default-profile';
26 |
27 | @Component({
28 | selector: 'dashboard',
29 | templateUrl: './dashboard.component.html',
30 | styleUrls: ['./dashboard.component.css', '../alert/alert.css']
31 | })
32 | export class DashboardComponent implements OnInit {
33 | errorMessage: string;
34 | alarms: Alarm[] = [];
35 |
36 | constructor(
37 | private router: Router,
38 | private alarmService: AlarmService,
39 | private authService: AuthService) {
40 | }
41 |
42 | ngOnInit() {
43 |
44 | let profile : any = this.authService.getProfile()
45 | if(profile instanceof DefaultProfile){
46 | this.router.navigate(['alarms']);
47 | return;
48 | }
49 |
50 | this.alarmService.getAlarmsBySubscriptionTarget(profile.email).subscribe(
51 | response => {
52 | this.alarms = response.filter(alarm => alarm.subscriptions.some(
53 | function(sub){
54 | return sub.enabled && sub.target === profile.email})
55 | );
56 | }
57 | );
58 | }
59 |
60 | gotoDetail(alarmId: String) {
61 | this.router.navigate(['alarms', alarmId]);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/dashboard/src/app/rxjs-extensions.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | // Observable class extensions
20 | import 'rxjs/add/observable/of';
21 | import 'rxjs/add/observable/throw';
22 |
23 | // Observable operators
24 | import 'rxjs/add/operator/catch';
25 | import 'rxjs/add/operator/debounceTime';
26 | import 'rxjs/add/operator/distinctUntilChanged';
27 | import 'rxjs/add/operator/do';
28 | import 'rxjs/add/operator/filter';
29 | import 'rxjs/add/operator/map';
30 | import 'rxjs/add/operator/switchMap';
31 |
--------------------------------------------------------------------------------
/dashboard/src/app/subscription/sort-subscription.pipe.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import { Pipe, PipeTransform } from '@angular/core';
20 |
21 | import { Subscription } from './subscription';
22 |
23 | /**
24 | * A pipe to sort subscription by type.
25 | * Subscription with type 'EMAIL' are returned first.
26 | */
27 | @Pipe({
28 | name : 'sortSubscriptionPipe'
29 | })
30 | export class SortSubscriptionPipe implements PipeTransform {
31 |
32 | transform(subscriptions: Subscription[]) {
33 | return subscriptions.sort(function (a, b){
34 | if (a.type === 'EMAIL' && b.type !== 'EMAIL') {
35 | return -1;
36 | }
37 | if (b.type === 'EMAIL' && a.type !== 'EMAIL') {
38 | return 1;
39 | }
40 | return 0;
41 | });
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/dashboard/src/app/subscription/subscription-time-format.pipe.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import { Pipe, PipeTransform } from '@angular/core';
20 |
21 | /**
22 | * Pipe to transform four digit to an readible time, e.g. 0830 ==> 08h30.
23 | * Used to convert subscription time.
24 | */
25 | @Pipe({
26 | name: 'subscriptionTimeFormat'
27 | })
28 | export class SubscriptionTimeFormatPipe implements PipeTransform {
29 |
30 | transform(subscriptionTime: string): string {
31 | let result = subscriptionTime;
32 | if (result && result.length === 4) {
33 | result = result.substring(0, 2) + 'h' + result.substring(2, 4);
34 | }
35 | return result;
36 | };
37 | }
38 |
--------------------------------------------------------------------------------
/dashboard/src/app/subscription/subscription.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | export class Subscription {
20 |
21 | constructor(
22 | public id: string,
23 | public target: string,
24 | public type: string,
25 | public su: boolean,
26 | public mo: boolean,
27 | public tu: boolean,
28 | public we: boolean,
29 | public th: boolean,
30 | public fr: boolean,
31 | public sa: boolean,
32 | public ignoreWarn: boolean,
33 | public ignoreError: boolean,
34 | public ignoreOk: boolean,
35 | public ignoreUnknown: boolean,
36 | public fromTime: string,
37 | public toTime: string,
38 | public enabled: boolean
39 | ) { }
40 | }
41 |
--------------------------------------------------------------------------------
/dashboard/src/app/target/overview/target-overview-component.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | @CHARSET "UTF-8";
20 |
21 | .keyName {
22 | margin-left: 10px;
23 | margin-top: 10px;
24 | font-weight: 600;
25 | }
--------------------------------------------------------------------------------
/dashboard/src/app/target/overview/target-overview.component.html:
--------------------------------------------------------------------------------
1 |
18 |
19 |
--------------------------------------------------------------------------------
/dashboard/src/app/target/overview/target-overview.component.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import { Component, Input } from '@angular/core';
20 |
21 | import { Alarm } from '../../alarm/alarm';
22 | import {AppConfig} from "../../app.config";
23 |
24 | @Component({
25 | selector: 'target-overview',
26 | templateUrl: './target-overview.component.html',
27 | styleUrls: ['./target-overview-component.css']
28 | })
29 | export class TargetOverviewComponent {
30 | _target: string;
31 |
32 | @Input()
33 | alarm: Alarm;
34 |
35 | @Input()
36 | showThresholds: boolean = true;
37 | @Input()
38 | showTargetLabel: boolean = false;
39 | @Input()
40 | aliasTarget: boolean = true;
41 | @Input()
42 | targetLabel: string;
43 |
44 | constructor(private config: AppConfig){}
45 |
46 | graphMiniUrl(period: string, title: string) {
47 | if (this.target != null) {
48 | let url = this.alarm.graphiteBaseUrl + (this.alarm.graphiteBaseUrl.endsWith("/") ? "" : "/") + "render?from=-" + period
49 | + (this.aliasTarget ? ("&target=alias(" + this.target + ",'Target')") : ("&target=" + this.target)) + "&title=" + title;
50 | if (this.showThresholds && this.alarm.warn != null && this.alarm.error != null) {
51 | url = url + "&target=alias(color(constantLine(" + this.alarm.warn + "),'orange'),'Warning')&target=alias(color(constantLine("
52 | + this.alarm.error + "),'red'),'Error')";
53 | }
54 | return url;
55 | }
56 | else {
57 | return "";
58 | }
59 | }
60 |
61 | graphMaxiUrl(period: string, title: string) {
62 | return this.graphMiniUrl(period, title) + "&width=800&height=600";
63 | }
64 |
65 | get target() {
66 | if (this._target != null) {
67 | return this._target;
68 | } else {
69 | return this.alarm.target;
70 | }
71 | }
72 |
73 | @Input()
74 | set target(target: string) {
75 | this._target = target;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/dashboard/src/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/assets/.gitkeep
--------------------------------------------------------------------------------
/dashboard/src/assets/alarm/edit/edit-alarm-2-observe.images/observe-keepLastValue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/assets/alarm/edit/edit-alarm-2-observe.images/observe-keepLastValue.png
--------------------------------------------------------------------------------
/dashboard/src/assets/alarm/edit/edit-alarm-2-observe.images/observe-summarize.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/assets/alarm/edit/edit-alarm-2-observe.images/observe-summarize.png
--------------------------------------------------------------------------------
/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-keepLastValue-compare-history-static-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-keepLastValue-compare-history-static-1.png
--------------------------------------------------------------------------------
/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-keepLastValue-compare-history-static-multi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-keepLastValue-compare-history-static-multi.png
--------------------------------------------------------------------------------
/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-keepLastValue-compare-history-summarize-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-keepLastValue-compare-history-summarize-1.png
--------------------------------------------------------------------------------
/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-keepLastValue-compare-history-summarize-multi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-keepLastValue-compare-history-summarize-multi.png
--------------------------------------------------------------------------------
/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-keepLastValue-compare-holtwinters.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-keepLastValue-compare-holtwinters.png
--------------------------------------------------------------------------------
/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-keepLastValue-compare-static.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-keepLastValue-compare-static.png
--------------------------------------------------------------------------------
/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-summarize-compare-history-static-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-summarize-compare-history-static-1.png
--------------------------------------------------------------------------------
/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-summarize-compare-history-static-multi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-summarize-compare-history-static-multi.png
--------------------------------------------------------------------------------
/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-summarize-compare-history-summarize-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-summarize-compare-history-summarize-1.png
--------------------------------------------------------------------------------
/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-summarize-compare-history-summarize-multi.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-summarize-compare-history-summarize-multi.png
--------------------------------------------------------------------------------
/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-summarize-compare-holtwinters.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-summarize-compare-holtwinters.png
--------------------------------------------------------------------------------
/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-summarize-compare-static.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/assets/alarm/edit/edit-alarm-3-compare.images/observe-summarize-compare-static.png
--------------------------------------------------------------------------------
/dashboard/src/assets/globals.json:
--------------------------------------------------------------------------------
1 | {
2 | "sep": "/",
3 | "services_url": "http://localhost:8080/cerebro-services",
4 | "theme": {
5 | "headerImage": "https://i.ytimg.com/vi/tSSIIu0fVaQ/maxresdefault.jpg",
6 | "logo": "https://apprecs.com/ios-meta/app-icons/256/869718796.jpg"
7 | },
8 | "contacts": {
9 | "documentation": {
10 | "name": "Wiki",
11 | "url": "http://"
12 | },
13 | "chat": {
14 | "name": "IM",
15 | "url": "http://"
16 | },
17 | "issueTracker": {
18 | "name": "Issues",
19 | "url": "http://"
20 | },
21 | "about": {
22 | "homepage": "https://github.com/voyages-sncf-technologies/cerebro",
23 | "author": "VSCT"
24 | },
25 | "email": "mailto:"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/dashboard/src/assets/keycloak.example.json:
--------------------------------------------------------------------------------
1 | //official keycloak web site http://www.keycloak.org/
2 | //keycloak demo app https://github.com/keycloak/keycloak/tree/master/examples/demo-template/angular2-product-app
3 | {
4 | "realm": "YOUR_REALM",
5 | "realm-public-key": "YOUR_REALM_PUBLIC_KEY",
6 | "auth-server-url": "YOUR_AUTH_SERVER_URL",
7 | "ssl-required": "external",
8 | "resource": "cerebro-dashboard-dev",
9 | "credentials": {
10 | "secret": "YOUR_SECRET"
11 | }
12 | }
--------------------------------------------------------------------------------
/dashboard/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/dashboard/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // The file contents for the current environment will overwrite these during build.
2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do
3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead.
4 | // The list of which env maps to which file can be found in `.angular-cli.json`.
5 |
6 | export const environment = {
7 | production: false
8 | };
9 |
--------------------------------------------------------------------------------
/dashboard/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/favicon.ico
--------------------------------------------------------------------------------
/dashboard/src/forms.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | .ng-valid[required] {
20 | border-left: 5px solid #42A948; /* green */
21 | }
22 |
23 | .ng-invalid:not(form) {
24 | border-left: 5px solid #a94442; /* red */
25 | }
26 |
27 | /*
28 | feature/SUPER-684
29 | [Cerebro] FIX : taille variable des checkboxes dans Chrome
30 | */
31 | input[type=checkbox].form-control {
32 | height: auto !important;
33 | }
34 |
35 | .toggle-button,
36 | .toggle-button:focus,
37 | .toggle-button:disabled {
38 | color: darkred;
39 | border-color: #babdb6;
40 | }
41 |
42 | .toggle-button:hover:enabled,
43 | .toggle-button.active:hover:disabled {
44 | color: green;
45 | }
46 |
47 | .toggle-button.active,
48 | .toggle-button.active:focus {
49 | color: green;
50 | }
51 |
52 | .toggle-button:hover:disabled,
53 | .toggle-button.active:hover:enabled {
54 | color: darkred;
55 | }
56 |
57 | .toggle-status.btn-default.active {
58 | color: white;
59 | background-color: grey;
60 | border-color: grey;
61 | }
62 |
63 | .panel-default-sup-alarms {
64 | border-color: #50c1bb;
65 | }
66 | .panel-heading-sup-alarms {
67 | padding: 5px 15px;
68 | cursor: cell;
69 | }
70 | .panel-sup-alarms {
71 | -webkit-box-shadow: 0 1px 1px rgb(195, 61, 61);
72 | box-shadow: 0 1px 1px rgb(195, 61, 61);
73 | }
74 |
--------------------------------------------------------------------------------
/dashboard/src/index.html:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 | Cerebro
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
Loading, please wait...
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/dashboard/src/jquery.ts:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sncf-connect-tech/cerebro/e6a34306b47bab48c2648d08a1fd4b43f7da3590/dashboard/src/jquery.ts
--------------------------------------------------------------------------------
/dashboard/src/main.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import { enableProdMode } from '@angular/core';
20 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
21 |
22 | import { AppModule } from './app/app.module';
23 | import { AuthService } from './app/common/auth/basic.auth.service';
24 | import { environment } from './environments/environment';
25 |
26 | if (environment.production) {
27 | enableProdMode();
28 | }
29 |
30 | platformBrowserDynamic().bootstrapModule(AppModule)
31 | .catch(err => console.log(err));
32 |
33 | // AuthService.init()
34 | // .then(() => {
35 | // platformBrowserDynamic().bootstrapModule(AppModule)
36 | // .catch(err => console.log(err));
37 | // })
38 | // .catch(() => window.location.reload());
--------------------------------------------------------------------------------
/dashboard/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/
22 | // import 'core-js/es6/symbol';
23 | // import 'core-js/es6/object';
24 | // import 'core-js/es6/function';
25 | // import 'core-js/es6/parse-int';
26 | // import 'core-js/es6/parse-float';
27 | // import 'core-js/es6/number';
28 | // import 'core-js/es6/math';
29 | // import 'core-js/es6/string';
30 | // import 'core-js/es6/date';
31 | // import 'core-js/es6/array';
32 | // import 'core-js/es6/regexp';
33 | // import 'core-js/es6/map';
34 | // import 'core-js/es6/weak-map';
35 | // import 'core-js/es6/set';
36 |
37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
38 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
39 |
40 | /** Evergreen browsers require these. **/
41 | import 'core-js/es6/reflect';
42 | import 'core-js/es7/reflect';
43 |
44 |
45 | /**
46 | * Required to support Web Animations `@angular/animation`.
47 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
48 | **/
49 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
50 |
51 |
52 |
53 | /***************************************************************************************************
54 | * Zone JS is required by Angular itself.
55 | */
56 | import 'zone.js/dist/zone'; // Included with Angular CLI.
57 |
58 |
59 |
60 | /***************************************************************************************************
61 | * APPLICATION IMPORTS
62 | */
63 |
64 | /**
65 | * Date, currency, decimal and percent pipes.
66 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
67 | */
68 | // import 'intl'; // Run `npm install --save intl`.
69 | /**
70 | * Need to import at least one locale-data with intl.
71 | */
72 | // import 'intl/locale-data/jsonp/en';
73 |
--------------------------------------------------------------------------------
/dashboard/src/styles.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | body {
20 | margin: 2em;
21 | padding: 0 2em;
22 | font-family: Arial, sans-serif;
23 | color: #024457;
24 | background: #f2f2f2;
25 | }
26 | input[text] {
27 | color: #888;
28 | font-family: Cambria, Georgia;
29 | }
30 | h1 span {
31 | color: #167F92;
32 | }
33 | button {
34 | font-family: Arial;
35 | background-color: #eee;
36 | border: none;
37 | padding: 5px 10px;
38 | border-radius: 4px;
39 | cursor: pointer;
40 | cursor: hand;
41 | }
42 | button:hover {
43 | background-color: #cfd8dc;
44 | }
45 | button:disabled {
46 | background-color: #eee;
47 | color: #aaa;
48 | cursor: auto;
49 | }
50 | /* everywhere else */
51 | * {
52 | font-family: Arial, Helvetica, sans-serif;
53 | }
54 | .error {
55 | color: red;
56 | }
57 |
58 | /* Search Box */
59 | #custom-search-input {
60 | margin:0;
61 | margin-top: 10px;
62 | padding: 0;
63 | }
64 |
65 | #custom-search-input .search-query {
66 | padding-right: 3px;
67 | padding-right: 4px \9;
68 | padding-left: 3px;
69 | padding-left: 4px \9;
70 |
71 | margin-bottom: 0;
72 | -webkit-border-radius: 3px;
73 | -moz-border-radius: 3px;
74 | border-radius: 3px;
75 | }
76 |
77 | #custom-search-input button {
78 | border: 0;
79 | background: none;
80 |
81 | padding: 2px 5px;
82 | margin-top: 2px;
83 | position: relative;
84 | left: -28px;
85 |
86 | margin-bottom: 0;
87 | -webkit-border-radius: 3px;
88 | -moz-border-radius: 3px;
89 | border-radius: 3px;
90 | color:#D9230F;
91 | }
92 |
93 | .search-query:focus + button {
94 | z-index: 3;
95 | }
96 |
97 | .target {
98 | word-wrap: break-word;
99 | margin-right: 8px;
100 | line-height: 22px;
101 | }
102 |
103 | .alarm_days-selector {
104 | text-align: right;
105 | }
106 |
107 | .very-large-modal {
108 | width: 90%;
109 | }
110 |
111 | .espace {
112 | margin-top: 1em;
113 | }
114 |
115 | .loading {
116 | -animation: spin 1.5s infinite linear;
117 | -webkit-animation: spin2 1.5s infinite linear;
118 | }
119 |
120 | .logout {
121 | cursor: pointer;
122 | float: right;
123 | }
124 |
125 | @-webkit-keyframes spin2 {
126 | from { -webkit-transform: rotate(0deg);}
127 | to { -webkit-transform: rotate(360deg);}
128 | }
129 |
130 | @keyframes spin {
131 | from { transform: scale(1) rotate(0deg);}
132 | to { transform: scale(1) rotate(360deg);}
133 | }
134 |
--------------------------------------------------------------------------------
/dashboard/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/dashboard/src/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../target/out-tsc/app",
5 | "baseUrl": "./",
6 | "module": "es2015",
7 | "types": [
8 | "intro.js"
9 | ]
10 | },
11 | "exclude": [
12 | "test.ts",
13 | "**/*.spec.ts"
14 | ]
15 | }
16 |
--------------------------------------------------------------------------------
/dashboard/src/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../target/out-tsc/spec",
5 | "baseUrl": "./",
6 | "module": "commonjs",
7 | "target": "es5",
8 | "types": [
9 | "jasmine",
10 | "node"
11 | ]
12 | },
13 | "files": [
14 | "test.ts"
15 | ],
16 | "include": [
17 | "**/*.spec.ts",
18 | "**/*.d.ts"
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/dashboard/src/typings.d.ts:
--------------------------------------------------------------------------------
1 | /* SystemJS module definition */
2 | declare var module: NodeModule;
3 | interface NodeModule {
4 | id: string;
5 | }
6 |
--------------------------------------------------------------------------------
/dashboard/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "outDir": "./target/dist/out-tsc",
5 | "sourceMap": true,
6 | "declaration": false,
7 | "moduleResolution": "node",
8 | "emitDecoratorMetadata": true,
9 | "experimentalDecorators": true,
10 | "target": "es5",
11 | "typeRoots": [
12 | "node_modules/@types"
13 | ],
14 | "lib": [
15 | "es2017",
16 | "dom"
17 | ],
18 | "removeComments": false,
19 | "noImplicitAny": false
20 | }
21 | }
--------------------------------------------------------------------------------
/dashboard/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/codelyzer"
4 | ],
5 | "rules": {
6 | "arrow-return-shorthand": true,
7 | "callable-types": true,
8 | "class-name": true,
9 | "comment-format": [
10 | true,
11 | "check-space"
12 | ],
13 | "curly": true,
14 | "eofline": true,
15 | "forin": true,
16 | "import-blacklist": [
17 | true,
18 | "rxjs"
19 | ],
20 | "import-spacing": true,
21 | "indent": [
22 | true,
23 | "spaces"
24 | ],
25 | "interface-over-type-literal": true,
26 | "label-position": true,
27 | "max-line-length": [
28 | true,
29 | 140
30 | ],
31 | "member-access": false,
32 | "member-ordering": [
33 | true,
34 | {
35 | "order": [
36 | "static-field",
37 | "instance-field",
38 | "static-method",
39 | "instance-method"
40 | ]
41 | }
42 | ],
43 | "no-arg": true,
44 | "no-bitwise": true,
45 | "no-console": [
46 | true,
47 | "debug",
48 | "info",
49 | "time",
50 | "timeEnd",
51 | "trace"
52 | ],
53 | "no-construct": true,
54 | "no-debugger": true,
55 | "no-duplicate-super": true,
56 | "no-empty": false,
57 | "no-empty-interface": true,
58 | "no-eval": true,
59 | "no-inferrable-types": [
60 | true,
61 | "ignore-params"
62 | ],
63 | "no-misused-new": true,
64 | "no-non-null-assertion": true,
65 | "no-shadowed-variable": true,
66 | "no-string-literal": false,
67 | "no-string-throw": true,
68 | "no-switch-case-fall-through": true,
69 | "no-trailing-whitespace": true,
70 | "no-unnecessary-initializer": true,
71 | "no-unused-expression": true,
72 | "no-use-before-declare": true,
73 | "no-var-keyword": true,
74 | "object-literal-sort-keys": false,
75 | "one-line": [
76 | true,
77 | "check-open-brace",
78 | "check-catch",
79 | "check-else",
80 | "check-whitespace"
81 | ],
82 | "prefer-const": true,
83 | "quotemark": [
84 | true,
85 | "single"
86 | ],
87 | "radix": true,
88 | "semicolon": [
89 | true,
90 | "always"
91 | ],
92 | "triple-equals": [
93 | true,
94 | "allow-null-check"
95 | ],
96 | "typedef-whitespace": [
97 | true,
98 | {
99 | "call-signature": "nospace",
100 | "index-signature": "nospace",
101 | "parameter": "nospace",
102 | "property-declaration": "nospace",
103 | "variable-declaration": "nospace"
104 | }
105 | ],
106 | "typeof-compare": true,
107 | "unified-signatures": true,
108 | "variable-name": false,
109 | "whitespace": [
110 | true,
111 | "check-branch",
112 | "check-decl",
113 | "check-operator",
114 | "check-separator",
115 | "check-type"
116 | ],
117 | "directive-selector": [
118 | true,
119 | "attribute",
120 | "app",
121 | "camelCase"
122 | ],
123 | "component-selector": [
124 | true,
125 | "element",
126 | "app",
127 | "kebab-case"
128 | ],
129 | "use-input-property-decorator": true,
130 | "use-output-property-decorator": true,
131 | "use-host-property-decorator": true,
132 | "no-input-rename": true,
133 | "no-output-rename": true,
134 | "use-life-cycle-interface": true,
135 | "use-pipe-transform-interface": true,
136 | "component-class-suffix": true,
137 | "directive-class-suffix": true,
138 | "no-access-missing-member": true,
139 | "templates-use-public": true,
140 | "invoke-injectable": true
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM busybox:latest
2 |
3 | # Copy services jar
4 | COPY target/dependency/cerebro-services.jar /opt/cerebro-services/cerebro-services.jar
5 |
6 | # Share volume for Java image
7 | VOLUME /opt/cerebro-services/
8 |
9 |
10 | # Copy dashboard tar
11 | COPY target/dependency/cerebro-dashboard.tar.gz /opt/cerebro-dashboard/cerebro-dashboard.tar.gz
12 | # Extract dashboard from archive
13 | RUN mkdir -p /usr/local/apache2/htdocs
14 | RUN tar xf /opt/cerebro-dashboard/cerebro-dashboard.tar.gz -C /usr/local/apache2/htdocs/
15 | RUN rm /opt/cerebro-dashboard/cerebro-dashboard.tar.gz
16 |
17 | # Share volume for httpd image
18 | VOLUME /usr/local/apache2/htdocs/
19 |
--------------------------------------------------------------------------------
/docker/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '2'
2 |
3 | services:
4 | mongodb:
5 | image: mongo:3.2
6 | command: mongod --smallfiles --quiet
7 | ports:
8 | - 27017:27017
9 |
10 | graphite:
11 | image: sitespeedio/graphite:0.9.14
12 | ports:
13 | - 8081:80
14 | - 2003:2003
15 | volumes:
16 | - ./properties/graphite.conf:/etc/nginx/sites-available/graphite.conf
17 | - ./properties/graphTemplates.conf:/opt/graphite/conf/graphTemplates.conf
18 |
19 | collectd:
20 | image: listhub/collectd-write-graphite
21 | links:
22 | - graphite
23 | environment:
24 | HOST_NAME: sample
25 | GRAPHITE_HOST: graphite
26 | GRAPHITE_PORT: 2003
27 | INSTANCE_ID: seyren
28 |
29 | seyren:
30 | build: seyren/
31 | links:
32 | - mongodb
33 | - graphite
34 | command: java -jar seyren-1.5.0.jar
35 | environment:
36 | MONGO_URL: mongodb://mongodb:27017/seyren
37 | GRAPHITE_URL: http://graphite
38 | SEYREN_LOG_PATH: /root
39 | ports:
40 | - 8000:8080
41 |
42 | cerebro-src:
43 | # Need to have built the image, read the README.adoc
44 | build: .
45 |
46 | cerebro-services:
47 | image: openjdk:8-jdk
48 | working_dir: /opt/cerebro-services
49 | command: ["java", "-jar", "cerebro-services.jar", "--seyren.host=http://seyren:8080", "--graphite.sources[0].url=http://localhost:8081"]
50 | ports:
51 | - 8080:8080
52 | links:
53 | - seyren:seyren
54 | volumes_from:
55 | - cerebro-src
56 |
57 | cerebro-dashboard:
58 | image: httpd:2.4
59 | ports:
60 | - 80:80
61 | volumes_from:
62 | - cerebro-src
63 | volumes:
64 | - ./properties/httpd.conf:/usr/local/apache2/conf/httpd.conf
65 |
--------------------------------------------------------------------------------
/docker/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
21 | 4.0.0
22 |
23 |
24 | com.vsct.supervision.web
25 | cerebro
26 | 1.0.0-SNAPSHOT
27 |
28 |
29 | com.vsct.supervision.web.cerebro
30 | cerebro-docker
31 | pom
32 |
33 | Cerebro Docker wrapper
34 | Docker wrappers to run Cerebro using Docker / Docker-Compose.
35 |
36 |
37 |
38 |
39 | com.vsct.supervision.web.cerebro
40 | cerebro-services
41 | ${project.version}
42 | runtime
43 |
44 |
45 | com.vsct.supervision.web.cerebro
46 | cerebro-dashboard
47 | ${project.version}
48 | tar.gz
49 | runtime
50 |
51 |
52 |
53 |
54 |
55 |
56 | maven-dependency-plugin
57 |
58 |
59 | copy-dependencies
60 | package
61 |
62 | copy-dependencies
63 |
64 |
65 | true
66 | true
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/docker/properties/graphTemplates.conf:
--------------------------------------------------------------------------------
1 | [default]
2 | background = white
3 | foreground = black
4 | majorLine = grey
5 | minorLine = grey
6 | lineColors = blue,green,red,purple,brown,yellow,aqua,grey,magenta,pink,gold,rose
7 | fontName = Sans
8 | fontSize = 10
9 | fontBold = False
10 | fontItalic = False
11 |
12 | [noc]
13 | background = white
14 | foreground = black
15 | majorLine = grey
16 | minorLine = grey
17 | lineColors = blue,green,red,yellow,purple,brown,aqua,grey,magenta,pink,gold,rose
18 | fontName = Sans
19 | fontSize = 10
20 | fontBold = False
21 | fontItalic = False
22 |
23 | [plain]
24 | background = black
25 | foreground = white
26 | minorLine = grey
27 | majorLine = rose
28 |
29 | [summary]
30 | background = white
31 | lineColors = #6666ff, #66ff66, #ff6666
32 |
33 | [alphas]
34 | background = black
35 | foreground = white
36 | majorLine = grey
37 | minorLine = rose
38 | lineColors = 00ff00aa,ff000077,00337799
--------------------------------------------------------------------------------
/docker/properties/graphite.conf:
--------------------------------------------------------------------------------
1 | server {
2 | listen 80;
3 | root /opt/graphite/webapp/content;
4 | index index.html;
5 |
6 | location /media {
7 | # django admin static files
8 | alias /usr/local/lib/python2.7/dist-packages/django/contrib/admin/media/;
9 | }
10 |
11 | location / {
12 | # checks for static file, if not found proxy to app
13 | try_files \$uri @app;
14 | }
15 |
16 | location @app {
17 | include fastcgi_params;
18 | fastcgi_split_path_info ^()(.*)$;
19 | fastcgi_pass 127.0.0.1:8080;
20 | add_header 'Access-Control-Allow-Origin' '*';
21 | add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
22 | add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type';
23 | add_header 'Access-Control-Allow-Credentials' 'true';
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/docker/seyren/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM java:8-jre
2 |
3 | RUN wget https://github.com/scobal/seyren/releases/download/1.5.0/seyren-1.5.0.jar -nv
--------------------------------------------------------------------------------
/selenium/src/main/java/AppSelenium.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import org.junit.Test;
20 | import org.slf4j.Logger;
21 | import org.slf4j.LoggerFactory;
22 |
23 | import test.chrome.ChromeTest;
24 | import test.firefox.FirefoxTest;
25 |
26 | public class AppSelenium {
27 |
28 | private static final Logger LOGGER = LoggerFactory.getLogger(AppSelenium.class);
29 |
30 | private static final String BASE_URL = "http://localhost:51010";
31 |
32 | public static void main(String[] args) {
33 | AppSelenium app = new AppSelenium();
34 | app.testOnChrome();
35 | app.testOnFireFox();
36 | }
37 |
38 | @Test
39 | public void testOnChrome() {
40 | LOGGER.info("Starting tests on Chrome...");
41 | ChromeTest.chrome(BASE_URL, false);
42 | LOGGER.info("Chrome tests have finished.");
43 | }
44 |
45 | @Test
46 | public void testOnFireFox() {
47 | LOGGER.info("Starting tests on Firefox...");
48 | FirefoxTest.firefox(BASE_URL, false);
49 | LOGGER.info("Firefox tests have finished.");
50 | }
51 | }
--------------------------------------------------------------------------------
/selenium/src/main/java/conf/Conf.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package conf;
20 |
21 | public class Conf {
22 |
23 | //TODO Indiquer ses identifiants (en attendant de trouver mieux)
24 | public static final String USERNAME = "selenium";
25 | public static final String PASSWORD = "password";
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/selenium/src/main/java/test/TestLogin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package test;
20 |
21 | import org.openqa.selenium.By;
22 | import org.openqa.selenium.WebDriver;
23 | import org.openqa.selenium.WebElement;
24 | import org.slf4j.Logger;
25 | import org.slf4j.LoggerFactory;
26 |
27 | import conf.Conf;
28 | import utils.Utils;
29 |
30 | public class TestLogin {
31 |
32 | private static final Logger LOGGER = LoggerFactory.getLogger(TestLogin.class);
33 |
34 | private WebDriver driver;
35 |
36 | public TestLogin(final WebDriver driver) {
37 | this.driver = driver;
38 | }
39 |
40 | public void login() {
41 | LOGGER.info("trying to log in");
42 | //Enter username
43 | WebElement usernameField = driver.findElement(By.id("username"));
44 | usernameField.sendKeys(Conf.USERNAME);
45 | LOGGER.info("enter username");
46 |
47 | //Enter password
48 | WebElement passwordField = driver.findElement(By.id("password"));
49 | passwordField.sendKeys(Conf.PASSWORD);
50 | LOGGER.info("enter password");
51 |
52 | //Log in
53 | Utils.clickWhenReady(driver,By.id("kc-login"));
54 | LOGGER.info("logged in");
55 | }
56 |
57 | public void logoutThenLogin(){
58 | LOGGER.info("trying to log out");
59 | Utils.clickWhenReady(driver,By.id("logout"));
60 | LOGGER.info("logged out");
61 | login();
62 | }
63 | }
--------------------------------------------------------------------------------
/selenium/src/main/java/test/TestNavigation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package test;
20 |
21 | import org.openqa.selenium.By;
22 | import org.openqa.selenium.WebDriver;
23 | import org.openqa.selenium.WebElement;
24 | import org.openqa.selenium.support.ui.ExpectedConditions;
25 | import org.openqa.selenium.support.ui.WebDriverWait;
26 | import org.slf4j.Logger;
27 | import org.slf4j.LoggerFactory;
28 |
29 | import utils.Utils;
30 |
31 | public class TestNavigation {
32 |
33 | private static final Logger LOGGER = LoggerFactory.getLogger(TestNavigation.class);
34 |
35 | private WebDriver driver;
36 |
37 | public TestNavigation(final WebDriver driver) {
38 | this.driver = driver;
39 | }
40 |
41 | public void tabs(){
42 | clickOnMyAlarms();
43 | clickOnAddAlarm();
44 | clickOnAllAlarms();
45 | }
46 |
47 | public void clickOnAllAlarms(){
48 | Utils.clickWhenReady(driver,By.id("all-alarms-tab"));
49 | LOGGER.info("on 'all alarms' tab");
50 | }
51 |
52 | public void clickOnAddAlarm(){
53 | Utils.clickWhenReady(driver,By.id("add-alarm-tab"));
54 | LOGGER.info("on 'add alarm' tab");
55 | }
56 |
57 | public void clickOnMyAlarms(){
58 |
59 | if(TestScenario.useKeycloak) {
60 | Utils.clickWhenReady(driver,By.id("my-alarms-tab"));
61 | LOGGER.info("on 'my alarms' tab");
62 | }
63 | else {
64 | LOGGER.info("test my alarms is disabled!");
65 | searchAlarm();
66 | }
67 |
68 | }
69 |
70 | public void searchAlarm(){
71 | TestScenario.navigation.clickOnAllAlarms();
72 | WebElement searchBar = driver.findElement(By.id("filterBarText"));
73 | new WebDriverWait(driver,Utils.DEFAULT_WAITING_TIME).until(ExpectedConditions.visibilityOf(searchBar));
74 | Utils.clickWhenReady(driver,By.id("showDisableCheck"));
75 | LOGGER.info("show disabled alarms");
76 | Utils.clickWhenReady(driver,searchBar);
77 | searchBar.sendKeys(TestCreation.NAME);
78 | LOGGER.info("Search for '" + TestCreation.NAME + "'");
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/selenium/src/main/java/test/TestScenario.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package test;
20 |
21 | import java.util.concurrent.TimeUnit;
22 |
23 | import org.openqa.selenium.WebDriver;
24 | import org.slf4j.Logger;
25 | import org.slf4j.LoggerFactory;
26 |
27 | public class TestScenario {
28 |
29 | static TestNavigation navigation;
30 |
31 | private static final Logger LOGGER = LoggerFactory.getLogger(TestNavigation.class);
32 | public static boolean useKeycloak = false;
33 |
34 | public static void test(WebDriver driver, String baseurl){
35 |
36 | driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
37 | driver.get(baseurl);
38 |
39 | navigation = new TestNavigation(driver);
40 |
41 |
42 | testLoginLogout(driver);
43 |
44 | testNavigation();
45 |
46 | testCreation(driver);
47 |
48 | testSubscription(driver);
49 |
50 | }
51 |
52 | public static void testNavigation(){
53 | navigation.tabs();
54 | }
55 |
56 | public static void testCreation(WebDriver driver){
57 | TestCreation createTest = new TestCreation(driver);
58 | createTest.createAlarm();
59 | createTest.testDetailPage();
60 | createTest.deleteAlarm();
61 | }
62 |
63 | public static void testLoginLogout(WebDriver driver){
64 |
65 | if(TestScenario.useKeycloak){
66 | TestLogin loginTest = new TestLogin(driver);
67 | loginTest.login();
68 | loginTest.logoutThenLogin();
69 | }
70 | else{
71 | LOGGER.info("testLoginLogout is disabled!");
72 | }
73 | }
74 |
75 | public static void testSubscription(WebDriver driver){
76 | TestSubscription subscriptionTest = new TestSubscription(driver);
77 | TestCreation createTest = new TestCreation(driver);
78 |
79 | navigation.clickOnAddAlarm();
80 | createTest.createAlarm();
81 | subscriptionTest.unsubscribe();
82 | subscriptionTest.subscribe();
83 | createTest.deleteAlarm();
84 | }
85 | }
--------------------------------------------------------------------------------
/selenium/src/main/java/test/TestSubscription.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package test;
20 |
21 | import org.openqa.selenium.By;
22 | import org.openqa.selenium.WebDriver;
23 | import org.openqa.selenium.support.ui.ExpectedConditions;
24 | import org.openqa.selenium.support.ui.WebDriverWait;
25 | import org.slf4j.Logger;
26 | import org.slf4j.LoggerFactory;
27 |
28 | import utils.Utils;
29 |
30 | public class TestSubscription {
31 | private static final Logger LOGGER = LoggerFactory.getLogger(TestSubscription.class);
32 |
33 | WebDriver driver;
34 |
35 | public TestSubscription(WebDriver driver){
36 | this.driver = driver;
37 | }
38 |
39 | public void unsubscribe(){
40 | TestScenario.navigation.clickOnMyAlarms();
41 |
42 | Utils.clickWhenReady(driver, driver.findElements(By.name("alarm-row")).get(0));
43 | LOGGER.info("Click on available alarm");
44 | if(TestScenario.useKeycloak) {
45 | Utils.clickWhenReady(driver, By.id("dashboard-details-alarm"));
46 | }
47 | else{
48 | Utils.clickWhenReady(driver, By.id("alarms-details-alarm"));
49 | }
50 | LOGGER.info("Open alarm details");
51 | new WebDriverWait(driver,Utils.DEFAULT_WAITING_TIME).until(ExpectedConditions.visibilityOf(driver.findElement(By.id("alarm-name-title"))));
52 | Utils.clickWhenReady(driver, driver.findElements(By.name("disable-subscription")).get(0));
53 | LOGGER.info("disable alarm subscription");
54 | new WebDriverWait(driver,Utils.DEFAULT_WAITING_TIME).until(ExpectedConditions.visibilityOf(driver.findElements(By.name("enabled-subscription")).get(0)));
55 | }
56 |
57 | public void subscribe(){
58 | TestScenario.navigation.searchAlarm();
59 | new WebDriverWait(driver,Utils.DEFAULT_WAITING_TIME).until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//div[@name='alarm-row' and text()[contains(.,'Selenium test')]]"))));
60 | Utils.clickWhenReady(driver, driver.findElements(By.name("alarm-row")).get(0));
61 | LOGGER.info("click on alarm");
62 | Utils.clickWhenReady(driver, By.id("alarms-details-alarm"));
63 | LOGGER.info("Open alarm details");
64 | Utils.clickWhenReady(driver, driver.findElements(By.name("enabled-subscription")).get(0));
65 | TestScenario.navigation.clickOnMyAlarms();
66 | LOGGER.info("go on 'my alarms' tab");
67 | Utils.clickWhenReady(driver, driver.findElements(By.name("alarm-row")).get(0));
68 | if(TestScenario.useKeycloak) {
69 | Utils.clickWhenReady(driver, By.id("dashboard-details-alarm"));
70 | }
71 | else{
72 | Utils.clickWhenReady(driver, By.id("alarms-details-alarm"));
73 | }
74 | }
75 | }
--------------------------------------------------------------------------------
/selenium/src/main/java/test/chrome/ChromeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package test.chrome;
20 |
21 | import java.util.concurrent.TimeUnit;
22 |
23 | import org.openqa.selenium.Dimension;
24 | import org.openqa.selenium.WebDriver;
25 | import org.openqa.selenium.chrome.ChromeDriver;
26 | import org.openqa.selenium.remote.CapabilityType;
27 | import org.openqa.selenium.remote.DesiredCapabilities;
28 |
29 | import io.github.bonigarcia.wdm.ChromeDriverManager;
30 | import test.TestScenario;
31 | import utils.Utils;
32 |
33 | public class ChromeTest {
34 |
35 | public static void chrome(String baseurl, boolean useKeycloak){
36 |
37 | WebDriver driver = null;
38 | try {
39 | DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
40 | desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
41 | desiredCapabilities.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, false);
42 |
43 | ChromeDriverManager.getInstance().setup();
44 | driver = new ChromeDriver(desiredCapabilities);
45 | driver.manage().window().setSize(new Dimension(Utils.WINDOW_WIDTH,Utils.WINDOW_HEIGHT));
46 | driver.manage().timeouts().implicitlyWait(Utils.DEFAULT_WAITING_TIME, TimeUnit.SECONDS);
47 |
48 | TestScenario.useKeycloak = useKeycloak;
49 | TestScenario.test(driver, baseurl);
50 | }
51 | finally {
52 | if(driver!=null) {
53 | driver.quit();
54 | }
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/selenium/src/main/java/test/firefox/FirefoxTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package test.firefox;
20 |
21 |
22 | import java.util.concurrent.TimeUnit;
23 |
24 | import org.openqa.selenium.Dimension;
25 | import org.openqa.selenium.WebDriver;
26 | import org.openqa.selenium.firefox.FirefoxDriver;
27 | import org.openqa.selenium.firefox.FirefoxProfile;
28 | import org.openqa.selenium.firefox.internal.ProfilesIni;
29 |
30 | import io.github.bonigarcia.wdm.FirefoxDriverManager;
31 | import test.TestScenario;
32 | import utils.Utils;
33 |
34 | public class FirefoxTest {
35 |
36 | public static void firefox(String baseurl, boolean useKeycloak){
37 | WebDriver driver = null;
38 | try {
39 | ProfilesIni allProfiles = new ProfilesIni();
40 | FirefoxProfile myProfile = allProfiles.getProfile("default");
41 | myProfile.setAcceptUntrustedCertificates(true);
42 | myProfile.setAssumeUntrustedCertificateIssuer(false);
43 | FirefoxDriverManager.getInstance().setup();
44 | driver = new FirefoxDriver(myProfile);
45 | driver.manage().window().setSize(new Dimension(Utils.WINDOW_WIDTH,Utils.WINDOW_HEIGHT));
46 | driver.manage().timeouts().implicitlyWait(Utils.DEFAULT_WAITING_TIME, TimeUnit.SECONDS);
47 |
48 | TestScenario.useKeycloak = useKeycloak;
49 | TestScenario.test(driver, baseurl);
50 | }
51 | finally {
52 | if(driver!=null) {
53 | driver.quit();
54 | }
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/selenium/src/main/java/utils/Utils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package utils;
20 |
21 | import org.openqa.selenium.By;
22 | import org.openqa.selenium.WebDriver;
23 | import org.openqa.selenium.WebElement;
24 | import org.openqa.selenium.interactions.Actions;
25 | import org.openqa.selenium.support.ui.ExpectedConditions;
26 | import org.openqa.selenium.support.ui.WebDriverWait;
27 |
28 | public class Utils {
29 |
30 | public final static int WINDOW_WIDTH = 1280;
31 | public final static int WINDOW_HEIGHT = 1024;
32 | public final static int DEFAULT_WAITING_TIME = 5;
33 |
34 | public static void clickWhenReady(WebDriver driver, By element){
35 | clickWhenReady(driver,driver.findElement(element));
36 | }
37 |
38 | public static void clickWhenReady(WebDriver driver, WebElement webElement){
39 | new WebDriverWait(driver,DEFAULT_WAITING_TIME).until(ExpectedConditions.visibilityOf(webElement));
40 | Actions actions = new Actions(driver);
41 | actions.moveToElement(webElement);
42 | new WebDriverWait(driver,DEFAULT_WAITING_TIME).until(ExpectedConditions.elementToBeClickable(webElement));
43 | webElement.click();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/selenium/src/main/resources/webdrivermanager.properties:
--------------------------------------------------------------------------------
1 | #
2 | # This file is part of the Cerebro distribution.
3 | # (https://github.com/voyages-sncf-technologies/cerebro)
4 | # Copyright (C) 2017 VSCT.
5 | #
6 | # Cerebro is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU Affero General Public License as
8 | # published by the Free Software Foundation, version 3 of the License.
9 | #
10 | # Cerebro is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU Affero General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Affero General Public License
16 | # along with this program. If not, see .
17 | #
18 |
19 | wdm.targetPath=${project.build.directory}/webdriver
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/config/CerebroConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.config;
20 |
21 | import org.springframework.beans.factory.annotation.Value;
22 |
23 | public class CerebroConfiguration {
24 |
25 | @Value("${application.serverType}")
26 | private String serverType;
27 |
28 | @Value("${application.trigram}")
29 | private String trigram;
30 |
31 | @Value("${application.domain}")
32 | private String domain;
33 |
34 | @Value("${dashboard.baseUrl}")
35 | private String dashboardBaseUrl;
36 |
37 | @Value("${updateNotificationsEnable:true}")
38 | private boolean updateNotificationsEnable;
39 |
40 | public String getDashboardBaseUrl() {
41 | return dashboardBaseUrl;
42 | }
43 |
44 | public boolean isUpdateNotificationsEnable() {
45 | return updateNotificationsEnable;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/ErrorCode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification;
20 |
21 | public enum ErrorCode {
22 | CEREBRO_UNKNOWN_ERROR,
23 | ALARM_UNKNOWN,
24 | ALARM_DUPLICATE_NAME,
25 | ALARM_DUPLICATE_DATAS,
26 | ALARM_INVALID,
27 | ALARM_TARGET_INVALID,
28 | SUBSCRIPTION_UNKNOWN,
29 | SUBSCRIPTION_DUPLICATE,
30 | SUBSCRIPTION_INVALID,
31 | SUBSCRIPTION_UPDATE_INVALID,
32 | SUBSCRIPTION_DELETE_ERROR,
33 | SEYREN_ERROR
34 | }
35 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/email/MailSenderImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.email;
20 |
21 | import java.util.Date;
22 | import java.util.List;
23 | import java.util.Properties;
24 |
25 | import javax.mail.internet.AddressException;
26 | import javax.mail.internet.InternetAddress;
27 |
28 | import org.slf4j.Logger;
29 | import org.slf4j.LoggerFactory;
30 | import org.springframework.mail.javamail.JavaMailSenderImpl;
31 | import org.springframework.mail.javamail.MimeMessageHelper;
32 | import org.springframework.mail.javamail.MimeMessagePreparator;
33 | import org.springframework.stereotype.Component;
34 |
35 | import com.vsct.supervision.notification.log.Loggable;
36 |
37 | @Loggable(service = "email", method = "send")
38 | @Component
39 | public class MailSenderImpl extends Sender {
40 | private static final Logger LOGGER = LoggerFactory.getLogger(MailSenderImpl.class);
41 |
42 | private JavaMailSenderImpl mailSender;
43 | private Properties properties;
44 |
45 | public MailSenderImpl() {
46 | properties = getProperties();
47 | initMailSender();
48 | }
49 |
50 |
51 | @Override
52 | public void send(final String title, final String text, final List recipients) {
53 | MimeMessagePreparator preparator = mimeMessage -> {
54 | MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
55 | message.setTo(toInternetAddresses(recipients));
56 | message.setFrom(properties.getProperty("sender"));
57 | message.setSubject(title);
58 | message.setSentDate(new Date());
59 |
60 | message.setText(text, true);
61 | };
62 | LOGGER.debug("send mail with title: {}", title);
63 | mailSender.send(preparator);
64 | }
65 |
66 | private InternetAddress[] toInternetAddresses(List recipients){
67 | InternetAddress[] addresses = new InternetAddress[recipients.size()];
68 | for(int i=0; i.
17 | */
18 |
19 | package com.vsct.supervision.notification.email;
20 |
21 | import java.io.IOException;
22 | import java.util.List;
23 | import java.util.Properties;
24 |
25 | import org.slf4j.Logger;
26 | import org.slf4j.LoggerFactory;
27 |
28 | public abstract class Sender {
29 | abstract void send(String title, String text, List recipients);
30 |
31 | private static final Logger LOGGER = LoggerFactory.getLogger(Sender.class);
32 |
33 | public Properties getProperties(){
34 | Properties props = new Properties();
35 | try {
36 | props.load(MailSenderImpl.class.getResourceAsStream("/config/email.properties"));
37 | } catch (IOException e) {
38 | LOGGER.error("Invalid mail properties file",e);
39 | }
40 | return props;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/exception/CerebroException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.exception;
20 |
21 | import com.fasterxml.jackson.annotation.JsonFilter;
22 | import com.vsct.supervision.notification.ErrorCode;
23 |
24 | @JsonFilter("responseFilter")
25 | public class CerebroException extends RuntimeException {
26 | private static final long serialVersionUID = 1L;
27 |
28 | private ErrorCode errorCode;
29 |
30 | private String errorMessage;
31 |
32 | public CerebroException(){
33 |
34 | }
35 |
36 | public CerebroException(ErrorCode errorCode, String errorMessage) {
37 | super(errorMessage);
38 | this.errorMessage = errorMessage;
39 | this.errorCode = errorCode;
40 | }
41 |
42 | public CerebroException(ErrorCode errorCode, String errorMessage, Throwable cause) {
43 | super(errorMessage, cause);
44 | this.errorMessage = errorMessage;
45 | this.errorCode = errorCode;
46 | }
47 |
48 | public void setErrorCode(ErrorCode errorCode) {
49 | this.errorCode = errorCode;
50 | }
51 |
52 |
53 | public ErrorCode getErrorCode() {
54 | return errorCode;
55 | }
56 |
57 | public void setErrorMessage(String errorMessage) {
58 | this.errorMessage = errorMessage;
59 | }
60 |
61 | public String getErrorMessage() {
62 | return errorMessage;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/exception/DuplicateSubscriptionException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.exception;
20 |
21 | import com.vsct.supervision.notification.ErrorCode;
22 |
23 | public class DuplicateSubscriptionException extends CerebroException {
24 | private static final long serialVersionUID = 1L;
25 |
26 | public DuplicateSubscriptionException(String message) {
27 | super(ErrorCode.SUBSCRIPTION_DUPLICATE, message);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/exception/SeyrenException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.exception;
20 |
21 | import org.springframework.web.bind.annotation.ResponseStatus;
22 |
23 | import com.vsct.supervision.notification.ErrorCode;
24 |
25 | @ResponseStatus
26 | public class SeyrenException extends CerebroException {
27 | private static final long serialVersionUID = 1L;
28 |
29 | private final String action;
30 | private final int httpStatus;
31 |
32 | public SeyrenException(final String action, final int httpStatus) {
33 | super(ErrorCode.SEYREN_ERROR, "Method: " + action);
34 | this.action = action;
35 | this.httpStatus = httpStatus;
36 | }
37 |
38 | public int getHttpStatus() {
39 | return httpStatus;
40 | }
41 |
42 | public String getAction() {
43 | return action;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/exception/SeyrenResponseErrorHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.exception;
20 |
21 | import java.io.IOException;
22 | import java.io.InputStreamReader;
23 |
24 | import org.slf4j.Logger;
25 | import org.slf4j.LoggerFactory;
26 | import org.springframework.http.client.ClientHttpResponse;
27 | import org.springframework.web.client.DefaultResponseErrorHandler;
28 |
29 | import com.google.common.io.CharStreams;
30 | import com.vsct.supervision.notification.ErrorCode;
31 | import com.vsct.supervision.notification.log.Loggable;
32 |
33 | @Loggable(service="SeyrenResponseErrorHandler")
34 | public class SeyrenResponseErrorHandler extends DefaultResponseErrorHandler {
35 | private static final Logger LOGGER = LoggerFactory.getLogger(SeyrenResponseErrorHandler.class);
36 |
37 | @Override
38 | public void handleError(ClientHttpResponse response) throws IOException {
39 | String seyrenResponseBody;
40 | LOGGER.debug("Response : {} {}", response.getStatusCode(), response.getStatusText());
41 | if (response.getBody() != null) {
42 | seyrenResponseBody = CharStreams.toString(new InputStreamReader(response.getBody(), "UTF-8"));
43 | } else {
44 | seyrenResponseBody = "Response whithout body";
45 | }
46 | CerebroException exception = new CerebroException(ErrorCode.SEYREN_ERROR, seyrenResponseBody);
47 | throw exception;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/log/LogWriter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.log;
20 |
21 | import org.slf4j.Logger;
22 | import org.slf4j.LoggerFactory;
23 | import org.slf4j.Marker;
24 | import org.slf4j.MarkerFactory;
25 | import org.springframework.boot.logging.LogLevel;
26 |
27 | public class LogWriter {
28 |
29 | public static void write(Class clazz, LogLevel logLevel, String message) {
30 | Logger logger = LoggerFactory.getLogger(clazz);
31 |
32 | switch (logLevel) {
33 | case TRACE:
34 | logger.trace(message);
35 | break;
36 | case DEBUG:
37 | logger.debug(message);
38 | break;
39 | case INFO:
40 | logger.info(message);
41 | break;
42 | case WARN:
43 | logger.warn(message);
44 | break;
45 | case ERROR:
46 | logger.error(message);
47 | break;
48 | case FATAL:
49 | Marker marker = MarkerFactory.getMarker("FATAL");
50 | logger.error(marker, message);
51 | break;
52 | default:
53 | logger.warn("No suitable log level found");
54 | break;
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/log/Loggable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.log;
20 |
21 | import java.lang.annotation.Documented;
22 | import java.lang.annotation.ElementType;
23 | import java.lang.annotation.Retention;
24 | import java.lang.annotation.RetentionPolicy;
25 | import java.lang.annotation.Target;
26 |
27 | import org.springframework.boot.logging.LogLevel;
28 | import org.springframework.stereotype.Component;
29 |
30 | @Component
31 | @Documented
32 | @Retention(RetentionPolicy.RUNTIME)
33 | @Target({ElementType.TYPE, ElementType.METHOD})
34 | public @interface Loggable {
35 | LogLevel value() default LogLevel.DEBUG;
36 |
37 | boolean traceParams() default true;
38 |
39 | boolean traceResult() default true;
40 |
41 | String service() default "";
42 |
43 | String method() default "";
44 | }
45 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/model/AlarmValidator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.model;
20 |
21 | import org.springframework.util.StringUtils;
22 |
23 | import com.vsct.supervision.notification.ErrorCode;
24 | import com.vsct.supervision.notification.exception.CerebroException;
25 | import com.vsct.supervision.seyren.api.Alarm;
26 |
27 | public class AlarmValidator {
28 |
29 |
30 | public void validateAlarm(final Alarm alarm) throws CerebroException {
31 | // Validate required fields
32 | if (StringUtils.isEmpty(alarm.getName())) {
33 | throw new CerebroException(ErrorCode.ALARM_INVALID, "Alarm name is required.");
34 | }
35 |
36 | if (StringUtils.isEmpty(alarm.getTarget()) || StringUtils.startsWithIgnoreCase(alarm.getTarget(), "*")) {
37 | throw new CerebroException(ErrorCode.ALARM_INVALID, "Alarm target is required.");
38 | }
39 |
40 | if (StringUtils.isEmpty(alarm.getWarn())) {
41 | throw new CerebroException(ErrorCode.ALARM_INVALID, "Alarm warning threshold is required.");
42 | }
43 |
44 | if (StringUtils.isEmpty(alarm.getError())) {
45 | throw new CerebroException(ErrorCode.ALARM_INVALID, "Alarm error threshold is required.");
46 | }
47 | }
48 |
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/model/CerebroAlarm.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.model;
20 |
21 | import java.util.Collection;
22 |
23 | import com.vsct.supervision.notification.util.GraphiteKeyUtil;
24 | import com.vsct.supervision.seyren.api.Alarm;
25 |
26 | public class CerebroAlarm {
27 | private Alarm alarm;
28 | private Collection targetGraphiteKeys;
29 |
30 | public CerebroAlarm(Alarm alarm) {
31 | this.alarm = alarm;
32 | this.targetGraphiteKeys = GraphiteKeyUtil.extractGraphiteKeys(alarm.getTarget());
33 | }
34 |
35 | public Alarm getAlarm() {
36 | return alarm;
37 | }
38 |
39 | public Collection getTargetGraphiteKeys() {
40 | return targetGraphiteKeys;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/model/GraphiteSources.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.model;
20 |
21 | import java.net.URI;
22 | import java.util.HashMap;
23 | import java.util.List;
24 | import java.util.Map;
25 |
26 | import javax.annotation.PostConstruct;
27 |
28 | import org.springframework.boot.context.properties.ConfigurationProperties;
29 | import org.springframework.stereotype.Component;
30 |
31 | @Component
32 | @ConfigurationProperties(prefix = "graphite")
33 | public class GraphiteSources {
34 |
35 | private List sources;
36 |
37 | private Map ipportsByUrl = new HashMap<>();
38 | private Map urlsByIpport = new HashMap<>();
39 |
40 | @PostConstruct
41 | public void initSourceMaps() {
42 | for (GraphiteSource source : sources) {
43 | URI uri = source.getUrl();
44 | URI ipport = source.getIpport();
45 | ipportsByUrl.put(uri, ipport);
46 | urlsByIpport.put(ipport, uri);
47 | }
48 | }
49 |
50 | public List getSources() {
51 | return sources;
52 | }
53 |
54 | public void setSources(List sources) {
55 | this.sources = sources;
56 | }
57 |
58 | public Map getIpportsByUrl() {
59 | return ipportsByUrl;
60 | }
61 |
62 | public Map getUrlsByIpport() {
63 | return urlsByIpport;
64 | }
65 |
66 | public static class GraphiteSource {
67 |
68 | private URI url;
69 |
70 | private URI ipport;
71 |
72 | public GraphiteSource() {
73 | }
74 |
75 | public GraphiteSource(URI url) {
76 | this.url = url;
77 | }
78 |
79 | public GraphiteSource(URI url, URI ipport) {
80 | this.url = url;
81 | this.ipport = ipport;
82 | }
83 |
84 | public URI getUrl() {
85 | return url;
86 | }
87 |
88 | public void setUrl(URI url) {
89 | this.url = url;
90 | }
91 |
92 | public URI getIpport() {
93 | return ipport;
94 | }
95 |
96 | public void setIpport(URI ipport) {
97 | this.ipport = ipport;
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/model/SelectOption.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.model;
20 |
21 | public class SelectOption {
22 |
23 | private String id;
24 |
25 | private String label;
26 |
27 | public SelectOption(String id, String label) {
28 | this.id = id;
29 | this.label = label;
30 | }
31 |
32 | public String getId() {
33 | return id;
34 | }
35 |
36 | public String getLabel() {
37 | return label;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/model/Stat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.model;
20 |
21 | import java.util.ArrayList;
22 | import java.util.HashMap;
23 | import java.util.List;
24 | import java.util.Map;
25 |
26 | import com.vsct.supervision.seyren.api.Alarm;
27 | import com.vsct.supervision.seyren.api.AlertType;
28 |
29 | /**
30 | * An object to store stat about alerts of an Alarm.
31 | *
32 | * Stat indicate how many time an Alarm have an alert with a type.
33 | *
34 | * You can build a list of stat with {@link StatBuilder}: this builder permit to list each alarm with no status change.
35 | *
36 | * @see StatBuilder
37 | */
38 | public class Stat {
39 | private String alarmId;
40 | private int count;
41 | private AlertType type;
42 |
43 | /**
44 | * Builder to list each alarm with no change in alert status
45 | */
46 | public static class StatBuilder {
47 | private final List ignoredId = new ArrayList<>();
48 | private Map alarmIdStat = new HashMap<>();
49 |
50 | /**
51 | * Increment the count of alerts with no change.
52 | *
53 | * If alarm is ignored, do nothing.
54 | *
55 | * @param alarmId ID of alarm with an alerts without change
56 | * @param type The type of the alert.
57 | */
58 | public void increment(final String alarmId, final AlertType type) {
59 | if (!ignoredId.contains(alarmId)) {
60 | if (alarmIdStat.containsKey(alarmId)) {
61 | alarmIdStat.get(alarmId).increment();
62 | } else {
63 | alarmIdStat.put(alarmId, new Stat(alarmId, type));
64 | }
65 | }
66 | }
67 |
68 | /**
69 | * Remove count for a alarm and ignore it for the future
70 | *
71 | * @param alarmId ID of alarm to ignore
72 | */
73 | public void removeAndIgnore(final String alarmId) {
74 | alarmIdStat.remove(alarmId);
75 | ignoredId.add(alarmId);
76 | }
77 |
78 | /**
79 | * Return the list of all stats.
80 | *
81 | * @return List of a stat for each Alarm kept
82 | */
83 | public List build() {
84 | return new ArrayList<>(alarmIdStat.values());
85 | }
86 | }
87 |
88 | private Stat(String alarmId, AlertType type) {
89 | this.alarmId = alarmId;
90 | this.type = type;
91 | this.count = 1;
92 | }
93 |
94 | private void increment() {
95 | count++;
96 | }
97 |
98 | public String getAlarmId() {
99 | return alarmId;
100 | }
101 |
102 | public int getCount() {
103 | return count;
104 | }
105 |
106 | public AlertType getType() {
107 | return type;
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/model/SubscriptionMapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.model;
20 |
21 | import org.springframework.stereotype.Component;
22 |
23 | import com.vsct.supervision.notification.exception.CerebroException;
24 | import com.vsct.supervision.seyren.api.Subscription;
25 | import com.vsct.supervision.seyren.api.SubscriptionType;
26 |
27 | @Component
28 | public class SubscriptionMapper {
29 |
30 | public static final String DEFAULT_FROM_TIME = "0800";
31 | public static final String DEFAULT_TO_TIME = "2000";
32 |
33 | /**
34 | * Validate and/or force field values in a new subscription form.
35 | *
36 | * @param subscription subscription to validate/update
37 | */
38 | public Subscription mapNewSubscriptionFormToSeyren(Subscription subscription) throws CerebroException {
39 |
40 | // Reset unwanted fields or enforced default values
41 | subscription.setId(null);
42 | subscription.setType(SubscriptionType.EMAIL);
43 |
44 | setDefaultFromToTimeIfEmptyOrNull(subscription);
45 |
46 | return subscription;
47 | }
48 |
49 | /**
50 | * Validate and/or force field values in a updated subscription form.
51 | *
52 | * @param subscription subscription to validate/update
53 | */
54 | public Subscription mapUpdateSubscriptionFormToSeyren(Subscription subscription) throws CerebroException {
55 | setDefaultFromToTimeIfEmptyOrNull(subscription);
56 |
57 | return subscription;
58 | }
59 |
60 | private Subscription setDefaultFromToTimeIfEmptyOrNull(Subscription subscription) {
61 | if (subscription.getFromTime() == null || subscription.getFromTime().isEmpty() || !subscription.getFromTime().matches("\\d{4}")) {
62 | subscription.setFromTime(DEFAULT_FROM_TIME);
63 | }
64 |
65 | if (subscription.getToTime() == null || subscription.getToTime().isEmpty() || !subscription.getToTime().matches("\\d{4}")) {
66 | subscription.setToTime(DEFAULT_TO_TIME);
67 | }
68 |
69 | return subscription;
70 | }
71 | }
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/service/SourceService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.service;
20 |
21 | import org.springframework.stereotype.Service;
22 |
23 | @Service
24 | public class SourceService {
25 | }
26 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/util/GraphiteKeyUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.util;
20 |
21 | import java.util.ArrayList;
22 | import java.util.Collection;
23 | import java.util.regex.Matcher;
24 | import java.util.regex.Pattern;
25 |
26 | import org.slf4j.Logger;
27 | import org.slf4j.LoggerFactory;
28 |
29 | public class GraphiteKeyUtil {
30 |
31 | private static final Logger LOGGER = LoggerFactory.getLogger(GraphiteKeyUtil.class);
32 |
33 | private static final Pattern GRAPHITE_KEY_PATTERN = Pattern.compile("([\\w,\\*_\\-\\{\\}]+[.])+((\\{[\\w|_,-]*\\}[.]*)*|[\\w*_-]*)[\\w*_-]*");
34 |
35 | private GraphiteKeyUtil() {
36 | }
37 |
38 | /**
39 | * Get all graphite key to compose check target without function.
40 | *
41 | * This method does not handle regular expression in Graphite target.
42 | * @param target a complete Graphite target
43 | * @return {@code Collection} paths
44 | */
45 | public static Collection extractGraphiteKeys(String target) {
46 | Collection collection = new ArrayList<>();
47 |
48 | LOGGER.debug("Extracting keys from target: " + target);
49 | Matcher matcher = GRAPHITE_KEY_PATTERN.matcher(target);
50 | while (matcher.find()) {
51 | collection.add(matcher.group());
52 | }
53 |
54 | LOGGER.debug("Found " + collection.size() + " key(s): " + collection);
55 | return collection;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/notification/util/SeyrenHealthIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.util;
20 |
21 | import java.io.IOException;
22 | import java.net.InetSocketAddress;
23 | import java.net.Socket;
24 | import java.net.URI;
25 |
26 | import org.springframework.beans.factory.annotation.Value;
27 | import org.springframework.boot.actuate.health.AbstractHealthIndicator;
28 | import org.springframework.boot.actuate.health.Health;
29 | import org.springframework.stereotype.Component;
30 |
31 | @Component
32 | public class SeyrenHealthIndicator extends AbstractHealthIndicator {
33 |
34 | @Value("${seyren.host}")
35 | private String seyrenUrl;
36 |
37 | @Override
38 | protected void doHealthCheck(Health.Builder builder) throws Exception {
39 | URI uri = new URI(seyrenUrl);
40 |
41 | if (pingHost(uri.getHost(), uri.getPort(), 2000)) {
42 | builder.up();
43 | } else {
44 | builder.down();
45 | }
46 | }
47 |
48 | public static boolean pingHost(String host, int port, int timeout) {
49 | try (Socket socket = new Socket()) {
50 | socket.connect(new InetSocketAddress(host, port), timeout);
51 | return true;
52 | } catch (IOException e) {
53 | return false; // Either timeout or unreachable or failed DNS lookup.
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/seyren/api/AlertType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | /**
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | */
32 | package com.vsct.supervision.seyren.api;
33 |
34 | public enum AlertType {
35 |
36 | UNKNOWN(0), OK(1), WARN(2), ERROR(3), EXCEPTION(4);
37 |
38 | private final int value;
39 |
40 | private AlertType(final int value) {
41 | this.value = value;
42 | }
43 |
44 | public boolean isWorseThan(final AlertType other) {
45 | if (other == null) {
46 | return true;
47 | }
48 | return value > other.value;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/seyren/api/CheckField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.seyren.api;
20 |
21 | /**
22 | * Created by francois_nollen on 30/03/2016.
23 | */
24 | public enum CheckField {
25 |
26 | ID("id"),
27 | NAME("name"),
28 | DESCRIPTION("description"),
29 | TARGET("target"),
30 | FROM("from"),
31 | UNTIL("until"),
32 | WARN("warn"),
33 | ERROR("error"),
34 | ENABLED("enabled"),
35 | LIVE("live"),
36 | STATE("state"),
37 | LASTCHECK("lastCheck"),
38 | SUBSCRIPTIONS("subscriptions");
39 |
40 | String fieldName;
41 |
42 | CheckField(String fieldName) {
43 | this.fieldName = fieldName;
44 | }
45 |
46 | public String getFieldName() {
47 | return fieldName;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/seyren/api/InstantOfEpochMilliDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.seyren.api;
20 |
21 | import java.io.IOException;
22 | import java.time.Instant;
23 |
24 | import com.fasterxml.jackson.core.JsonParser;
25 | import com.fasterxml.jackson.core.JsonProcessingException;
26 | import com.fasterxml.jackson.databind.DeserializationContext;
27 | import com.fasterxml.jackson.databind.JsonDeserializer;
28 |
29 | public class InstantOfEpochMilliDeserializer extends JsonDeserializer {
30 |
31 | @Override
32 | public Instant deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException, JsonProcessingException {
33 | return Instant.ofEpochMilli(p.getLongValue());
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/seyren/api/SeyrenResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.seyren.api;
20 |
21 | import java.util.List;
22 |
23 | public class SeyrenResponse {
24 |
25 | private List values;
26 |
27 | private int items;
28 |
29 | private int start;
30 |
31 | private int total;
32 |
33 | public List getValues() {
34 | return values;
35 | }
36 |
37 | public void setValues(final List values) {
38 | this.values = values;
39 | }
40 |
41 | public int getItems() {
42 | return items;
43 | }
44 |
45 | public void setItems(final int items) {
46 | this.items = items;
47 | }
48 |
49 | public int getStart() {
50 | return start;
51 | }
52 |
53 | public void setStart(final int start) {
54 | this.start = start;
55 | }
56 |
57 | public int getTotal() {
58 | return total;
59 | }
60 |
61 | public void setTotal(final int total) {
62 | this.total = total;
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/services/src/main/java/com/vsct/supervision/seyren/api/SubscriptionType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.seyren.api;
20 |
21 | import com.fasterxml.jackson.annotation.JsonCreator;
22 |
23 | public enum SubscriptionType {
24 |
25 | EMAIL,
26 | PAGERDUTY,
27 | HIPCHAT,
28 | HUBOT,
29 | FLOWDOCK,
30 | HTTP,
31 | IRCCAT,
32 | PUSHOVER,
33 | LOGGER,
34 | SNMP,
35 | SLACK,
36 | TWILIO,
37 | VICTOROPS,
38 | OPSGENIE,
39 | SHELL,
40 | UNKNOW;
41 |
42 | @JsonCreator
43 | public static SubscriptionType forValue(String value) {
44 | for (SubscriptionType type : SubscriptionType.values()) {
45 | if (type.name().equals(value)) {
46 | return type;
47 | }
48 | }
49 | return SubscriptionType.UNKNOW;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/services/src/main/resources/config/application.properties:
--------------------------------------------------------------------------------
1 | #
2 | # This file is part of the Cerebro distribution.
3 | # (https://github.com/voyages-sncf-technologies/cerebro)
4 | # Copyright (C) 2017 VSCT.
5 | #
6 | # Cerebro is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU Affero General Public License as
8 | # published by the Free Software Foundation, version 3 of the License.
9 | #
10 | # Cerebro is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU Affero General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Affero General Public License
16 | # along with this program. If not, see .
17 | #
18 |
19 | # URL de base
20 | server.contextPath=/cerebro-services
21 |
22 | application.domain=SUP
23 | application.trigram=CRB
24 | application.serverType=WAS
25 | application.name=${project.artifactId}
26 | application.version=${project.version}
27 | application.basedir=${project.build.outputDirectory}
28 | application.logdir=${application.basedir}/logs
29 | updateNotificationsEnable=true
--------------------------------------------------------------------------------
/services/src/main/resources/config/email.properties:
--------------------------------------------------------------------------------
1 | #
2 | # This file is part of the Cerebro distribution.
3 | # (https://github.com/voyages-sncf-technologies/cerebro)
4 | # Copyright (C) 2017 VSCT.
5 | #
6 | # Cerebro is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU Affero General Public License as
8 | # published by the Free Software Foundation, version 3 of the License.
9 | #
10 | # Cerebro is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU Affero General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Affero General Public License
16 | # along with this program. If not, see .
17 | #
18 |
19 | resource.loader=class
20 | class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
21 | server=0.0.0.0
22 | port=25
23 | sender=notifications@cerebro.org
--------------------------------------------------------------------------------
/services/src/main/resources/config/instance.properties:
--------------------------------------------------------------------------------
1 | #
2 | # This file is part of the Cerebro distribution.
3 | # (https://github.com/voyages-sncf-technologies/cerebro)
4 | # Copyright (C) 2017 VSCT.
5 | #
6 | # Cerebro is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU Affero General Public License as
8 | # published by the Free Software Foundation, version 3 of the License.
9 | #
10 | # Cerebro is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU Affero General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Affero General Public License
16 | # along with this program. If not, see .
17 | #
18 |
19 | # Seyren backend URL - alarm store and scheduler
20 | seyren.host=http://YOURSEYRENBACKEND:8000
21 |
22 | # Graphite backend(s) accessible through Seyren
23 | # This list is exposed as one one of the services in the Cerebro API, so that Cerebro dashboard does not need Graphite location to be
24 | # configured. Why multiple backends? AT VSCT we currently fork the open source vanilla Seyren, to make it possible for a single Seyren
25 | # instance to run checks against multiple Graphite servers. For this reason we set a list of Graphite backends. Using vanilla Seyren, only
26 | # one backend/location should be set.
27 | # graphite.sources[0].url = ... (required, this is the location displayed/manipulated by Cerebro dashboard users)
28 | # graphite.sources[0].ipport = ... (optional - in case Seyren instance cannot resolve Graphite URL)
29 | graphite.sources[0].url=http://YOURGRAPHITEBACKEND
30 |
31 | #Spring server port
32 | server.port=8080
33 |
34 | # Cerebro dashboard URL
35 | dashboard.baseUrl=http://localhost/
36 |
37 | # keycloak configuration
38 | #keycloak.realm = YOUR_REALM
39 | #keycloak.realmKey = YOUR_REALM_PUBLIC_KEY
40 | #keycloak.auth-server-url = YOUR_AUTH_SERVER_URL
41 | #keycloak.ssl-required = external
42 | #keycloak.resource = cerebro-service-dev
43 | #keycloak.bearer-only = true
44 | ##keycloak.enable-cors = true
45 | ##keycloak.cors-allowed-methods = "GET,POST,DELETE,PUT,OPTIONS"
46 | ##keycloak.use-resource-role-mappings = true
47 | #keycloak.credentials.secret = YOUR_SECRET
48 | #keycloak.securityConstraints[0].securityCollections[0].name = spring secured api
49 | #keycloak.securityConstraints[0].securityCollections[0].authRoles[0] = uma_authorization
50 | #keycloak.securityConstraints[0].securityCollections[0].patterns[0] = /*
51 | #keycloak.securityConstraints[0].securityCollections[0].omittedMethods[0] = OPTIONS
52 | #keycloak.securityConstraints[0].securityCollections[1].name = healthckeck not secured
53 | #keycloak.securityConstraints[0].securityCollections[1].authRoles[0] = uma_authorization
54 | #keycloak.securityConstraints[0].securityCollections[1].patterns[0] = /health
55 | #keycloak.securityConstraints[0].securityCollections[1].omittedMethods[0] = GET
56 | #keycloak.securityConstraints[0].securityCollections[2].name = Swagger UI not secured
57 | #keycloak.securityConstraints[0].securityCollections[2].authRoles[0] = uma_authorization
58 | #keycloak.securityConstraints[0].securityCollections[2].patterns[0] = /v2/api-docs/*
59 | #keycloak.securityConstraints[0].securityCollections[2].patterns[1] = /swagger-ui.html
60 | #keycloak.securityConstraints[0].securityCollections[2].patterns[2] = /swagger-resources/*
61 | #keycloak.securityConstraints[0].securityCollections[2].patterns[3] = /webjars/springfox-swagger-ui/*
62 | #keycloak.securityConstraints[0].securityCollections[2].omittedMethods[0] = GET
63 |
--------------------------------------------------------------------------------
/services/src/main/resources/config/logback.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | %d{yyyy-MM-dd HH:mm:ss.SSSZ}|${instance}|%-5p|%c|%m%n%throwable{1}
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
38 | ${application.logdir}/debug.log
39 |
40 |
41 | %d{yyyy-MM-dd HH:mm:ss} - %msg%n
42 |
43 |
44 |
45 |
46 |
47 | ${application.logdir}/archived/debug.%d{yyyy-MM-dd}.%i.log
48 |
49 |
51 | 5MB
52 |
53 |
54 |
55 |
56 |
57 |
59 | ${application.logdir}/error.log
60 |
61 |
62 | %d{yyyy-MM-dd HH:mm:ss} - %msg%n
63 |
64 |
65 |
66 |
67 |
68 | ${application.logdir}/archived/error.%d{yyyy-MM-dd}.%i.log
69 |
70 |
72 | 5MB
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/services/src/main/resources/logback-spring.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/services/src/main/resources/templates/alarmModified.vm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
One of your alerts has been ${status}:
4 |
5 | Your "${alert}" alert on Cerebro has just been ${status}.
6 |
7 |
8 | Do not hesitate to go to the alert page to see the changes.
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/services/src/test/java/com/vsct/supervision/notification/AppTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification;
20 |
21 | import org.springframework.boot.SpringApplication;
22 | import org.springframework.boot.autoconfigure.SpringBootApplication;
23 |
24 | @SpringBootApplication
25 | public class AppTest {
26 |
27 | public static void main(final String[] args) {
28 | SpringApplication app = new SpringApplication(AppTest.class);
29 | app.run(args);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/services/src/test/java/com/vsct/supervision/notification/controller/AbstractControllerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Cerebro distribution.
3 | * (https://github.com/voyages-sncf-technologies/cerebro)
4 | * Copyright (C) 2017 VSCT.
5 | *
6 | * Cerebro is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as
8 | * published by the Free Software Foundation, version 3 of the License.
9 | *
10 | * Cerebro is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package com.vsct.supervision.notification.controller;
20 |
21 | import java.util.List;
22 |
23 | import org.junit.runner.RunWith;
24 | import org.springframework.boot.test.SpringApplicationConfiguration;
25 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
26 | import org.springframework.test.context.web.WebAppConfiguration;
27 |
28 | import com.vsct.supervision.notification.AppTest;
29 | import com.vsct.supervision.notification.model.SelectOption;
30 | import com.vsct.supervision.notification.model.Stat;
31 | import com.vsct.supervision.seyren.api.Alert;
32 | import com.vsct.supervision.seyren.api.AlertType;
33 | import com.vsct.supervision.seyren.api.Alarm;
34 | import com.vsct.supervision.seyren.api.Subscription;
35 |
36 | @WebAppConfiguration
37 | @RunWith(SpringJUnit4ClassRunner.class)
38 | @SpringApplicationConfiguration(classes = AppTest.class)
39 | public abstract class AbstractControllerTest {
40 |
41 | public static Alarm getAlarm(String id){
42 | Alarm alarm = new Alarm();
43 | alarm.setId(id);
44 | alarm.setName("name");
45 | alarm.setTarget("target");
46 | return alarm;
47 | }
48 |
49 | public static Alarm getAlarm(String id, int idx){
50 | Alarm alarm = new Alarm();
51 | alarm.setId(id+idx);
52 | alarm.setName("name"+idx);
53 | alarm.setTarget("target"+idx);
54 | return alarm;
55 | }
56 |
57 | public static Subscription getSubscription(String id){
58 | Subscription subscription = new Subscription();
59 | subscription.setId(id);
60 | return subscription;
61 | }
62 |
63 | public static Alert getAlert(String id){
64 | Alert alert = new Alert();
65 | alert.setId(id);
66 | return alert;
67 | }
68 |
69 | public static List getStats(int nb, AlertType alertType){
70 | final Stat.StatBuilder stat = new Stat.StatBuilder();
71 | for(int i=0; i < nb; i++){
72 | stat.increment("alarm"+i,alertType);
73 | }
74 | return stat.build();
75 | }
76 |
77 | public static SelectOption getSelectOption(String id){
78 | return new SelectOption(id,"label-"+id);
79 |
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/services/src/test/resources/application-test.properties:
--------------------------------------------------------------------------------
1 | #
2 | # This file is part of the Cerebro distribution.
3 | # (https://github.com/voyages-sncf-technologies/cerebro)
4 | # Copyright (C) 2017 VSCT.
5 | #
6 | # Cerebro is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU Affero General Public License as
8 | # published by the Free Software Foundation, version 3 of the License.
9 | #
10 | # Cerebro is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU Affero General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Affero General Public License
16 | # along with this program. If not, see .
17 | #
18 |
19 | # main URL
20 | server.contextPath=/cerebro-services
21 |
22 | graphite.sources[0].url=http://localhost/graphite/
23 | graphite.sources[0].ipport=http://localhost:9100/
24 |
25 | application.domain=SUP
26 | application.trigram=CRB
27 | application.serverType=WAS
28 | application.name=${project.artifactId}
29 | application.version=${project.version}
30 |
31 | # Seyren instance
32 | seyren.host=http://locahost:52000
33 | sumon.graphite.host=127.0.0.1
34 | sumon.graphite.port=2003
35 | sumon.platforme=DEV
36 | sumon.site=DEV
37 |
38 | #Listening port of the jar
39 | server.port=8080
40 |
41 | #Configuration for centralization of metrics
42 | sumon.graphite.enable=false
43 |
44 | dashboard.baseUrl=http://localhost/cerebro
45 |
--------------------------------------------------------------------------------
/services/src/test/resources/checkBadSubscriptionType.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": "badCheck",
3 | "name": "Bad check",
4 | "description": "A bad check with bad subscription for tests",
5 | "target": "keepLastValue(target.fake)",
6 | "from": "-25min",
7 | "until": "-1min",
8 | "graphiteBaseUrl": "http://toto/",
9 | "warn": "1310",
10 | "error": "1524",
11 | "enabled": false,
12 | "live": false,
13 | "allowNoData": true,
14 | "state": "WARN",
15 | "lastCheck": 1468408054468,
16 | "subscriptions": [
17 | {
18 | "id": "badSub",
19 | "target": "aberge",
20 | "type": "COUCOU",
21 | "su": false,
22 | "mo": true,
23 | "tu": true,
24 | "we": true,
25 | "th": true,
26 | "fr": true,
27 | "sa": false,
28 | "ignoreWarn": true,
29 | "ignoreError": false,
30 | "ignoreOk": false,
31 | "ignoreUnknown": true,
32 | "fromTime": "1030",
33 | "toTime": "1800",
34 | "enabled": true
35 | }
36 | ]
37 | }
38 |
--------------------------------------------------------------------------------
/services/src/test/resources/checkBadURI.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": "badCheck",
3 | "name": "Bad check",
4 | "description": "A bad check with bad subscription for tests",
5 | "target": "keepLastValue(target.fake)",
6 | "from": "-25min",
7 | "until": "-1min",
8 | "graphiteBaseUrl": "1.2.3.4:56789",
9 | "warn": "1310",
10 | "error": "1524",
11 | "enabled": false,
12 | "live": false,
13 | "allowNoData": true,
14 | "state": "WARN",
15 | "lastCheck": 1468408054468,
16 | "subscriptions": [
17 | {
18 | "id": "badSub",
19 | "target": "aberge",
20 | "type": "COUCOU",
21 | "su": false,
22 | "mo": true,
23 | "tu": true,
24 | "we": true,
25 | "th": true,
26 | "fr": true,
27 | "sa": false,
28 | "ignoreWarn": true,
29 | "ignoreError": false,
30 | "ignoreOk": false,
31 | "ignoreUnknown": true,
32 | "fromTime": "1030",
33 | "toTime": "1800",
34 | "enabled": true
35 | }
36 | ]
37 | }
--------------------------------------------------------------------------------
/services/src/test/resources/checkGood.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": "goodCheck",
3 | "name": "Good check",
4 | "description": "A good check for tests",
5 | "target": "keepLastValue(target.fake)",
6 | "from": "-25min",
7 | "until": "-1min",
8 | "graphiteBaseUrl": "http://toto/",
9 | "warn": "1310",
10 | "error": "1524",
11 | "enabled": false,
12 | "live": false,
13 | "allowNoData": true,
14 | "state": "WARN",
15 | "lastCheck": 1468408054468,
16 | "subscriptions": [
17 | {
18 | "id": "goodSub",
19 | "target": "sub@test.com",
20 | "type": "EMAIL",
21 | "su": false,
22 | "mo": true,
23 | "tu": true,
24 | "we": true,
25 | "th": true,
26 | "fr": true,
27 | "sa": false,
28 | "ignoreWarn": true,
29 | "ignoreError": false,
30 | "ignoreOk": false,
31 | "ignoreUnknown": true,
32 | "fromTime": "1030",
33 | "toTime": "1800",
34 | "enabled": true
35 | }
36 | ]
37 | }
38 |
--------------------------------------------------------------------------------
/services/src/test/resources/checkInvalid.json:
--------------------------------------------------------------------------------
1 | {
2 | "id":"576bb0cc0cf25814181a2ffb",
3 | "name":"Bad Request",
4 | "description":"Seyren response to bad request",
5 | "target":null,
6 | "from":"-25min",
7 | "until":"-1min",
8 | "graphiteBaseUrl":null,
9 | "warn":null,
10 | "error":null,
11 | "enabled":true,
12 | "live":false,
13 | "allowNoData":true,
14 | "state":"OK",
15 | "lastCheck":1467041095.011
16 | }
--------------------------------------------------------------------------------
/services/src/test/resources/email.properties:
--------------------------------------------------------------------------------
1 | #
2 | # This file is part of the Cerebro distribution.
3 | # (https://github.com/voyages-sncf-technologies/cerebro)
4 | # Copyright (C) 2017 VSCT.
5 | #
6 | # Cerebro is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU Affero General Public License as
8 | # published by the Free Software Foundation, version 3 of the License.
9 | #
10 | # Cerebro is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | # GNU Affero General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Affero General Public License
16 | # along with this program. If not, see .
17 | #
18 |
19 | resource.loader=class
20 | class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
21 | server=0.0.0.0
22 | port=25
23 | sender=cerebro@noreply.org
--------------------------------------------------------------------------------
/services/src/test/resources/logback-spring.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/services/src/test/resources/templates/checkModified.vm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
One of your alerts has been ${status}:
4 |
5 | Your "${alert}" alert on Cerebro has just been ${status}.
6 |
7 |
8 | Do not hesitate to go to the alert page to see the changes.
9 |