/**
* 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 com.seyren.core.service.notification;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.seyren.core.domain.Alert;
import com.seyren.core.domain.Check;
import com.seyren.core.domain.Subscription;
import com.seyren.core.domain.SubscriptionType;
import com.seyren.core.exception.NotificationFailedException;
import com.seyren.core.util.config.SeyrenConfig;
@Named
public class LoggerNotificationService implements NotificationService {
private static final Logger LOGGER = LoggerFactory.getLogger(LoggerNotificationService.class);
private final SeyrenConfig seyrenConfig;
@Inject
public LoggerNotificationService(SeyrenConfig seyrenConfig) {
this.seyrenConfig = seyrenConfig;
}
@Override
public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) throws NotificationFailedException {
LOGGER.info("Seyren notification '{}' changed state to '{}' @ '{}' with {} alert(s)",
check.getName(),
check.getState().name(),
url(check),
alerts.size());
}
@Override
public boolean canHandle(SubscriptionType subscriptionType) {
return subscriptionType == SubscriptionType.LOGGER;
}
String url(Check check) {
return String.format("%s/#/checks/%s", seyrenConfig.getBaseUrl(), check.getId());
}
}