Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-boot-admin
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-boot-admin
Commits
74c1089d
Commit
74c1089d
authored
May 02, 2017
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove PagerdutyNotifier
parent
14cbcec5
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
333 deletions
+35
-333
NotifierConfiguration.java
.../codecentric/boot/admin/config/NotifierConfiguration.java
+19
-38
PagerdutyNotifier.java
...a/de/codecentric/boot/admin/notify/PagerdutyNotifier.java
+0
-170
NotifierConfigurationTest.java
...ecentric/boot/admin/config/NotifierConfigurationTest.java
+16
-22
PagerdutyNotifierTest.java
.../codecentric/boot/admin/notify/PagerdutyNotifierTest.java
+0
-103
No files found.
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/config/NotifierConfiguration.java
View file @
74c1089d
...
...
@@ -15,8 +15,18 @@
*/
package
de
.
codecentric
.
boot
.
admin
.
config
;
import
java.util.List
;
import
de.codecentric.boot.admin.notify.CompositeNotifier
;
import
de.codecentric.boot.admin.notify.HipchatNotifier
;
import
de.codecentric.boot.admin.notify.LetsChatNotifier
;
import
de.codecentric.boot.admin.notify.MailNotifier
;
import
de.codecentric.boot.admin.notify.Notifier
;
import
de.codecentric.boot.admin.notify.NotifierListener
;
import
de.codecentric.boot.admin.notify.SlackNotifier
;
import
de.codecentric.boot.admin.notify.filter.FilteringNotifier
;
import
de.codecentric.boot.admin.notify.filter.web.NotificationFilterController
;
import
de.codecentric.boot.admin.web.PrefixHandlerMapping
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
...
...
@@ -33,18 +43,6 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.mail.MailSender
;
import
de.codecentric.boot.admin.notify.CompositeNotifier
;
import
de.codecentric.boot.admin.notify.HipchatNotifier
;
import
de.codecentric.boot.admin.notify.MailNotifier
;
import
de.codecentric.boot.admin.notify.Notifier
;
import
de.codecentric.boot.admin.notify.NotifierListener
;
import
de.codecentric.boot.admin.notify.PagerdutyNotifier
;
import
de.codecentric.boot.admin.notify.SlackNotifier
;
import
de.codecentric.boot.admin.notify.LetsChatNotifier
;
import
de.codecentric.boot.admin.notify.filter.FilteringNotifier
;
import
de.codecentric.boot.admin.notify.filter.web.NotificationFilterController
;
import
de.codecentric.boot.admin.web.PrefixHandlerMapping
;
@Configuration
public
class
NotifierConfiguration
{
...
...
@@ -63,7 +61,7 @@ public class NotifierConfiguration {
@Configuration
@ConditionalOnBean
(
Notifier
.
class
)
@AutoConfigureBefore
({
NotifierListenerConfiguration
.
class
})
@AutoConfigureBefore
({
NotifierListenerConfiguration
.
class
})
public
static
class
CompositeNotifierConfiguration
{
@Bean
@Primary
...
...
@@ -91,7 +89,7 @@ public class NotifierConfiguration {
private
FilteringNotifier
filteringNotifier
;
@Autowired
private
AdminServerProperties
adminServerProperties
;
private
AdminServerProperties
adminServer
;
@Bean
public
NotificationFilterController
notificationFilterController
()
{
...
...
@@ -101,16 +99,15 @@ public class NotifierConfiguration {
@Bean
public
PrefixHandlerMapping
prefixHandlerMappingNotificationFilterController
()
{
PrefixHandlerMapping
prefixHandlerMapping
=
new
PrefixHandlerMapping
(
notificationFilterController
());
prefixHandlerMapping
.
setPrefix
(
adminServerProperties
.
getContextPath
());
prefixHandlerMapping
.
setPrefix
(
adminServer
.
getContextPath
());
return
prefixHandlerMapping
;
}
}
@Configuration
@ConditionalOnBean
(
MailSender
.
class
)
@AutoConfigureAfter
({
MailSenderAutoConfiguration
.
class
})
@AutoConfigureBefore
({
NotifierListenerConfiguration
.
class
,
CompositeNotifierConfiguration
.
class
})
@AutoConfigureAfter
({
MailSenderAutoConfiguration
.
class
})
@AutoConfigureBefore
({
NotifierListenerConfiguration
.
class
,
CompositeNotifierConfiguration
.
class
})
public
static
class
MailNotifierConfiguration
{
@Autowired
private
MailSender
mailSender
;
...
...
@@ -124,22 +121,8 @@ public class NotifierConfiguration {
}
@Configuration
@ConditionalOnProperty
(
prefix
=
"spring.boot.admin.notify.pagerduty"
,
name
=
"service-key"
)
@AutoConfigureBefore
({
NotifierListenerConfiguration
.
class
,
CompositeNotifierConfiguration
.
class
})
public
static
class
PagerdutyNotifierConfiguration
{
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties
(
"spring.boot.admin.notify.pagerduty"
)
public
PagerdutyNotifier
pagerdutyNotifier
()
{
return
new
PagerdutyNotifier
();
}
}
@Configuration
@ConditionalOnProperty
(
prefix
=
"spring.boot.admin.notify.hipchat"
,
name
=
"url"
)
@AutoConfigureBefore
({
NotifierListenerConfiguration
.
class
,
CompositeNotifierConfiguration
.
class
})
@AutoConfigureBefore
({
NotifierListenerConfiguration
.
class
,
CompositeNotifierConfiguration
.
class
})
public
static
class
HipchatNotifierConfiguration
{
@Bean
@ConditionalOnMissingBean
...
...
@@ -151,8 +134,7 @@ public class NotifierConfiguration {
@Configuration
@ConditionalOnProperty
(
prefix
=
"spring.boot.admin.notify.slack"
,
name
=
"webhook-url"
)
@AutoConfigureBefore
({
NotifierListenerConfiguration
.
class
,
CompositeNotifierConfiguration
.
class
})
@AutoConfigureBefore
({
NotifierListenerConfiguration
.
class
,
CompositeNotifierConfiguration
.
class
})
public
static
class
SlackNotifierConfiguration
{
@Bean
@ConditionalOnMissingBean
...
...
@@ -164,8 +146,7 @@ public class NotifierConfiguration {
@Configuration
@ConditionalOnProperty
(
prefix
=
"spring.boot.admin.notify.letschat"
,
name
=
"url"
)
@AutoConfigureBefore
({
NotifierListenerConfiguration
.
class
,
CompositeNotifierConfiguration
.
class
})
@AutoConfigureBefore
({
NotifierListenerConfiguration
.
class
,
CompositeNotifierConfiguration
.
class
})
public
static
class
LetsChatNotifierConfiguration
{
@Bean
@ConditionalOnMissingBean
...
...
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/notify/PagerdutyNotifier.java
deleted
100644 → 0
View file @
14cbcec5
/*
* Copyright 2013-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
de
.
codecentric
.
boot
.
admin
.
notify
;
import
static
java
.
util
.
Collections
.
singletonList
;
import
java.net.URI
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.springframework.expression.Expression
;
import
org.springframework.expression.ParserContext
;
import
org.springframework.expression.spel.standard.SpelExpressionParser
;
import
org.springframework.web.client.RestTemplate
;
import
de.codecentric.boot.admin.event.ClientApplicationEvent
;
import
de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent
;
/**
* Notifier submitting events to Pagerduty.
*
* @author Johannes Edmeier
*/
public
class
PagerdutyNotifier
extends
AbstractStatusChangeNotifier
{
public
static
final
URI
DEFAULT_URI
=
URI
.
create
(
"https://events.pagerduty.com/generic/2010-04-15/create_event.json"
);
private
static
final
String
DEFAULT_DESCRIPTION
=
"#{application.name}/#{application.id} is #{to.status}"
;
private
final
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
private
RestTemplate
restTemplate
=
new
RestTemplate
();
/**
* URI for pagerduty-REST-API
*/
private
URI
url
=
DEFAULT_URI
;
/**
* Service-Key for pagerduty-REST-API
*/
private
String
serviceKey
;
/**
* Client for pagerduty-REST-API
*/
private
String
client
;
/**
* Client-url for pagerduty-REST-API
*/
private
URI
clientUrl
;
/**
* Trigger description. SpEL template using event as root;
*/
private
Expression
description
;
public
PagerdutyNotifier
()
{
this
.
description
=
parser
.
parseExpression
(
DEFAULT_DESCRIPTION
,
ParserContext
.
TEMPLATE_EXPRESSION
);
}
@Override
protected
void
doNotify
(
ClientApplicationEvent
event
)
throws
Exception
{
restTemplate
.
postForEntity
(
url
,
createPagerdutyEvent
(
event
),
Void
.
class
);
}
protected
Map
<
String
,
Object
>
createPagerdutyEvent
(
ClientApplicationEvent
event
)
{
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
result
.
put
(
"service_key"
,
serviceKey
);
result
.
put
(
"incident_key"
,
event
.
getApplication
().
getName
()
+
"/"
+
event
.
getApplication
().
getId
());
result
.
put
(
"description"
,
getDescription
(
event
));
Map
<
String
,
Object
>
details
=
getDetails
(
event
);
result
.
put
(
"details"
,
details
);
if
(
event
instanceof
ClientApplicationStatusChangedEvent
)
{
if
(
"UP"
.
equals
(((
ClientApplicationStatusChangedEvent
)
event
).
getTo
().
getStatus
()))
{
result
.
put
(
"event_type"
,
"resolve"
);
}
else
{
result
.
put
(
"event_type"
,
"trigger"
);
if
(
client
!=
null
)
{
result
.
put
(
"client"
,
client
);
}
if
(
clientUrl
!=
null
)
{
result
.
put
(
"client_url"
,
clientUrl
);
}
Map
<
String
,
Object
>
context
=
new
HashMap
<>();
context
.
put
(
"type"
,
"link"
);
context
.
put
(
"href"
,
event
.
getApplication
().
getHealthUrl
());
context
.
put
(
"text"
,
"Application health-endpoint"
);
result
.
put
(
"contexts"
,
singletonList
(
context
));
}
}
return
result
;
}
protected
String
getDescription
(
ClientApplicationEvent
event
)
{
return
description
.
getValue
(
event
,
String
.
class
);
}
protected
Map
<
String
,
Object
>
getDetails
(
ClientApplicationEvent
event
)
{
Map
<
String
,
Object
>
details
=
new
HashMap
<>();
if
(
event
instanceof
ClientApplicationStatusChangedEvent
)
{
details
.
put
(
"from"
,
((
ClientApplicationStatusChangedEvent
)
event
).
getFrom
());
details
.
put
(
"to"
,
((
ClientApplicationStatusChangedEvent
)
event
).
getTo
());
}
return
details
;
}
public
void
setUrl
(
URI
url
)
{
this
.
url
=
url
;
}
public
URI
getUrl
()
{
return
url
;
}
public
void
setClient
(
String
client
)
{
this
.
client
=
client
;
}
public
String
getClient
()
{
return
client
;
}
public
void
setClientUrl
(
URI
clientUrl
)
{
this
.
clientUrl
=
clientUrl
;
}
public
URI
getClientUrl
()
{
return
clientUrl
;
}
public
void
setServiceKey
(
String
serviceKey
)
{
this
.
serviceKey
=
serviceKey
;
}
public
String
getServiceKey
()
{
return
serviceKey
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
parser
.
parseExpression
(
description
,
ParserContext
.
TEMPLATE_EXPRESSION
);
}
public
String
getDescription
()
{
return
description
.
getExpressionString
();
}
public
void
setRestTemplate
(
RestTemplate
restTemplate
)
{
this
.
restTemplate
=
restTemplate
;
}
}
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/config/NotifierConfigurationTest.java
View file @
74c1089d
...
...
@@ -15,11 +15,19 @@
*/
package
de
.
codecentric
.
boot
.
admin
.
config
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
de.codecentric.boot.admin.event.ClientApplicationEvent
;
import
de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent
;
import
de.codecentric.boot.admin.model.Application
;
import
de.codecentric.boot.admin.model.StatusInfo
;
import
de.codecentric.boot.admin.notify.CompositeNotifier
;
import
de.codecentric.boot.admin.notify.HipchatNotifier
;
import
de.codecentric.boot.admin.notify.MailNotifier
;
import
de.codecentric.boot.admin.notify.Notifier
;
import
de.codecentric.boot.admin.notify.NotifierListener
;
import
de.codecentric.boot.admin.notify.SlackNotifier
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration
;
...
...
@@ -28,23 +36,15 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
de.codecentric.boot.admin.event.ClientApplicationEvent
;
import
de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent
;
import
de.codecentric.boot.admin.model.Application
;
import
de.codecentric.boot.admin.model.StatusInfo
;
import
de.codecentric.boot.admin.notify.CompositeNotifier
;
import
de.codecentric.boot.admin.notify.HipchatNotifier
;
import
de.codecentric.boot.admin.notify.MailNotifier
;
import
de.codecentric.boot.admin.notify.Notifier
;
import
de.codecentric.boot.admin.notify.NotifierListener
;
import
de.codecentric.boot.admin.notify.PagerdutyNotifier
;
import
de.codecentric.boot.admin.notify.SlackNotifier
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
NotifierConfigurationTest
{
private
static
final
ClientApplicationEvent
APP_DOWN
=
new
ClientApplicationStatusChangedEvent
(
Application
.
create
(
"App"
).
withId
(
"id-1"
).
withHealthUrl
(
"http://health"
)
.
withStatusInfo
(
StatusInfo
.
ofDown
()).
build
(),
StatusInfo
.
ofUp
(),
StatusInfo
.
ofDown
());
Application
.
create
(
"App"
)
.
withId
(
"id-1"
)
.
withHealthUrl
(
"http://health"
)
.
withStatusInfo
(
StatusInfo
.
ofDown
())
.
build
(),
StatusInfo
.
ofUp
(),
StatusInfo
.
ofDown
());
private
AnnotationConfigWebApplicationContext
context
;
...
...
@@ -75,12 +75,6 @@ public class NotifierConfigurationTest {
}
@Test
public
void
test_pagerduty
()
{
load
(
null
,
"spring.boot.admin.notify.pagerduty.service-key:foo"
);
assertThat
(
context
.
getBean
(
PagerdutyNotifier
.
class
)).
isInstanceOf
(
PagerdutyNotifier
.
class
);
}
@Test
public
void
test_hipchat
()
{
load
(
null
,
"spring.boot.admin.notify.hipchat.url:http://example.com"
);
assertThat
(
context
.
getBean
(
HipchatNotifier
.
class
)).
isInstanceOf
(
HipchatNotifier
.
class
);
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/notify/PagerdutyNotifierTest.java
deleted
100644 → 0
View file @
14cbcec5
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
de
.
codecentric
.
boot
.
admin
.
notify
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
java.net.URI
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.web.client.RestTemplate
;
import
de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent
;
import
de.codecentric.boot.admin.model.Application
;
import
de.codecentric.boot.admin.model.StatusInfo
;
public
class
PagerdutyNotifierTest
{
private
PagerdutyNotifier
notifier
;
private
RestTemplate
restTemplate
;
@Before
public
void
setUp
()
{
restTemplate
=
mock
(
RestTemplate
.
class
);
notifier
=
new
PagerdutyNotifier
();
notifier
.
setServiceKey
(
"--service--"
);
notifier
.
setClient
(
"TestClient"
);
notifier
.
setClientUrl
(
URI
.
create
(
"http://localhost"
));
notifier
.
setRestTemplate
(
restTemplate
);
}
@Test
public
void
test_onApplicationEvent_resolve
()
{
StatusInfo
infoDown
=
StatusInfo
.
ofDown
();
StatusInfo
infoUp
=
StatusInfo
.
ofUp
();
notifier
.
notify
(
new
ClientApplicationStatusChangedEvent
(
Application
.
create
(
"App"
).
withId
(
"-id-"
).
withHealthUrl
(
"http://health"
).
build
(),
infoDown
,
infoUp
));
Map
<
String
,
Object
>
expected
=
new
HashMap
<
String
,
Object
>();
expected
.
put
(
"service_key"
,
"--service--"
);
expected
.
put
(
"incident_key"
,
"App/-id-"
);
expected
.
put
(
"event_type"
,
"resolve"
);
expected
.
put
(
"description"
,
"App/-id- is UP"
);
Map
<
String
,
Object
>
details
=
new
HashMap
<
String
,
Object
>();
details
.
put
(
"from"
,
infoDown
);
details
.
put
(
"to"
,
infoUp
);
expected
.
put
(
"details"
,
details
);
verify
(
restTemplate
).
postForEntity
(
eq
(
PagerdutyNotifier
.
DEFAULT_URI
),
eq
(
expected
),
eq
(
Void
.
class
));
}
@Test
public
void
test_onApplicationEvent_trigger
()
{
StatusInfo
infoDown
=
StatusInfo
.
ofDown
();
StatusInfo
infoUp
=
StatusInfo
.
ofUp
();
notifier
.
notify
(
new
ClientApplicationStatusChangedEvent
(
Application
.
create
(
"App"
).
withId
(
"-id-"
).
withHealthUrl
(
"http://health"
).
build
(),
infoUp
,
infoDown
));
Map
<
String
,
Object
>
expected
=
new
HashMap
<
String
,
Object
>();
expected
.
put
(
"service_key"
,
"--service--"
);
expected
.
put
(
"incident_key"
,
"App/-id-"
);
expected
.
put
(
"event_type"
,
"trigger"
);
expected
.
put
(
"description"
,
"App/-id- is DOWN"
);
expected
.
put
(
"client"
,
"TestClient"
);
expected
.
put
(
"client_url"
,
URI
.
create
(
"http://localhost"
));
Map
<
String
,
Object
>
details
=
new
HashMap
<
String
,
Object
>();
details
.
put
(
"from"
,
infoUp
);
details
.
put
(
"to"
,
infoDown
);
expected
.
put
(
"details"
,
details
);
Map
<
String
,
Object
>
context
=
new
HashMap
<
String
,
Object
>();
context
.
put
(
"type"
,
"link"
);
context
.
put
(
"href"
,
"http://health"
);
context
.
put
(
"text"
,
"Application health-endpoint"
);
expected
.
put
(
"contexts"
,
Arrays
.
asList
(
context
));
verify
(
restTemplate
).
postForEntity
(
eq
(
PagerdutyNotifier
.
DEFAULT_URI
),
eq
(
expected
),
eq
(
Void
.
class
));
}
}
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