diff --git a/docker/configs/grafana-defaults.ini b/docker/configs/grafana-defaults.ini index 2098edf4..611cdeec 100644 --- a/docker/configs/grafana-defaults.ini +++ b/docker/configs/grafana-defaults.ini @@ -45,10 +45,10 @@ domain = localhost enforce_domain = false # The full public facing url -root_url = %(protocol)s://%(domain)s:%(http_port)s/ +root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana # Serve Grafana from subpath specified in `root_url` setting. By default it is set to `false` for compatibility reasons. -serve_from_sub_path = false +serve_from_sub_path = true # Log web requests router_logging = false @@ -202,7 +202,7 @@ cookie_secure = false cookie_samesite = lax # set to true if you want to allow browsers to render Grafana in a , + diff --git a/src/app/pages/grafana/grafana/grafana.details.component.scss b/src/app/pages/grafana/grafana/grafana.details.component.scss new file mode 100644 index 00000000..7914022d --- /dev/null +++ b/src/app/pages/grafana/grafana/grafana.details.component.scss @@ -0,0 +1,4 @@ +iframe { + height: 720px; + width: 100%; + } \ No newline at end of file diff --git a/src/app/pages/grafana/grafana/grafana.details.component.ts b/src/app/pages/grafana/grafana/grafana.details.component.ts new file mode 100644 index 00000000..01f4d395 --- /dev/null +++ b/src/app/pages/grafana/grafana/grafana.details.component.ts @@ -0,0 +1,102 @@ +import { Component, OnInit } from '@angular/core'; +import { DomSanitizer } from '@angular/platform-browser'; +import { ActivatedRoute } from '@angular/router'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { NotificationsService } from 'app/common/services/notifications/notifications.service'; +import { PageFilters, TablePage, Thing } from '../../../common/interfaces/mainflux.interface'; +import { ThingsService } from '../../../common/services/things/things.service'; + +@Component({ + selector: 'ngx-grafana-details', + templateUrl: './grafana.details.component.html', + styleUrls: ['./grafana.details.component.scss'], +}) +export class GrafanaDetailsComponent implements OnInit { + iframeGrafana: any; + page: TablePage = {}; + pageFilters: PageFilters = {}; + thing: Thing; + + + constructor( + private domSanitizer: DomSanitizer, + private http: HttpClient, + private notificationsService: NotificationsService, + private thingsService: ThingsService, + ) { } + + + loginGrafana(){ + const headers = new HttpHeaders({ + 'Content-type': 'application/json; charset=UTF-8', + 'X-Auth-Request-User' : 'moko2@example.com', + }); + // const creds = { + // user: "moko2@example.com", + // email: "", + // }; + return this.http.get('/grafana/profile' , { observe: 'response', headers: headers }) + .map( + resp => { + console.log(resp) + return resp + }, + err => { + this.notificationsService.error( + 'Failed to login to grafana', + `Error: ${err.status} - ${err.statusText}`); + }, + ); + } + + + getThings(name?: string): void { + this.page = {}; + + this.pageFilters.name = name; + + this.pageFilters.metadata = { + "dashboard":"grafana" + }; + + this.thingsService.getThings(this.pageFilters).subscribe( + (resp: any) => { + this.page = { + offset: resp.offset, + limit: resp.limit, + total: resp.total, + rows: resp.things, + }; + + // Check if there is a type defined in the metadata + this.page.rows.forEach( (thing: Thing) => { + thing.type = thing.metadata ? thing.metadata.type : ''; + }); + }, + ); + + if (this.thing.metadata&& this.thing.metadata.dashboard == 'grafana'){ + this.iframeGrafana = this.domSanitizer.bypassSecurityTrustResourceUrl(`${this.thing.metadata.dashboardURL}&kiosk&var-publisher=${this.thing.id}`); + } + + + } + + ngOnInit() { + // const id = this.route.snapshot.paramMap.get('id'); + // const headers = new HttpHeaders({ + // 'Content-type': 'application/json; charset=UTF-8', + // '' + // }); + this.getThings() + this.thing = this.page.rows[0] as Thing + this.loginGrafana().subscribe( + (resp:any) =>{ + console.log(resp) + } + ); + if (this.thing.metadata&& this.thing.metadata.dashboard == 'grafana'){ + this.iframeGrafana = this.domSanitizer.bypassSecurityTrustResourceUrl(`${this.thing.metadata.dashboardURL}&kiosk&var-publisher=${this.thing.id}`); + } + } +} diff --git a/src/app/pages/pages-menu.ts b/src/app/pages/pages-menu.ts index f5a364eb..669b2cd4 100644 --- a/src/app/pages/pages-menu.ts +++ b/src/app/pages/pages-menu.ts @@ -15,6 +15,11 @@ export const MENU_ITEMS: NbMenuItem[] = environment.production ? icon: 'film-outline', link: appPrefix + '/pages/things', }, + { + title: 'Grafana', + icon: 'film-outline', + link: appPrefix + '/pages/grafana', + }, { title: 'Channels', icon: 'flip-2-outline', @@ -43,6 +48,11 @@ export const MENU_ITEMS: NbMenuItem[] = environment.production ? icon: 'film-outline', link: appPrefix + '/pages/things', }, + { + title: 'Grafana', + icon: 'film-outline', + link: appPrefix + '/pages/grafana', + }, { title: 'Channels', icon: 'flip-2-outline', diff --git a/src/app/pages/pages-routing.module.ts b/src/app/pages/pages-routing.module.ts index 7007add3..75ded00b 100644 --- a/src/app/pages/pages-routing.module.ts +++ b/src/app/pages/pages-routing.module.ts @@ -19,6 +19,7 @@ import { ThingsDetailsComponent } from './things/details/things.details.componen // Mainflux - Channels import { ChannelsComponent } from './channels/channels.component'; import { ChannelsDetailsComponent } from './channels/details/channels.details.component'; +import { GrafanaDetailsComponent } from './grafana/grafana/grafana.details.component'; const children = environment.production ? [ @@ -47,6 +48,10 @@ const children = environment.production ? path: 'channels/details/:id', component: ChannelsDetailsComponent, }, + { + path: 'grafana', + component: GrafanaDetailsComponent, + }, { path: 'profile', component: ProfileComponent, @@ -89,6 +94,10 @@ const children = environment.production ? path: 'channels', component: ChannelsComponent, }, + { + path: 'grafana', + component: GrafanaDetailsComponent, + }, { path: 'channels/details/:id', component: ChannelsDetailsComponent, diff --git a/src/app/pages/pages.module.ts b/src/app/pages/pages.module.ts index 10461c16..21679357 100644 --- a/src/app/pages/pages.module.ts +++ b/src/app/pages/pages.module.ts @@ -41,6 +41,7 @@ import { ChannelsComponent } from 'app/pages/channels/channels.component'; import { ChannelsAddComponent } from 'app/pages/channels/add/channels.add.component'; import { ChannelsDetailsComponent } from 'app/pages/channels/details/channels.details.component'; import { NgJsonEditorModule } from 'ang-jsoneditor'; +import { GrafanaDetailsComponent } from './grafana/grafana/grafana.details.component'; @NgModule({ imports: [ @@ -86,6 +87,7 @@ import { NgJsonEditorModule } from 'ang-jsoneditor'; ThingsAddComponent, ThingsCertComponent, ThingsDetailsComponent, + GrafanaDetailsComponent, // Channels ChannelsComponent, ChannelsAddComponent,