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
22652889
Commit
22652889
authored
Feb 15, 2015
by
Jason Wilder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CLI: Add datasource:create command
Allows creating a datasource from the command line
parent
04a970ed
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
2 deletions
+100
-2
main.go
+1
-1
pkg/cmd/datasource.go
+98
-1
pkg/models/datasource.go
+1
-0
No files found.
main.go
View file @
22652889
...
...
@@ -33,7 +33,7 @@ func main() {
app
.
Version
=
version
app
.
Commands
=
[]
cli
.
Command
{
cmd
.
Web
,
cmd
.
ImportJson
,
cmd
.
ListAccounts
,
cmd
.
CreateAccount
,
cmd
.
DeleteAccount
,
cmd
.
ListDataSources
,
cmd
.
DescribeDataSource
}
cmd
.
ListDataSources
,
cmd
.
CreateDataSource
,
cmd
.
DescribeDataSource
}
app
.
Flags
=
append
(
app
.
Flags
,
[]
cli
.
Flag
{
cli
.
StringFlag
{
Name
:
"config"
,
...
...
pkg/cmd/datasource.go
View file @
22652889
...
...
@@ -19,6 +19,41 @@ var (
Description
:
"Lists the datasources in the system"
,
Action
:
listDatasources
,
}
CreateDataSource
=
cli
.
Command
{
Name
:
"datasource:create"
,
Usage
:
"creates a new datasource"
,
Description
:
"Creates a new datasource"
,
Action
:
createDataSource
,
Flags
:
[]
cli
.
Flag
{
cli
.
StringFlag
{
Name
:
"type"
,
Value
:
"graphite"
,
Usage
:
fmt
.
Sprintf
(
"Datasource type [%s,%s,%s,%s]"
,
m
.
DS_GRAPHITE
,
m
.
DS_INFLUXDB
,
m
.
DS_ES
,
m
.
DS_OPENTSDB
),
},
cli
.
StringFlag
{
Name
:
"access"
,
Value
:
"proxy"
,
Usage
:
"Datasource access [proxy,direct]"
,
},
cli
.
BoolFlag
{
Name
:
"default"
,
Usage
:
"Make this the default datasource"
,
},
cli
.
StringFlag
{
Name
:
"db"
,
Usage
:
"InfluxDB DB"
,
},
cli
.
StringFlag
{
Name
:
"user"
,
Usage
:
"InfluxDB username"
,
},
cli
.
StringFlag
{
Name
:
"password"
,
Usage
:
"InfluxDB password"
,
},
},
}
DescribeDataSource
=
cli
.
Command
{
Name
:
"datasource:info"
,
Usage
:
"describe the details of a datasource"
,
...
...
@@ -27,6 +62,68 @@ var (
}
)
func
createDataSource
(
c
*
cli
.
Context
)
{
setting
.
NewConfigContext
()
sqlstore
.
NewEngine
()
sqlstore
.
EnsureAdminUser
()
if
len
(
c
.
Args
())
!=
3
{
log
.
ConsoleFatal
(
"Missing required arguments"
)
}
name
:=
c
.
Args
()
.
First
()
ds
:=
c
.
Args
()[
1
]
url
:=
c
.
Args
()[
2
]
dsType
:=
c
.
String
(
"type"
)
dsAccess
:=
c
.
String
(
"access"
)
dsDefault
:=
c
.
Bool
(
"default"
)
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
{
if
err
!=
m
.
ErrDataSourceNotFound
{
log
.
ConsoleFatalf
(
"Failed to query for existing datasource: %s"
,
err
)
}
}
if
query
.
Result
.
Id
>
0
{
log
.
ConsoleFatalf
(
"DataSource %s already exists"
,
ds
)
}
cmd
:=
m
.
AddDataSourceCommand
{
AccountId
:
accountId
,
Name
:
ds
,
Url
:
url
,
Type
:
m
.
DsType
(
dsType
),
Access
:
m
.
DsAccess
(
dsAccess
),
IsDefault
:
dsDefault
,
}
switch
dsType
{
case
m
.
DS_INFLUXDB
:
db
:=
c
.
String
(
"db"
)
if
db
==
""
{
log
.
ConsoleFatal
(
"db name is required for influxdb datasources"
)
}
cmd
.
Database
=
db
cmd
.
User
=
c
.
String
(
"user"
)
cmd
.
Password
=
c
.
String
(
"password"
)
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
log
.
ConsoleFatalf
(
"Failed to create datasource: %s"
,
err
)
}
datasource
:=
cmd
.
Result
log
.
ConsoleInfof
(
"Datasource %s created"
,
datasource
.
Name
)
}
func
listDatasources
(
c
*
cli
.
Context
)
{
setting
.
NewConfigContext
()
sqlstore
.
NewEngine
()
...
...
@@ -80,7 +177,7 @@ func describeDataSource(c *cli.Context) {
query
:=
m
.
GetDataSourceByNameQuery
{
AccountId
:
accountId
,
Name
:
ds
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
log
.
ConsoleFatalf
(
"Failed to find
accounts
: %s"
,
err
)
log
.
ConsoleFatalf
(
"Failed to find
datasource
: %s"
,
err
)
}
datasource
:=
query
.
Result
...
...
pkg/models/datasource.go
View file @
22652889
...
...
@@ -9,6 +9,7 @@ const (
DS_GRAPHITE
=
"graphite"
DS_INFLUXDB
=
"influxdb"
DS_ES
=
"elasticsearch"
DS_OPENTSDB
=
"opentsdb"
DS_ACCESS_DIRECT
=
"direct"
DS_ACCESS_PROXY
=
"proxy"
)
...
...
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