1 Commits

Author SHA1 Message Date
6545e01f9b Merge pull request 'feature/task-11-mdadm_status' (#35) from feature/task-11-mdadm_status into master
All checks were successful
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good
Reviewed-on: #35
2023-11-22 20:10:07 +03:00
2 changed files with 18 additions and 34 deletions

View File

@@ -15,7 +15,6 @@ import ru.ldeloff.servermonitorbot.utils.SshServerUtils;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@Service
@Slf4j
@@ -56,7 +55,7 @@ public class MdadmStatusCommand extends CommandTemplate {
.findFirst();
if (server.isPresent()) {
// узнаю скок рейдов
Command commandRaid = sshService.execute(new Command("mdadm --detail --scan", 500, server.get()));
Command commandRaid = sshService.execute(new Command("mdadm --monitor", 500, server.get()));
List<String> raidNames = parseRaidNames(commandRaid);
// Для каждого рейда надо выяснить статус
StringBuilder result = new StringBuilder();
@@ -73,8 +72,9 @@ public class MdadmStatusCommand extends CommandTemplate {
}
}
private List<String> parseRaidNames(Command result) {
String raidInfo = result.getResponse();
List<String> names = new ArrayList<>();
Arrays.stream(result.getResponse().split("\n"))
Arrays.stream(raidInfo.split("\n"))
.map(line -> line.split(" "))
.filter(lineArray -> lineArray.length >= 2)
.map(lineArray -> lineArray[1])
@@ -83,31 +83,18 @@ public class MdadmStatusCommand extends CommandTemplate {
}
private List<String> parseHddState(Command result) {
String raidInfo = result.getResponse();
List<String> names = new ArrayList<>();
names.add("Number Name State");
String[] lines = result.getResponse().split("\n");
Pattern pattern = Pattern.compile("^\\s*(\\d+)\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\w+\\s+(.+)$");
Matcher matcher = pattern.matcher(raidInfo);
boolean foundHeader = false;
for (String line : lines) {
if (!foundHeader) {
if ( line.contains("Number") &&
line.contains("Major") &&
line.contains("Minor") &&
line.contains("RaidDevice") ) {
foundHeader = true;
}
} else {
List<String> elements = Arrays.stream(line.split(" "))
.filter(x -> !Objects.equals(x, "")).toList();
names.add(elements.get(0) + ", "
+ elements.get(6) + ", "
+ elements.get(4) + " "
+ elements.get(5));
}
while (matcher.find()) {
String number = matcher.group(1);
String state = matcher.group(2);
names.add("Number: " + number + ", State: " + state);
}
return names;
}
}

View File

@@ -26,17 +26,14 @@ public class TelegramBotKeyboard implements UiFormer {
ArrayList<KeyboardRow> keyboardRows = new ArrayList<>();
KeyboardRow keyboardRow1 = new KeyboardRow();
keyboardRows.add(keyboardRow1);
KeyboardRow keyboardRow = new KeyboardRow();
keyboardRows.add(keyboardRow);
keyboardRow1.add(new KeyboardButton(STATUS));
keyboardRow1.add(new KeyboardButton(UNAME));
keyboardRow1.add(new KeyboardButton(CPU_TEMP));
keyboardRow1.add(new KeyboardButton(HDD_TEMP));
KeyboardRow keyboardRow2 = new KeyboardRow();
keyboardRows.add(keyboardRow2);
keyboardRow2.add(new KeyboardButton(MDADM));
keyboardRow.add(new KeyboardButton(STATUS));
keyboardRow.add(new KeyboardButton(UNAME));
keyboardRow.add(new KeyboardButton(CPU_TEMP));
keyboardRow.add(new KeyboardButton(HDD_TEMP));
keyboardRow.add(new KeyboardButton(MDADM));
replyKeyboardMarkup.setKeyboard(keyboardRows);
message.setReplyMarkup(replyKeyboardMarkup);