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
f443b708
Commit
f443b708
authored
Feb 15, 2015
by
Jason Wilder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CLI: Add datasource:info command
Describes the full datasource details given an account and datasource name.
parent
9cb11703
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
3 deletions
+71
-3
main.go
+1
-1
pkg/cmd/datasource.go
+53
-2
pkg/models/datasource.go
+6
-0
pkg/services/sqlstore/datasource.go
+11
-0
No files found.
main.go
View file @
f443b708
...
@@ -33,7 +33,7 @@ func main() {
...
@@ -33,7 +33,7 @@ func main() {
app
.
Version
=
version
app
.
Version
=
version
app
.
Commands
=
[]
cli
.
Command
{
cmd
.
Web
,
cmd
.
ImportJson
,
app
.
Commands
=
[]
cli
.
Command
{
cmd
.
Web
,
cmd
.
ImportJson
,
cmd
.
ListAccounts
,
cmd
.
CreateAccount
,
cmd
.
DeleteAccount
,
cmd
.
ListAccounts
,
cmd
.
CreateAccount
,
cmd
.
DeleteAccount
,
cmd
.
ListDataSources
}
cmd
.
ListDataSources
,
cmd
.
DescribeDataSource
}
app
.
Flags
=
append
(
app
.
Flags
,
[]
cli
.
Flag
{
app
.
Flags
=
append
(
app
.
Flags
,
[]
cli
.
Flag
{
cli
.
StringFlag
{
cli
.
StringFlag
{
Name
:
"config"
,
Name
:
"config"
,
...
...
pkg/cmd/datasource.go
View file @
f443b708
...
@@ -12,12 +12,20 @@ import (
...
@@ -12,12 +12,20 @@ import (
"text/tabwriter"
"text/tabwriter"
)
)
var
ListDataSources
=
cli
.
Command
{
var
(
ListDataSources
=
cli
.
Command
{
Name
:
"datasource"
,
Name
:
"datasource"
,
Usage
:
"list datasources"
,
Usage
:
"list datasources"
,
Description
:
"Lists the datasources in the system"
,
Description
:
"Lists the datasources in the system"
,
Action
:
listDatasources
,
Action
:
listDatasources
,
}
}
DescribeDataSource
=
cli
.
Command
{
Name
:
"datasource:info"
,
Usage
:
"describe the details of a datasource"
,
Description
:
"Describes the details of a datasource"
,
Action
:
describeDataSource
,
}
)
func
listDatasources
(
c
*
cli
.
Context
)
{
func
listDatasources
(
c
*
cli
.
Context
)
{
setting
.
NewConfigContext
()
setting
.
NewConfigContext
()
...
@@ -50,3 +58,46 @@ func listDatasources(c *cli.Context) {
...
@@ -50,3 +58,46 @@ func listDatasources(c *cli.Context) {
}
}
w
.
Flush
()
w
.
Flush
()
}
}
func
describeDataSource
(
c
*
cli
.
Context
)
{
setting
.
NewConfigContext
()
sqlstore
.
NewEngine
()
sqlstore
.
EnsureAdminUser
()
if
len
(
c
.
Args
())
!=
2
{
log
.
ConsoleFatal
(
"Account and datasource name args are required"
)
}
name
:=
c
.
Args
()
.
First
()
ds
:=
c
.
Args
()[
1
]
accountQuery
:=
m
.
GetAccountByNameQuery
{
Name
:
name
}
if
err
:=
bus
.
Dispatch
(
&
accountQuery
);
err
!=
nil
{
log
.
ConsoleFatalf
(
"Failed to find account: %s"
,
err
)
}
accountId
:=
accountQuery
.
Result
.
Id
query
:=
m
.
GetDataSourceByNameQuery
{
AccountId
:
accountId
,
Name
:
ds
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
log
.
ConsoleFatalf
(
"Failed to find accounts: %s"
,
err
)
}
datasource
:=
query
.
Result
w
:=
tabwriter
.
NewWriter
(
os
.
Stdout
,
20
,
1
,
4
,
' '
,
0
)
fmt
.
Fprintf
(
w
,
"NAME
\t
%s
\n
"
,
datasource
.
Name
)
fmt
.
Fprintf
(
w
,
"URL
\t
%s
\n
"
,
datasource
.
Url
)
fmt
.
Fprintf
(
w
,
"DEFAULT
\t
%t
\n
"
,
datasource
.
IsDefault
)
fmt
.
Fprintf
(
w
,
"ACCESS
\t
%s
\n
"
,
datasource
.
Access
)
fmt
.
Fprintf
(
w
,
"TYPE
\t
%s
\n
"
,
datasource
.
Type
)
switch
datasource
.
Type
{
case
m
.
DS_INFLUXDB
:
fmt
.
Fprintf
(
w
,
"DATABASE
\t
%s
\n
"
,
datasource
.
Database
)
fmt
.
Fprintf
(
w
,
"DB USER
\t
%s
\n
"
,
datasource
.
User
)
fmt
.
Fprintf
(
w
,
"DB PASSWORD
\t
%s
\n
"
,
datasource
.
Password
)
case
m
.
DS_ES
:
fmt
.
Fprintf
(
w
,
"INDEX
\t
%s
\n
"
,
datasource
.
Database
)
}
w
.
Flush
()
}
pkg/models/datasource.go
View file @
f443b708
...
@@ -93,6 +93,12 @@ type GetDataSourceByIdQuery struct {
...
@@ -93,6 +93,12 @@ type GetDataSourceByIdQuery struct {
Result
DataSource
Result
DataSource
}
}
type
GetDataSourceByNameQuery
struct
{
Name
string
AccountId
int64
Result
DataSource
}
// ---------------------
// ---------------------
// EVENTS
// EVENTS
type
DataSourceCreatedEvent
struct
{
type
DataSourceCreatedEvent
struct
{
...
...
pkg/services/sqlstore/datasource.go
View file @
f443b708
...
@@ -15,6 +15,7 @@ func init() {
...
@@ -15,6 +15,7 @@ func init() {
bus
.
AddHandler
(
"sql"
,
DeleteDataSource
)
bus
.
AddHandler
(
"sql"
,
DeleteDataSource
)
bus
.
AddHandler
(
"sql"
,
UpdateDataSource
)
bus
.
AddHandler
(
"sql"
,
UpdateDataSource
)
bus
.
AddHandler
(
"sql"
,
GetDataSourceById
)
bus
.
AddHandler
(
"sql"
,
GetDataSourceById
)
bus
.
AddHandler
(
"sql"
,
GetDataSourceByName
)
}
}
func
GetDataSourceById
(
query
*
m
.
GetDataSourceByIdQuery
)
error
{
func
GetDataSourceById
(
query
*
m
.
GetDataSourceByIdQuery
)
error
{
...
@@ -27,6 +28,16 @@ func GetDataSourceById(query *m.GetDataSourceByIdQuery) error {
...
@@ -27,6 +28,16 @@ func GetDataSourceById(query *m.GetDataSourceByIdQuery) error {
return
err
return
err
}
}
func
GetDataSourceByName
(
query
*
m
.
GetDataSourceByNameQuery
)
error
{
sess
:=
x
.
Limit
(
100
,
0
)
.
Where
(
"account_id=? AND name=?"
,
query
.
AccountId
,
query
.
Name
)
has
,
err
:=
sess
.
Get
(
&
query
.
Result
)
if
!
has
{
return
m
.
ErrDataSourceNotFound
}
return
err
}
func
GetDataSources
(
query
*
m
.
GetDataSourcesQuery
)
error
{
func
GetDataSources
(
query
*
m
.
GetDataSourcesQuery
)
error
{
sess
:=
x
.
Limit
(
100
,
0
)
.
Where
(
"account_id=?"
,
query
.
AccountId
)
.
Asc
(
"name"
)
sess
:=
x
.
Limit
(
100
,
0
)
.
Where
(
"account_id=?"
,
query
.
AccountId
)
.
Asc
(
"name"
)
...
...
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