Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
1cd632cc
Commit
1cd632cc
authored
Apr 07, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugins: added state property to plugins
parent
26804d63
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
12 additions
and
177 deletions
+12
-177
pkg/api/dataproxy.go
+0
-11
pkg/api/dtos/plugins.go
+2
-0
pkg/api/plugins.go
+2
-0
pkg/api/sqldb/sqldb.go
+0
-164
pkg/models/datasource.go
+0
-2
pkg/plugins/models.go
+1
-0
public/app/features/plugins/ds_edit_ctrl.ts
+1
-0
public/app/features/plugins/partials/ds_edit.html
+5
-0
public/app/plugins/datasource/mysql/plugin.json
+1
-0
No files found.
pkg/api/dataproxy.go
View file @
1cd632cc
...
...
@@ -10,7 +10,6 @@ import (
"time"
"github.com/grafana/grafana/pkg/api/cloudwatch"
"github.com/grafana/grafana/pkg/api/sqldb"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/metrics"
...
...
@@ -99,16 +98,6 @@ func ProxyDataSourceRequest(c *middleware.Context) {
return
}
if
ds
.
Type
==
m
.
DS_SQLDB
{
targetUrl
,
_
:=
url
.
Parse
(
ds
.
Url
)
if
!
checkWhiteList
(
c
,
targetUrl
.
Host
)
{
return
}
sqldb
.
HandleRequest
(
c
,
ds
)
return
}
targetUrl
,
_
:=
url
.
Parse
(
ds
.
Url
)
if
!
checkWhiteList
(
c
,
targetUrl
.
Host
)
{
return
...
...
pkg/api/dtos/plugins.go
View file @
1cd632cc
...
...
@@ -21,6 +21,7 @@ type PluginSetting struct {
LatestVersion
string
`json:"latestVersion"`
HasUpdate
bool
`json:"hasUpdate"`
State
string
`json:"state"`
}
type
PluginListItem
struct
{
...
...
@@ -33,6 +34,7 @@ type PluginListItem struct {
LatestVersion
string
`json:"latestVersion"`
HasUpdate
bool
`json:"hasUpdate"`
DefaultNavUrl
string
`json:"defaultNavUrl"`
State
string
`json:"state"`
}
type
PluginList
[]
PluginListItem
...
...
pkg/api/plugins.go
View file @
1cd632cc
...
...
@@ -48,6 +48,7 @@ func GetPluginList(c *middleware.Context) Response {
LatestVersion
:
pluginDef
.
GrafanaNetVersion
,
HasUpdate
:
pluginDef
.
GrafanaNetHasUpdate
,
DefaultNavUrl
:
pluginDef
.
DefaultNavUrl
,
State
:
pluginDef
.
State
,
}
if
pluginSetting
,
exists
:=
pluginSettingsMap
[
pluginDef
.
Id
];
exists
{
...
...
@@ -97,6 +98,7 @@ func GetPluginSettingById(c *middleware.Context) Response {
DefaultNavUrl
:
def
.
DefaultNavUrl
,
LatestVersion
:
def
.
GrafanaNetVersion
,
HasUpdate
:
def
.
GrafanaNetHasUpdate
,
State
:
def
.
State
,
}
query
:=
m
.
GetPluginSettingByIdQuery
{
PluginId
:
pluginId
,
OrgId
:
c
.
OrgId
}
...
...
pkg/api/sqldb/sqldb.go
deleted
100644 → 0
View file @
26804d63
package
sqldb
import
(
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"strings"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/middleware"
m
"github.com/grafana/grafana/pkg/models"
_
"github.com/go-sql-driver/mysql"
"github.com/go-xorm/core"
"github.com/go-xorm/xorm"
_
"github.com/lib/pq"
_
"github.com/mattn/go-sqlite3"
)
type
sqlDataRequest
struct
{
Query
string
`json:"query"`
Body
[]
byte
`json:"-"`
}
type
seriesStruct
struct
{
Columns
[]
string
`json:"columns"`
Name
string
`json:"name"`
Values
[][]
interface
{}
`json:"values"`
}
type
resultsStruct
struct
{
Series
[]
seriesStruct
`json:"series"`
}
type
dataStruct
struct
{
Results
[]
resultsStruct
`json:"results"`
}
func
getEngine
(
ds
*
m
.
DataSource
)
(
*
xorm
.
Engine
,
error
)
{
dbms
,
err
:=
ds
.
JsonData
.
Get
(
"dbms"
)
.
String
()
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"Invalid DBMS"
)
}
host
,
err
:=
ds
.
JsonData
.
Get
(
"host"
)
.
String
()
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"Invalid host"
)
}
port
,
err
:=
ds
.
JsonData
.
Get
(
"port"
)
.
String
()
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"Invalid port"
)
}
constr
:=
""
switch
dbms
{
case
"mysql"
:
constr
=
fmt
.
Sprintf
(
"%s:%s@tcp(%s:%s)/%s?charset=utf8"
,
ds
.
User
,
ds
.
Password
,
host
,
port
,
ds
.
Database
)
case
"postgres"
:
sslEnabled
,
_
:=
ds
.
JsonData
.
Get
(
"ssl"
)
.
Bool
()
sslMode
:=
"disable"
if
sslEnabled
{
sslMode
=
"require"
}
constr
=
fmt
.
Sprintf
(
"user=%s password=%s host=%s port=%s dbname=%s sslmode=%s"
,
ds
.
User
,
ds
.
Password
,
host
,
port
,
ds
.
Database
,
sslMode
)
default
:
return
nil
,
fmt
.
Errorf
(
"Unknown DBMS: %s"
,
dbms
)
}
return
xorm
.
NewEngine
(
dbms
,
constr
)
}
func
getData
(
db
*
core
.
DB
,
req
*
sqlDataRequest
)
(
interface
{},
error
)
{
queries
:=
strings
.
Split
(
req
.
Query
,
";"
)
data
:=
dataStruct
{}
data
.
Results
=
make
([]
resultsStruct
,
1
)
data
.
Results
[
0
]
.
Series
=
make
([]
seriesStruct
,
0
)
for
i
:=
range
queries
{
if
queries
[
i
]
==
""
{
continue
}
rows
,
err
:=
db
.
Query
(
queries
[
i
])
if
err
!=
nil
{
return
nil
,
err
}
defer
rows
.
Close
()
name
:=
fmt
.
Sprintf
(
"table_%d"
,
i
+
1
)
series
,
err
:=
arrangeResult
(
rows
,
name
)
if
err
!=
nil
{
return
nil
,
err
}
data
.
Results
[
0
]
.
Series
=
append
(
data
.
Results
[
0
]
.
Series
,
series
.
(
seriesStruct
))
}
return
data
,
nil
}
func
arrangeResult
(
rows
*
core
.
Rows
,
name
string
)
(
interface
{},
error
)
{
columnNames
,
err
:=
rows
.
Columns
()
series
:=
seriesStruct
{}
series
.
Columns
=
columnNames
series
.
Name
=
name
for
rows
.
Next
()
{
columnValues
:=
make
([]
interface
{},
len
(
columnNames
))
err
=
rows
.
ScanSlice
(
&
columnValues
)
if
err
!=
nil
{
return
nil
,
err
}
// bytes -> string
for
i
:=
range
columnValues
{
switch
columnValues
[
i
]
.
(
type
)
{
case
[]
byte
:
columnValues
[
i
]
=
fmt
.
Sprintf
(
"%s"
,
columnValues
[
i
])
}
}
series
.
Values
=
append
(
series
.
Values
,
columnValues
)
}
return
series
,
err
}
func
HandleRequest
(
c
*
middleware
.
Context
,
ds
*
m
.
DataSource
)
{
var
req
sqlDataRequest
req
.
Body
,
_
=
ioutil
.
ReadAll
(
c
.
Req
.
Request
.
Body
)
json
.
Unmarshal
(
req
.
Body
,
&
req
)
log
.
Debug
(
"SQL request: query='%v'"
,
req
.
Query
)
engine
,
err
:=
getEngine
(
ds
)
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Unable to open SQL connection"
,
err
)
return
}
defer
engine
.
Close
()
session
:=
engine
.
NewSession
()
defer
session
.
Close
()
db
:=
session
.
DB
()
result
,
err
:=
getData
(
db
,
&
req
)
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
fmt
.
Sprintf
(
"Data error: %v, Query: %s"
,
err
.
Error
(),
req
.
Query
),
err
)
return
}
c
.
JSON
(
200
,
result
)
}
pkg/models/datasource.go
View file @
1cd632cc
...
...
@@ -17,7 +17,6 @@ const (
DS_CLOUDWATCH
=
"cloudwatch"
DS_KAIROSDB
=
"kairosdb"
DS_PROMETHEUS
=
"prometheus"
DS_SQLDB
=
"sqldb"
DS_ACCESS_DIRECT
=
"direct"
DS_ACCESS_PROXY
=
"proxy"
)
...
...
@@ -63,7 +62,6 @@ var knownDatasourcePlugins map[string]bool = map[string]bool{
DS_CLOUDWATCH
:
true
,
DS_PROMETHEUS
:
true
,
DS_OPENTSDB
:
true
,
DS_SQLDB
:
true
,
"opennms"
:
true
,
"druid"
:
true
,
"dalmatinerdb"
:
true
,
...
...
pkg/plugins/models.go
View file @
1cd632cc
...
...
@@ -39,6 +39,7 @@ type PluginBase struct {
Module
string
`json:"module"`
BaseUrl
string
`json:"baseUrl"`
HideFromList
bool
`json:"hideFromList"`
State
string
`json:"state"`
IncludedInAppId
string
`json:"-"`
PluginDir
string
`json:"-"`
...
...
public/app/features/plugins/ds_edit_ctrl.ts
View file @
1cd632cc
...
...
@@ -93,6 +93,7 @@ export class DataSourceEditCtrl {
this
.
hasDashboards
=
false
;
return
this
.
backendSrv
.
get
(
'/api/plugins/'
+
this
.
current
.
type
+
'/settings'
).
then
(
pluginInfo
=>
{
this
.
datasourceMeta
=
pluginInfo
;
console
.
log
(
this
.
datasourceMeta
)
;
this
.
hasDashboards
=
_
.
find
(
pluginInfo
.
includes
,
{
type
:
'dashboard'
});
});
}
...
...
public/app/features/plugins/partials/ds_edit.html
View file @
1cd632cc
...
...
@@ -48,6 +48,11 @@
</div>
</div>
<div
class=
"alert alert-info gf-form-group"
ng-if=
"ctrl.datasourceMeta.state === 'alpha'"
>
This plugin is marked as being in alpha state, which means it is in early development phase and
updates will include breaking changes.
</div>
<rebuild-on-change
property=
"ctrl.datasourceMeta.id"
>
<plugin-component
type=
"datasource-config-ctrl"
>
</plugin-component>
...
...
public/app/plugins/datasource/mysql/plugin.json
View file @
1cd632cc
...
...
@@ -14,6 +14,7 @@
}
},
"state"
:
"alpha"
,
"alerting"
:
true
,
"annotations"
:
true
,
"metrics"
:
true
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment