diff --git a/src/main/java/ru/ldeloff/servermonitorbot/controller/TelegramBotController.java b/src/main/java/ru/ldeloff/servermonitorbot/controller/TelegramBotController.java index 4ec8c43..a9147f3 100644 --- a/src/main/java/ru/ldeloff/servermonitorbot/controller/TelegramBotController.java +++ b/src/main/java/ru/ldeloff/servermonitorbot/controller/TelegramBotController.java @@ -10,8 +10,6 @@ import ru.ldeloff.servermonitorbot.repository.SshRepository; import ru.ldeloff.servermonitorbot.service.command.FirstUseCommand; import ru.ldeloff.servermonitorbot.service.command.GetStatusSessions; 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; @@ -29,8 +27,6 @@ public class TelegramBotController extends TelegramLongPollingBot { final UnameAggregateCommand unameAggregateCommand; final SwitchToMainMenu switchToMainMenu; final UnameCommand unameCommand; - final CpuTempAggregateCommand cpuTempAggregateCommand; - final CpuTempCommand cpuTempCommand; final HddTempAggregateCommand hddTempAggregateCommand; final HddTempCommand hddTempCommand; @@ -49,9 +45,6 @@ public class TelegramBotController extends TelegramLongPollingBot { case "uname" -> { unameAggregateCommand.execute(update, this); } - case "CPU.temp" -> { - cpuTempAggregateCommand.execute(update, this); - } case "HDD.temp" -> { hddTempAggregateCommand.execute(update, this); } @@ -67,9 +60,6 @@ public class TelegramBotController extends TelegramLongPollingBot { case "uname" -> { unameCommand.execute(update, this); } - case "CPU.temp" -> { - cpuTempCommand.execute(update, this); - } case "HDD.temp" -> { hddTempCommand.execute(update, this); } diff --git a/src/main/java/ru/ldeloff/servermonitorbot/service/command/cputemp/CpuTempAggregateCommand.java b/src/main/java/ru/ldeloff/servermonitorbot/service/command/cputemp/CpuTempAggregateCommand.java deleted file mode 100644 index 90d2eb2..0000000 --- a/src/main/java/ru/ldeloff/servermonitorbot/service/command/cputemp/CpuTempAggregateCommand.java +++ /dev/null @@ -1,24 +0,0 @@ -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); - } -} diff --git a/src/main/java/ru/ldeloff/servermonitorbot/service/command/cputemp/CpuTempCommand.java b/src/main/java/ru/ldeloff/servermonitorbot/service/command/cputemp/CpuTempCommand.java deleted file mode 100644 index fb046c1..0000000 --- a/src/main/java/ru/ldeloff/servermonitorbot/service/command/cputemp/CpuTempCommand.java +++ /dev/null @@ -1,67 +0,0 @@ -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 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 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; - } - } -} diff --git a/src/main/java/ru/ldeloff/servermonitorbot/utils/ui/TelegramBotKeyboard.java b/src/main/java/ru/ldeloff/servermonitorbot/utils/ui/TelegramBotKeyboard.java index a7f776c..817c456 100644 --- a/src/main/java/ru/ldeloff/servermonitorbot/utils/ui/TelegramBotKeyboard.java +++ b/src/main/java/ru/ldeloff/servermonitorbot/utils/ui/TelegramBotKeyboard.java @@ -13,10 +13,8 @@ import java.util.ArrayList; public class TelegramBotKeyboard implements UiFormer { private final String STATUS = "Статус"; private final String UNAME = "uname"; - private final String CPU_TEMP = "CPU.temp"; private final String HDD_TEMP = "HDD.temp"; - @Override public SendMessage uiForm(SendMessage message) { ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup(); @@ -30,7 +28,6 @@ public class TelegramBotKeyboard implements UiFormer { keyboardRow.add(new KeyboardButton(STATUS)); keyboardRow.add(new KeyboardButton(UNAME)); - keyboardRow.add(new KeyboardButton(CPU_TEMP)); keyboardRow.add(new KeyboardButton(HDD_TEMP)); replyKeyboardMarkup.setKeyboard(keyboardRows);