-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Systemlink Tag data source | ||
|
||
<!-- | ||
TODO: Write a short description of your plugin and document any extra | ||
configuration that is required for development. | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { | ||
DataQueryRequest, | ||
DataQueryResponse, | ||
DataSourceApi, | ||
DataSourceInstanceSettings, | ||
MutableDataFrame, | ||
FieldType, | ||
} from '@grafana/data'; | ||
|
||
import { TestingStatus, getBackendSrv } from '@grafana/runtime'; | ||
|
||
import { TagQuery } from './types'; | ||
|
||
export class TagDataSource extends DataSourceApi<TagQuery> { | ||
baseUrl: string; | ||
constructor(private instanceSettings: DataSourceInstanceSettings) { | ||
super(instanceSettings); | ||
// TODO: set base path of the service | ||
this.baseUrl = this.instanceSettings.url + '/nifoo/v2'; | ||
} | ||
|
||
async query(options: DataQueryRequest<TagQuery>): Promise<DataQueryResponse> { | ||
const { range } = options; | ||
const from = range!.from.valueOf(); | ||
const to = range!.to.valueOf(); | ||
|
||
// Return a constant for each query. | ||
const data = options.targets.map((target) => { | ||
return new MutableDataFrame({ | ||
refId: target.refId, | ||
fields: [ | ||
{ name: 'Time', values: [from, to], type: FieldType.time }, | ||
{ name: 'Value', values: [target.constant, target.constant], type: FieldType.number }, | ||
], | ||
}); | ||
}); | ||
|
||
return { data }; | ||
} | ||
|
||
async testDatasource(): Promise<TestingStatus> { | ||
// TODO: Implement a health and authentication check | ||
await getBackendSrv().get(this.baseUrl + '/bar'); | ||
return { status: 'success', message: 'Data source connected and authentication successful!' }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, { ChangeEvent } from 'react'; | ||
import { InlineField, Input } from '@grafana/ui'; | ||
import { QueryEditorProps } from '@grafana/data'; | ||
import { TagDataSource } from '../TagDataSource'; | ||
import { TagQuery } from '../types'; | ||
|
||
type Props = QueryEditorProps<TagDataSource, TagQuery>; | ||
|
||
export function TagQueryEditor({ query, onChange, onRunQuery }: Props) { | ||
const onQueryTextChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
onChange({ ...query, queryText: event.target.value }); | ||
}; | ||
|
||
const onConstantChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
onChange({ ...query, constant: parseFloat(event.target.value) }); | ||
// executes the query | ||
onRunQuery(); | ||
}; | ||
|
||
const { queryText, constant } = query; | ||
|
||
return ( | ||
<div className="gf-form"> | ||
<InlineField label="Constant"> | ||
<Input onChange={onConstantChange} value={constant} width={8} type="number" step="0.1" /> | ||
</InlineField> | ||
<InlineField label="Query Text" labelWidth={16} tooltip="Not used yet"> | ||
<Input onChange={onQueryTextChange} value={queryText || ''} /> | ||
</InlineField> | ||
</div> | ||
); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { DataSourcePlugin } from '@grafana/data'; | ||
import { TagDataSource } from './TagDataSource'; | ||
import { TagQueryEditor } from './components/TagQueryEditor'; | ||
import { HttpConfigEditor } from 'core/HttpConfigEditor'; | ||
|
||
export const plugin = new DataSourcePlugin(TagDataSource) | ||
.setConfigEditor(HttpConfigEditor) | ||
.setQueryEditor(TagQueryEditor); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"type": "datasource", | ||
"name": "SystemLink Tags", | ||
"id": "ni-sltag-datasource", | ||
"metrics": true, | ||
"info": { | ||
"author": { | ||
"name": "NI" | ||
}, | ||
"logos": { | ||
"small": "img/logo-ni.svg", | ||
"large": "img/logo-ni.svg" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { DataQuery } from '@grafana/schema' | ||
|
||
export interface TagQuery extends DataQuery { | ||
queryText?: string; | ||
constant: number; | ||
} |