How to use the @grafana/runtime.getTemplateSrv function in @grafana/runtime

To help you get started, we’ve selected a few @grafana/runtime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mtanda / grafana-aws-athena-datasource / src / datasource.ts View on Github external
applyTemplateVariables(query: AwsAthenaQuery, scopedVars: ScopedVars) {
    // TODO: pass scopedVars to templateSrv.replace()
    const templateSrv = getTemplateSrv();
    query.region = templateSrv.replace(query.region, scopedVars);
    query.maxRows = query.maxRows || '';
    query.cacheDuration = query.cacheDuration || '';
    if (typeof query.queryString === 'undefined' || query.queryString === '') {
      query.queryExecutionId = templateSrv.replace(query.queryExecutionId, scopedVars);
      query.inputs = query.queryExecutionId.split(/,/).map(id => {
        return {
          queryExecutionId: id,
        };
      });
    } else {
      query.queryExecutionId = '';
      query.inputs = [];
    }
    query.queryString = templateSrv.replace(query.queryString, scopedVars) || '';
    query.outputLocation = this.outputLocation;
github sbueringer / grafana-consul-datasource / src / DataSource.ts View on Github external
query(options: DataQueryRequest): Observable {
    for (const target of options.targets) {
      target.target = getTemplateSrv().replace(target.target, options.scopedVars);
    }

    // store the targets in activeTargets so we can
    // access the legendFormat later on via the refId
    let activeTargets: { [key: string]: any } = {};
    for (const target of options.targets) {
      if (target.hide) {
        continue;
      }
      activeTargets[target.refId] = target;
    }

    return super.query(options).pipe(
      map((rsp: DataQueryResponse) => {
        const finalRsp: DataQueryResponse = { data: [], state: LoadingState.Done };
github OctopusDeploy / OctopusGrafanaDataSource / src / DataSource.ts View on Github external
async getUrl(entityName: string, spaceName: string, datasource: string) {
    const datasourceId = await this.datasourceNameToId(datasource);

    if (entityName === 'spaces') {
      return `api/datasources/${datasourceId}/resources/spaces/nameid`;
    }

    /**
     * Get space names mapped to IDs
     */
    const spaces = await fetch(`api/datasources/${datasourceId}/resources/spaces/nameid`).then(response =>
      response.json()
    );

    const spaceNameFixed = getTemplateSrv().replace(spaceName);
    // treat an empty space as the default, which is identified as a single space
    const spaceNameDealWithDefault = spaceNameFixed || ' ';

    if (spaces[spaceNameDealWithDefault]) {
      return `api/datasources/${datasourceId}/resources/${spaces[spaceNameDealWithDefault]}/nameid/${entityName}`;
    }

    throw 'Space could not be found';
  }
github OctopusDeploy / OctopusGrafanaDataSource / src / DataSource.ts View on Github external
async getSpaceId(spaceName: string, datasource: string): Promise {
    const url = await this.getUrl('spaces', '', datasource);
    const entities = await fetch(url).then(response => response.json());
    const entityNameFixed = getTemplateSrv().replace(spaceName);
    const entityNameOrDefault = entityNameFixed === '' ? ' ' : entityNameFixed;
    return entities[entityNameOrDefault] || '';
  }
github fr-ser / grafana-sqlite-datasource / src / DataSource.ts View on Github external
constructor(instanceSettings: DataSourceInstanceSettings) {
    super(instanceSettings);

    this.templateSrv = getTemplateSrv();
  }
github OctopusDeploy / OctopusGrafanaDataSource / src / DataSource.ts View on Github external
async getEntityId(spaceName: string, entityType: string, entityName: string, datasource: string): Promise {
    const entityNameFixed = getTemplateSrv().replace(entityName);
    const url = await this.getUrl(entityType, spaceName, datasource);
    const entities = await fetch(url).then(response => response.json());
    return entities[entityNameFixed] || '';
  }
github OctopusDeploy / OctopusGrafanaDataSource / src / DataSource.ts View on Github external
applyTemplateVariables(query: MyQuery) {
    const templateSrv = getTemplateSrv();

    return {
      ...query,
      spaceName: query.spaceName ? templateSrv.replace(query.spaceName) : '',
      projectName: query.projectName ? templateSrv.replace(query.projectName) : '',
      tenantName: query.tenantName ? templateSrv.replace(query.tenantName) : '',
      environmentName: query.environmentName ? templateSrv.replace(query.environmentName) : '',
      channelName: query.channelName ? templateSrv.replace(query.channelName) : '',
      releaseVersion: query.releaseVersion ? templateSrv.replace(query.releaseVersion) : '',
      taskState: query.taskState ? templateSrv.replace(query.taskState) : '',
    };
  }
github RedisGrafana / grafana-redis-datasource / src / data-source / data-source.ts View on Github external
applyTemplateVariables(query: RedisQuery, scopedVars: ScopedVars) {
    const templateSrv = getTemplateSrv();

    /**
     * Replace variables
     */
    return {
      ...query,
      keyName: query.keyName ? templateSrv.replace(query.keyName, scopedVars) : '',
      query: query.query ? templateSrv.replace(query.query, scopedVars) : '',
      field: query.field ? templateSrv.replace(query.field, scopedVars) : '',
      filter: query.filter ? templateSrv.replace(query.filter, scopedVars) : '',
      legend: query.legend ? templateSrv.replace(query.legend, scopedVars) : '',
      value: query.value ? templateSrv.replace(query.value, scopedVars) : '',
    };
  }