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
3b4e4876
Unverified
Commit
3b4e4876
authored
Feb 01, 2018
by
Carl Bergquist
Committed by
GitHub
Feb 01, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10715 from grafana/7883_alerting
Implement new url format in alerting
parents
d8d82c17
90207bcb
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
66 additions
and
22 deletions
+66
-22
pkg/api/alerting.go
+2
-1
pkg/models/dashboards.go
+21
-1
pkg/services/alerting/eval_context.go
+15
-12
pkg/services/alerting/notifier.go
+2
-2
pkg/services/sqlstore/dashboard.go
+22
-2
public/app/containers/AlertRuleList/AlertRuleList.jest.tsx
+1
-1
public/app/containers/AlertRuleList/AlertRuleList.tsx
+1
-1
public/app/containers/AlertRuleList/__snapshots__/AlertRuleList.jest.tsx.snap
+2
-2
No files found.
pkg/api/alerting.go
View file @
3b4e4876
...
@@ -105,7 +105,8 @@ func transformToDTOs(alerts []*models.Alert, c *middleware.Context) ([]*dtos.Ale
...
@@ -105,7 +105,8 @@ func transformToDTOs(alerts []*models.Alert, c *middleware.Context) ([]*dtos.Ale
for
_
,
alert
:=
range
alertDTOs
{
for
_
,
alert
:=
range
alertDTOs
{
for
_
,
dash
:=
range
dashboardsQuery
.
Result
{
for
_
,
dash
:=
range
dashboardsQuery
.
Result
{
if
alert
.
DashboardId
==
dash
.
Id
{
if
alert
.
DashboardId
==
dash
.
Id
{
alert
.
DashbboardUri
=
"db/"
+
dash
.
Slug
alert
.
DashbboardUri
=
dash
.
GenerateUrl
()
break
}
}
}
}
}
}
...
...
pkg/models/dashboards.go
View file @
3b4e4876
...
@@ -162,6 +162,11 @@ func (dash *Dashboard) GetUrl() string {
...
@@ -162,6 +162,11 @@ func (dash *Dashboard) GetUrl() string {
return
GetDashboardFolderUrl
(
dash
.
IsFolder
,
dash
.
Uid
,
dash
.
Slug
)
return
GetDashboardFolderUrl
(
dash
.
IsFolder
,
dash
.
Uid
,
dash
.
Slug
)
}
}
// Return the html url for a dashboard
func
(
dash
*
Dashboard
)
GenerateUrl
()
string
{
return
GetDashboardUrl
(
dash
.
Uid
,
dash
.
Slug
)
}
// GetDashboardFolderUrl return the html url for a folder if it's folder, otherwise for a dashboard
// GetDashboardFolderUrl return the html url for a folder if it's folder, otherwise for a dashboard
func
GetDashboardFolderUrl
(
isFolder
bool
,
uid
string
,
slug
string
)
string
{
func
GetDashboardFolderUrl
(
isFolder
bool
,
uid
string
,
slug
string
)
string
{
if
isFolder
{
if
isFolder
{
...
@@ -171,11 +176,16 @@ func GetDashboardFolderUrl(isFolder bool, uid string, slug string) string {
...
@@ -171,11 +176,16 @@ func GetDashboardFolderUrl(isFolder bool, uid string, slug string) string {
return
GetDashboardUrl
(
uid
,
slug
)
return
GetDashboardUrl
(
uid
,
slug
)
}
}
//
GetDashboardUrl r
eturn the html url for a dashboard
//
R
eturn the html url for a dashboard
func
GetDashboardUrl
(
uid
string
,
slug
string
)
string
{
func
GetDashboardUrl
(
uid
string
,
slug
string
)
string
{
return
fmt
.
Sprintf
(
"%s/d/%s/%s"
,
setting
.
AppSubUrl
,
uid
,
slug
)
return
fmt
.
Sprintf
(
"%s/d/%s/%s"
,
setting
.
AppSubUrl
,
uid
,
slug
)
}
}
// Return the full url for a dashboard
func
GetFullDashboardUrl
(
uid
string
,
slug
string
)
string
{
return
fmt
.
Sprintf
(
"%s%s"
,
setting
.
AppUrl
,
GetDashboardUrl
(
uid
,
slug
))
}
// GetFolderUrl return the html url for a folder
// GetFolderUrl return the html url for a folder
func
GetFolderUrl
(
folderUid
string
,
slug
string
)
string
{
func
GetFolderUrl
(
folderUid
string
,
slug
string
)
string
{
return
fmt
.
Sprintf
(
"%s/dashboards/f/%s/%s"
,
setting
.
AppSubUrl
,
folderUid
,
slug
)
return
fmt
.
Sprintf
(
"%s/dashboards/f/%s/%s"
,
setting
.
AppSubUrl
,
folderUid
,
slug
)
...
@@ -277,3 +287,13 @@ type DashboardPermissionForUser struct {
...
@@ -277,3 +287,13 @@ type DashboardPermissionForUser struct {
Permission
PermissionType
`json:"permission"`
Permission
PermissionType
`json:"permission"`
PermissionName
string
`json:"permissionName"`
PermissionName
string
`json:"permissionName"`
}
}
type
DashboardRef
struct
{
Uid
string
Slug
string
}
type
GetDashboardUIDByIdQuery
struct
{
Id
int64
Result
*
DashboardRef
}
pkg/services/alerting/eval_context.go
View file @
3b4e4876
...
@@ -22,7 +22,9 @@ type EvalContext struct {
...
@@ -22,7 +22,9 @@ type EvalContext struct {
EndTime
time
.
Time
EndTime
time
.
Time
Rule
*
Rule
Rule
*
Rule
log
log
.
Logger
log
log
.
Logger
dashboardSlug
string
dashboardRef
*
m
.
DashboardRef
ImagePublicUrl
string
ImagePublicUrl
string
ImageOnDiskPath
string
ImageOnDiskPath
string
NoDataFound
bool
NoDataFound
bool
...
@@ -83,29 +85,30 @@ func (c *EvalContext) GetNotificationTitle() string {
...
@@ -83,29 +85,30 @@ func (c *EvalContext) GetNotificationTitle() string {
return
"["
+
c
.
GetStateModel
()
.
Text
+
"] "
+
c
.
Rule
.
Name
return
"["
+
c
.
GetStateModel
()
.
Text
+
"] "
+
c
.
Rule
.
Name
}
}
func
(
c
*
EvalContext
)
GetDashboard
Slug
()
(
string
,
error
)
{
func
(
c
*
EvalContext
)
GetDashboard
UID
()
(
*
m
.
DashboardRef
,
error
)
{
if
c
.
dashboard
Slug
!=
""
{
if
c
.
dashboard
Ref
!=
nil
{
return
c
.
dashboard
Slug
,
nil
return
c
.
dashboard
Ref
,
nil
}
}
slugQuery
:=
&
m
.
GetDashboardSlug
ByIdQuery
{
Id
:
c
.
Rule
.
DashboardId
}
uidQuery
:=
&
m
.
GetDashboardUID
ByIdQuery
{
Id
:
c
.
Rule
.
DashboardId
}
if
err
:=
bus
.
Dispatch
(
slug
Query
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
uid
Query
);
err
!=
nil
{
return
""
,
err
return
nil
,
err
}
}
c
.
dashboard
Slug
=
slug
Query
.
Result
c
.
dashboard
Ref
=
uid
Query
.
Result
return
c
.
dashboard
Slug
,
nil
return
c
.
dashboard
Ref
,
nil
}
}
const
urlFormat
=
"%s?fullscreen=true&edit=true&tab=alert&panelId=%d&orgId=%d"
func
(
c
*
EvalContext
)
GetRuleUrl
()
(
string
,
error
)
{
func
(
c
*
EvalContext
)
GetRuleUrl
()
(
string
,
error
)
{
if
c
.
IsTestRun
{
if
c
.
IsTestRun
{
return
setting
.
AppUrl
,
nil
return
setting
.
AppUrl
,
nil
}
}
if
slug
,
err
:=
c
.
GetDashboardSlug
();
err
!=
nil
{
if
ref
,
err
:=
c
.
GetDashboardUID
();
err
!=
nil
{
return
""
,
err
return
""
,
err
}
else
{
}
else
{
ruleUrl
:=
fmt
.
Sprintf
(
"%sdashboard/db/%s?fullscreen&edit&tab=alert&panelId=%d&orgId=%d"
,
setting
.
AppUrl
,
slug
,
c
.
Rule
.
PanelId
,
c
.
Rule
.
OrgId
)
return
fmt
.
Sprintf
(
urlFormat
,
m
.
GetFullDashboardUrl
(
ref
.
Uid
,
ref
.
Slug
),
c
.
Rule
.
PanelId
,
c
.
Rule
.
OrgId
),
nil
return
ruleUrl
,
nil
}
}
}
}
pkg/services/alerting/notifier.go
View file @
3b4e4876
...
@@ -87,10 +87,10 @@ func (n *notificationService) uploadImage(context *EvalContext) (err error) {
...
@@ -87,10 +87,10 @@ func (n *notificationService) uploadImage(context *EvalContext) (err error) {
IsAlertContext
:
true
,
IsAlertContext
:
true
,
}
}
if
slug
,
err
:=
context
.
GetDashboardSlug
();
err
!=
nil
{
if
ref
,
err
:=
context
.
GetDashboardUID
();
err
!=
nil
{
return
err
return
err
}
else
{
}
else
{
renderOpts
.
Path
=
fmt
.
Sprintf
(
"d
ashboard-solo/db/%s?&panelId=%d"
,
s
lug
,
context
.
Rule
.
PanelId
)
renderOpts
.
Path
=
fmt
.
Sprintf
(
"d
-solo/%s/%s?panelId=%d"
,
ref
.
Uid
,
ref
.
S
lug
,
context
.
Rule
.
PanelId
)
}
}
if
imagePath
,
err
:=
renderer
.
RenderToPng
(
renderOpts
);
err
!=
nil
{
if
imagePath
,
err
:=
renderer
.
RenderToPng
(
renderOpts
);
err
!=
nil
{
...
...
pkg/services/sqlstore/dashboard.go
View file @
3b4e4876
...
@@ -19,9 +19,11 @@ func init() {
...
@@ -19,9 +19,11 @@ func init() {
bus
.
AddHandler
(
"sql"
,
SearchDashboards
)
bus
.
AddHandler
(
"sql"
,
SearchDashboards
)
bus
.
AddHandler
(
"sql"
,
GetDashboardTags
)
bus
.
AddHandler
(
"sql"
,
GetDashboardTags
)
bus
.
AddHandler
(
"sql"
,
GetDashboardSlugById
)
bus
.
AddHandler
(
"sql"
,
GetDashboardSlugById
)
bus
.
AddHandler
(
"sql"
,
GetDashboardUIDById
)
bus
.
AddHandler
(
"sql"
,
GetDashboardsByPluginId
)
bus
.
AddHandler
(
"sql"
,
GetDashboardsByPluginId
)
bus
.
AddHandler
(
"sql"
,
GetFoldersForSignedInUser
)
bus
.
AddHandler
(
"sql"
,
GetFoldersForSignedInUser
)
bus
.
AddHandler
(
"sql"
,
GetDashboardPermissionsForUser
)
bus
.
AddHandler
(
"sql"
,
GetDashboardPermissionsForUser
)
bus
.
AddHandler
(
"sql"
,
GetDashboardsBySlug
)
}
}
var
generateNewUid
func
()
string
=
util
.
GenerateShortUid
var
generateNewUid
func
()
string
=
util
.
GenerateShortUid
...
@@ -159,6 +161,7 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error {
...
@@ -159,6 +161,7 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error {
return
err
return
err
})
})
}
}
func
generateNewDashboardUid
(
sess
*
DBSession
,
orgId
int64
)
(
string
,
error
)
{
func
generateNewDashboardUid
(
sess
*
DBSession
,
orgId
int64
)
(
string
,
error
)
{
for
i
:=
0
;
i
<
3
;
i
++
{
for
i
:=
0
;
i
<
3
;
i
++
{
uid
:=
generateNewUid
()
uid
:=
generateNewUid
()
...
@@ -539,7 +542,7 @@ func GetDashboardSlugById(query *m.GetDashboardSlugByIdQuery) error {
...
@@ -539,7 +542,7 @@ func GetDashboardSlugById(query *m.GetDashboardSlugByIdQuery) error {
var
rawSql
=
`SELECT slug from dashboard WHERE Id=?`
var
rawSql
=
`SELECT slug from dashboard WHERE Id=?`
var
slug
=
DashboardSlugDTO
{}
var
slug
=
DashboardSlugDTO
{}
exists
,
err
:=
x
.
S
ql
(
rawSql
,
query
.
Id
)
.
Get
(
&
slug
)
exists
,
err
:=
x
.
S
QL
(
rawSql
,
query
.
Id
)
.
Get
(
&
slug
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -552,7 +555,7 @@ func GetDashboardSlugById(query *m.GetDashboardSlugByIdQuery) error {
...
@@ -552,7 +555,7 @@ func GetDashboardSlugById(query *m.GetDashboardSlugByIdQuery) error {
}
}
func
GetDashboardsBySlug
(
query
*
m
.
GetDashboardsBySlugQuery
)
error
{
func
GetDashboardsBySlug
(
query
*
m
.
GetDashboardsBySlugQuery
)
error
{
var
dashboards
=
make
([]
*
m
.
Dashboard
,
0
)
var
dashboards
[]
*
m
.
Dashboard
if
err
:=
x
.
Where
(
"org_id=? AND slug=?"
,
query
.
OrgId
,
query
.
Slug
)
.
Find
(
&
dashboards
);
err
!=
nil
{
if
err
:=
x
.
Where
(
"org_id=? AND slug=?"
,
query
.
OrgId
,
query
.
Slug
)
.
Find
(
&
dashboards
);
err
!=
nil
{
return
err
return
err
...
@@ -561,3 +564,20 @@ func GetDashboardsBySlug(query *m.GetDashboardsBySlugQuery) error {
...
@@ -561,3 +564,20 @@ func GetDashboardsBySlug(query *m.GetDashboardsBySlugQuery) error {
query
.
Result
=
dashboards
query
.
Result
=
dashboards
return
nil
return
nil
}
}
func
GetDashboardUIDById
(
query
*
m
.
GetDashboardUIDByIdQuery
)
error
{
var
rawSql
=
`SELECT uid, slug from dashboard WHERE Id=?`
us
:=
&
m
.
DashboardRef
{}
exists
,
err
:=
x
.
SQL
(
rawSql
,
query
.
Id
)
.
Get
(
us
)
if
err
!=
nil
{
return
err
}
else
if
exists
==
false
{
return
m
.
ErrDashboardNotFound
}
query
.
Result
=
us
return
nil
}
public/app/containers/AlertRuleList/AlertRuleList.jest.tsx
View file @
3b4e4876
...
@@ -23,7 +23,7 @@ describe('AlertRuleList', () => {
...
@@ -23,7 +23,7 @@ describe('AlertRuleList', () => {
.
format
(),
.
format
(),
evalData
:
{},
evalData
:
{},
executionError
:
''
,
executionError
:
''
,
dashboardUri
:
'd
b/mygoo
l'
,
dashboardUri
:
'd
/ufkcofof/my-goa
l'
,
canEdit
:
true
,
canEdit
:
true
,
},
},
])
])
...
...
public/app/containers/AlertRuleList/AlertRuleList.tsx
View file @
3b4e4876
...
@@ -137,7 +137,7 @@ export class AlertRuleItem extends React.Component<AlertRuleItemProps, any> {
...
@@ -137,7 +137,7 @@ export class AlertRuleItem extends React.Component<AlertRuleItemProps, any> {
'fa-pause'
:
!
rule
.
isPaused
,
'fa-pause'
:
!
rule
.
isPaused
,
});
});
let
ruleUrl
=
`
dashboard/
${
rule
.
dashboardUri
}
?panelId=
${
rule
.
panelId
}
&fullscreen&edit
&tab=alert`
;
let
ruleUrl
=
`
${
rule
.
dashboardUri
}
?panelId=
${
rule
.
panelId
}
&fullscreen=true&edit=true
&tab=alert`
;
return
(
return
(
<
li
className=
"alert-rule-item"
>
<
li
className=
"alert-rule-item"
>
...
...
public/app/containers/AlertRuleList/__snapshots__/AlertRuleList.jest.tsx.snap
View file @
3b4e4876
...
@@ -21,7 +21,7 @@ exports[`AlertRuleList should render 1 rule 1`] = `
...
@@ -21,7 +21,7 @@ exports[`AlertRuleList should render 1 rule 1`] = `
className="alert-rule-item__name"
className="alert-rule-item__name"
>
>
<a
<a
href="d
ashboard/db/mygool?panelId=3&fullscreen&edit
&tab=alert"
href="d
/ufkcofof/my-goal?panelId=3&fullscreen=true&edit=true
&tab=alert"
>
>
<Highlighter
<Highlighter
highlightClassName="highlight-search-match"
highlightClassName="highlight-search-match"
...
@@ -92,7 +92,7 @@ exports[`AlertRuleList should render 1 rule 1`] = `
...
@@ -92,7 +92,7 @@ exports[`AlertRuleList should render 1 rule 1`] = `
</button>
</button>
<a
<a
className="btn btn-small btn-inverse alert-list__btn width-2"
className="btn btn-small btn-inverse alert-list__btn width-2"
href="d
ashboard/db/mygool?panelId=3&fullscreen&edit
&tab=alert"
href="d
/ufkcofof/my-goal?panelId=3&fullscreen=true&edit=true
&tab=alert"
title="Edit alert rule"
title="Edit alert rule"
>
>
<i
<i
...
...
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