Skip to content

Commit 91e3767

Browse files
authored
TECH-236: Add controller for notification from alertmanager (#1)
* Add controller for notification from alertmanager * Fix controller for notification from alertmanager and service logic * Fix bot properties * Fix application.yml * Add github actions * Add new-line-at-end-of-file
1 parent 83c10dd commit 91e3767

File tree

16 files changed

+700
-0
lines changed

16 files changed

+700
-0
lines changed

.github/settings.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# These settings are synced to GitHub by https://probot.github.io/apps/settings/
2+
_extends: .github
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Vality basic linters
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "*"
7+
8+
jobs:
9+
lint:
10+
uses: valitydev/base-workflows/.github/workflows/basic-linters.yml@v1

.github/workflows/build.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Build Maven Artifact
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- '*'
7+
8+
jobs:
9+
build:
10+
uses: valitydev/java-workflow/.github/workflows/maven-service-build.yml@v3

.github/workflows/deploy.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Maven Deploy Artifact
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
8+
jobs:
9+
build-and-deploy:
10+
uses: valitydev/java-workflow/.github/workflows/maven-service-deploy.yml@v3
11+
secrets:
12+
github-token: ${{ secrets.GITHUB_TOKEN }}
13+
mm-webhook-url: ${{ secrets.MATTERMOST_WEBHOOK_URL }}

.github/workflows/settings.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# These settings are synced to GitHub by https://probot.github.io/apps/settings/
2+
_extends: .github

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
.env
15+
16+
### Eclipse ###
17+
.apt_generated
18+
.classpath
19+
.factorypath
20+
.project
21+
.settings
22+
.springBeans
23+
.sts4-cache
24+
25+
### NetBeans ###
26+
/nbproject/private/
27+
/nbbuild/
28+
/dist/
29+
/nbdist/
30+
/.nb-gradle/
31+
build/
32+
!**/src/main/**/build/
33+
!**/src/test/**/build/
34+
35+
### VS Code ###
36+
.vscode/
37+
38+
### Mac OS ###
39+
.DS_Store

pom.xml

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>dev.vality</groupId>
9+
<artifactId>service-parent-pom</artifactId>
10+
<version>3.0.9</version>
11+
</parent>
12+
13+
<artifactId>alerting-tg-bot</artifactId>
14+
<version>1.0.0</version>
15+
16+
<properties>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
19+
<java.version>21</java.version>
20+
<maven.compiler.source>${java.version}</maven.compiler.source>
21+
<maven.compiler.target>${java.version}</maven.compiler.target>
22+
<server.port>8022</server.port>
23+
<management.port>8023</management.port>
24+
<exposed.ports>${server.port} ${management.port}</exposed.ports>
25+
<testcontainers.annotations.version>2.0.4</testcontainers.annotations.version>
26+
</properties>
27+
28+
<dependencyManagement>
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.springframework.cloud</groupId>
32+
<artifactId>spring-cloud-dependencies</artifactId>
33+
<version>2024.0.0</version>
34+
<type>pom</type>
35+
<scope>import</scope>
36+
</dependency>
37+
</dependencies>
38+
</dependencyManagement>
39+
40+
<dependencies>
41+
<!--spring-->
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter</artifactId>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-starter-web</artifactId>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-starter-validation</artifactId>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.springframework.boot</groupId>
56+
<artifactId>spring-boot-starter-actuator</artifactId>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-configuration-processor</artifactId>
61+
<optional>true</optional>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.springframework.boot</groupId>
65+
<artifactId>spring-boot-starter-jooq</artifactId>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.springframework.boot</groupId>
69+
<artifactId>spring-boot-starter-cache</artifactId>
70+
</dependency>
71+
<dependency>
72+
<groupId>com.github.ben-manes.caffeine</groupId>
73+
<artifactId>caffeine</artifactId>
74+
</dependency>
75+
76+
<!--third party-->
77+
<dependency>
78+
<groupId>org.telegram</groupId>
79+
<artifactId>telegrambots-spring-boot-starter</artifactId>
80+
<version>6.9.7.1</version>
81+
</dependency>
82+
<dependency>
83+
<groupId>javax.ws.rs</groupId>
84+
<artifactId>javax.ws.rs-api</artifactId>
85+
<version>2.1.1</version>
86+
</dependency>
87+
<dependency>
88+
<groupId>javax.xml.bind</groupId>
89+
<artifactId>jaxb-api</artifactId>
90+
<version>2.3.1</version>
91+
</dependency>
92+
<dependency>
93+
<groupId>org.projectlombok</groupId>
94+
<artifactId>lombok</artifactId>
95+
<scope>provided</scope>
96+
</dependency>
97+
<dependency>
98+
<groupId>io.micrometer</groupId>
99+
<artifactId>micrometer-core</artifactId>
100+
</dependency>
101+
<dependency>
102+
<groupId>io.micrometer</groupId>
103+
<artifactId>micrometer-registry-prometheus</artifactId>
104+
</dependency>
105+
106+
<!--test-->
107+
<dependency>
108+
<groupId>org.springframework.boot</groupId>
109+
<artifactId>spring-boot-starter-test</artifactId>
110+
<scope>test</scope>
111+
</dependency>
112+
</dependencies>
113+
114+
<build>
115+
<resources>
116+
<resource>
117+
<directory>${project.build.directory}/maven-shared-archive-resources</directory>
118+
<targetPath>${project.build.directory}</targetPath>
119+
<includes>
120+
<include>Dockerfile</include>
121+
</includes>
122+
<filtering>true</filtering>
123+
</resource>
124+
<resource>
125+
<directory>${project.build.directory}/maven-shared-archive-resources</directory>
126+
<filtering>true</filtering>
127+
<excludes>
128+
<exclude>Dockerfile</exclude>
129+
</excludes>
130+
</resource>
131+
<resource>
132+
<directory>src/main/resources</directory>
133+
<filtering>true</filtering>
134+
</resource>
135+
</resources>
136+
<plugins>
137+
<plugin>
138+
<groupId>org.springframework.boot</groupId>
139+
<artifactId>spring-boot-maven-plugin</artifactId>
140+
</plugin>
141+
<plugin>
142+
<groupId>org.apache.maven.plugins</groupId>
143+
<artifactId>maven-remote-resources-plugin</artifactId>
144+
<version>3.2.0</version>
145+
<dependencies>
146+
<dependency>
147+
<groupId>org.apache.maven.shared</groupId>
148+
<artifactId>maven-filtering</artifactId>
149+
<version>3.4.0</version>
150+
</dependency>
151+
</dependencies>
152+
<configuration>
153+
<resourceBundles>
154+
<resourceBundle>dev.vality:shared-resources:${shared-resources.version}</resourceBundle>
155+
</resourceBundles>
156+
<attachToMain>false</attachToMain>
157+
<attachToTest>false</attachToTest>
158+
</configuration>
159+
<executions>
160+
<execution>
161+
<goals>
162+
<goal>process</goal>
163+
</goals>
164+
</execution>
165+
</executions>
166+
</plugin>
167+
</plugins>
168+
</build>
169+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package dev.vality.alerting.tg.bot;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
6+
import org.springframework.boot.web.servlet.ServletComponentScan;
7+
import org.springframework.scheduling.annotation.EnableScheduling;
8+
9+
@EnableScheduling
10+
@ServletComponentScan
11+
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
12+
public class TgBotApplication extends SpringApplication {
13+
14+
public static void main(String[] args) {
15+
SpringApplication.run(TgBotApplication.class, args);
16+
}
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dev.vality.alerting.tg.bot.config;
2+
3+
import dev.vality.alerting.tg.bot.service.AlertBot;
4+
import lombok.RequiredArgsConstructor;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
import org.telegram.telegrambots.meta.TelegramBotsApi;
8+
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
9+
10+
@Configuration
11+
@RequiredArgsConstructor
12+
public class AlertBotConfig {
13+
14+
private final AlertBot alertBot;
15+
16+
@Bean
17+
public TelegramBotsApi telegramBotsApi() throws Exception {
18+
TelegramBotsApi api = new TelegramBotsApi(DefaultBotSession.class);
19+
api.registerBot(alertBot);
20+
return api;
21+
}
22+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package dev.vality.alerting.tg.bot.config.properties;
2+
3+
import lombok.Data;
4+
import org.springframework.boot.context.properties.ConfigurationProperties;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
import jakarta.validation.constraints.NotNull;
8+
9+
@Data
10+
@Configuration
11+
@ConfigurationProperties(prefix = "bot")
12+
public class AlertBotProperties {
13+
14+
@NotNull
15+
private String token;
16+
@NotNull
17+
private String name;
18+
@NotNull
19+
private Long chatId;
20+
21+
@NotNull
22+
private Topics topics;
23+
24+
@Data
25+
public static class Topics {
26+
@NotNull
27+
private Integer commands;
28+
@NotNull
29+
private Integer errors5xx;
30+
@NotNull
31+
private Integer altpayConversion;
32+
@NotNull
33+
private Integer failedMachines;
34+
@NotNull
35+
private Integer pendingPayments;
36+
}
37+
}

0 commit comments

Comments
 (0)