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
b4a8c227
Commit
b4a8c227
authored
Apr 11, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(update checks): started work on update checks
parent
8047f902
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
136 additions
and
1 deletions
+136
-1
conf/defaults.ini
+7
-0
conf/sample.ini
+7
-0
latest.json
+2
-1
pkg/api/dtos/plugins.go
+2
-0
pkg/plugins/models.go
+3
-0
pkg/plugins/plugins.go
+4
-0
pkg/plugins/update_checker.go
+109
-0
pkg/setting/setting.go
+2
-0
No files found.
conf/defaults.ini
View file @
b4a8c227
...
...
@@ -111,6 +111,13 @@ gc_interval_time = 86400
# Change this option to false to disable reporting.
reporting_enabled
=
true
# Set to false to disable all checks to https://grafana.net
# for new vesions (grafana itself and plugins), check is used
# in some UI views to notify that grafana or plugin update exists
# This option does not cause any auto updates, nor send any information
# only a GET request to http://grafana.net to get latest versions
check_for_updates
=
true
# Google Analytics universal tracking code, only enabled if you specify an id here
google_analytics_ua_id
=
...
...
conf/sample.ini
View file @
b4a8c227
...
...
@@ -100,6 +100,13 @@
# Change this option to false to disable reporting.
;reporting_enabled = true
# Set to false to disable all checks to https://grafana.net
# for new vesions (grafana itself and plugins), check is used
# in some UI views to notify that grafana or plugin update exists
# This option does not cause any auto updates, nor send any information
# only a GET request to http://grafana.net to get latest versions
check_for_updates
=
true
# Google Analytics universal tracking code, only enabled if you specify an id here
;google_analytics_ua_id =
...
...
latest.json
View file @
b4a8c227
{
"version"
:
"2.1.1"
"stable"
:
"2.6.0"
,
"testing"
:
"3.0.0-beta1"
}
pkg/api/dtos/plugins.go
View file @
b4a8c227
...
...
@@ -24,6 +24,8 @@ type PluginListItem struct {
Enabled
bool
`json:"enabled"`
Pinned
bool
`json:"pinned"`
Info
*
plugins
.
PluginInfo
`json:"info"`
LastesVersion
string
`json:"latestVersion"`
HasUpdate
bool
`json:"hasUpdate"`
}
type
PluginList
[]
PluginListItem
...
...
pkg/plugins/models.go
View file @
b4a8c227
...
...
@@ -44,6 +44,9 @@ type PluginBase struct {
PluginDir
string
`json:"-"`
DefaultNavUrl
string
`json:"-"`
GrafanaNetVersion
string
`json:"-"`
GrafanaNetHasUpdate
bool
`json:"-"`
// cache for readme file contents
Readme
[]
byte
`json:"-"`
}
...
...
pkg/plugins/plugins.go
View file @
b4a8c227
...
...
@@ -22,6 +22,9 @@ var (
Apps
map
[
string
]
*
AppPlugin
Plugins
map
[
string
]
*
PluginBase
PluginTypes
map
[
string
]
interface
{}
GrafanaLatestVersion
string
GrafanaHasUpdate
bool
)
type
PluginScanner
struct
{
...
...
@@ -70,6 +73,7 @@ func Init() error {
app
.
initApp
()
}
StartPluginUpdateChecker
()
return
nil
}
...
...
pkg/plugins/update_checker.go
0 → 100644
View file @
b4a8c227
package
plugins
import
(
"encoding/json"
"io/ioutil"
"net/http"
"strings"
"time"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/setting"
)
type
GrafanaNetPlugins
struct
{
Plugins
[]
GrafanaNetPlugin
`json:"plugins"`
}
type
GrafanaNetPlugin
struct
{
Id
string
`json:"id"`
Versions
[]
GrafanaNetPluginVersion
`json:"versions"`
}
type
GrafanaNetPluginVersion
struct
{
Version
string
`json:"version"`
}
type
GithubLatest
struct
{
Stable
string
`json:"stable"`
Testing
string
`json:"testing"`
}
func
StartPluginUpdateChecker
()
{
if
!
setting
.
CheckForUpdates
{
return
}
ticker
:=
time
.
NewTicker
(
time
.
Second
*
24
)
for
{
select
{
case
<-
ticker
.
C
:
checkForUpdates
()
}
}
}
func
checkForUpdates
()
{
log
.
Trace
(
"Checking for updates"
)
client
:=
http
.
Client
{
Timeout
:
time
.
Duration
(
5
*
time
.
Second
)}
resp
,
err
:=
client
.
Get
(
"https://grafana.net/api/plugins/repo?grafanaVersion="
+
setting
.
BuildVersion
)
if
err
!=
nil
{
log
.
Trace
(
"Failed to get plugins repo from grafana.net, %v"
,
err
.
Error
())
return
}
defer
resp
.
Body
.
Close
()
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
log
.
Trace
(
"Update check failed, reading response from grafana.net, %v"
,
err
.
Error
())
return
}
var
data
GrafanaNetPlugins
err
=
json
.
Unmarshal
(
body
,
&
data
)
if
err
!=
nil
{
log
.
Trace
(
"Failed to unmarshal plugin repo, reading response from grafana.net, %v"
,
err
.
Error
())
return
}
for
_
,
plug
:=
range
Plugins
{
for
_
,
gplug
:=
range
data
.
Plugins
{
if
gplug
.
Id
==
plug
.
Id
{
if
len
(
gplug
.
Versions
)
>
0
{
plug
.
GrafanaNetVersion
=
gplug
.
Versions
[
0
]
.
Version
plug
.
GrafanaNetHasUpdate
=
plug
.
Info
.
Version
!=
plug
.
GrafanaNetVersion
}
}
}
}
resp2
,
err
:=
client
.
Get
(
"https://raw.githubusercontent.com/grafana/grafana/master/latest.json"
)
if
err
!=
nil
{
log
.
Trace
(
"Failed to get lates.json repo from github: %v"
,
err
.
Error
())
return
}
defer
resp2
.
Body
.
Close
()
body
,
err
=
ioutil
.
ReadAll
(
resp2
.
Body
)
if
err
!=
nil
{
log
.
Trace
(
"Update check failed, reading response from github.net, %v"
,
err
.
Error
())
return
}
var
githubLatest
GithubLatest
err
=
json
.
Unmarshal
(
body
,
&
githubLatest
)
if
err
!=
nil
{
log
.
Trace
(
"Failed to unmarshal github latest, reading response from github: %v"
,
err
.
Error
())
return
}
if
strings
.
Contains
(
setting
.
BuildVersion
,
"-"
)
{
GrafanaLatestVersion
=
githubLatest
.
Testing
}
else
{
GrafanaLatestVersion
=
githubLatest
.
Stable
GrafanaHasUpdate
=
githubLatest
.
Stable
!=
setting
.
BuildVersion
}
}
pkg/setting/setting.go
View file @
b4a8c227
...
...
@@ -124,6 +124,7 @@ var (
appliedEnvOverrides
[]
string
ReportingEnabled
bool
CheckForUpdates
bool
GoogleAnalyticsId
string
GoogleTagManagerId
string
...
...
@@ -475,6 +476,7 @@ func NewConfigContext(args *CommandLineArgs) error {
analytics
:=
Cfg
.
Section
(
"analytics"
)
ReportingEnabled
=
analytics
.
Key
(
"reporting_enabled"
)
.
MustBool
(
true
)
CheckForUpdates
=
analytics
.
Key
(
"check_for_updates"
)
.
MustBool
(
true
)
GoogleAnalyticsId
=
analytics
.
Key
(
"google_analytics_ua_id"
)
.
String
()
GoogleTagManagerId
=
analytics
.
Key
(
"google_tag_manager_id"
)
.
String
()
...
...
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