Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add list configuration field We need a field to move email receivers into the email callback model. * Add missing prop to DropdownField * Add support to get list in `Configuration` * Move email receivers to `EmailAlarmCallback` - Make user/email receivers part of the `EmailAlarmCallback` model - Add configuration fields to the callback, ensuring we do not offer user auto-completion if the user does not have permissions to list users - Move logic to resolve email addresses to its own class * Clean up alert receivers Clean up frontend code related to alert receivers. * Add Builder to AlarmCallbackConfigurationAVImpl This allows us to modify the object instead of creating new ones. * More clean up of alert receivers This time remove some unused backend code, and adapt previous API to add/remove receivers to use an `EmailAlarmCallback` if available. * Convert EmailAlarmCallback migration into a Migration We need to do this to ensure it runs before the upcoming alert receivers migration. I also changed the event that gets stored in the cluster config, as that was still not release and there's no harm running the migration again in our development machines. * Move existing alert receivers to EmailAlarmCallback The migration will move all alert receivers from the streams having at least a condition and an EmailAlarmCallback. * Fix condition to run EmailAlarmCallback migrations Also modified some tests to ensure this works as expected.
- Loading branch information
Showing
45 changed files
with
1,160 additions
and
479 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
39 changes: 0 additions & 39 deletions
39
...2-server/src/main/java/org/graylog2/alarmcallbacks/events/EmailAlarmCallbackMigrated.java
This file was deleted.
Oops, something went wrong.
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
81 changes: 81 additions & 0 deletions
81
graylog2-server/src/main/java/org/graylog2/alerts/EmailRecipients.java
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,81 @@ | |||
/** | |||
* This file is part of Graylog. | |||
* | |||
* Graylog is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Graylog is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.graylog2.alerts; | |||
|
|||
import com.google.common.base.Splitter; | |||
import com.google.common.collect.ImmutableSet; | |||
import com.google.inject.Inject; | |||
import com.google.inject.assistedinject.Assisted; | |||
import org.graylog2.plugin.database.users.User; | |||
import org.graylog2.shared.users.UserService; | |||
|
|||
import java.util.List; | |||
import java.util.Set; | |||
|
|||
import static com.google.common.base.Strings.isNullOrEmpty; | |||
|
|||
public class EmailRecipients { | |||
private final UserService userService; | |||
|
|||
private final List<String> usernames; | |||
private final List<String> emails; | |||
|
|||
private Set<String> resolvedEmails; | |||
|
|||
public interface Factory { | |||
EmailRecipients create( | |||
@Assisted("usernames") List<String> usernames, | |||
@Assisted("emails") List<String> emails); | |||
} | |||
|
|||
@Inject | |||
public EmailRecipients(UserService userService, | |||
@Assisted("usernames") List<String> usernames, | |||
@Assisted("emails") List<String> emails) { | |||
this.userService = userService; | |||
this.usernames = usernames; | |||
this.emails = emails; | |||
} | |||
|
|||
public Set<String> getEmailRecipients() { | |||
if (resolvedEmails != null) { | |||
return resolvedEmails; | |||
} | |||
|
|||
final ImmutableSet.Builder<String> emails = ImmutableSet.builder(); | |||
emails.addAll(this.emails); | |||
|
|||
for (String username : usernames) { | |||
final User user = userService.load(username); | |||
|
|||
if (user != null && !isNullOrEmpty(user.getEmail())) { | |||
// LDAP users might have multiple email addresses defined. | |||
// See: https://github.com/Graylog2/graylog2-server/issues/1439 | |||
final Iterable<String> addresses = Splitter.on(",").omitEmptyStrings().trimResults().split(user.getEmail()); | |||
emails.addAll(addresses); | |||
} | |||
} | |||
|
|||
resolvedEmails = emails.build(); | |||
|
|||
return resolvedEmails; | |||
} | |||
|
|||
public boolean isEmpty() { | |||
return usernames.isEmpty() && emails.isEmpty(); | |||
} | |||
} |
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
Oops, something went wrong.