Compare commits
24 Commits
feature/ta
...
74f02e7827
| Author | SHA1 | Date | |
|---|---|---|---|
| 74f02e7827 | |||
| dc07591612 | |||
| 0f9721f562 | |||
| 742d246cdb | |||
| 0ac12deed3 | |||
| 9a4652b8f2 | |||
| edd29ea029 | |||
| 7838e60a82 | |||
| 02a56ee434 | |||
| d60187cc07 | |||
| 6359c59af9 | |||
| c84e935f05 | |||
| f9ad7fddbd | |||
| f011205a22 | |||
| 5920067b02 | |||
| 9e6cba52f6 | |||
| 638dc42a46 | |||
| fd4248d722 | |||
| b71b4db66e | |||
| 9ee1a4de3c | |||
| c42781c5ee | |||
| daf9e9cb06 | |||
| d0be1f0a62 | |||
| e75c496ea8 |
11
Dockerfile
Normal file
11
Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Используем официальный образ OpenJDK 17 как базовый образ
|
||||||
|
FROM openjdk:17-jre-slim
|
||||||
|
|
||||||
|
# Установка рабочей директории внутри контейнера
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Копируем JAR-файл приложения из локальной директории внутрь контейнера
|
||||||
|
COPY target/ServerMonitorBot-0.0.1-SNAPSHOT.jar app.jar
|
||||||
|
|
||||||
|
# Команда для запуска Spring Boot приложения при старте контейнера
|
||||||
|
CMD ["java", "-jar", "app.jar"]
|
||||||
15
Jenkinsfile
vendored
Normal file
15
Jenkinsfile
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
pipeline {
|
||||||
|
agent {
|
||||||
|
docker {
|
||||||
|
image 'maven'
|
||||||
|
args '-v /root/.m2:/root/.m2'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stages {
|
||||||
|
stage('Build') {
|
||||||
|
steps {
|
||||||
|
sh 'mvn -B -DskipTests clean package'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
docker-compose.yml
Normal file
14
docker-compose.yml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:latest
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: servermonitorbot
|
||||||
|
POSTGRES_PASSWORD: servermonitorbot
|
||||||
|
POSTGRES_DB: servermonitorbot
|
||||||
83
pom.xml
83
pom.xml
@@ -15,6 +15,10 @@
|
|||||||
<description>ServerMonitorBot</description>
|
<description>ServerMonitorBot</description>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
|
<flyway.version>9.16.0</flyway.version>
|
||||||
|
<db.url>${db.url}</db.url>
|
||||||
|
<db.user>${db.username}</db.user>
|
||||||
|
<db.password>${db.password}</db.password>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -51,30 +55,85 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.liquibase</groupId>
|
|
||||||
<artifactId>liquibase-core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.postgresql</groupId>
|
<groupId>org.postgresql</groupId>
|
||||||
<artifactId>postgresql</artifactId>
|
<artifactId>postgresql</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.flywaydb</groupId>
|
||||||
|
<artifactId>flyway-core</artifactId>
|
||||||
|
<version>${flyway.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version> <!-- Укажите актуальную версию плагина -->
|
||||||
<configuration>
|
<configuration>
|
||||||
<excludes>
|
<source>${java.version}</source> <!-- Укажите версию исходного кода Java -->
|
||||||
<exclude>
|
<target>${java.version}</target> <!-- Укажите версию целевого байт-кода Java -->
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
</exclude>
|
|
||||||
</excludes>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.flywaydb</groupId>
|
||||||
|
<artifactId>flyway-maven-plugin</artifactId>
|
||||||
|
<version>${flyway.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>migrate</id>
|
||||||
|
<phase>deploy</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>migrate</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<url>${db.url}</url>
|
||||||
|
<user>${db.username}</user>
|
||||||
|
<password>${db.password}</password>
|
||||||
|
<locations>
|
||||||
|
<location>classpath:db/migration</location>
|
||||||
|
</locations>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.spotify</groupId>
|
||||||
|
<artifactId>docker-maven-plugin</artifactId>
|
||||||
|
<version>1.2.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>build-image</id>
|
||||||
|
<phase>install</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>build</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<imageName>ServerMonitorBot</imageName>
|
||||||
|
<serverId>remote-docker</serverId>
|
||||||
|
<dockerDirectory>.</dockerDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<targetPath>/</targetPath>
|
||||||
|
<directory>${project.build.directory}</directory>
|
||||||
|
<include>${project.build.finalName}.jar</include>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>build-image</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>build</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ import ru.ldeloff.servermonitorbot.repository.SshRepository;
|
|||||||
import ru.ldeloff.servermonitorbot.service.command.FirstUseCommand;
|
import ru.ldeloff.servermonitorbot.service.command.FirstUseCommand;
|
||||||
import ru.ldeloff.servermonitorbot.service.command.GetStatusSessions;
|
import ru.ldeloff.servermonitorbot.service.command.GetStatusSessions;
|
||||||
import ru.ldeloff.servermonitorbot.service.command.SwitchToMainMenu;
|
import ru.ldeloff.servermonitorbot.service.command.SwitchToMainMenu;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.command.cputemp.CpuTempAggregateCommand;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.command.cputemp.CpuTempCommand;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.command.hddtemp.HddTempAggregateCommand;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.command.hddtemp.HddTempCommand;
|
||||||
import ru.ldeloff.servermonitorbot.service.command.uname.UnameAggregateCommand;
|
import ru.ldeloff.servermonitorbot.service.command.uname.UnameAggregateCommand;
|
||||||
import ru.ldeloff.servermonitorbot.service.command.uname.UnameCommand;
|
import ru.ldeloff.servermonitorbot.service.command.uname.UnameCommand;
|
||||||
|
|
||||||
@@ -17,7 +21,6 @@ import ru.ldeloff.servermonitorbot.service.command.uname.UnameCommand;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class TelegramBotController extends TelegramLongPollingBot {
|
public class TelegramBotController extends TelegramLongPollingBot {
|
||||||
|
|
||||||
final TelegramBot telegramBot;
|
final TelegramBot telegramBot;
|
||||||
final SshRepository sshRepository;
|
final SshRepository sshRepository;
|
||||||
|
|
||||||
@@ -26,6 +29,10 @@ public class TelegramBotController extends TelegramLongPollingBot {
|
|||||||
final UnameAggregateCommand unameAggregateCommand;
|
final UnameAggregateCommand unameAggregateCommand;
|
||||||
final SwitchToMainMenu switchToMainMenu;
|
final SwitchToMainMenu switchToMainMenu;
|
||||||
final UnameCommand unameCommand;
|
final UnameCommand unameCommand;
|
||||||
|
final CpuTempAggregateCommand cpuTempAggregateCommand;
|
||||||
|
final CpuTempCommand cpuTempCommand;
|
||||||
|
final HddTempAggregateCommand hddTempAggregateCommand;
|
||||||
|
final HddTempCommand hddTempCommand;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdateReceived(Update update) {
|
public void onUpdateReceived(Update update) {
|
||||||
@@ -42,6 +49,12 @@ public class TelegramBotController extends TelegramLongPollingBot {
|
|||||||
case "uname" -> {
|
case "uname" -> {
|
||||||
unameAggregateCommand.execute(update, this);
|
unameAggregateCommand.execute(update, this);
|
||||||
}
|
}
|
||||||
|
case "CPU.temp" -> {
|
||||||
|
cpuTempAggregateCommand.execute(update, this);
|
||||||
|
}
|
||||||
|
case "HDD.temp" -> {
|
||||||
|
hddTempAggregateCommand.execute(update, this);
|
||||||
|
}
|
||||||
default -> {
|
default -> {
|
||||||
switchToMainMenu.execute(update, this);
|
switchToMainMenu.execute(update, this);
|
||||||
}
|
}
|
||||||
@@ -54,6 +67,12 @@ public class TelegramBotController extends TelegramLongPollingBot {
|
|||||||
case "uname" -> {
|
case "uname" -> {
|
||||||
unameCommand.execute(update, this);
|
unameCommand.execute(update, this);
|
||||||
}
|
}
|
||||||
|
case "CPU.temp" -> {
|
||||||
|
cpuTempCommand.execute(update, this);
|
||||||
|
}
|
||||||
|
case "HDD.temp" -> {
|
||||||
|
hddTempCommand.execute(update, this);
|
||||||
|
}
|
||||||
default -> {
|
default -> {
|
||||||
switchToMainMenu.execute(update, this);
|
switchToMainMenu.execute(update, this);
|
||||||
}
|
}
|
||||||
@@ -63,17 +82,14 @@ public class TelegramBotController extends TelegramLongPollingBot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getBotUsername() {
|
public String getBotUsername() {
|
||||||
return telegramBot.getBotUsername();
|
return telegramBot.getBotUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getBotToken() {
|
public String getBotToken() {
|
||||||
return telegramBot.getBotToken();
|
return telegramBot.getBotToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClosing() {
|
public void onClosing() {
|
||||||
super.onClosing();
|
super.onClosing();
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package ru.ldeloff.servermonitorbot.service.command.cputemp;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
||||||
|
import ru.ldeloff.servermonitorbot.model.User;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.command.CommandTemplate;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.role.RoleService;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.user.UserService;
|
||||||
|
import ru.ldeloff.servermonitorbot.utils.ui.uname.ServerListButtons;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CpuTempAggregateCommand extends CommandTemplate {
|
||||||
|
final ServerListButtons serverListButtons;
|
||||||
|
|
||||||
|
public CpuTempAggregateCommand(UserService userService, RoleService roleService, ServerListButtons serverListButtons) {
|
||||||
|
super(userService, roleService);
|
||||||
|
this.serverListButtons = serverListButtons;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SendMessage actionForAuth(User user, SendMessage message) {
|
||||||
|
return serverListButtons.uiForm(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package ru.ldeloff.servermonitorbot.service.command.cputemp;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
||||||
|
import ru.ldeloff.servermonitorbot.model.Command;
|
||||||
|
import ru.ldeloff.servermonitorbot.model.SshServer;
|
||||||
|
import ru.ldeloff.servermonitorbot.model.User;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.command.CommandTemplate;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.role.RoleService;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.ssh.SshService;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.user.UserService;
|
||||||
|
import ru.ldeloff.servermonitorbot.utils.SshServerUtils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class CpuTempCommand extends CommandTemplate {
|
||||||
|
final SshService sshService;
|
||||||
|
public CpuTempCommand(UserService userService, RoleService roleService, SshService sshService) {
|
||||||
|
super(userService, roleService);
|
||||||
|
this.sshService = sshService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SendMessage actionForAuth(User user, SendMessage message) {
|
||||||
|
String [] tags = Arrays.stream(message.getText().split(":"))
|
||||||
|
.map(String::trim)
|
||||||
|
.toArray(String[]::new);
|
||||||
|
|
||||||
|
if (tags[1].equals("all")) {
|
||||||
|
message.setText(hddTempAllHost());
|
||||||
|
} else {
|
||||||
|
message.setText(Objects.requireNonNull(hddTempSpecificHost(tags[1])));
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String hddTempAllHost() {
|
||||||
|
List<SshServer> servers = SshServerUtils.filterGoodServers(sshService.getSshServers());
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
servers.forEach(server -> response.append(hddTempSpecificHost(server.getName())).append("\n"));
|
||||||
|
return response.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String hddTempSpecificHost(String serverName) {
|
||||||
|
Optional<SshServer> server = sshService.getSshServers()
|
||||||
|
.stream()
|
||||||
|
.filter(x -> x.getName().equals(serverName))
|
||||||
|
.findFirst();
|
||||||
|
if (server.isPresent()) {
|
||||||
|
Command result = sshService.execute(new Command("cat /sys/class/thermal/thermal_zone0/temp", 100, server.get()));
|
||||||
|
return server.get().getName() + ": \n" +
|
||||||
|
(Objects.isNull(result.getResponse()) ? "ошибка при выполнении команды" :
|
||||||
|
String.format("%.1f",
|
||||||
|
Double.parseDouble(result.getResponse().replaceAll("\n", ""))/1000))
|
||||||
|
+ "°C";
|
||||||
|
} else {
|
||||||
|
log.error("Ошибка при выполнении команды 'CPUtemp'. Искомый сервер (" + serverName + ") не найден");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package ru.ldeloff.servermonitorbot.service.command.hddtemp;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
||||||
|
import ru.ldeloff.servermonitorbot.model.User;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.command.CommandTemplate;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.role.RoleService;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.user.UserService;
|
||||||
|
import ru.ldeloff.servermonitorbot.utils.ui.uname.ServerListButtons;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class HddTempAggregateCommand extends CommandTemplate {
|
||||||
|
final ServerListButtons serverListButtons;
|
||||||
|
|
||||||
|
public HddTempAggregateCommand(UserService userService, RoleService roleService, ServerListButtons serverListButtons) {
|
||||||
|
super(userService, roleService);
|
||||||
|
this.serverListButtons = serverListButtons;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SendMessage actionForAuth(User user, SendMessage message) {
|
||||||
|
return serverListButtons.uiForm(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package ru.ldeloff.servermonitorbot.service.command.hddtemp;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
||||||
|
import ru.ldeloff.servermonitorbot.model.Command;
|
||||||
|
import ru.ldeloff.servermonitorbot.model.SshServer;
|
||||||
|
import ru.ldeloff.servermonitorbot.model.User;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.command.CommandTemplate;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.role.RoleService;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.ssh.SshService;
|
||||||
|
import ru.ldeloff.servermonitorbot.service.user.UserService;
|
||||||
|
import ru.ldeloff.servermonitorbot.utils.SshServerUtils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class HddTempCommand extends CommandTemplate {
|
||||||
|
final SshService sshService;
|
||||||
|
public HddTempCommand(UserService userService, RoleService roleService, SshService sshService) {
|
||||||
|
super(userService, roleService);
|
||||||
|
this.sshService = sshService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SendMessage actionForAuth(User user, SendMessage message) {
|
||||||
|
String [] tags = Arrays.stream(message.getText().split(":"))
|
||||||
|
.map(String::trim)
|
||||||
|
.toArray(String[]::new);
|
||||||
|
|
||||||
|
if (tags[1].equals("all")) {
|
||||||
|
message.setText(hddTempAllHost());
|
||||||
|
} else {
|
||||||
|
message.setText(Objects.requireNonNull(hddTempSpecificHost(tags[1])));
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String hddTempAllHost() {
|
||||||
|
List<SshServer> servers = SshServerUtils.filterGoodServers(sshService.getSshServers());
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
servers.forEach(server -> response.append(hddTempSpecificHost(server.getName())).append("\n"));
|
||||||
|
return response.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String hddTempSpecificHost(String serverName) {
|
||||||
|
Optional<SshServer> server = sshService.getSshServers()
|
||||||
|
.stream()
|
||||||
|
.filter(x -> x.getName().equals(serverName))
|
||||||
|
.findFirst();
|
||||||
|
if (server.isPresent()) {
|
||||||
|
Command result = sshService.execute(new Command("hddtemp /dev/sd*", 500, server.get()));
|
||||||
|
return server.get().getName() + ": \n" +
|
||||||
|
(Objects.isNull(result.getResponse()) ? "ошибка при выполнении команды" : result.getResponse());
|
||||||
|
} else {
|
||||||
|
log.error("Ошибка при выполнении команды 'hddtemp'. Искомый сервер (" + serverName + ") не найден");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,19 +6,19 @@ import ru.ldeloff.servermonitorbot.model.User;
|
|||||||
import ru.ldeloff.servermonitorbot.service.command.CommandTemplate;
|
import ru.ldeloff.servermonitorbot.service.command.CommandTemplate;
|
||||||
import ru.ldeloff.servermonitorbot.service.role.RoleService;
|
import ru.ldeloff.servermonitorbot.service.role.RoleService;
|
||||||
import ru.ldeloff.servermonitorbot.service.user.UserService;
|
import ru.ldeloff.servermonitorbot.service.user.UserService;
|
||||||
import ru.ldeloff.servermonitorbot.utils.ui.uname.UnameChatButtonAggregate;
|
import ru.ldeloff.servermonitorbot.utils.ui.uname.ServerListButtons;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UnameAggregateCommand extends CommandTemplate {
|
public class UnameAggregateCommand extends CommandTemplate {
|
||||||
final UnameChatButtonAggregate unameChatButtonAggregate;
|
final ServerListButtons serverListButtons;
|
||||||
|
|
||||||
public UnameAggregateCommand(UserService userService, RoleService roleService, UnameChatButtonAggregate unameChatButtonAggregate) {
|
public UnameAggregateCommand(UserService userService, RoleService roleService, ServerListButtons serverListButtons) {
|
||||||
super(userService, roleService);
|
super(userService, roleService);
|
||||||
this.unameChatButtonAggregate = unameChatButtonAggregate;
|
this.serverListButtons = serverListButtons;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SendMessage actionForAuth(User user, SendMessage message) {
|
public SendMessage actionForAuth(User user, SendMessage message) {
|
||||||
return unameChatButtonAggregate.uiForm(message);
|
return serverListButtons.uiForm(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ import java.util.ArrayList;
|
|||||||
public class TelegramBotKeyboard implements UiFormer {
|
public class TelegramBotKeyboard implements UiFormer {
|
||||||
private final String STATUS = "Статус";
|
private final String STATUS = "Статус";
|
||||||
private final String UNAME = "uname";
|
private final String UNAME = "uname";
|
||||||
|
private final String CPU_TEMP = "CPU.temp";
|
||||||
|
private final String HDD_TEMP = "HDD.temp";
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SendMessage uiForm(SendMessage message) {
|
public SendMessage uiForm(SendMessage message) {
|
||||||
@@ -27,6 +30,8 @@ public class TelegramBotKeyboard implements UiFormer {
|
|||||||
|
|
||||||
keyboardRow.add(new KeyboardButton(STATUS));
|
keyboardRow.add(new KeyboardButton(STATUS));
|
||||||
keyboardRow.add(new KeyboardButton(UNAME));
|
keyboardRow.add(new KeyboardButton(UNAME));
|
||||||
|
keyboardRow.add(new KeyboardButton(CPU_TEMP));
|
||||||
|
keyboardRow.add(new KeyboardButton(HDD_TEMP));
|
||||||
|
|
||||||
replyKeyboardMarkup.setKeyboard(keyboardRows);
|
replyKeyboardMarkup.setKeyboard(keyboardRows);
|
||||||
message.setReplyMarkup(replyKeyboardMarkup);
|
message.setReplyMarkup(replyKeyboardMarkup);
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package ru.ldeloff.servermonitorbot.utils.ui.uname;
|
package ru.ldeloff.servermonitorbot.utils.ui.uname;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
||||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
|
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
|
||||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
|
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
|
||||||
import ru.ldeloff.servermonitorbot.repository.SshRepository;
|
|
||||||
import ru.ldeloff.servermonitorbot.service.ssh.SshService;
|
import ru.ldeloff.servermonitorbot.service.ssh.SshService;
|
||||||
import ru.ldeloff.servermonitorbot.utils.ui.UiFormer;
|
import ru.ldeloff.servermonitorbot.utils.ui.UiFormer;
|
||||||
|
|
||||||
@@ -16,7 +14,7 @@ import java.util.Objects;
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class UnameChatButtonAggregate implements UiFormer {
|
public class ServerListButtons implements UiFormer {
|
||||||
|
|
||||||
private final SshService sshService;
|
private final SshService sshService;
|
||||||
|
|
||||||
@@ -32,7 +30,7 @@ public class UnameChatButtonAggregate implements UiFormer {
|
|||||||
List<InlineKeyboardButton> keyboardRow = new ArrayList<>();
|
List<InlineKeyboardButton> keyboardRow = new ArrayList<>();
|
||||||
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
|
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
|
||||||
inlineKeyboardButton.setText(sshServer.getName());
|
inlineKeyboardButton.setText(sshServer.getName());
|
||||||
inlineKeyboardButton.setCallbackData("uname: " + sshServer.getName());
|
inlineKeyboardButton.setCallbackData(message.getText() + ": " + sshServer.getName());
|
||||||
keyboardRow.add(inlineKeyboardButton);
|
keyboardRow.add(inlineKeyboardButton);
|
||||||
keyboard.add(keyboardRow);
|
keyboard.add(keyboardRow);
|
||||||
}
|
}
|
||||||
@@ -43,14 +41,14 @@ public class UnameChatButtonAggregate implements UiFormer {
|
|||||||
List<InlineKeyboardButton> keyboardRow = new ArrayList<>();
|
List<InlineKeyboardButton> keyboardRow = new ArrayList<>();
|
||||||
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
|
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
|
||||||
inlineKeyboardButton.setText("Все сервера");
|
inlineKeyboardButton.setText("Все сервера");
|
||||||
inlineKeyboardButton.setCallbackData("uname: all");
|
inlineKeyboardButton.setCallbackData(message.getText() + ": all");
|
||||||
keyboardRow.add(inlineKeyboardButton);
|
keyboardRow.add(inlineKeyboardButton);
|
||||||
keyboard.add(keyboardRow);
|
keyboard.add(keyboardRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
inlineKeyboardMarkup.setKeyboard(keyboard);
|
inlineKeyboardMarkup.setKeyboard(keyboard);
|
||||||
message.setReplyMarkup(inlineKeyboardMarkup);
|
message.setReplyMarkup(inlineKeyboardMarkup);
|
||||||
message.setText("Выполнить uname для");
|
message.setText("Выполнить " + message.getText() + " для");
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
@@ -2,20 +2,14 @@ spring:
|
|||||||
application:
|
application:
|
||||||
name: ServerMonitorBot
|
name: ServerMonitorBot
|
||||||
datasource:
|
datasource:
|
||||||
url: jdbc:postgresql://localhost:5432/servermonitorbot
|
url: @db.url@
|
||||||
username: servermonitorbot
|
username: @db.username@
|
||||||
password: servermonitorbot
|
password: @db.password@
|
||||||
jpa:
|
jpa:
|
||||||
hibernate:
|
hibernate:
|
||||||
ddl-auto: none
|
ddl-auto: none
|
||||||
liquibase:
|
flyway:
|
||||||
enabled: true
|
locations: classpath:db/migration
|
||||||
change-log: classpath:db/scripts/changelog-master.xml
|
|
||||||
url: jdbc:postgresql://localhost:5432/servermonitorbot
|
|
||||||
user: servermonitorbot
|
|
||||||
password: servermonitorbot
|
|
||||||
liquibase-schema: "liquibase"
|
|
||||||
default-schema: "servermonitorbot"
|
|
||||||
bot:
|
bot:
|
||||||
name: "ServerMonitorBot"
|
name: "ServerMonitorBot"
|
||||||
token: "token"
|
token: "token"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
--changeset L_DelOff:create_table_users rollbackSplitStatements:true
|
--changeset L_DelOff:create_table_users rollbackSplitStatements:true
|
||||||
--comment: Создание таблицы пользователей
|
--comment: Создание таблицы пользователей
|
||||||
|
CREATE SCHEMA servermonitorbot;
|
||||||
CREATE TABLE users
|
CREATE TABLE users
|
||||||
(
|
(
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<databaseChangeLog
|
|
||||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
|
||||||
|
|
||||||
<include file="release_0_0_1/changelog.xml" relativeToChangelogFile="true"/>
|
|
||||||
|
|
||||||
|
|
||||||
</databaseChangeLog>
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<databaseChangeLog
|
|
||||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
|
||||||
|
|
||||||
<include file="scripts/01_create_table_users.sql" relativeToChangelogFile="true"/>
|
|
||||||
<include file="scripts/02_create_table_roles.sql" relativeToChangelogFile="true"/>
|
|
||||||
<include file="scripts/03_add_FK_users_to_roles.sql" relativeToChangelogFile="true"/>
|
|
||||||
<include file="scripts/04_add_roles.sql" relativeToChangelogFile="true"/>
|
|
||||||
<include file="scripts/05_add_anonymous_role.sql" relativeToChangelogFile="true"/>
|
|
||||||
<include file="scripts/06_refactor_users_table.sql" relativeToChangelogFile="true"/>
|
|
||||||
<include file="scripts/07_refactor_roles_table.sql" relativeToChangelogFile="true"/>
|
|
||||||
<include file="scripts/08_add_roles.sql" relativeToChangelogFile="true"/>
|
|
||||||
|
|
||||||
</databaseChangeLog>
|
|
||||||
Reference in New Issue
Block a user