forked from opendistro-for-elasticsearch/alerting
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d2f165
commit 498496f
Showing
8 changed files
with
115 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...kotlin/com/amazon/opendistroforelasticsearch/alerting/settings/DestinationMailSettings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.amazon.opendistroforelasticsearch.alerting.settings | ||
|
||
import org.elasticsearch.common.settings.Setting | ||
import org.elasticsearch.common.settings.Settings | ||
import org.elasticsearch.common.settings.SecureSetting | ||
import org.elasticsearch.common.settings.SecureString | ||
import java.io.IOException | ||
|
||
/** | ||
* settings specific to mail destination. | ||
*/ | ||
data class DestinationMailSettings( | ||
val host: String, | ||
val port: Int, | ||
val method: String, | ||
val from: String, | ||
val username: SecureString, | ||
val password: SecureString | ||
) { | ||
companion object { | ||
val DESTINATION_MAIL_HOST = Setting.simpleString( | ||
"opendistro.alerting.destination.mail.host", | ||
"localhost", | ||
Setting.Property.NodeScope, Setting.Property.Dynamic | ||
) | ||
|
||
val DESTINATION_MAIL_PORT = Setting.intSetting( | ||
"opendistro.alerting.destination.mail.port", | ||
25, | ||
Setting.Property.NodeScope, Setting.Property.Dynamic | ||
) | ||
|
||
val DESTINATION_MAIL_METHOD = Setting.simpleString( | ||
"opendistro.alerting.destination.mail.method", | ||
"none", | ||
Setting.Property.NodeScope, Setting.Property.Dynamic | ||
) | ||
|
||
val DESTINATION_MAIL_FROM = Setting.simpleString( | ||
"opendistro.alerting.destination.mail.from", | ||
"opendistro-alerting@localhost", | ||
Setting.Property.NodeScope, Setting.Property.Dynamic | ||
) | ||
|
||
val DESTINATION_MAIL_USERNAME = SecureSetting.secureString( | ||
"opendistro.alerting.destination.mail.username", | ||
null | ||
) | ||
|
||
val DESTINATION_MAIL_PASSWORD = SecureSetting.secureString( | ||
"opendistro.alerting.destination.mail.password", | ||
null | ||
) | ||
|
||
@JvmStatic | ||
@Throws(IOException::class) | ||
fun parse(settings: Settings): DestinationMailSettings { | ||
return DestinationMailSettings( | ||
DESTINATION_MAIL_HOST.get(settings), | ||
DESTINATION_MAIL_PORT.get(settings), | ||
DESTINATION_MAIL_METHOD.get(settings), | ||
DESTINATION_MAIL_FROM.get(settings), | ||
DESTINATION_MAIL_USERNAME.get(settings), | ||
DESTINATION_MAIL_PASSWORD.get(settings) | ||
) | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ain/kotlin/com/amazon/opendistroforelasticsearch/alerting/settings/DestinationSettings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.amazon.opendistroforelasticsearch.alerting.settings | ||
|
||
import org.elasticsearch.common.settings.Settings | ||
import java.io.IOException | ||
|
||
/** | ||
* settings specific to mail destination. | ||
*/ | ||
data class DestinationSettings( | ||
val mail: DestinationMailSettings | ||
) { | ||
companion object { | ||
@JvmStatic | ||
@Throws(IOException::class) | ||
fun parse(settings: Settings): DestinationSettings { | ||
val prefix: (String) -> (Boolean) = { it.startsWith("opendistro.alerting.destination.mail") } | ||
return DestinationSettings( | ||
DestinationMailSettings.parse(settings.filter(prefix)) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,7 +101,7 @@ public void testHostMissingMessage() { | |
.withMessage("dummyMessage") | ||
.withFrom("[email protected]") | ||
.withRecipients("[email protected]").build(); | ||
|
||
} catch (Exception ex) { | ||
Assert.assertEquals("Host name should be provided", ex.getMessage()); | ||
throw ex; | ||
|
@@ -128,21 +128,21 @@ public void testFromMissingMessage() { | |
.withMessage("dummyMessage") | ||
.withHost("abc.com") | ||
.withRecipients("[email protected]").build(); | ||
|
||
} catch (Exception ex) { | ||
Assert.assertEquals("From address should be provided", ex.getMessage()); | ||
throw ex; | ||
} | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testRecipientsMissingMessage() { | ||
try { | ||
MailMessage message = new MailMessage.Builder("mail") | ||
.withMessage("dummyMessage") | ||
.withHost("abc.com") | ||
.withFrom("[email protected]").build(); | ||
|
||
} catch (Exception ex) { | ||
Assert.assertEquals("Comma separated recipients should be provided", ex.getMessage()); | ||
throw ex; | ||
|