Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/slack thread error #48

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME

CURRENT_PID=$(pgrep -f $APP_NAME)

if [ -z $CURRENT_PID ] #2
if [ -z $CURRENT_PID ]
then
echo "> ν˜„μž¬ ꡬ동쀑인 μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ΄ μ—†μœΌλ―€λ‘œ μ’…λ£Œν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."
else
Expand All @@ -16,5 +16,5 @@ else
sleep 5
fi

echo "> $JAR_PATH 배포" #3
nohup java -jar -Dspring.profiles.active=prod $JAR_PATH >> $REPOSITORY/log/deploy.log 2 > $REPOSITORY/log/deploy_err.log &
echo "> $JAR_PATH 배포"
nohup java -jar -Dspring.profiles.active=prod $JAR_PATH >> $REPOSITORY/log/deploy.log 2>> $REPOSITORY/log/deploy_err.log &
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.ku.covigator.dto.response.ErrorResponse;
import com.ku.covigator.exception.CovigatorException;
import com.ku.covigator.support.SlackAlarmGenerator;
import com.ku.covigator.support.slack.SlackAlarmGenerator;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

public interface ChatRepository extends MongoRepository<Chat, Long> {

public List<Chat> findChatByCourseIdOrderByTimestampAsc(Long courseId);
List<Chat> findChatByCourseIdOrderByTimestampAsc(Long courseId);
}
24 changes: 24 additions & 0 deletions src/main/java/com/ku/covigator/support/slack/RequestInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.ku.covigator.support.slack;

import jakarta.servlet.http.HttpServletRequest;
import lombok.Builder;
import lombok.Getter;

@Builder
@Getter
public class RequestInfo {

private String header;
private String remoteAddr;
private String method;
private String requestURL;

public static RequestInfo from(HttpServletRequest request) {
return RequestInfo.builder()
.header(request.getHeader("X-FORWARDED-FOR"))
.remoteAddr(request.getRemoteAddr())
.method(request.getMethod())
.requestURL(request.getRequestURI())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ku.covigator.support;
package com.ku.covigator.support.slack;

import com.ku.covigator.config.properties.SlackProperties;
import com.slack.api.Slack;
Expand Down Expand Up @@ -29,21 +29,24 @@ public class SlackAlarmGenerator {

@Async
public void sendSlackAlertErrorLog(Exception e, HttpServletRequest request) {

RequestInfo requestInfo = RequestInfo.from(request);

try {
slack.send(slackProperties.getUrl(), payload(p -> p
.text("[μ„œλ²„ μ—λŸ¬ λ°œμƒ]")
.attachments(
List.of(generateSlackAttachment(e, request))
List.of(generateSlackAttachment(e, requestInfo))
)
));
} catch (IOException slackError) {
log.error("Slack 톡신 μ˜ˆμ™Έ λ°œμƒ");
}
}

private Attachment generateSlackAttachment(Exception e, HttpServletRequest request) {
private Attachment generateSlackAttachment(Exception e, RequestInfo request) {
String requestTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS").format(LocalDateTime.now());
String xffHeader = request.getHeader("X-FORWARDED-FOR");
String xffHeader = request.getHeader();
return Attachment.builder()
.color("ff0000")
.title(requestTime + " λ°œμƒ μ—λŸ¬ 둜그")
Expand Down
Loading